Skip to content

Commit

Permalink
Merge pull request #18 from dseichter/sonarqube_fixes
Browse files Browse the repository at this point in the history
Sonarqube fixes
  • Loading branch information
Daniel Seichter authored Jul 28, 2024
2 parents 9655a0b + ca0bb61 commit 6043475
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 42 deletions.
30 changes: 28 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,20 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: VATValidation-cli-windows-${{ github.ref_name }}.exe
path: dist/VATValidation-cli-windows-${{ github.ref_name }}.exe
path: dist/VATValidation-cli-windows-${{ github.ref_name }}.exe

test-cli-windows:
runs-on: windows-latest
needs: [build-windows-binary-cli]
steps:

- uses: actions/download-artifact@v4
with:
name: VATValidation-cli-windows-${{ github.ref_name }}.exe

- name: Run tests
run: |
VATValidation-cli-windows-${{ github.ref_name }}.exe --version
build-linux-binary:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -140,9 +153,22 @@ jobs:
name: VATValidation-cli-linux-${{ github.ref_name }}
path: dist/VATValidation-cli-linux-${{ github.ref_name }}

test-cli-linux:
runs-on: ubuntu-latest
needs: [build-linux-binary-cli]
steps:

- uses: actions/download-artifact@v4
with:
name: VATValidation-cli-linux-${{ github.ref_name }}

- name: Run tests
run: |
./VATValidation-cli-linux-${{ github.ref_name }} --version
deploy:
runs-on: ubuntu-latest
needs: [build-windows-binary, build-linux-binary, build-windows-binary-cli, build-linux-binary-cli]
needs: [build-windows-binary, build-linux-binary, test-cli-windows, test-cli-linux]
steps:
- uses: actions/download-artifact@v4
with:
Expand Down
59 changes: 35 additions & 24 deletions src/validate_bzst.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,41 +91,20 @@ def start_validation(payload, iscli=True):

try:
resp = http.request("GET", URL, fields=bzstmap)
dom = minidom.parseString(resp.data)
params = dom.childNodes

rc = {}
for param in params:
arrays = param.getElementsByTagName("array")
iskey = True
for array in arrays:
values = array.getElementsByTagName("value")
for value in values:
strings = value.getElementsByTagName("string")
if iskey:
iskey = False
for string in strings:
newkey = gettext(string.childNodes)
else:
iskey = True
for string in strings:
newvalue = gettext(string.childNodes)
rc[newkey] = newvalue
rc = parse_response(resp.data)

validationresult = {
"key1": payload["key1"],
"key2": payload["key2"],
"ownvat": payload["ownvat"],
"foreignvat": payload["foreignvat"],
"type": "BZST",
"valid": rc["ErrorCode"] in ["200", "216"],
"valid": is_valid(rc["ErrorCode"]),
"errorcode": rc["ErrorCode"],
"errorcode_description": load_codes(payload["lang"], rc["ErrorCode"]),
"valid_from": rc["Gueltig_ab"],
"valid_to": rc["Gueltig_bis"],
"timestamp": datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%dT%H:%M:%S"
),
"timestamp": get_current_timestamp(),
"company": rc["Firmenname"],
"address": "",
"town": rc["Ort"],
Expand All @@ -139,6 +118,38 @@ def start_validation(payload, iscli=True):
return {"vatError": "VAT3500", "vatErrorMessage": repr(e)}


def parse_response(response_data):
dom = minidom.parseString(response_data)
params = dom.childNodes

rc = {}
for param in params:
arrays = param.getElementsByTagName("array")
iskey = True
for array in arrays:
values = array.getElementsByTagName("value")
for value in values:
strings = value.getElementsByTagName("string")
if iskey:
iskey = False
for string in strings:
newkey = gettext(string.childNodes)
else:
iskey = True
for string in strings:
newvalue = gettext(string.childNodes)
rc[newkey] = newvalue
return rc


def is_valid(error_code):
return error_code in ["200", "216"]


def get_current_timestamp():
return datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")


def substitute_variables_in_description(payload):
description = payload["errorcode_description"]

Expand Down
20 changes: 4 additions & 16 deletions src/validate_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,10 @@ def return_fielderror(fieldname):
def start_validation(payload, iscli=True):
logger.debug(payload)

if "key1" not in payload:
return return_fielderror("key1")
if "key2" not in payload:
return return_fielderror("key2")
if "ownvat" not in payload:
return return_fielderror("ownvat")
if "foreignvat" not in payload:
return return_fielderror("foreignvat")
if "company" not in payload:
return return_fielderror("company")
if "town" not in payload:
return return_fielderror("town")
if "zip" not in payload:
return return_fielderror("zip")
if "street" not in payload:
return return_fielderror("street")
required_fields = ["key1", "key2", "ownvat", "foreignvat", "company", "town", "zip", "street"]
for field in required_fields:
if field not in payload:
return return_fielderror(field)

if "type" not in payload:
payload["type"] = (
Expand Down

0 comments on commit 6043475

Please sign in to comment.