Skip to content

Commit a288fd7

Browse files
authored
Merge pull request #35 from stax-labs/feat/status_code
feat(exception) add status_code to exception
2 parents 76643bf + bc4ae8b commit a288fd7

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
3+
from staxapp.config import Config
4+
from staxapp.openapi import StaxClient
5+
6+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
7+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
8+
9+
# The name of the token
10+
token_name = <Api Token Name>
11+
# What access the token will have to the api
12+
token_role = <Api Token Role>
13+
# Whether the secret to store the token in ssm params
14+
# Otherwise it will be returned in the response
15+
store_token = <Store Token?>
16+
17+
# Create an Api token with access to your Stax Organisation
18+
teams = StaxClient("teams")
19+
response = teams.CreateApiToken(Name=token_name, Role=token_role, StoreToken=store_token)
20+
print(response)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
3+
from staxapp.config import Config
4+
from staxapp.openapi import StaxClient
5+
6+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
7+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
8+
9+
# The token to delete's AccessKey
10+
access_key = <Access Key>
11+
12+
# Delete an Api Token
13+
teams = StaxClient("teams")
14+
response = teams.DeleteApiToken(AccessKey=access_key)
15+
16+
print(response)

staxapp/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class ApiException(Exception):
66
def __init__(self, message, response, detail=""):
77
try:
8+
self.status_code = response.status_code
89
if response.json().get("Error"):
910
logging.error(f"{response.status_code}: {response.json()}")
1011
self.message = f"Api Exception: {response.status_code} -{detail} {response.json()['Error']}"

0 commit comments

Comments
 (0)