azure

package
v2.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MSIURL             = "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=%s"
	MSIURLWithClientID = "http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=%s&client_id=%s"
)
View Source
const (
	DefaultCloud = "azurePublicCloud"

	// PrivateCloud cloud type
	PrivateCloud string = "Private"

	// DefaultEndpointSuffixKey is the default endpoint key in trigger metadata
	DefaultEndpointSuffixKey string = "endpointSuffix"

	// DefaultStorageSuffixKey is the default storage endpoint key in trigger metadata
	DefaultStorageSuffixKey string = "storageEndpointSuffix"

	// DefaultActiveDirectoryEndpointKey is the default active directory endpoint key in trigger metadata
	DefaultActiveDirectoryEndpointKey string = "activeDirectoryEndpoint"
)
View Source
const (
	DefaultAppInsightsResourceURL = "https://api.applicationinsights.io"
)
View Source
const (
	DefaultEventhubResourceURL = "https://eventhubs.azure.net/"
)

Variables

View Source
var (
	// ErrAzureConnectionStringKeyName indicates an error in the connection string AccountKey or AccountName.
	ErrAzureConnectionStringKeyName = errors.New("can't parse storage connection string. Missing key or name")

	// ErrAzureConnectionStringEndpoint indicates an error in the connection string DefaultEndpointsProtocol or EndpointSuffix.
	ErrAzureConnectionStringEndpoint = errors.New("can't parse storage connection string. Missing DefaultEndpointsProtocol or EndpointSuffix")
)
View Source
var AppInsightsResourceURLInCloud = map[string]string{
	"AZUREPUBLICCLOUD":       "https://api.applicationinsights.io",
	"AZUREUSGOVERNMENTCLOUD": "https://api.applicationinsights.us",
	"AZURECHINACLOUD":        "https://api.applicationinsights.azure.cn",
}
View Source
var DefaultAuthorityHost string
View Source
var DefaultClientID string
View Source
var DefaultTenantID string
View Source
var TokenFilePath string

Functions

func CreateAzureDataExplorerClient added in v2.7.0

func CreateAzureDataExplorerClient(metadata *DataExplorerMetadata, httpClient *http.Client) (*kusto.Client, error)

func GetAzureAppInsightsMetricValue added in v2.6.0

func GetAzureAppInsightsMetricValue(ctx context.Context, info AppInsightsInfo, podIdentity kedav1alpha1.AuthPodIdentity, ignoreNullValues bool) (float64, error)

GetAzureAppInsightsMetricValue returns the value of an Azure App Insights metric, rounded to the nearest int

func GetAzureBlobListLength

func GetAzureBlobListLength(ctx context.Context, httpClient util.HTTPDoer, podIdentity kedav1alpha1.AuthPodIdentity, meta *BlobMetadata) (int64, error)

GetAzureBlobListLength returns the count of the blobs in blob container in int

func GetAzureDataExplorerMetricValue added in v2.7.0

func GetAzureDataExplorerMetricValue(ctx context.Context, client *kusto.Client, db string, query string) (float64, error)

func GetAzureMetricValue

func GetAzureMetricValue(ctx context.Context, info MonitorInfo, podIdentity kedav1alpha1.AuthPodIdentity) (float64, error)

GetAzureMetricValue returns the value of an Azure Monitor metric, rounded to the nearest int

func GetAzureQueueLength

func GetAzureQueueLength(ctx context.Context, httpClient util.HTTPDoer, podIdentity kedav1alpha1.AuthPodIdentity, connectionString, queueName, accountName, endpointSuffix string) (int64, error)

GetAzureQueueLength returns the length of a queue in int, see https://learn.microsoft.com/en-us/azure/storage/queues/storage-dotnet-how-to-use-queues?tabs=dotnet#get-the-queue-length

func GetEventHubClient

func GetEventHubClient(ctx context.Context, info EventHubInfo) (*eventhub.Hub, error)

GetEventHubClient returns eventhub client

func NewADWorkloadIdentityCredential added in v2.9.0

func NewADWorkloadIdentityCredential(identityID, identityTenantID string) (*azidentity.WorkloadIdentityCredential, error)

func NewAzureADWorkloadIdentityConfig added in v2.8.0

func NewAzureADWorkloadIdentityConfig(ctx context.Context, identityID, identityTenantID, identityAuthorityHost, resource string) auth.AuthorizerConfig

func NewChainedCredential added in v2.9.2

func NewChainedCredential(logger logr.Logger, identityID, identityTenantID string, podIdentity v1alpha1.PodIdentityProvider) (*azidentity.ChainedTokenCredential, error)

func ParseActiveDirectoryEndpoint added in v2.7.0

func ParseActiveDirectoryEndpoint(metadata map[string]string) (string, error)

func ParseAzureEventHubConnectionString

func ParseAzureEventHubConnectionString(connectionString string) (string, string, error)

ParseAzureEventHubConnectionString parses Event Hub connection string into (namespace, name) Connection string should be in following format: Endpoint=sb://eventhub-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=secretKey123;EntityPath=eventhub-name

func ParseAzureStorageBlobConnection

func ParseAzureStorageBlobConnection(ctx context.Context, httpClient util.HTTPDoer, podIdentity kedav1alpha1.AuthPodIdentity, connectionString, accountName, endpointSuffix string) (azblob.Credential, *url.URL, error)

ParseAzureStorageBlobConnection parses blob connection string and returns credential and resource url

func ParseAzureStorageEndpointSuffix added in v2.4.0

func ParseAzureStorageEndpointSuffix(metadata map[string]string, endpointType StorageEndpointType) (string, error)

ParseAzureStorageEndpointSuffix parses cloud and endpointSuffix metadata and returns endpoint suffix

func ParseAzureStorageQueueConnection

func ParseAzureStorageQueueConnection(ctx context.Context, httpClient util.HTTPDoer, podIdentity kedav1alpha1.AuthPodIdentity, connectionString, accountName, endpointSuffix string) (azqueue.Credential, *url.URL, error)

ParseAzureStorageQueueConnection parses queue connection string and returns credential and resource url

func ParseEnvironmentProperty added in v2.7.0

func ParseEnvironmentProperty(metadata map[string]string, propertyKey string, envPropertyProvider EnvironmentPropertyProvider) (string, error)

ParseEnvironmentProperty parses cloud metadata and returns the resolved property

func TryAndGetAzureManagedPrometheusHTTPRoundTripper added in v2.10.0

func TryAndGetAzureManagedPrometheusHTTPRoundTripper(logger logr.Logger, podIdentity kedav1alpha1.AuthPodIdentity, triggerMetadata map[string]string) (http.RoundTripper, error)

TryAndGetAzureManagedPrometheusHTTPRoundTripper tries to get a round tripper. If the pod identity represents azure auth, it creates a round tripper and returns that. Returns error if fails to create one. If its not azure auth, then this becomes a no-op. Neither returns round tripper nor error.

Types

type AADToken

type AADToken struct {
	AccessToken         string    `json:"access_token"`
	RefreshToken        string    `json:"refresh_token"`
	ExpiresIn           string    `json:"expires_in"`
	ExpiresOn           string    `json:"expires_on"`
	ExpiresOnTimeObject time.Time `json:"expires_on_object"`
	NotBefore           string    `json:"not_before"`
	Resource            string    `json:"resource"`
	TokenType           string    `json:"token_type"`
	GrantedScopes       []string  `json:"grantedScopes"`
	DeclinedScopes      []string  `json:"DeclinedScopes"`
}

AADToken is the token from Azure AD

func GetAzureADPodIdentityToken

func GetAzureADPodIdentityToken(ctx context.Context, httpClient util.HTTPDoer, identityID, audience string) (AADToken, error)

GetAzureADPodIdentityToken returns the AADToken for resource

func GetAzureADWorkloadIdentityToken added in v2.8.0

func GetAzureADWorkloadIdentityToken(ctx context.Context, identityID, identityTenantID, identityAuthorityHost, resource string) (AADToken, error)

GetAzureADWorkloadIdentityToken returns the AADToken for resource

type ADWorkloadIdentityConfig added in v2.8.0

type ADWorkloadIdentityConfig struct {
	IdentityID            string
	IdentityTenantID      string
	IdentityAuthorityHost string
	Resource              string
	// contains filtered or unexported fields
}

func (ADWorkloadIdentityConfig) Authorizer added in v2.8.0

func (aadWiConfig ADWorkloadIdentityConfig) Authorizer() (autorest.Authorizer, error)

Authorizer implements the auth.AuthorizerConfig interface

type ADWorkloadIdentityTokenProvider added in v2.8.0

type ADWorkloadIdentityTokenProvider struct {
	IdentityID            string
	IdentityTenantID      string
	IdentityAuthorityHost string
	Resource              string
	// contains filtered or unexported fields
}

ADWorkloadIdentityTokenProvider is a type that implements the adal.OAuthTokenProvider and adal.Refresher interfaces. The OAuthTokenProvider interface is used by the BearerAuthorizer to get the token when preparing the HTTP Header. The Refresher interface is used by the BearerAuthorizer to refresh the token.

func NewAzureADWorkloadIdentityTokenProvider added in v2.8.0

func NewAzureADWorkloadIdentityTokenProvider(ctx context.Context, identityID, identityTenantID, identityAuthorityHost, resource string) *ADWorkloadIdentityTokenProvider

func (*ADWorkloadIdentityTokenProvider) EnsureFresh added in v2.8.0

func (wiTokenProvider *ADWorkloadIdentityTokenProvider) EnsureFresh() error

EnsureFresh is for implementing the adal.Refresher interface

func (*ADWorkloadIdentityTokenProvider) GetToken added in v2.8.0

func (wiTokenProvider *ADWorkloadIdentityTokenProvider) GetToken(_ string) (*amqpAuth.Token, error)

GetToken is for implementing the auth.TokenProvider interface

func (*ADWorkloadIdentityTokenProvider) OAuthToken added in v2.8.0

func (wiTokenProvider *ADWorkloadIdentityTokenProvider) OAuthToken() string

OAuthToken is for implementing the adal.OAuthTokenProvider interface. It returns the current access token.

func (*ADWorkloadIdentityTokenProvider) Refresh added in v2.8.0

func (wiTokenProvider *ADWorkloadIdentityTokenProvider) Refresh() error

Refresh is for implementing the adal.Refresher interface

func (*ADWorkloadIdentityTokenProvider) RefreshExchange added in v2.8.0

func (wiTokenProvider *ADWorkloadIdentityTokenProvider) RefreshExchange(resource string) error

RefreshExchange is for implementing the adal.Refresher interface

type AppInsightsInfo added in v2.6.0

type AppInsightsInfo struct {
	ApplicationInsightsID   string
	TenantID                string
	MetricID                string
	AggregationTimespan     string
	AggregationType         string
	Filter                  string
	ClientID                string
	ClientPassword          string
	AppInsightsResourceURL  string
	ActiveDirectoryEndpoint string
}

type ApplicationInsightsMetric added in v2.6.0

type ApplicationInsightsMetric struct {
	Value map[string]interface{}
}

type BlobMetadata added in v2.7.0

type BlobMetadata struct {
	TargetBlobCount           int64
	ActivationTargetBlobCount int64
	BlobContainerName         string
	BlobDelimiter             string
	BlobPrefix                string
	Connection                string
	AccountName               string
	EndpointSuffix            string
	TriggerIndex              int
	GlobPattern               *glob.Glob
}

type Checkpoint

type Checkpoint struct {
	PartitionID    string `json:"PartitionId"`
	SequenceNumber int64  `json:"SequenceNumber"`
}

Checkpoint in a common format

func GetCheckpointFromBlobStorage

func GetCheckpointFromBlobStorage(ctx context.Context, httpClient util.HTTPDoer, info EventHubInfo, partitionID string) (Checkpoint, error)

GetCheckpointFromBlobStorage reads depending of the CheckpointStrategy the checkpoint from a azure storage

func NewCheckpoint added in v2.13.0

func NewCheckpoint(sequenceNumber int64) Checkpoint

type DataExplorerMetadata added in v2.7.0

type DataExplorerMetadata struct {
	ClientID                string
	ClientSecret            string
	DatabaseName            string
	Endpoint                string
	MetricName              string
	PodIdentity             kedav1alpha1.AuthPodIdentity
	Query                   string
	TenantID                string
	Threshold               float64
	ActivationThreshold     float64
	ActiveDirectoryEndpoint string
}

type EnvironmentPropertyProvider added in v2.7.0

type EnvironmentPropertyProvider func(env az.Environment) (string, error)

EnvironmentPropertyProvider for different types of Azure scalers

type EventHubInfo

type EventHubInfo struct {
	EventHubConnection       string
	EventHubConsumerGroup    string
	StorageConnection        string
	StorageAccountName       string
	BlobStorageEndpoint      string
	BlobContainer            string
	Namespace                string
	EventHubName             string
	CheckpointStrategy       string
	ServiceBusEndpointSuffix string
	ActiveDirectoryEndpoint  string
	EventHubResourceURL      string
	PodIdentity              kedav1alpha1.AuthPodIdentity
}

EventHubInfo to keep event hub connection and resources

type ManagedIdentityWrapper added in v2.9.2

type ManagedIdentityWrapper struct {
	// contains filtered or unexported fields
}

func ManagedIdentityWrapperCredential added in v2.9.2

func ManagedIdentityWrapperCredential(clientID string) (*ManagedIdentityWrapper, error)

func (*ManagedIdentityWrapper) GetToken added in v2.9.2

type MonitorInfo

type MonitorInfo struct {
	ResourceURI                  string
	TenantID                     string
	SubscriptionID               string
	ResourceGroupName            string
	Name                         string
	Namespace                    string
	Filter                       string
	AggregationInterval          string
	AggregationType              string
	ClientID                     string
	ClientPassword               string
	AzureResourceManagerEndpoint string
	ActiveDirectoryEndpoint      string
}

MonitorInfo to create metric request

type StorageEndpointType

type StorageEndpointType int

StorageEndpointType for different types of storage provided by Azure

const (
	// BlobEndpoint storage type
	BlobEndpoint StorageEndpointType = iota
	// QueueEndpoint storage type
	QueueEndpoint
	// TableEndpoint storage type
	TableEndpoint
	// FileEndpoint storage type
	FileEndpoint
)

func (StorageEndpointType) GetEndpointSuffix added in v2.4.0

func (e StorageEndpointType) GetEndpointSuffix(environment az.Environment) string

GetEndpointSuffix returns the endpoint suffix for a StorageEndpointType based on the specified environment

func (StorageEndpointType) Name

func (e StorageEndpointType) Name() string

Name returns resource name for StorageEndpointType

func (StorageEndpointType) Prefix

func (e StorageEndpointType) Prefix() string

Prefix returns prefix for a StorageEndpointType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL