altametris.sara.core.auth.config ================================ .. py:module:: altametris.sara.core.auth.config .. autoapi-nested-parse:: Authentication configuration for Data Science Azure services. This module provides configuration classes for Azure authentication, supporting multiple authentication methods: 1. Managed Identity (production - Azure resources) 2. Service Principal (CI/CD pipelines) 3. Connection String (local development - fallback) Environment Variables (DS_* prefix for Data Science): Storage: AZURE_STORAGE_ACCOUNT_NAME: Storage account name DS_WEIGHTS_CONTAINER: Container for weights (default: "weights-dev") DS_WEIGHTS_PREFIX: Prefix/folder for weights (default: "yolo-sara") DS_TEST_CONTAINER: Container for test data (default: "unit-tests") DS_TEST_PREFIX: Prefix/folder for test data (default: "yolo-sara") DS_TEST_WEIGHT_NAME: Test weight filename (default: "yolo11n.pt") DS_TEST_IMAGE_NAME: Test image filename (default: "000000000139.jpg") API: DS_API_BASE_URL: APIM base URL DS_API_SCOPE: OAuth2 scope for API Authentication: AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET: Service Principal AZURE_STORAGE_CONNECTION_STRING: Connection string (fallback) Classes ------- .. autoapisummary:: altametris.sara.core.auth.config.DsAuthConfig Module Contents --------------- .. py:class:: DsAuthConfig Authentication configuration for Data Science Azure services. This configuration class loads authentication settings from environment variables and supports multiple authentication methods following Azure best practices. Authentication Priority: 1. DefaultAzureCredential (Managed Identity or Service Principal via env vars) 2. Connection String (fallback for local development) Blob Path Structure: {container}/{prefix}/{filename} Example: weights-dev/yolo-sara/yolo11n.pt .. rubric:: Example >>> # From environment variables >>> config = DsAuthConfig.from_env() >>> print(config.get_weight_blob_path("yolo11n.pt")) 'yolo-sara/yolo11n.pt' >>> # Manual creation >>> config = DsAuthConfig( ... storage_account_name="myaccount", ... weights_container="weights-dev", ... weights_prefix="my-project" ... ) .. py:attribute:: storage_account_name :type: Optional[str] :value: None .. py:attribute:: weights_container :type: str :value: 'weights-dev' .. py:attribute:: test_container :type: str :value: 'unit-tests' .. py:attribute:: weights_prefix :type: str :value: 'yolo-sara' .. py:attribute:: test_prefix :type: str :value: 'yolo-sara' .. py:attribute:: test_weight_name :type: str :value: 'yolo11n.pt' .. py:attribute:: test_image_name :type: str :value: '000000000139.jpg' .. py:attribute:: api_base_url :type: str :value: 'https://am-ds-apiman-dev.azure-api.net' .. py:attribute:: api_scope :type: Optional[str] :value: None .. py:method:: from_env() -> DsAuthConfig :classmethod: Load configuration from environment variables. This method reads all authentication and configuration settings from environment variables. It provides sensible defaults for optional ones. Environment Variables: DS_WEIGHTS_CONTAINER: Container for weights (default: "weights-dev") DS_WEIGHTS_PREFIX: Prefix/folder for weights (default: "yolo-sara") DS_TEST_CONTAINER: Container for test data (default: "unit-tests") DS_TEST_PREFIX: Prefix/folder for test data (default: "yolo-sara") DS_TEST_WEIGHT_NAME: Test weight filename (default: "yolo11n.pt") DS_TEST_IMAGE_NAME: Test image filename (default: "000000000139.jpg") DS_API_BASE_URL: APIM base URL DS_API_SCOPE: OAuth2 scope for API :returns: Configured authentication settings :rtype: DsAuthConfig .. rubric:: Example >>> import os >>> os.environ["DS_API_SCOPE"] = "api://ds-dev/.default" >>> os.environ["DS_WEIGHTS_PREFIX"] = "my-project" >>> config = DsAuthConfig.from_env() .. py:property:: has_service_principal :type: bool Check if Service Principal credentials are configured. :returns: True if all Service Principal env vars are set :rtype: bool .. py:property:: has_connection_string :type: bool Check if Connection String is configured. :returns: True if connection string is set :rtype: bool .. py:property:: auth_method :type: str Get the primary authentication method that will be used. :returns: One of "service_principal", "connection_string", "default_azure" :rtype: str .. rubric:: Example >>> config = DsAuthConfig.from_env() >>> print(config.auth_method) 'default_azure' .. py:method:: get_storage_account_url() -> str Get the full Blob Storage account URL. :returns: Full HTTPS URL to the storage account :rtype: str :raises DsAuthError: If storage_account_name is not configured .. rubric:: Example >>> config = DsAuthConfig(storage_account_name="myaccount") >>> config.get_storage_account_url() 'https://myaccount.blob.core.windows.net' .. py:method:: get_weight_blob_path(filename: str) -> str Build the full blob path for a weight file. Constructs path as: {prefix}/{filename} :param filename: Name of the weight file (e.g., "yolo11n.pt") :returns: Full blob path (e.g., "yolo-sara/yolo11n.pt") :rtype: str .. rubric:: Example >>> config = DsAuthConfig(weights_prefix="yolo-sara") >>> config.get_weight_blob_path("yolo11n.pt") 'yolo-sara/yolo11n.pt' >>> config = DsAuthConfig(weights_prefix="") >>> config.get_weight_blob_path("yolo11n.pt") 'yolo11n.pt' .. py:method:: get_test_weight_blob_path() -> str Get the full blob path for the test weight file. :returns: Full blob path (e.g., "yolo-sara/yolo11n.pt") :rtype: str .. rubric:: Example >>> config = DsAuthConfig.from_env() >>> config.get_test_weight_blob_path() 'yolo-sara/yolo11n.pt' .. py:method:: get_test_image_blob_path() -> str Get the full blob path for the test image file. :returns: Full blob path (e.g., "yolo-sara/000000000139.jpg") :rtype: str .. rubric:: Example >>> config = DsAuthConfig.from_env() >>> config.get_test_image_blob_path() 'yolo-sara/000000000139.jpg' .. py:method:: get_apim_weight_url(filename: str) -> str Build the full APIM URL for downloading a weight file. Constructs URL as: {api_base_url}/weights/{prefix}/{filename} :param filename: Name of the weight file (e.g., "yolo11n.pt") :returns: Full APIM URL :rtype: str .. rubric:: Example >>> config = DsAuthConfig( ... api_base_url="https://am-ds-apiman-dev.azure-api.net", ... weights_prefix="yolo-sara" ... ) >>> config.get_apim_weight_url("yolo11n.pt") 'https://am-ds-apiman-dev.azure-api.net/weights/yolo-sara/yolo11n.pt' .. py:method:: get_apim_list_url() -> str Build the APIM URL for listing available weights. Constructs URL as: {api_base_url}/weights/list :returns: Full APIM URL for listing weights :rtype: str .. rubric:: Example >>> config = DsAuthConfig( ... api_base_url="https://am-ds-apiman-dev.azure-api.net" ... ) >>> config.get_apim_list_url() 'https://am-ds-apiman-dev.azure-api.net/weights/list'