Skip to content
Snippets Groups Projects
Commit 3c68ccab authored by Tim Jaacks's avatar Tim Jaacks
Browse files

Alphaplan: add script for importing alphaplan data

The script has mostly been copied from alphaplan_fwr.py, but with
different input data.

Adding a job to the CI-test environment for testing this.
parent 3b3238a1
No related branches found
No related tags found
1 merge request!227CI-test: new deploy pipeline
Pipeline #45803 passed with stages
in 1 minute and 6 seconds
...@@ -215,3 +215,22 @@ workflow: ...@@ -215,3 +215,22 @@ workflow:
artifacts: artifacts:
paths: paths:
- alphaplan-import*.json - alphaplan-import*.json
.import-alphaplan-data:
extends:
- .infrastructure
rules:
- when: manual
variables:
# Most AP_WEBSERVICE_* variables are set in GitLab CI variables. We're defining the
# URL here, though, so that it can be overridden in a job's variables block.
AP_WEBSERVICE_URL: >
https://SRV06.hamburg.garz-fricke.de/Alphaplan-API/Artikel/CreateFirmware
script:
- echo "${AP_WEBSERVICE_CERT}" > GarzFrickeGmbH-CA.cer
- .gitlab-ci/scripts/alphaplan_fwr_import.py
--url=${AP_WEBSERVICE_URL}
--user=${AP_WEBSERVICE_USR}
--password=${AP_WEBSERVICE_PW}
--cert-file=GarzFrickeGmbH-CA.cer
--file=alphaplan-import*.json
...@@ -295,3 +295,11 @@ generate-alphaplan-data-seco-mx6: ...@@ -295,3 +295,11 @@ generate-alphaplan-data-seco-mx6:
stage: Alphaplan stage: Alphaplan
needs: needs:
- deploy-seco-mx6 - deploy-seco-mx6
import-alphaplan-data-seco-mx6:
extends: .import-alphaplan-data
stage: Alphaplan
variables:
AP_WEBSERVICE_URL: https://SRV06.hamburg.garz-fricke.de/Test/Alphaplan-API/Artikel/CreateFirmware
needs:
- generate-alphaplan-data-seco-mx6
#!/usr/bin/env python3
import argparse
import glob
import json
import sys
import requests
def ap_send_json(jsonobj: dict, url: str, user: str, password: str, cert_file: str):
"""Sends the generated files to the Alphaplan webservice"""
msg = requests.post(
url, json=jsonobj, auth=(user, password), verify=cert_file, timeout=10
)
msg_json = msg.json()
if msg_json["Status"] != "Ok":
sys.exit("ERROR: AlphaPlan webservice post request failed")
print("AlphaPlan webservice response: {}".format(msg_json["Meldung"]))
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--file",
help="""JSON file for Alphaplan FWR import""",
dest="file",
required=True,
)
parser.add_argument(
"--url",
help="""URL to the Alphaplan webservice""",
dest="url",
required=True,
)
parser.add_argument(
"--user",
help="""User for the Alphaplan webservice""",
dest="user",
required=True,
)
parser.add_argument(
"--password",
help="""Password for the Alphaplan webservice""",
dest="password",
required=True,
)
parser.add_argument(
"--cert-file",
help="""Certificate file for the Alphaplan webservice""",
dest="cert_file",
required=True,
)
args, _ = parser.parse_known_args()
files = glob.glob(args.file, recursive=True)
if not files:
sys.exit("ERROR: no file(s) matching '%s' found" % args.file)
print("Sending data to Alphaplan FWR webservice at %s" % args.url)
# Get files from passed glob
for filename in files:
print("Importing JSON file %s" % filename)
with open(filename, "r", encoding="utf-8") as f:
ap_send_json(
json.load(f),
args.url,
args.user,
args.password,
args.cert_file,
)
if __name__ == "__main__":
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment