Documentation
¶
Index ¶
- Constants
- Variables
- func ApplySubscriptionFilter(subscriptions []account.Subscription, filterIds []string) ([]account.Subscription, bool)
- func FilterSubscriptionsByTenantId(subscriptions []account.Subscription, tenantId string) []account.Subscription
- func FormatSubscriptionDisplay(subscription *account.Subscription, hideId bool) string
- func FormatTenantDisplay(index int, t TenantInfo) string
- func IsDemoModeEnabled() bool
- func LoadSubscriptionFilter(cfg config.Config, tenantId string) ([]string, bool)
- func PromptCustomResource[T any](ctx context.Context, options CustomResourceOptions[T]) (*T, error)
- func RemoveSubscriptionFilter(cfg config.Config, tenantId string) error
- func SaveSubscriptionFilter(cfg config.Config, tenantId string, subscriptionIds []string) error
- type AuthManager
- type AzureContext
- type AzureResourceList
- func (arl *AzureResourceList) Add(resourceId string) error
- func (arl *AzureResourceList) Find(predicate func(resourceId *arm.ResourceID) bool) (*arm.ResourceID, bool)
- func (arl *AzureResourceList) FindAll(predicate func(resourceId *arm.ResourceID) bool) ([]*arm.ResourceID, bool)
- func (arl *AzureResourceList) FindAllByType(resourceType azapi.AzureResourceType) ([]*arm.ResourceID, bool)
- func (arl *AzureResourceList) FindById(resourceId string) (*arm.ResourceID, bool)
- func (arl *AzureResourceList) FindByType(resourceType azapi.AzureResourceType) (*arm.ResourceID, bool)
- func (arl *AzureResourceList) FindByTypeAndKind(ctx context.Context, resourceType azapi.AzureResourceType, kinds []string) (*arm.ResourceID, bool)
- func (arl *AzureResourceList) FindByTypeAndName(resourceType azapi.AzureResourceType, resourceName string) (*arm.ResourceID, bool)
- type AzureScope
- type CustomResourceOptions
- type DefaultPrompter
- func (p *DefaultPrompter) IsNoPromptMode() bool
- func (p *DefaultPrompter) PromptLocation(ctx context.Context, subId string, msg string, filter LocationFilterPredicate, ...) (string, error)
- func (p *DefaultPrompter) PromptResourceGroup(ctx context.Context, options PromptResourceOptions) (string, error)
- func (p *DefaultPrompter) PromptResourceGroupFrom(ctx context.Context, subscriptionId string, location string, ...) (string, error)
- func (p *DefaultPrompter) PromptSubscription(ctx context.Context, msg string) (subscriptionId string, err error)
- type LocationFilterPredicate
- type PromptResourceGroupFromOptions
- type PromptResourceOptions
- type PromptService
- type Prompter
- type ResourceGroupOptions
- type ResourceOptions
- type ResourceService
- type SelectOptions
- type SubscriptionManager
- type TenantDisplayNameProvider
- type TenantInfo
Constants ¶
const FilteredSubscriptionNote = "Using saved subscription filter." +
" Run 'azd config sub-filter set' to update."
FilteredSubscriptionNote is the message shown when a subscription filter is active.
const ShowAllSubscriptionsOption = "Show all subscriptions"
ShowAllSubscriptionsOption is the sentinel option text appended to filtered lists.
Variables ¶
var ( ErrNoResourcesFound = fmt.Errorf("no resources found") ErrNoResourceSelected = fmt.Errorf("no resource selected") )
Functions ¶
func ApplySubscriptionFilter ¶ added in v1.26.0
func ApplySubscriptionFilter( subscriptions []account.Subscription, filterIds []string, ) ([]account.Subscription, bool)
ApplySubscriptionFilter filters subscriptions to only those whose IDs are in the given filter list. Returns the filtered list and true if a filter was applied. If filterIds is nil or empty, returns the original list unchanged.
func FilterSubscriptionsByTenantId ¶ added in v1.26.0
func FilterSubscriptionsByTenantId( subscriptions []account.Subscription, tenantId string, ) []account.Subscription
FilterSubscriptionsByTenantId filters subscriptions to only those accessible through the specified tenant ID. If tenantId is empty, all subscriptions are returned.
func FormatSubscriptionDisplay ¶ added in v1.26.0
func FormatSubscriptionDisplay(subscription *account.Subscription, hideId bool) string
FormatSubscriptionDisplay formats a subscription for display in selection prompts.
func FormatTenantDisplay ¶ added in v1.26.0
func FormatTenantDisplay(index int, t TenantInfo) string
FormatTenantDisplay formats a tenant option for display in selection prompts.
func IsDemoModeEnabled ¶ added in v1.26.0
func IsDemoModeEnabled() bool
IsDemoModeEnabled checks if AZD_DEMO_MODE is enabled.
func LoadSubscriptionFilter ¶ added in v1.26.0
LoadSubscriptionFilter loads the saved subscription filter for the given tenant from user config. Returns the list of subscription IDs and whether a filter exists.
func PromptCustomResource ¶
func PromptCustomResource[T any](ctx context.Context, options CustomResourceOptions[T]) (*T, error)
PromptCustomResource prompts the user to select a custom resource from a list of resources. This function is used internally to power selection of subscriptions, resource groups and other resources. This can be used directly when the list of resources require integration with other Azure SDKs for resource selection.
func RemoveSubscriptionFilter ¶ added in v1.26.0
RemoveSubscriptionFilter removes the subscription filter for the given tenant from user config. Returns an error if tenantId is empty.
Types ¶
type AuthManager ¶
type AuthManager interface {
ClaimsForCurrentUser(ctx context.Context, options *auth.ClaimsForCurrentUserOptions) (auth.TokenClaims, error)
}
type AzureContext ¶
type AzureContext struct {
Scope AzureScope
Resources *AzureResourceList
// contains filtered or unexported fields
}
AzureContext contains the Scope and list of Resources from an Azure deployment.
func NewAzureContext ¶
func NewAzureContext( promptService PromptService, scope AzureScope, resourceList *AzureResourceList, noPrompt bool, ) *AzureContext
NewAzureContext creates a new Azure context.
func NewEmptyAzureContext ¶
func NewEmptyAzureContext() *AzureContext
NewEmptyAzureContext creates a new empty Azure context.
func (*AzureContext) EnsureLocation ¶
func (pc *AzureContext) EnsureLocation(ctx context.Context) error
EnsureLocation ensures that the Azure context has a location. If the location is not set, the user is prompted to select a location.
func (*AzureContext) EnsureResourceGroup ¶
func (pc *AzureContext) EnsureResourceGroup(ctx context.Context) error
EnsureResourceGroup ensures that the Azure context has a resource group. If the resource group is not set, the user is prompted to select a resource group.
func (*AzureContext) EnsureSubscription ¶
func (pc *AzureContext) EnsureSubscription(ctx context.Context) error
EnsureSubscription ensures that the Azure context has a subscription. If the subscription is not set, the user is prompted to select a subscription.
type AzureResourceList ¶
type AzureResourceList struct {
// contains filtered or unexported fields
}
AzureResourceList contains a list of Azure resources.
func NewAzureResourceList ¶
func NewAzureResourceList(resourceService ResourceService, resources []*arm.ResourceID) *AzureResourceList
NewAzureResourceList creates a new Azure resource list.
func (*AzureResourceList) Add ¶
func (arl *AzureResourceList) Add(resourceId string) error
Add adds an Azure resource to the list.
func (*AzureResourceList) Find ¶
func (arl *AzureResourceList) Find(predicate func(resourceId *arm.ResourceID) bool) (*arm.ResourceID, bool)
Find finds the first Azure resource matched by the predicate function.
func (*AzureResourceList) FindAll ¶
func (arl *AzureResourceList) FindAll(predicate func(resourceId *arm.ResourceID) bool) ([]*arm.ResourceID, bool)
FindAll finds all Azure resources matched by the predicate function.
func (*AzureResourceList) FindAllByType ¶
func (arl *AzureResourceList) FindAllByType(resourceType azapi.AzureResourceType) ([]*arm.ResourceID, bool)
FindAllByType finds all Azure resources by the specified type.
func (*AzureResourceList) FindById ¶
func (arl *AzureResourceList) FindById(resourceId string) (*arm.ResourceID, bool)
FindById finds the first Azure resource by the specified ID.
func (*AzureResourceList) FindByType ¶
func (arl *AzureResourceList) FindByType(resourceType azapi.AzureResourceType) (*arm.ResourceID, bool)
FindByType finds the first Azure resource by the specified type.
func (*AzureResourceList) FindByTypeAndKind ¶
func (arl *AzureResourceList) FindByTypeAndKind( ctx context.Context, resourceType azapi.AzureResourceType, kinds []string, ) (*arm.ResourceID, bool)
FindByTypeAndKind finds the first Azure resource by the specified type and kind.
func (*AzureResourceList) FindByTypeAndName ¶
func (arl *AzureResourceList) FindByTypeAndName( resourceType azapi.AzureResourceType, resourceName string, ) (*arm.ResourceID, bool)
FindByTypeAndName finds the first Azure resource by the specified type and name.
type AzureScope ¶
type AzureScope struct {
TenantId string
SubscriptionId string
Location string
ResourceGroup string
}
Azure Scope contains the high level metadata about an Azure deployment.
type CustomResourceOptions ¶
type CustomResourceOptions[T any] struct { // SelectorOptions contains options for the resource selector. SelectorOptions *SelectOptions // LoadData is a function that loads the resource data. LoadData func(ctx context.Context) ([]*T, error) // DisplayResource is a function that displays the resource. DisplayResource func(resource *T) (string, error) // SortResource is a function that sorts the resources. SortResource func(a *T, b *T) int // Selected is a function that determines if a resource is selected Selected func(resource *T) bool // NewResourceValue is the default value returned when creating a new resource. NewResourceValue T }
CustomResourceOptions contains options for prompting the user to select a custom resource.
type DefaultPrompter ¶
type DefaultPrompter struct {
// contains filtered or unexported fields
}
func (*DefaultPrompter) IsNoPromptMode ¶ added in v1.24.2
func (p *DefaultPrompter) IsNoPromptMode() bool
func (*DefaultPrompter) PromptLocation ¶
func (p *DefaultPrompter) PromptLocation( ctx context.Context, subId string, msg string, filter LocationFilterPredicate, defaultLocation *string, ) (string, error)
func (*DefaultPrompter) PromptResourceGroup ¶
func (p *DefaultPrompter) PromptResourceGroup(ctx context.Context, options PromptResourceOptions) (string, error)
func (*DefaultPrompter) PromptResourceGroupFrom ¶
func (p *DefaultPrompter) PromptResourceGroupFrom( ctx context.Context, subscriptionId string, location string, options PromptResourceGroupFromOptions) (string, error)
func (*DefaultPrompter) PromptSubscription ¶
type LocationFilterPredicate ¶
type PromptResourceOptions ¶
type PromptResourceOptions struct {
// DisableCreateNew disables the option to create a new resource group.
DisableCreateNew bool
// DefaultName is the default name to use when creating a new resource group.
// If not specified, the default name will be generated based on the environment name.
DefaultName string
}
type PromptService ¶
type PromptService interface {
PromptSubscription(ctx context.Context, selectorOptions *SelectOptions) (*account.Subscription, error)
PromptLocation(
ctx context.Context,
azureContext *AzureContext,
selectorOptions *SelectOptions,
) (*account.Location, error)
PromptResourceGroup(
ctx context.Context,
azureContext *AzureContext,
options *ResourceGroupOptions,
) (*azapi.ResourceGroup, error)
PromptSubscriptionResource(
ctx context.Context,
azureContext *AzureContext,
options ResourceOptions,
) (*azapi.ResourceExtended, error)
PromptResourceGroupResource(
ctx context.Context,
azureContext *AzureContext,
options ResourceOptions,
) (*azapi.ResourceExtended, error)
}
PromptServiceInterface defines the methods that the PromptService must implement.
func NewPromptService ¶
func NewPromptService( authManager AuthManager, console input.Console, userConfigManager config.UserConfigManager, subscriptionManager SubscriptionManager, resourceService ResourceService, ) PromptService
NewPromptService creates a new prompt service.
type Prompter ¶
type Prompter interface {
PromptSubscription(ctx context.Context, msg string) (subscriptionId string, err error)
PromptLocation(
ctx context.Context,
subId string,
msg string,
filter LocationFilterPredicate,
defaultLocation *string) (string, error)
// PromptResourceGroup prompts for an existing or optionally a new resource group.
// A location saved as AZURE_LOCATION is also prompted as part of creating a new resource group.
PromptResourceGroup(ctx context.Context, options PromptResourceOptions) (string, error)
// PromptResourceGroupFrom is like PromptResourceGroup, but it takes an existing subscription ID and location.
PromptResourceGroupFrom(
ctx context.Context, subscriptionId string, location string, options PromptResourceGroupFromOptions) (string, error)
// IsNoPromptMode returns true when --no-prompt is active and interactive prompts are disabled.
IsNoPromptMode() bool
}
func NewDefaultPrompter ¶
func NewDefaultPrompter( env *environment.Environment, console input.Console, accountManager account.Manager, userConfigManager config.UserConfigManager, resourceService *azapi.ResourceService, cloud *cloud.Cloud, ) Prompter
type ResourceGroupOptions ¶
type ResourceGroupOptions struct {
// SelectorOptions contains options for the resource group selector.
SelectorOptions *SelectOptions
}
ResourceGroupOptions contains options for prompting the user to select a resource group.
type ResourceOptions ¶
type ResourceOptions struct {
// ResourceType is the type of resource to select.
ResourceType *azapi.AzureResourceType
// Kinds is a list of resource kinds to filter by.
Kinds []string
// ResourceTypeDisplayName is the display name of the resource type.
ResourceTypeDisplayName string
// SelectorOptions contains options for the resource selector.
SelectorOptions *SelectOptions
// Selected is a function that determines if a resource is selected
Selected func(resource *azapi.ResourceExtended) bool
}
ResourceOptions contains options for prompting the user to select a resource.
type ResourceService ¶
type ResourceService interface {
ListResourceGroup(
ctx context.Context,
subscriptionId string,
listOptions *azapi.ListResourceGroupOptions,
) ([]*azapi.Resource, error)
ListResourceGroupResources(
ctx context.Context,
subscriptionId string,
resourceGroupName string,
listOptions *azapi.ListResourceGroupResourcesOptions,
) ([]*azapi.ResourceExtended, error)
ListSubscriptionResources(
ctx context.Context,
subscriptionId string,
listOptions *armresources.ClientListOptions,
) ([]*azapi.ResourceExtended, error)
CreateOrUpdateResourceGroup(
ctx context.Context,
subscriptionId string,
resourceGroupName string,
location string,
tags map[string]*string,
) (*azapi.ResourceGroup, error)
GetResource(
ctx context.Context,
subscriptionId string,
resourceId string,
apiVersion string,
) (azapi.ResourceExtended, error)
}
ResourceService defines the methods that the ResourceService must implement.
type SelectOptions ¶
type SelectOptions struct {
// ForceNewResource specifies whether to force the user to create a new resource.
ForceNewResource *bool
// AllowNewResource specifies whether to allow the user to create a new resource.
AllowNewResource *bool
// NewResourceMessage is the message to display to the user when creating a new resource.
NewResourceMessage string
// Message is the message to display to the user.
Message string
// HelpMessage is the help message to display to the user.
HelpMessage string
// LoadingMessage is the loading message to display to the user.
LoadingMessage string
// SkipLoadingSpinner skips the loading spinner in PromptCustomResource.
// Use this when data is pre-loaded and LoadData returns immediately.
SkipLoadingSpinner bool
// DisplayNumbers specifies whether to display numbers next to the choices.
DisplayNumbers *bool
// DisplayCount is the number of choices to display at a time.
DisplayCount int
// Hint is the hint to display to the user.
Hint string
// EnableFiltering specifies whether to enable filtering of choices.
EnableFiltering *bool
// AllowedValues limits candidates for prompts that support value filtering,
// such as PromptLocation.
AllowedValues []string
// Writer is the writer to use for output.
Writer io.Writer
}
SelectOptions contains options for prompting the user to select a resource.
type SubscriptionManager ¶
type SubscriptionManager interface {
GetSubscriptions(ctx context.Context) ([]account.Subscription, error)
GetLocations(ctx context.Context, subscriptionId string) ([]account.Location, error)
GetTenantDisplayNames(ctx context.Context) (map[string]string, error)
}
SubscriptionManager defines the methods that the SubscriptionManager must implement.
type TenantDisplayNameProvider ¶ added in v1.25.1
TenantDisplayNameProvider is a function that fetches tenant display names.
type TenantInfo ¶ added in v1.26.0
type TenantInfo struct {
// Id is the tenant ID (GUID).
Id string
// DisplayName is the friendly name of the tenant, or the ID if no name is available.
DisplayName string
// SubscriptionCount is the number of subscriptions accessible via this tenant.
SubscriptionCount int
}
TenantInfo holds display metadata for a tenant extracted from the subscription list.
func ExtractUniqueTenants ¶ added in v1.26.0
func ExtractUniqueTenants( subscriptions []account.Subscription, tenantDisplayNames map[string]string, ) []TenantInfo
ExtractUniqueTenants extracts unique tenants from a list of subscriptions, grouped by UserAccessTenantId (falling back to TenantId when UserAccessTenantId is empty). The returned list is sorted by DisplayName. Tenant display names are resolved from the provided tenantDisplayNames map; if a tenant ID is not in the map, the ID itself is used as the display name.