Skip to content

feat(sdk): allow for multi config #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 15, 2022
Merged

feat(sdk): allow for multi config #86

merged 9 commits into from
Aug 15, 2022

Conversation

ZXYmania
Copy link
Contributor

@ZXYmania ZXYmania commented Jul 11, 2022

allow each client to have a seperate config

  • Example usage
from staxapp.config import Config
from staxapp.openapi import StaxClient

Config.access_key = "0ba825b2-ad6a-4b51-9189-26c20ecb57e3"
Config.secret_key = "first default config"
Config.hostname = "api.core.dev.juma.cloud"

# Use default creds to hit the Api
api_response = Api.get(f"/20190206/accounts")

# Read all accounts within your Stax Organisation
accounts = StaxClient("accounts")
response = accounts.ReadAccounts()

# Able to create instances of configs with the infomation set
second_config = Config(access_key = "aea77423-7cf0-48c4-9397-43fca29683e2", secret_key = "first custom config", hostname = "api.core.test.juma.cloud")
second_accounts = StaxClient("accounts", config=second_config)
s_response = second_accounts.ReadAccounts()

# Hit the Api with a custom config
second_config.init()
api_response_2 = Api.get(f"/20190206/accounts", None, second_config)

# Can have multiple default clients each client will be locked to what was default at time of creation
Config.access_key = "22225b2-ad6a-4b51-9189-26c20ecb57e3"
Config.secret_key = "second default config"
Config.hostname = "api.core.dev.juma.cloud"

workloads = StaxClient("workloads")
work_response = workloads.ReadWorkloads()

# Can create a config and the update the information
third_config = Config()
third_config.access_key = "0ba36500-abb3-48b2-8654-6c8fd0be0f29"
third_config.secret_key = "2nd custom config"

#The clients config will not be affected by changes to the original config
third_accounts = StaxClient("accounts", config=third_config)
third_config.access_key = None
t_response = third_accounts.ReadAccounts()

# Empty configs will be empty until assigned
fourth_config = Config()
fourth_accounts = StaxClient("accounts", config=fourth_config)
try:
    fourth_accounts.ReadAccounts()
except InvalidCredentialsException:
    print("You must specify creds for every new config")

  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    Feature: allow for each client to have their own config and auth.

  • What is the current behavior? (You can also link to an open issue here)
    Currently all auth and config is globally applied

  • Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
    Backwards compatibility has been maintained by retaining a global config that can be used in addition to config instances

@ZXYmania ZXYmania force-pushed the feat/multi_config branch from 7893c41 to 7f79018 Compare July 11, 2022 05:12
allow each client to have a seperate config
@ZXYmania ZXYmania force-pushed the feat/multi_config branch from 7f79018 to 5a9c04a Compare July 11, 2022 05:51
@ZXYmania ZXYmania requested a review from wolfeidau July 26, 2022 06:18
@Anton0 Anton0 added the enhancement New feature or request label Aug 7, 2022
@ZXYmania ZXYmania force-pushed the feat/multi_config branch from 531bc46 to e3eda4d Compare August 9, 2022 07:01
make clients immutable
fix inconsistent default
@ZXYmania ZXYmania marked this pull request as ready for review August 10, 2022 00:16
@ZXYmania ZXYmania requested a review from a team as a code owner August 10, 2022 00:16
fix api backwards compatibility
increase coverage on unit tests
Anton0
Anton0 previously approved these changes Aug 10, 2022
Copy link
Contributor

@Anton0 Anton0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a good approach to me, I think it'd be nice to have some notes on this in the README.md since auth is normally the first task someone needs to solve to get the SDK up and running, or perhaps an example that shows multiple clients like your PR description.

add an example for how to use a config client
add auth configuration to the readme
revert schema changes
@codecov
Copy link

codecov bot commented Aug 11, 2022

Codecov Report

Merging #86 (9043ab6) into master (cfdd181) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master       #86   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            8         8           
  Lines          436       474   +38     
=========================================
+ Hits           436       474   +38     
Impacted Files Coverage Δ
staxapp/api.py 100.00% <100.00%> (ø)
staxapp/auth.py 100.00% <100.00%> (ø)
staxapp/config.py 100.00% <100.00%> (ø)
staxapp/contract.py 100.00% <100.00%> (ø)
staxapp/openapi.py 100.00% <100.00%> (ø)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants