pub struct AzureAdConfig {
pub auth_method: String,
pub tenant_id: Option<String>,
pub client_id: Option<String>,
pub client_secret: Option<String>,
pub subscription_id: Option<String>,
pub resource_group: Option<String>,
pub namespace: Option<String>,
}Expand description
Configuration for Azure Active Directory authentication and resource access.
This struct contains all the necessary information for authenticating with Azure AD and accessing Azure Service Bus resources. It supports multiple authentication methods and can load configuration from both direct values and environment variables.
§Authentication Methods
device_code- Interactive device code flow (default for CLI usage)client_secret- Service principal authenticationconnection_string- Direct connection string authentication
§Examples
use quetty_server::service_bus_manager::AzureAdConfig;
let config = AzureAdConfig {
auth_method: "device_code".to_string(),
tenant_id: Some("tenant-id".to_string()),
client_id: Some("client-id".to_string()),
subscription_id: Some("subscription-id".to_string()),
resource_group: Some("resource-group".to_string()),
namespace: Some("servicebus-namespace".to_string()),
..Default::default()
};Fields§
§auth_method: StringAuthentication method: “device_code”, “client_secret”, or “connection_string”
tenant_id: Option<String>Azure AD tenant ID
client_id: Option<String>Azure AD application (client) ID
client_secret: Option<String>Azure AD application client secret (required for client_secret)
subscription_id: Option<String>Azure subscription ID for resource discovery
resource_group: Option<String>Resource group name containing the Service Bus namespace
namespace: Option<String>Service Bus namespace name
Implementations§
Source§impl AzureAdConfig
impl AzureAdConfig
Sourcepub fn tenant_id(&self) -> Result<&str, ServiceBusError>
pub fn tenant_id(&self) -> Result<&str, ServiceBusError>
Gets the Azure AD tenant ID, returning an error if not configured.
§Returns
The tenant ID as a string reference
§Errors
Returns ServiceBusError::ConfigurationError if the tenant ID is not set
Sourcepub fn client_id(&self) -> Result<&str, ServiceBusError>
pub fn client_id(&self) -> Result<&str, ServiceBusError>
Gets the Azure AD client ID, returning an error if not configured.
§Returns
The client ID as a string reference
§Errors
Returns ServiceBusError::ConfigurationError if the client ID is not set
Sourcepub fn client_secret(&self) -> Result<String, ServiceBusError>
pub fn client_secret(&self) -> Result<String, ServiceBusError>
Gets the Azure AD client secret, returning an error if not configured.
Required for client credentials authentication flow.
§Returns
The client secret as a string reference
§Errors
Returns ServiceBusError::ConfigurationError if the client secret is not set
Sourcepub fn subscription_id(&self) -> Result<String, ServiceBusError>
pub fn subscription_id(&self) -> Result<String, ServiceBusError>
Gets the Azure subscription ID from config or environment variables.
Checks the config first, then falls back to the AZURE_AD__SUBSCRIPTION_ID environment variable.
§Returns
The subscription ID as a string
§Errors
Returns ServiceBusError::ConfigurationError if the subscription ID is not found
Sourcepub fn resource_group(&self) -> Result<String, ServiceBusError>
pub fn resource_group(&self) -> Result<String, ServiceBusError>
Gets the Azure resource group name from config or environment variables.
Checks the config first, then falls back to the AZURE_AD__RESOURCE_GROUP environment variable.
§Returns
The resource group name as a string
§Errors
Returns ServiceBusError::ConfigurationError if the resource group is not found
Sourcepub fn namespace(&self) -> Result<String, ServiceBusError>
pub fn namespace(&self) -> Result<String, ServiceBusError>
Gets the Service Bus namespace name from config or environment variables.
Checks the config first, then falls back to the AZURE_AD__NAMESPACE environment variable.
§Returns
The namespace name as a string
§Errors
Returns ServiceBusError::ConfigurationError if the namespace is not found
Sourcepub fn has_tenant_id(&self) -> bool
pub fn has_tenant_id(&self) -> bool
Checks if tenant ID is configured (in config only, not environment).
§Returns
true if tenant ID is set in the configuration
Sourcepub fn has_client_id(&self) -> bool
pub fn has_client_id(&self) -> bool
Checks if client ID is configured (in config only, not environment).
§Returns
true if client ID is set in the configuration
Sourcepub fn has_client_secret(&self) -> bool
pub fn has_client_secret(&self) -> bool
Checks if client secret is configured (in config only, not environment).
§Returns
true if client secret is set in the configuration
Sourcepub fn has_subscription_id(&self) -> bool
pub fn has_subscription_id(&self) -> bool
Checks if subscription ID is available (config or environment).
§Returns
true if subscription ID is available from config or environment variables
Sourcepub fn has_resource_group(&self) -> bool
pub fn has_resource_group(&self) -> bool
Checks if resource group is available (config or environment).
§Returns
true if resource group is available from config or environment variables
Sourcepub fn has_namespace(&self) -> bool
pub fn has_namespace(&self) -> bool
Checks if namespace is available (config or environment).
§Returns
true if namespace is available from config or environment variables
Sourcepub async fn get_azure_ad_token(
&self,
http_client: &Client,
) -> Result<String, Box<dyn Error>>
pub async fn get_azure_ad_token( &self, http_client: &Client, ) -> Result<String, Box<dyn Error>>
Obtains an Azure AD access token using the configured authentication method.
This method tries different authentication approaches based on the configured auth method:
- For device code flow, attempts UI-integrated auth first
- Falls back to regular auth provider for other methods
- Returns an error for connection string auth (no Azure AD token available)
§Arguments
http_client- HTTP client for making authentication requests
§Returns
An Azure AD access token string
§Errors
Returns an error if:
- Authentication fails
- Connection string auth is used (Azure AD tokens not available)
- Required configuration is missing
Sourcepub async fn list_queues_azure_ad(
&self,
http_client: &Client,
) -> Result<Vec<String>, Box<dyn Error>>
pub async fn list_queues_azure_ad( &self, http_client: &Client, ) -> Result<Vec<String>, Box<dyn Error>>
Lists all Service Bus queues in the configured namespace using Azure AD authentication.
§Arguments
http_client- HTTP client for making API requests
§Returns
A vector of queue names
§Errors
Returns an error if:
- Authentication fails
- Azure Management API request fails
- Required configuration (subscription, resource group, namespace) is missing
Sourcepub async fn list_namespaces_azure_ad(
&self,
http_client: &Client,
) -> Result<Vec<String>, Box<dyn Error>>
pub async fn list_namespaces_azure_ad( &self, http_client: &Client, ) -> Result<Vec<String>, Box<dyn Error>>
Lists all Service Bus namespaces in the configured resource group using Azure AD authentication.
§Arguments
http_client- HTTP client for making API requests
§Returns
A vector of namespace names
§Errors
Returns an error if:
- Authentication fails
- Azure Management API request fails
- Required configuration (subscription, resource group) is missing
Trait Implementations§
Source§impl Clone for AzureAdConfig
impl Clone for AzureAdConfig
Source§fn clone(&self) -> AzureAdConfig
fn clone(&self) -> AzureAdConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more