Skip to content
Snippets Groups Projects
Commit 06075866 authored by Thomas Bock's avatar Thomas Bock :speech_balloon:
Browse files

rename zz -> dummy, add json-dcc endpoint, update readme

parent 63003a15
No related branches found
No related tags found
No related merge requests found
......@@ -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)
dummy.json 0 → 100644
This diff is collapsed.
......@@ -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'])
......@@ -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 = {
'<':'&lt;',
'>':'&gt;'
}
pass
return version
ltx2entity = {'<':'&lt;',
'>':'&gt;'}
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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment