ai_core_sdk.credentials module

ai_core_sdk.credentials.get_nested_value(data_dict, keys: List[str])

Retrieve a nested value from a dictionary using a list of strings.

Parameters:
  • data_dict – The dictionary to search.

  • keys – A list of strings representing nested keys.

Returns:

The value associated with the nested keys, or None if not found.

class ai_core_sdk.credentials.VCAPEnvironment(services: 'List[Service]')

Bases: object

services: List[Service]
classmethod from_env(env_var: str | None = None)
classmethod from_dict(env: Dict[str, Any])
get_service(label, exactly_one: bool = True) Service
get_service_by_name(name, exactly_one: bool = True) Service
__init__(services: List[Service]) None
class ai_core_sdk.credentials.Service(env: Dict[str, Any])

Bases: object

__init__(env: Dict[str, Any])
property label: str | None
property name: str | None
get(key, default=NoDefault)
class ai_core_sdk.credentials.CredentialsValue(name: 'str', vcap_key: 'Optional[Tuple[str, ...]]' = None, transform_fn: 'Optional[Callable]' = None)

Bases: object

name: str
vcap_key: Tuple[str, ...] | None = None
transform_fn: Callable | None = None
__init__(name: str, vcap_key: Tuple[str, ...] | None = None, transform_fn: Callable | None = None) None
class ai_core_sdk.credentials.Source(name: 'str', get: 'Callable[[CredentialsValue], Optional[str]]')

Bases: object

name: str
get: Callable[[CredentialsValue], str | None]
__init__(name: str, get: Callable[[CredentialsValue], str | None]) None
ai_core_sdk.credentials.init_conf(profile: str = None)
ai_core_sdk.credentials.resolve_resource_group(sources: List[Source]) str | None

Find resource_group from the first source that defines it.

ai_core_sdk.credentials.validate_credentials(credentials: Dict[str, str]) None

Validate that we have a complete authentication method.

ai_core_sdk.credentials.fetch_credentials(profile: str = None, credential_values: ~typing.List[~ai_core_sdk.credentials.CredentialsValue] = [CredentialsValue(name='client_id', vcap_key=('credentials', 'clientid'), transform_fn=None), CredentialsValue(name='client_secret', vcap_key=('credentials', 'clientsecret'), transform_fn=None), CredentialsValue(name='auth_url', vcap_key=('credentials', 'url'), transform_fn=<lambda>), CredentialsValue(name='base_url', vcap_key=('credentials', 'serviceurls', 'AI_API_URL'), transform_fn=<lambda>), CredentialsValue(name='resource_group', vcap_key=None, transform_fn=None), CredentialsValue(name='cert_url', vcap_key=('credentials', 'certurl'), transform_fn=<lambda>), CredentialsValue(name='cert_file_path', vcap_key=None, transform_fn=None), CredentialsValue(name='key_file_path', vcap_key=None, transform_fn=None), CredentialsValue(name='cert_str', vcap_key=('credentials', 'certificate'), transform_fn=<lambda>), CredentialsValue(name='key_str', vcap_key=('credentials', 'key'), transform_fn=<lambda>)], validate: bool = True, **kwargs) Dict[str, str]

Fetch credentials from a single source based on precedence.

Precedence order: kwargs > environment variables > config file > VCAP service

Once a source is selected (first one with any credential), all credentials come from that source only. Resource group is an exception and follows precedence independently.

If credential_values is provided and it’s not extended from the CORE_CREDENTIAL_VALUES, set validate to False