Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def delete(self, endpoint: str):
req = r.delete(
self.url.format(
endpoint=endpoint, host=self.host, port=self.port
),
auth=(self.username, self.password),
)
if req.status_code != 200:
raise HawkbitError(
'Wrong statuscode, got {} instead of 200, with error {}'.
format(req.status_code, req.json())
)
def get_endpoint(self, endpoint: str):
headers = {'Content-Type': 'application/json;charset=UTF-8'}
req = r.get(
self.url.format(
endpoint=endpoint, host=self.host, port=self.port
),
headers=headers,
auth=(self.username, self.password)
)
if req.status_code != 200:
raise HawkbitError(
'Wrong statuscode, got {} instead of 200, with error {}'.
format(req.status_code, req.json())
)
return req.json()
def post_json(self, endpoint: str, data: dict):
headers = {'Content-Type': 'application/json;charset=UTF-8'}
req = r.post(
self.url.format(
endpoint=endpoint, host=self.host, port=self.port
),
headers=headers,
auth=(self.username, self.password),
json=data
)
if req.status_code != 200 and req.status_code != 201:
raise HawkbitError(
'Wrong statuscode, got {} instead of 200/201, with error {}'.
format(req.status_code, req.json())
)
return req.json()
def post(self, endpoint: str):
req = r.post(
self.url.format(
endpoint=endpoint, host=self.host, port=self.port
),
auth=(self.username, self.password),
)
if req.status_code != 200 and req.status_code != 201:
raise HawkbitError(
'Wrong statuscode, got {} instead of 200/201'.
format(req.status_code)
)