Skip to content

Commit

Permalink
tier: Add support of service principal to Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis Elleuch committed Dec 7, 2023
1 parent 9ef2480 commit bd33148
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tier-azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ package madmin

//go:generate msgp -file $GOFILE

type ServicePrincipalAuth struct {
TenantID string `json:",omitempty"`
ClientID string `json:",omitempty"`
ClientSecret string `json:",omitempty"`
}

// TierAzure represents the remote tier configuration for Azure Blob Storage.
type TierAzure struct {
Endpoint string `json:",omitempty"`
Expand All @@ -30,11 +36,27 @@ type TierAzure struct {
Prefix string `json:",omitempty"`
Region string `json:",omitempty"`
StorageClass string `json:",omitempty"`

SPAuth ServicePrincipalAuth `json:",omitempty"`
}

func (ti TierAzure) IsServicePrincipalEnabled() bool {
return ti.SPAuth.TenantID != "" || ti.SPAuth.ClientID != "" || ti.SPAuth.ClientSecret != ""
}

// AzureOptions supports NewTierAzure to take variadic options
type AzureOptions func(*TierAzure) error

// AzureServicePrincipal helper to supply optional service principal credentials
func AzureServicePrincipal(tenantID, clientID, clientSecret string) func(az *TierAzure) error {
return func(az *TierAzure) error {
az.SPAuth.TenantID = tenantID
az.SPAuth.ClientID = clientID
az.SPAuth.ClientSecret = clientSecret
return nil
}
}

// AzurePrefix helper to supply optional object prefix to NewTierAzure
func AzurePrefix(prefix string) func(az *TierAzure) error {
return func(az *TierAzure) error {
Expand Down

0 comments on commit bd33148

Please sign in to comment.