-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path__init__.py
More file actions
27 lines (20 loc) · 815 Bytes
/
__init__.py
File metadata and controls
27 lines (20 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import json
import logging
import urllib.parse
log = logging.getLogger("socketdev")
class LicenseMetadata:
def __init__(self, api):
self.api = api
def post(self, licenses: list, params: dict = None) -> dict:
path = f"license-metadata"
if params:
query_args = urllib.parse.urlencode(params)
path += f"?{query_args}"
payload = json.dumps(licenses)
response = self.api.do_request(path=path, method="POST", payload=payload)
if response.status_code == 200:
result = response.json()
return result
error_message = response.json().get("error", {}).get("message", "Unknown error")
log.error(f"Failed to create license metadata: {response.status_code}, message: {error_message}")
return {}