Skip to content

Commit 317dc15

Browse files
committed
feat(sdk): make clients immutable
make clients immutable fix inconsistent default
1 parent e3eda4d commit 317dc15

5 files changed

Lines changed: 25 additions & 14 deletions

File tree

staxapp/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class Api:
1010
@classmethod
11-
def get_config(cls, config=None, **kwargs):
11+
def get_config(cls, config=None):
1212
if config is None:
1313
config = Config.GetDefaultConfig()
1414
return config

staxapp/auth.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def id_token_from_cognito(
6161
client_id=self.client_id,
6262
client=srp_client,
6363
)
64+
6465
try:
6566
tokens = aws.authenticate_user()
6667
except ClientError as e:

staxapp/config.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
22
import os
33
import platform as sysinfo
4+
from distutils.command.config import config
5+
from email.policy import default
46

57
import requests
68

@@ -23,13 +25,13 @@ class Config:
2325
access_key = None
2426
secret_key = None
2527
auth_class = None
28+
auth = None
2629
_requests_auth = None
2730
_initialized = False
2831
base_url = None
2932
_hostname = f"api.{STAX_REGION}"
3033
hostname = None
3134
org_id = None
32-
auth = None
3335
expiration = None
3436
load_live_schema = True
3537

@@ -59,14 +61,16 @@ def get_api_config(cls, config_url):
5961
cls.cached_api_config["caching"] = config_url
6062
return config_response.json()
6163

62-
def init(self, hostname=None):
63-
if self._initialized:
64-
return
64+
def __init__(self, hostname=None, access_key=None, secret_key=None):
65+
self.hostname = hostname
6566
if self.hostname is None:
66-
self.hostname = hostname
67-
if self.hostname is None:
68-
self.hostname = Config._hostname
67+
self.hostname = Config._hostname
68+
self.access_key = access_key
69+
self.secret_key = secret_key
6970

71+
def init(self):
72+
if self._initialized:
73+
return
7074
self.set_config()
7175

7276
self._initialized = True
@@ -81,7 +85,7 @@ def api_base_url(self):
8185

8286
@classmethod
8387
def GetDefaultConfig(cls):
84-
config = Config()
88+
config = Config(Config.hostname, Config.access_key, Config.secret_key)
8589
return config
8690

8791
def branch(cls):

staxapp/openapi.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ class StaxClient:
1919
def _get_config(self):
2020
return self._config
2121

22-
def __init__(self, classname, force=False, config=Config.GetDefaultConfig()):
22+
def __init__(self, classname, force=False, config=None):
2323
# Stax feature, eg 'quotas', 'workloads'
24-
self._config = config
25-
if not config._initialized:
24+
if config is None:
25+
config = Config.GetDefaultConfig()
26+
self._config = Config(
27+
hostname=config.hostname,
28+
access_key=config.access_key,
29+
secret_key=config.secret_key,
30+
)
31+
if not self._config._initialized:
2632
self._config.init()
2733

2834
if force or not self._operation_map:

tests/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def testInit(self, set_config_mock):
2929
Test init method
3030
"""
3131
test_hostname = "test.staxapp.cloud"
32-
config = Config()
33-
config.init(hostname=test_hostname)
32+
config = Config(hostname=test_hostname)
33+
config.init()
3434
self.assertEqual(
3535
test_hostname,
3636
config.hostname,

0 commit comments

Comments
 (0)