Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
vl-dcc
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
vl-dcc
Commits
06075866
Commit
06075866
authored
2 years ago
by
Thomas Bock
Browse files
Options
Downloads
Patches
Plain Diff
rename zz -> dummy, add json-dcc endpoint, update readme
parent
63003a15
No related branches found
No related tags found
No related merge requests found
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
README.md
+14
-3
14 additions, 3 deletions
README.md
dummy.json
+1116
-0
1116 additions, 0 deletions
dummy.json
server.py
+20
-10
20 additions, 10 deletions
server.py
utils.py
+25
-28
25 additions, 28 deletions
utils.py
zz.json
+0
-1678
0 additions, 1678 deletions
zz.json
with
1175 additions
and
1719 deletions
README.md
+
14
−
3
View file @
06075866
...
...
@@ -19,6 +19,18 @@ curl -s http://a73434:5006/vl-dcc/2019-75046 | \
curl
-s
-X
POST
-H
"Content-Type: text/xml"
-d
@- http://a73434:5005/validate
```
### `json-dcc` (POST)
Returns a DCC based on the
`POST`
ed
`json`
document. This repository
contains a file named
`dummy.json`
.
```
shell
H
=
"Content-Type: application/json"
URL
=
"http://localhost:5006/json-dcc"
curl
-X
POST
-H
"
$H
"
-d
@dummy.json
"
$URL
"
--noproxy
"*"
```
### `update` (POST)
The update endpoint pulls the latest program version from origin master
...
...
@@ -128,11 +140,10 @@ The /zz (GET) endpoint
curl
-s
http://localhost:5006/zz
>
zz.xml
```
returns a xml version based on the dummy certificate-document (
`zz.json`
)
for test purpose.
## TODO
*
update
`zz.json`
*
allow json POST
*
update
`zz.json`
(done)
*
allow json POST
(done)
This diff is collapsed.
Click to expand it.
dummy.json
0 → 100644
+
1116
−
0
View file @
06075866
This diff is collapsed.
Click to expand it.
server.py
+
20
−
10
View file @
06075866
...
...
@@ -17,10 +17,20 @@ app = Flask(__name__, static_url_path='')
app
.
url_map
.
strict_slashes
=
False
CORS
(
app
)
@app.route
(
'
/json-dcc
'
,
methods
=
[
'
POST
'
])
def
json_dcc
():
try
:
cert_doc
=
request
.
get_json
()
res
=
make_response
(
trans
.
cert_to_xml
(
cert_doc
))
res
=
utils
.
set_filename_header
(
res
=
res
,
no
=
cert_doc
.
get
(
"
_id
"
))
return
res
except
Exception
as
error
:
return
jsonify
({
'
error
'
:
str
(
error
)})
@app.route
(
'
/vl-dcc/<year_cert>
'
,
methods
=
[
'
GET
'
])
def
to_xml
(
year_cert
):
def
vl_dcc
(
year_cert
):
cert_doc
=
utils
.
get_dcc_cert_doc
(
year_cert
)
###pprint(cert_doc)
###pprint(cert_doc)
if
not
'
error
'
in
cert_doc
:
###pprint(cert_doc)
res
=
make_response
(
trans
.
cert_to_xml
(
cert_doc
))
...
...
@@ -29,9 +39,9 @@ def to_xml(year_cert):
else
:
return
utils
.
res_json
(
cert_doc
)
@app.route
(
'
/
zz
'
,
methods
=
[
'
GET
'
])
def
to_xml_zz
():
cert_doc
=
utils
.
get_dcc_cert_doc_dummy
()
@app.route
(
'
/
dummy
'
,
methods
=
[
'
GET
'
])
def
dummy
():
cert_doc
=
utils
.
get_dcc_cert_doc_dummy
()
res
=
make_response
(
trans
.
cert_to_xml
(
cert_doc
))
res
=
utils
.
set_filename_header
(
res
=
res
,
no
=
'
2020_ZZZZZ
'
)
return
res
...
...
@@ -44,7 +54,7 @@ def append_cert(year_cert):
@app.route
(
'
/vl-dcc
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
def
main
():
return
utils
.
return_error
(
'
Cert ID missing
'
)
@app.route
(
'
/update
'
,
methods
=
[
'
POST
'
])
def
update
():
app
.
logger
.
debug
(
'
hit update
'
)
...
...
@@ -53,7 +63,7 @@ def update():
tarball_url
=
req
[
'
repository
'
][
'
homepage
'
]
+
'
/-/archive/master/
'
+
\
req
[
'
repository
'
][
'
name
'
]
+
'
-master.tar
'
version
=
str
(
utils
.
get_version
())
with
open
(
'
./LOG
'
,
'
a
'
)
as
f
:
with
open
(
'
./LOG
'
,
'
a
'
)
as
f
:
print
(
datetime
.
now
().
strftime
(
"
[%Y-%m-%d %H:%M:%S]
"
+
version
),
file
=
f
)
try
:
ps
=
subprocess
.
Popen
((
'
/usr/bin/curl
'
,
'
--insecure
'
,
'
--silent
'
,
\
...
...
@@ -62,9 +72,9 @@ def update():
'
-f
'
,
'
-
'
,
'
--strip-components=1
'
),
stdin
=
ps
.
stdout
)
ps
.
wait
()
except
Exception
as
error
:
app
.
logger
.
debug
(
str
(
error
))
app
.
logger
.
debug
(
str
(
error
))
return
jsonify
({
'
error
'
:
str
(
error
)})
return
jsonify
({
'
OK
'
:
True
})
@app.route
(
'
/version
'
,
methods
=
[
'
GET
'
])
...
...
@@ -75,6 +85,6 @@ def version():
return
jsonify
({
'
version
'
:
version
})
else
:
return
jsonify
({
'
error
'
:
'
Version unknown
'
})
if
__name__
==
'
__main__
'
:
app
.
run
(
host
=
config
[
'
server
'
][
'
host
'
],
port
=
config
[
'
server
'
][
'
port
'
])
This diff is collapsed.
Click to expand it.
utils.py
+
25
−
28
View file @
06075866
...
...
@@ -5,26 +5,26 @@ import datetime
from
flask
import
jsonify
,
Response
def
set_filename_header
(
res
,
no
):
today
=
get_current_date
()
today
=
get_current_date
()
res
.
headers
[
'
Content-Type
'
]
=
'
text/xml;charset=utf-8
'
res
.
headers
[
'
content-disposition
'
]
=
'
attachment
'
res
.
headers
[
'
Access-Control-Expose-Headers
'
]
=
\
'
filename, content-disposition, Server, Date, Content-Type
'
res
.
headers
[
'
filename
'
]
=
'
\"
ks-{
no
}-{
today
}.xml
\"
'
.
format
(
no
=
no
,
today
=
today
)
# TODO: today sinnvoll?
return
res
res
.
headers
[
'
Content-Type
'
]
=
'
text/xml;charset=utf-8
'
res
.
headers
[
'
content-disposition
'
]
=
'
attachment
'
res
.
headers
[
'
Access-Control-Expose-Headers
'
]
=
\
'
filename, content-disposition, Server, Date, Content-Type
'
res
.
headers
[
'
filename
'
]
=
'
\"
ks-{}-{}.xml
\"
'
.
format
(
no
,
today
)
return
res
def
get_config_dict
():
with
open
(
'
./config.json
'
)
as
json_config_file
:
config
=
json
.
load
(
json_config_file
)
config
=
json
.
load
(
json_config_file
)
return
config
def
path_file
(
path
,
file
):
return
"
{path}/{file}
"
.
format
(
path
=
path
,
file
=
file
)
config
=
get_config_dict
()
def
return_ok
():
return
res_json
({
'
ok
'
:
True
})
...
...
@@ -41,34 +41,31 @@ def get_current_date(short=False):
return
"
{}
"
.
format
(
datetime
.
datetime
.
today
().
date
())
def
get_dcc_cert_doc_dummy
():
with
open
(
'
./
zz
.json
'
)
as
f
:
ret
=
json
.
load
(
f
)
return
ret
with
open
(
'
./
dummy
.json
'
)
as
f
:
ret
=
json
.
load
(
f
)
return
ret
def
get_dcc_cert_doc
(
year_cert
):
url
=
'
{}{}
'
.
format
(
config
[
'
cert_doc_url
'
],
year_cert
)
print
(
'
############
'
+
url
)
try
:
r
=
requests
.
get
(
url
)
d
=
r
.
json
()
return
d
return
r
.
json
()
except
:
return
{
'
error
'
:
'
Cert document not
accessible
'
}
return
{
'
error
'
:
'
Cert document not
found at {}
'
.
format
(
url
)
}
def
get_version
():
version
=
False
try
:
with
open
(
'
./VERSION
'
,
'
r
'
)
as
f
:
version
=
f
.
read
().
rstrip
()
return
version
version
=
f
.
read
().
rstrip
()
except
:
return
False
ltx2entity
=
{
'
<
'
:
'
<
'
,
'
>
'
:
'
>
'
}
pass
return
version
ltx2entity
=
{
'
<
'
:
'
<
'
,
'
>
'
:
'
>
'
}
def
sanitize_ltx
(
x
):
# unnecessary, as done by canonicalize
for
key
in
ltx2entity
:
x
=
x
.
replace
(
key
,
ltx2entity
[
key
])
x
=
x
.
replace
(
key
,
ltx2entity
[
key
])
return
x
This diff is collapsed.
Click to expand it.
zz.json
deleted
100644 → 0
+
0
−
1678
View file @
63003a15
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