Documentation
¶
Index ¶
- Variables
- type Azure
- func (a Azure) ArmToken(ctx context.Context) (string, error)
- func (a *Azure) Authenticate(ctx context.Context, interactive bool) error
- func (a Azure) FetchLogStreamAuthToken(ctx context.Context, resourceGroup, resourcePath, apiVersion string) (string, error)
- func (a Azure) NewBlobContainersClient() (*armstorage.BlobContainersClient, error)
- func (a Azure) NewCreds() (azcore.TokenCredential, error)
- func (a Azure) NewStorageAccountsClient() (*armstorage.AccountsClient, error)
- type Location
Constants ¶
This section is empty.
Variables ¶
var ManagementEndpoint = "https://management.azure.com"
ManagementEndpoint is the base URL for Azure Resource Manager REST calls. It is exposed as a variable so tests can swap in an httptest.Server URL.
var NewCredsFunc = func(a Azure) (azcore.TokenCredential, error) { if a.Cred != nil { return a.Cred, nil } if len(a.SubscriptionID) == 0 { return nil, errors.New("environment variable AZURE_SUBSCRIPTION_ID is not set") } cred, err := azidentity.NewDefaultAzureCredential(nil) if err != nil { return nil, fmt.Errorf("failed to create default Azure credentials: %w", err) } return &tokenCredentialWithTimeout{cred: cred, timeout: cliTimeout}, nil }
NewCredsFunc builds a TokenCredential for ARM calls. Tests can override this to inject a fake credential; the default implementation returns any cred populated by Authenticate, falling back to DefaultAzureCredential.
var PollOptions = &runtime.PollUntilDoneOptions{Frequency: 2 * time.Second}
Functions ¶
This section is empty.
Types ¶
type Azure ¶
type Azure struct {
Location Location
SubscriptionID string
// Cred is populated by Authenticate and, when non-nil, is returned by
// NewCreds instead of building a fresh DefaultAzureCredential.
Cred azcore.TokenCredential
// TokenStore persists the AuthenticationRecord returned by the
// device-code flow so future invocations can silently reuse the user's
// session (the actual refresh token lives in the OS-level token cache,
// not the TokenStore).
TokenStore tokenstore.TokenStore
}
func (Azure) ArmToken ¶
ArmToken returns a Bearer token scoped to the Azure management endpoint, suitable for direct REST API calls that the ARM SDK does not expose.
func (*Azure) Authenticate ¶
Authenticate sets up Azure credentials for the session in order of preference:
- GitHub Actions OIDC — when ACTIONS_ID_TOKEN_REQUEST_URL is set and the stack file's AZURE_CLIENT_ID + AZURE_TENANT_ID identify a federated UAMI, exchange the GitHub OIDC token for an ARM token. Mirrors the GCP path in pkg/clouds/gcp/login.go::findGithubCredentials.
- Existing default Azure credentials — env vars (AZURE_TENANT_ID/CLIENT_ID/ CLIENT_SECRET), managed identity, workload identity, an `az login` session picked up via AzureCLICredential, etc.
- Silent token acquisition via MSAL, using its on-disk cache (persisted through defang's TokenStore). Covers the common case of a returning user with a still-valid refresh token.
- Interactive device-code login (equivalent to `az login --use-device-code`). On success the refresh token is written to the cache so step 2 works on the next invocation.
On success a.Cred is populated with an msalCred (for path 2/3), a ClientAssertionCredential (path 0), or a DefaultAzureCredential wrapper (path 1). All honor per-scope GetToken requests from the Azure SDK.
func (Azure) FetchLogStreamAuthToken ¶
func (a Azure) FetchLogStreamAuthToken(ctx context.Context, resourceGroup, resourcePath, apiVersion string) (string, error)
FetchLogStreamAuthToken POSTs to the `getAuthToken` action on an ACA resource (container app or job) and returns the short-lived token that the resource's log-stream endpoint accepts. resourcePath is the segment after "providers/", e.g. "Microsoft.App/containerApps/{name}" or "Microsoft.App/jobs/{name}".
func (Azure) NewBlobContainersClient ¶
func (a Azure) NewBlobContainersClient() (*armstorage.BlobContainersClient, error)
func (Azure) NewStorageAccountsClient ¶
func (a Azure) NewStorageAccountsClient() (*armstorage.AccountsClient, error)
type Location ¶
type Location string
const ( LocationAsia Location = "asia" LocationAsiaPacific Location = "asiapacific" LocationAustralia Location = "australia" LocationAustraliaCentral Location = "australiacentral" LocationAustraliaCentral2 Location = "australiacentral2" LocationAustraliaEast Location = "australiaeast" LocationAustraliaSouthEast Location = "australiasoutheast" LocationAustriaEast Location = "austriaeast" LocationBrazil Location = "brazil" LocationBrazilSouth Location = "brazilsouth" LocationBrazilSouthEast Location = "brazilsoutheast" LocationBrazilUS Location = "brazilus" LocationCanada Location = "canada" LocationCanadaCentral Location = "canadacentral" LocationCanadaEast Location = "canadaeast" LocationCentralIndia Location = "centralindia" LocationCentralUS Location = "centralus" LocationCentralUSEuap Location = "centraluseuap" LocationCentralUSStage Location = "centralusstage" LocationChileCentral Location = "chilecentral" LocationEastAsia Location = "eastasia" LocationEastAsiaStage Location = "eastasiastage" LocationEastUS Location = "eastus" LocationEastUS2 Location = "eastus2" LocationEastUS2Euap Location = "eastus2euap" LocationEastUS2Stage Location = "eastus2stage" LocationEastUSStage Location = "eastusstage" LocationEastUSStg Location = "eastusstg" LocationEurope Location = "europe" LocationFrance Location = "france" LocationFranceCentral Location = "francecentral" LocationFranceSouth Location = "francesouth" LocationGermany Location = "germany" LocationGermanyNorth Location = "germanynorth" LocationGermanyWestCentral Location = "germanywestcentral" LocationGlobal Location = "global" LocationIndia Location = "india" LocationIndonesia Location = "indonesia" LocationIndonesiaCentral Location = "indonesiacentral" LocationIsrael Location = "israel" LocationIsraelCentral Location = "israelcentral" LocationItaly Location = "italy" LocationItalyNorth Location = "italynorth" LocationJapan Location = "japan" LocationJapanEast Location = "japaneast" LocationJapanWest Location = "japanwest" LocationJioIndiaCentral Location = "jioindiacentral" LocationJioIndiaWest Location = "jioindiawest" LocationKorea Location = "korea" LocationKoreaCentral Location = "koreacentral" LocationKoreaSouth Location = "koreasouth" LocationMalaysia Location = "malaysia" LocationMalaysiaWest Location = "malaysiawest" LocationMexico Location = "mexico" LocationMexicoCentral Location = "mexicocentral" LocationNewZealand Location = "newzealand" LocationNewZealandNorth Location = "newzealandnorth" LocationNorthCentralUS Location = "northcentralus" LocationNorthCentralUSStage Location = "northcentralusstage" LocationNorthEurope Location = "northeurope" LocationNorway Location = "norway" LocationNorwayEast Location = "norwayeast" LocationNorwayWest Location = "norwaywest" LocationPoland Location = "poland" LocationPolandCentral Location = "polandcentral" LocationQatar Location = "qatar" LocationQatarCentral Location = "qatarcentral" LocationSingapore Location = "singapore" LocationSouthAfrica Location = "southafrica" LocationSouthAfricaNorth Location = "southafricanorth" LocationSouthAfricaWest Location = "southafricawest" LocationSouthCentralUS Location = "southcentralus" LocationSouthCentralUSStage Location = "southcentralusstage" LocationSouthCentralUSStg Location = "southcentralusstg" LocationSoutheastAsia Location = "southeastasia" LocationSoutheastAsiaStage Location = "southeastasiastage" LocationSouthIndia Location = "southindia" LocationSpain Location = "spain" LocationSpainCentral Location = "spaincentral" LocationSweden Location = "sweden" LocationSwedenCentral Location = "swedencentral" LocationSwedenSouth Location = "swedensouth" LocationSwitzerland Location = "switzerland" LocationSwitzerlandNorth Location = "switzerlandnorth" LocationSwitzerlandWest Location = "switzerlandwest" LocationTaiwan Location = "taiwan" LocationUae Location = "uae" LocationUaeCentral Location = "uaecentral" LocationUaeNorth Location = "uaenorth" LocationUK Location = "uk" LocationUKSouth Location = "uksouth" LocationUKWest Location = "ukwest" LocationUnitedStates Location = "unitedstates" LocationUnitedStatesEuap Location = "unitedstateseuap" LocationWestCentralUS Location = "westcentralus" LocationWestEurope Location = "westeurope" LocationWestIndia Location = "westindia" LocationWestUS Location = "westus" LocationWestUS2 Location = "westus2" LocationWestUS2Stage Location = "westus2stage" LocationWestUS3 Location = "westus3" LocationWestUSStage Location = "westusstage" )