Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
xml-validation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vaclab
xml-validation
Commits
532c7f1d
Commit
532c7f1d
authored
6 years ago
by
wactbprot
Browse files
Options
Downloads
Patches
Plain Diff
rdm
parent
91abd2e0
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+34
-4
34 additions, 4 deletions
README.md
server.py
+19
-6
19 additions, 6 deletions
server.py
utils.py
+14
-5
14 additions, 5 deletions
utils.py
with
67 additions
and
15 deletions
README.md
+
34
−
4
View file @
532c7f1d
...
@@ -36,8 +36,38 @@ xmllint --valid --noout 11044_17_DCC_v1.8.1_Au.xml
...
@@ -36,8 +36,38 @@ xmllint --valid --noout 11044_17_DCC_v1.8.1_Au.xml
> ./server
> ./server
```
```
##
# Example
##
API
'
``
### /is_valid endpoint [POST]
curl -X POST -H "Content-Type: text/xml" -d @11044_17_DCC_v1.8.1_Au.xml http://localhost:5005/is_valid
``
`
\ No newline at end of file
```
> curl -X POST -H "Content-Type: text/xml" -d @valid_xml_matches_xsd http://localhost:5005/is_valid
> <ok/>
```
```
> curl -X POST -H "Content-Type: text/xml" -d @no_valid_xml http://localhost:5005/is_valid
> <error>unvalid xml data</error>
```
```
> curl -X POST -H "Content-Type: text/xml" -d @valid_xml_but_dont_matches_xsd http://localhost:5005/is_valid
> <error>not valid</error>
```
Example:
```
> curl -X POST -H "Content-Type: text/xml" -d @11044_17_DCC_v1.8.1_Au.xml http://localhost:5005/is_valid
> <ok/>
```
### /version [GET]
Returns the version of the validation server:
```
> curl http://localhost:5005/version
> <version>0.2.0</version>
```
This diff is collapsed.
Click to expand it.
server.py
+
19
−
6
View file @
532c7f1d
from
flask
import
Flask
,
request
,
Response
from
flask
import
Flask
,
request
from
flask_cors
import
CORS
from
flask_cors
import
CORS
import
utils
as
utils
import
utils
as
utils
...
@@ -14,7 +14,19 @@ CORS(app)
...
@@ -14,7 +14,19 @@ CORS(app)
@app.route
(
'
/version
'
,
methods
=
[
'
get
'
])
@app.route
(
'
/version
'
,
methods
=
[
'
get
'
])
def
version
():
def
version
():
app
.
logger
.
debug
(
'
hit version
'
)
app
.
logger
.
debug
(
'
hit version
'
)
return
Response
(
git_cmd
.
describe
(),
content_type
=
'
text/xml; charset=utf-8
'
)
ret
=
'
<version>{version}</version>
'
.
format
(
version
=
git_cmd
.
describe
())
return
utils
.
xml_response
(
ret
)
@app.route
(
'
/update
'
,
methods
=
[
'
post
'
])
def
update
():
app
.
logger
.
debug
(
'
hit update
'
)
req
=
request
.
get_json
()
git_cmd
.
pull
()
app
.
logger
.
info
(
"
pulled {log}
"
.
format
(
log
=
g
.
log
(
"
-n 1
"
)))
ret
=
'
<ok/>
'
return
utils
.
xml_response
(
ret
)
@app.route
(
'
/update_xsd
'
,
methods
=
[
'
post
'
])
@app.route
(
'
/update_xsd
'
,
methods
=
[
'
post
'
])
def
update_xsd
():
def
update_xsd
():
...
@@ -24,7 +36,7 @@ def update_xsd():
...
@@ -24,7 +36,7 @@ def update_xsd():
if
xsd_xml
:
if
xsd_xml
:
res
=
utils
.
save_xsd
(
config
,
xsd_str
,
xsd_file_name
)
res
=
utils
.
save_xsd
(
config
,
xsd_str
,
xsd_file_name
)
return
Response
(
res
,
content_type
=
'
text/xml; charset=utf-8
'
)
return
utils
.
xml_response
(
ret
)
@app.route
(
'
/is_valid
'
,
methods
=
[
'
post
'
])
@app.route
(
'
/is_valid
'
,
methods
=
[
'
post
'
])
...
@@ -38,11 +50,12 @@ def is_valid():
...
@@ -38,11 +50,12 @@ def is_valid():
if
res
:
if
res
:
ret
=
'
<ok/>
'
ret
=
'
<ok/>
'
else
:
else
:
ret
=
'
<error/>
'
ret
=
'
<error>not valid</error>
'
else
:
ret
=
'
<error>unvalid xml data</error>
'
return
Response
(
ret
,
content_type
=
'
text/xml; charset=utf-8
'
)
return
utils
.
xml_response
(
ret
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
app
.
run
(
host
=
config
[
'
server
'
][
'
host
'
],
port
=
config
[
'
server
'
][
'
port
'
])
app
.
run
(
host
=
config
[
'
server
'
][
'
host
'
],
port
=
config
[
'
server
'
][
'
port
'
])
\ No newline at end of file
This diff is collapsed.
Click to expand it.
utils.py
+
14
−
5
View file @
532c7f1d
import
json
import
json
import
git
import
git
import
requests
import
requests
from
flask
import
Response
from
xml.etree
import
ElementTree
as
ET
from
xml.etree
import
ElementTree
as
ET
import
xmlschema
import
xmlschema
...
@@ -14,18 +15,25 @@ def get_config_dict():
...
@@ -14,18 +15,25 @@ def get_config_dict():
def
git_cmd
(
config
):
def
git_cmd
(
config
):
return
git
.
cmd
.
Git
(
config
[
'
git
'
][
'
dir
'
])
return
git
.
cmd
.
Git
(
config
[
'
git
'
][
'
dir
'
])
def
get_xsd_url
(
config
,
xsd_name
):
return
"
{uri}/{xsd_name}
"
.
format
(
uri
=
config
[
'
xsd
'
][
'
url
'
],
xsd_name
=
xsd_name
)
def
get_xsd_path_file
(
config
,
xsd_name
):
return
"
{dir}/{xsd_name}
"
.
format
(
dir
=
config
[
'
xsd
'
][
'
dir
'
],
xsd_name
=
xsd_name
)
def
get_xsd
(
config
,
xsd_name
,
from_server
=
True
):
def
get_xsd
(
config
,
xsd_name
,
from_server
=
True
):
if
from_server
:
if
from_server
:
url
=
"
{uri}/{xsd_name}
"
.
format
(
uri
=
config
[
'
xsd
'
][
'
url
'
],
xsd_name
=
xsd_name
)
url
=
get_xsd_url
(
config
,
xsd_name
)
xsd_str
=
requests
.
get
(
url
).
text
xsd_str
=
requests
.
get
(
url
).
text
else
:
else
:
path_file
=
"
{dir}/{xsd_name}
"
.
format
(
dir
=
config
[
'
xsd
'
][
'
dir
'
],
xsd_name
=
xsd_name
)
path_file
=
get_xsd_path_file
(
config
,
xsd_name
)
xsd_str
=
open
(
path_file
).
read
()
xsd_str
=
open
(
path_file
).
read
()
return
xsd_str
return
xsd_str
def
save_xsd
(
config
,
xsd_str
,
file_name
):
def
save_xsd
(
config
,
xsd_str
,
xsd_name
):
file
=
open
(
"
{dir}/{file}
"
.
format
(
dir
=
config
[
'
xsd
'
][
'
dir
'
],
file
=
file_name
),
"
w
"
)
path_file
=
get_xsd_path_file
(
config
,
xsd_name
)
file
=
open
(
path_file
,
"
w
"
)
file
.
write
(
xsd_str
)
file
.
write
(
xsd_str
)
return
'
ok
'
return
'
ok
'
...
@@ -46,4 +54,5 @@ def is_valid(xml_str, xsd_str):
...
@@ -46,4 +54,5 @@ def is_valid(xml_str, xsd_str):
else
:
else
:
return
False
return
False
def
xml_response
(
xml_str
):
\ No newline at end of file
return
Response
(
xml_str
,
content_type
=
'
text/xml; charset=utf-8
'
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment