Profiles

Profiles functionality

Simple profile management for NiPyAPI development configurations.

nipyapi.profiles.load_profiles_from_file(file_path=None)[source]

Load profile configurations from a YAML or JSON file.

Supports both YAML and JSON formats since JSON is a subset of YAML syntax.

Parameters:

file_path (str, optional) – Path to YAML or JSON file containing profile definitions. If None, resolves using: 1. NIPYAPI_PROFILES_FILE environment variable 2. nipyapi.config.default_profiles_file

Returns:

Profile configurations

Return type:

dict

nipyapi.profiles.resolve_profile_config(profile_name, profiles_file_path=None)[source]

Complete profile configuration resolution with environment overrides and absolute paths.

Supports both simple shared certificates and complex per-service PKI configurations. Accepts both YAML and JSON profile files.

Special “env” profile: When profile_name is “env”, configuration is loaded entirely from environment variables without requiring a profiles file. This is useful for CI/CD pipelines and containerized deployments where all configuration comes from the environment.

Parameters:
  • profile_name (str) – Name of profile to resolve. Use “env” for pure environment variable configuration without a profiles file.

  • profiles_file_path (str, optional) – Path to profiles YAML or JSON file. Default resolution handled by load_profiles_from_file(). Ignored when profile_name is “env”.

Returns:

Fully resolved configuration with all paths and overrides applied

Return type:

dict

nipyapi.profiles.switch(profile_name, profiles_file=None, login=True)[source]

Switch to a different profile at runtime using configuration-driven authentication.

Automatically detects authentication methods based on available configuration parameters rather than profile names, making it flexible for custom profiles.

Supported authentication methods:

  • OIDC: Requires oidc_token_endpoint, oidc_client_id, oidc_client_secret.

    Optional nifi_user, nifi_pass (enables Resource Owner Password flow; without them uses Client Credentials flow)

  • mTLS: Requires client_cert, client_key (+ optional client_key_password)

  • Basic: Requires nifi_user/nifi_pass for NiFi, registry_user/registry_pass for Registry

Parameters:
  • profile_name (str) – Name of the profile to switch to. Use “env” for pure environment variable configuration without a profiles file.

  • profiles_file (str, optional) – Path to profiles file. Resolution order: 1. Explicit profiles_file parameter 2. NIPYAPI_PROFILES_FILE environment variable 3. nipyapi.config.default_profiles_file Ignored when profile_name is “env”.

  • login (bool, optional) – Whether to attempt authentication. Defaults to True. If False, configures SSL/endpoints but skips login attempts. Useful for readiness checks where you don’t want to send credentials.

Returns:

(profile_name, metadata) where metadata varies by authentication method:
  • OIDC: token_data dict containing JWT token info for UUID extraction (login=True)

  • Basic: username string of the logged-in user (login=True)

  • mTLS: None (no metadata extracted)

  • Any method with login=False: None

Return type:

tuple

Raises:

ValueError – If profile not found or required authentication parameters are missing

Example

>>> import nipyapi.profiles
>>> nipyapi.profiles.switch('single-user')  # Uses basic auth (nifi_user/nifi_pass)
>>> nipyapi.profiles.switch('secure-mtls')  # Uses mTLS auth (client_cert/client_key)
>>> nipyapi.profiles.switch('secure-oidc')  # Uses OIDC auth (oidc_* params)
>>> nipyapi.profiles.switch('my-custom')    # Uses whatever auth method is configured
>>>
>>> # Pure environment variable configuration (no profiles file needed)
>>> # Set NIFI_API_ENDPOINT, NIFI_USERNAME, NIFI_PASSWORD in environment
>>> nipyapi.profiles.switch('env')
>>>
>>> # Custom profiles file
>>> nipyapi.profiles.switch('production',
...                          profiles_file='/home/user/.nipyapi/profiles.yml')