account

package
v0.0.0-...-d611558 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	DefaultSubscription *Subscription `json:"defaultSubscription"`
	DefaultLocation     *Location     `json:"defaultLocation"`
}

AZD Account configuration

type Location

type Location struct {
	// The name of the location (e.g. "westus2")
	Name string `json:"name"`
	// The human friendly name of the location (e.g. "West US 2")
	DisplayName string `json:"displayName"`
	// The human friendly name of the location, prefixed with a
	// region name (e.g "(US) West US 2")
	RegionalDisplayName string `json:"regionalDisplayName"`
}

type Manager

type Manager interface {
	Clear(ctx context.Context) error
	HasDefaultSubscription() bool
	HasDefaultLocation() bool
	GetAccountDefaults(ctx context.Context) (*Account, error)
	GetDefaultLocationName(ctx context.Context) string
	GetDefaultSubscriptionID(ctx context.Context) string
	GetSubscriptions(ctx context.Context) ([]Subscription, error)
	GetSubscriptionsWithDefaultSet(ctx context.Context) ([]Subscription, error)
	GetLocations(ctx context.Context, subscriptionId string) ([]Location, error)
	SetDefaultSubscription(ctx context.Context, subscriptionId string) (*Subscription, error)
	SetDefaultLocation(ctx context.Context, subscriptionId string, location string) (*Location, error)
}

func NewManager

func NewManager(
	configManager config.FileConfigManager,
	subManager *SubscriptionsManager) (Manager, error)

Creates a new Account Manager instance

type Subscription

type Subscription struct {
	Id       string `json:"id"`
	Name     string `json:"name"`
	TenantId string `json:"tenantId"`
	// The tenant under which the user has access to the subscription.
	UserAccessTenantId string `json:"userAccessTenantId"`
	IsDefault          bool   `json:"isDefault,omitempty"`
}

type SubscriptionCredentialProvider

type SubscriptionCredentialProvider interface {
	CredentialForSubscription(ctx context.Context, subscriptionId string) (azcore.TokenCredential, error)
}

SubscriptionCredentialProvider provides an azcore.TokenCredential configured to use the tenant id that corresponds to the tenant the given subscription is located in.

type SubscriptionTenantResolver

type SubscriptionTenantResolver interface {
	// Resolve the tenant ID required by the current account to access the given subscription.
	LookupTenant(ctx context.Context, subscriptionId string) (tenantId string, err error)
}

SubscriptionTenantResolver allows resolving the correct tenant ID that allows the current account access to a given subscription.

type SubscriptionsCache

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

SubscriptionsCache caches the list of subscriptions accessible by the currently logged in account.

The cache is backed by an in-memory copy, then by local file system storage.

func NewSubscriptionsCache

func NewSubscriptionsCache() (*SubscriptionsCache, error)

func NewSubscriptionsCacheWithDir

func NewSubscriptionsCacheWithDir(cachePath string) (*SubscriptionsCache, error)

func (*SubscriptionsCache) Clear

func (s *SubscriptionsCache) Clear() error

Clear removes all stored cache information. Returns an error if a filesystem error other than ErrNotExist occurred.

func (*SubscriptionsCache) Load

func (s *SubscriptionsCache) Load() ([]Subscription, error)

Load loads the subscriptions from cache. Returns any error reading the cache.

func (*SubscriptionsCache) Save

func (s *SubscriptionsCache) Save(subscriptions []Subscription) error

Save saves the subscriptions to cache.

type SubscriptionsManager

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

SubscriptionsManager manages listing, storing and retrieving subscriptions for the current account.

Since the application supports multi-tenancy, subscriptions can be accessed by the user through different tenants. To lookup access to a given subscription, LookupTenant can be used to lookup the current account's required tenantID to access a given subscription.

func NewSubscriptionsManager

func NewSubscriptionsManager(
	service *SubscriptionsService,
	auth *auth.Manager,
	console input.Console) (*SubscriptionsManager, error)

func (*SubscriptionsManager) ClearSubscriptions

func (m *SubscriptionsManager) ClearSubscriptions(ctx context.Context) error

Clears stored cached subscriptions. This can only return an error is a filesystem error other than ErrNotExist occurred.

func (*SubscriptionsManager) GetLocation

func (m *SubscriptionsManager) GetLocation(ctx context.Context, subscriptionId, locationName string) (Location, error)

func (*SubscriptionsManager) GetSubscription

func (m *SubscriptionsManager) GetSubscription(ctx context.Context, subscriptionId string) (*Subscription, error)

func (*SubscriptionsManager) GetSubscriptions

func (m *SubscriptionsManager) GetSubscriptions(ctx context.Context) ([]Subscription, error)

GetSubscriptions retrieves subscriptions accessible by the current account with caching semantics.

Unlike ListSubscriptions, GetSubscriptions first examines the subscriptions cache. On cache miss, subscriptions are fetched, the cached is updated, before the result is returned.

func (*SubscriptionsManager) ListLocations

func (m *SubscriptionsManager) ListLocations(
	ctx context.Context,
	subscriptionId string,
) ([]Location, error)

func (*SubscriptionsManager) ListSubscriptions

func (m *SubscriptionsManager) ListSubscriptions(ctx context.Context) ([]Subscription, error)

ListSubscription lists subscriptions accessible by the current account by calling azure management services.

func (*SubscriptionsManager) LookupTenant

func (m *SubscriptionsManager) LookupTenant(ctx context.Context, subscriptionId string) (tenantId string, err error)

Resolve the tenant ID required by the current account to access the given subscription.

  • If the account is logged in with a service principal specified, the service principal's tenant ID is immediately returned (single-tenant mode).

  • Otherwise, the tenant ID is resolved by examining the stored subscriptionID to tenantID cache. See SubscriptionCache for details about caching. On cache miss, all tenants and subscriptions are queried from azure management services for the current account to build the mapping and populate the cache.

func (*SubscriptionsManager) RefreshSubscriptions

func (m *SubscriptionsManager) RefreshSubscriptions(ctx context.Context) error

Updates stored cached subscriptions.

type SubscriptionsService

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

SubscriptionsService allows querying of subscriptions and tenants.

func NewSubscriptionsService

func NewSubscriptionsService(
	credentialProvider auth.MultiTenantCredentialProvider,
	armClientOptions *arm.ClientOptions,
) *SubscriptionsService

func (*SubscriptionsService) GetSubscription

func (s *SubscriptionsService) GetSubscription(
	ctx context.Context, subscriptionId string, tenantId string) (*armsubscriptions.Subscription, error)

func (*SubscriptionsService) ListSubscriptionLocations

func (s *SubscriptionsService) ListSubscriptionLocations(
	ctx context.Context, subscriptionId string, tenantId string) ([]Location, error)

ListSubscriptionLocations lists physical locations in Azure for the given subscription.

func (*SubscriptionsService) ListSubscriptions

func (s *SubscriptionsService) ListSubscriptions(
	ctx context.Context,
	tenantId string,
) ([]*armsubscriptions.Subscription, error)

func (*SubscriptionsService) ListTenants

Jump to

Keyboard shortcuts

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