Configuring the SDK¶
Certain configuration items are required to connect and interact with the 10Duke Scale API. Additional configuration items can be specified to control the behavior of the SDK.
The [tenduke_core.config.TendukeConfig] class is used to configure the SDK.
See the documentation for the attributes of [tenduke_core.config.TendukeConfig] for the definition of each configuration item.
Configuration items can be set via a configuration file, environment variables, programmatically or through any combination of the the three options.
If a configuration item is presented in more than one source, the priority order is:
- environment variable
- file
- code
Environment variables are highest priority, code is lowest. This order is intended to reflect how easy it is to change the values. It is easier to update environment variables or edit a configuration file than it is to deploy new code.
Configuration File¶
Parameter values can be specified in a configuration file in HOCON, JSON, or YAML formats.
Example configuration file (HOCON format):
{
token_path="./local-config",
public_key_path="./local-config",
licensing_api_url="https://{tenant}.dev.lic-api.scale.10duke.com",
licensing_api_authorization_model="",
idp_oidc_discovery_url="{URL}",
idp_oauth_authorization_url="{URL}",
idp_oauth_device_code_url="{URL}",
idp_oauth_token_url="{URL}",
idp_oauth_client_id="{string}",
idp_oauth_client_secret="{string}",
idp_oauth_scope="openid profile email",
idp_userinfo_url="{URL}",
token_refresh_leeway=10,
auth_success_message=success.http,
https_proxy = "http://user:pass@host:port"
}
You can load a configuration file like this:
from tenduke_core.config import TendukeConfig
config = TendukeConfig.load(file_name="my_config.hocon")
Environment variables¶
To specify the configuration items using environment variables simply set or export the variables.
tenduke_core.config.TendukeConfig.load will load values from the environment variables if they are present.
The environment variable names can be prefixed to identify them more easily as relating to 10Duke
Scale or your application. A prefix can be passed to the tenduke_core.config.TendukeConfig.load
method. For example, SCALE_
and then the attribute name (as uppercase):
EXPORT SCALE_IDP_OIDC_DISCOVERY_URL="https://accounts.google.com/.well-known/openid-configuration"
If all of the configuration items you wish to set are provided as environment variables, you can load the configuration as follows:
from tenduke_core.config import TendukeConfig
config = TendukeConfig.load()
If for some reason you want to use a different prefix for the environment variables (e.g.
MYAPP_IDP_OIDC_DISCOVERY_URL
) then you can pass a prefix to the
TendukeConfig.load method:
from tenduke_core.config import TendukeConfig
config = TendukeConfig.load(prefix="MYAPP")
If you are providing some values in a configuration file and some values from environment variables simply pass the file name in (as shown in the first example above):
from tenduke_core.config import TendukeConfig
config = TendukeConfig.load(file_name="my_config.hocon")
Note
If the configuration item is specified in an environment variable and the configuration file, the environment variable takes precedence.
Programmatic configuration¶
Setting configuration items in code is achieved by passing kwargs to
TendukeConfig.load. Calling the load
method is preferred
to directly initializing the config class as it allows a combination of environment variable, file,
and code parameters to be used in a single configuration.
from tenduke_core.config import TendukeConfig
# set a parameter - this will also load environment variables
config = TendukeConfig.load(idp_oauth_client_id="my_app_credentials")
Combining all three sources:
from tenduke_core.config import TendukeConfig
config = TendukeConfig.load(
file_name="my_config.hocon", idp_oauth_client_id="my_app_credentials"
)
Obtaining OpenID Connect provider configuration from the discovery endpoint¶
If you require your application to load the Open ID Connect provider information from the provider's discovery endpoint, then this is an extra step needed after loading other sources of configuration information and before initiating the authorization flow with the desired OAuthClient.
config = TendukeConfig.load(
idp_oidc_discovery_url="https://idp.example.com/user/.well-known/openid-configuration",
)
session_factory = ScaleSessionFactory(config, "id-token-auth-example", "1.0.0")
load_openid_config(session_factory, config)
http_timeout_seconds
¶
The documentation for http_timeout_seconds
specifies that this is the timeout for HTTP requests
(in seconds).
PyTendukeScale is using requests to make HTTP requests.
The http_timeout_seconds
is being passed as both the connect
and
read
timeouts.
This means that the effective timeout for HTTP requests is double the
value you set for http_timeout_seconds
See the documentation for requests for further details of how timeouts are configured in requests.