Skip to content

Commit e7040a2

Browse files
authored
Merge pull request #42 from stax-labs/feat/accounts-examples
feat(JUMA-3378) add examples for accounts and account types
2 parents 3e58160 + 95ada00 commit e7040a2

File tree

8 files changed

+169
-0
lines changed

8 files changed

+169
-0
lines changed
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+
account_type_name = "sdk-2" #<Account Type Name>
7+
8+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
9+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
10+
11+
accounts = StaxClient('accounts')
12+
13+
response = accounts.CreateAccountType(
14+
Name=account_type_name
15+
)
16+
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+
account_type_id = <Account Type Id>
7+
8+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
9+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
10+
11+
accounts = StaxClient('accounts')
12+
13+
response = accounts.DeleteAccountType(
14+
account_type_id=account_type_id
15+
)
16+
print(response)
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+
# The account type to update
7+
account_type_id = <Account Type Id>
8+
# The new name for the account type
9+
account_type_name = <Account Type Name>
10+
11+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
12+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
13+
14+
accounts = StaxClient('accounts')
15+
16+
response = accounts.UpdateAccountType(
17+
account_type_id = account_type_id,
18+
Name = account_type_name
19+
)
20+
print(response)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
accounts = StaxClient('accounts')
10+
11+
# An array of access_role dicts to enable or empty array
12+
# Properties: RoleName, AccountTypeId, GroupId
13+
access_roles_to_add = <An array of access_roles?>
14+
15+
# # An array of access_role dicts to disable or empty arry
16+
access_roles_to_remove = <An array of access_roles?>
17+
18+
19+
response = accounts.UpdateAccountTypeAccess(
20+
AddRoles= access_roles_to_add,
21+
RemoveRoles=access_roles_to_remove
22+
)
23+
print(response)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
3+
from staxapp.config import Config
4+
from staxapp.openapi import StaxClient
5+
6+
# The account to change membership
7+
account_id = <Account Id>
8+
9+
# The account type that will become the new owner
10+
account_type_id = <Account Type Id>
11+
12+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
13+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
14+
15+
accounts = StaxClient('accounts')
16+
17+
account_type_mappings = [{}]
18+
account_type_mappings[0]["AccountId"] = account_id
19+
account_type_mappings[0]["AccountTypeId"] = account_type_id
20+
21+
response = accounts.UpdateAccountTypeMembers(
22+
Members=account_type_mappings
23+
)
24+
print(response)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
accounts = StaxClient('accounts')
10+
11+
# An array of Account Type-Policy dicts to enable or an empty array
12+
# Properties: AccountTypeId, PolicyId
13+
policies_to_add = <An array of Account type-Policies?>
14+
15+
# An array of Account Type-Policy dicts to disable or an empty arry
16+
policies_to_remove = <An array of Account type-Policies?>
17+
18+
response = accounts.UpdatePolicies(
19+
AddPolicies= policies_to_add,
20+
RemovePolicies= policies_to_remove
21+
)
22+
print(response)

examples/accounts/create_accounts.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
from staxapp.config import Config
4+
from staxapp.openapi import StaxClient
5+
6+
account_name = <Account Name>
7+
account_type = <Account Type Id>
8+
9+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
10+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
11+
12+
accounts = StaxClient('accounts')
13+
14+
response = accounts.CreateAccount(
15+
Name=account_name,
16+
AccountType=account_type,
17+
)
18+
print(response)

examples/accounts/update_account.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import os
2+
3+
from staxapp.config import Config
4+
from staxapp.openapi import StaxClient
5+
6+
# The account you want to update
7+
account_id = <Account Id>
8+
9+
#To change account types include an account type id
10+
account_type_id = <Account Type Id?>
11+
12+
# To change the tags include a dictionary of tags
13+
tags_dict = <A dictionary of tags?>
14+
15+
Config.access_key = os.getenv("STAX_ACCESS_KEY")
16+
Config.secret_key = os.getenv("STAX_SECRET_KEY")
17+
18+
accounts = StaxClient('accounts')
19+
20+
update_properties = {}
21+
if tags_dict:
22+
update_properties.update(tags)
23+
if account_type_id:
24+
update_properties["AccountType"] = account_type_id
25+
26+
response = accounts.UpdateAccount(
27+
account_id=account_id,
28+
**update_properties
29+
)
30+
print(response)

0 commit comments

Comments
 (0)