Documentation ¶
Index ¶
- Variables
- func PromptCustomResource[T any](ctx context.Context, options CustomResourceOptions[T]) (*T, 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) 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 SubscriptionService
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoResourcesFound = fmt.Errorf("no resources found") ErrNoResourceSelected = fmt.Errorf("no resource selected") )
Functions ¶
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.
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, ) *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 // CreateResource is a function that creates a new resource. CreateResource func(ctx context.Context) (*T, error) }
CustomResourceOptions contains options for prompting the user to select a custom resource.
type DefaultPrompter ¶
type DefaultPrompter struct {
// contains filtered or unexported fields
}
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 bool
}
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, userConfigManager config.UserConfigManager, subscriptionService SubscriptionService, 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(ctx context.Context, options PromptResourceOptions) (string, error) PromptResourceGroupFrom( ctx context.Context, subscriptionId string, location string, options PromptResourceGroupFromOptions) (string, error) }
func NewDefaultPrompter ¶
func NewDefaultPrompter( env *environment.Environment, console input.Console, accountManager account.Manager, 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 // CreateResource is a function that creates a new resource. CreateResource func(ctx context.Context) (*azapi.ResourceExtended, error) // 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 // CreatingMessage is the message to display to the user when creating a new resource. CreatingMessage 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 // 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 // Writer is the writer to use for output. Writer io.Writer }
SelectOptions contains options for prompting the user to select a resource.
type SubscriptionService ¶
type SubscriptionService interface { ListSubscriptions(ctx context.Context, tenantId string) ([]*armsubscriptions.Subscription, error) GetSubscription(ctx context.Context, subscriptionId string, tenantId string) (*armsubscriptions.Subscription, error) ListSubscriptionLocations(ctx context.Context, subscriptionId string, tenantId string) ([]account.Location, error) ListTenants(ctx context.Context) ([]armsubscriptions.TenantIDDescription, error) }
SubscriptionService defines the methods that the SubscriptionsService must implement.