Skip to content

Commit

Permalink
Fix bugs in license sync script
Browse files Browse the repository at this point in the history
Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
  • Loading branch information
AyanSinhaMahapatra committed Jul 26, 2023
1 parent 17dd1a2 commit 176d2b0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions etc/scripts/licenses/synclic.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,29 +746,29 @@ def create_or_update_license(api_url, api_key, lico, update=False):
"""
_owner = get_or_create_owner(api_url, api_key, lico.owner, create=True)

url = f"{api_url}/licenses/"
new_license_url = f"{api_url}/licenses/"
headers = get_api_headers(api_key)

# recheck that the license key does not exists remotely
params = dict(key=lico.key)
# note: we GET params
response = requests.get(url, headers=headers, params=params)
response = requests.get(new_license_url, headers=headers, params=params)
if not response.ok:
content = response.content
headers = response.headers
raise Exception(f"Failed to fetch license for {lico.key} at {url}:\n{headers}\n{content}")
raise Exception(f"Failed to fetch license for {lico.key} at {new_license_url}:\n{headers}\n{content}")

results = response.json().get("results", [])

if not results:
# add new license
data = license_to_dict(lico)
data = add_license_creation_fields(data)
response = requests.post(url, headers=headers, json=data)
response = requests.post(new_license_url, headers=headers, json=data)
if not response.ok:
content = response.content
headers = response.headers
raise Exception(f"Failed to create license: {lico.key} at {url}:\n{headers}\n{content}")
raise Exception(f"Failed to create license: {lico.key} at {new_license_url}:\n{headers}\n{content}")

print("Created new license:", lico)
created = response.json()
Expand Down

0 comments on commit 176d2b0

Please sign in to comment.