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 f6947e9
Show file tree
Hide file tree
Showing 4 changed files with 425 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/vulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ 1.21.4 ]
go-version: [ 1.21.5 ]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
Expand Down
23 changes: 23 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,28 @@ type TierAzure struct {
Prefix string `json:",omitempty"`
Region string `json:",omitempty"`
StorageClass string `json:",omitempty"`

SPAuth ServicePrincipalAuth `json:",omitempty"`
}

// IsSPEnabled returns true if some SP related fields are provided
func (ti TierAzure) IsSPEnabled() 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
293 changes: 288 additions & 5 deletions tier-azure_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f6947e9

Please sign in to comment.