environment

package
v0.0.0-...-4d33260 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const AksClusterEnvVarName = "AZURE_AKS_CLUSTER_NAME"

AksClusterEnvVarName is the name of they key used to store the endpoint of the AKS cluster to push to.

View Source
const AzdInitialEnvironmentConfigName = "AZD_INITIAL_ENVIRONMENT_CONFIG"
View Source
const ConfigFileName = "config.json"
View Source
const ContainerRegistryEndpointEnvVarName = "AZURE_CONTAINER_REGISTRY_ENDPOINT"

ContainerRegistryEndpointEnvVarName is the name of they key used to store the endpoint of the container registry to push to.

View Source
const DotEnvFileName = ".env"
View Source
const EnvNameEnvVarName = "AZURE_ENV_NAME"

EnvNameEnvVarName is the name of the key used to store the envname property in the environment.

View Source
const LocationEnvVarName = "AZURE_LOCATION"

LocationEnvVarName is the name of the key used to store the location property in the environment.

View Source
const PlatformTypeEnvVarName = "AZD_PLATFORM_TYPE"

PlatformTypeEnvVarName is the name of the key used to store the current azd platform type

View Source
const PrincipalIdEnvVarName = "AZURE_PRINCIPAL_ID"

PrincipalIdEnvVarName is the name of they key used to store the id of a principal in the environment.

View Source
const ResourceGroupEnvVarName = "AZURE_RESOURCE_GROUP"

ResourceGroupEnvVarName is the name of the azure resource group that should be used for deployments

View Source
const SubscriptionIdEnvVarName = "AZURE_SUBSCRIPTION_ID"

SubscriptionIdEnvVarName is the name of they key used to store the subscription id property in the environment.

View Source
const TenantIdEnvVarName = "AZURE_TENANT_ID"

TenantIdEnvVarName is the tenant that owns the subscription

Variables

View Source
var (
	// Error returned when an environment with the specified name already exists
	ErrExists = errors.New("environment already exists")

	// Error returned when an environment with a specified name cannot be found
	ErrNotFound = errors.New("environment not found")

	// Error returned when an environment name is not specified
	ErrNameNotSpecified = errors.New("environment not specified")
)
View Source
var (
	ErrAccessDenied     = errors.New("access denied connecting Azure Blob Storage container.")
	ErrInvalidContainer = errors.New("storage container name is invalid.")
)
View Source
var EnvironmentNameMaxLength = 64

The maximum length of an environment name.

View Source
var EnvironmentNameRegexp = regexp.MustCompile(`^[a-zA-Z0-9-\(\)_\.]{1,64}$`)

Same restrictions as a deployment name (ref: https://docs.microsoft.com/azure/azure-resource-manager/management/resource-name-rules#microsoftresources)

View Source
var ValidRemoteKinds = []string{
	string(RemoteKindAzureBlobStorage),
}

Functions

func CleanName

func CleanName(name string) string

CleanName returns a version of [name] where all characters not allowed in an environment name have been replaced with hyphens

func IsValidEnvironmentName

func IsValidEnvironmentName(name string) bool

func Key

func Key(name string) string

Key returns the environment key name for the given name.

Types

type DataStore

type DataStore interface {
	// Gets the path to the environment .env file
	EnvPath(env *Environment) string

	// Gets the path to the environment JSON config file
	ConfigPath(env *Environment) string

	// Gets a list of all environments within the stat store
	List(ctx context.Context) ([]*contracts.EnvListEnvironment, error)

	// Gets the environment instance for the specified environment name
	Get(ctx context.Context, name string) (*Environment, error)

	// Reloads the environment from the persistent data store
	Reload(ctx context.Context, env *Environment) error

	// Saves the environment to the persistent data store
	Save(ctx context.Context, env *Environment, options *SaveOptions) error

	// Deletes the environment from the persistent data store
	Delete(ctx context.Context, name string) error
}

type Description

type Description struct {
	// The name of the environment
	Name string
	// The path to the local .env file for the environment. Useful for IDEs like VS / VSCode
	DotEnvPath string
	// Specifies when the environment exists locally
	HasLocal bool
	// Specifies when the environment exists remotely
	HasRemote bool
	// Specifies when the environment is the default environment
	IsDefault bool
}

Description is a metadata description of an environment returned for the `azd env list` command

type Environment

type Environment struct {

	// Config is environment specific config
	Config config.Config
	// contains filtered or unexported fields
}

The zero value of an Environment is not valid. Use New to create one. When writing tests, [Ephemeral] and [EphemeralWithValues] are useful to create environments which are not persisted to disk.

func New

func New(name string) *Environment

New returns a new environment with the specified name.

func NewWithValues

func NewWithValues(name string, values map[string]string) *Environment

NewWithValues returns an ephemeral environment (i.e. not backed by a data store) with a set of values. Useful for testing. The name parameter is added to the environment with the AZURE_ENV_NAME key, replacing an existing value in the provided values map. A nil values is treated the same way as an empty map.

func (*Environment) Dotenv

func (e *Environment) Dotenv() map[string]string

Dotenv returns a copy of the key value pairs from the .env file in the environment.

func (*Environment) DotenvDelete

func (e *Environment) DotenvDelete(key string)

DotenvDelete removes the given key from the .env file in the environment, it is a no-op if the key does not exist. [Save] should be called to ensure this change is persisted.

func (*Environment) DotenvSet

func (e *Environment) DotenvSet(key string, value string)

DotenvSet sets the value of [key] to [value] in the .env file associated with the environment. [Save] should be called to ensure this change is persisted.

func (*Environment) Environ

func (e *Environment) Environ() []string

Creates a slice of key value pairs, based on the entries in the `.env` file like `KEY=VALUE` that can be used to pass into command runner or similar constructs.

func (*Environment) GetLocation

func (e *Environment) GetLocation() string

GetLocation is shorthand for Getenv(LocationEnvVarName)

func (*Environment) GetServiceProperty

func (e *Environment) GetServiceProperty(serviceName string, propertyName string) string

GetServiceProperty is shorthand for Getenv(SERVICE_$SERVICE_NAME_$PROPERTY_NAME)

func (*Environment) GetSubscriptionId

func (e *Environment) GetSubscriptionId() string

GetSubscriptionId is shorthand for Getenv(SubscriptionIdEnvVarName)

func (*Environment) GetTenantId

func (e *Environment) GetTenantId() string

GetTenantId is shorthand for Getenv(TenantIdEnvVarName)

func (*Environment) Getenv

func (e *Environment) Getenv(key string) string

Getenv behaves like os.Getenv, except that any keys in the `.env` file associated with this environment are considered first.

func (*Environment) LookupEnv

func (e *Environment) LookupEnv(key string) (string, bool)

LookupEnv behaves like os.LookupEnv, except that any keys in the `.env` file associated with this environment are considered first.

func (*Environment) Name

func (e *Environment) Name() string

Name gets the name of the environment If empty will fallback to the value of the AZURE_ENV_NAME environment variable

func (*Environment) SetLocation

func (e *Environment) SetLocation(location string)

SetLocation is shorthand for DotenvSet(LocationEnvVarName, location)

func (*Environment) SetServiceProperty

func (e *Environment) SetServiceProperty(serviceName string, propertyName string, value string)

Sets the value of a service-namespaced property in the environment.

func (*Environment) SetSubscriptionId

func (e *Environment) SetSubscriptionId(id string)

SetLocation is shorthand for DotenvSet(SubscriptionIdEnvVarName, location)

type EnvironmentInitError

type EnvironmentInitError struct {
	Name string
}

func NewEnvironmentInitError

func NewEnvironmentInitError(envName string) *EnvironmentInitError

func (*EnvironmentInitError) Error

func (err *EnvironmentInitError) Error() string

type EnvironmentResolver

type EnvironmentResolver func(ctx context.Context) (*Environment, error)

type LocalDataStore

type LocalDataStore DataStore

func NewLocalFileDataStore

func NewLocalFileDataStore(azdContext *azdcontext.AzdContext, configManager config.FileConfigManager) LocalDataStore

NewLocalFileDataStore creates a new LocalFileDataStore instance

type LocalFileDataStore

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

LocalFileDataStore is a DataStore implementation that stores environment data in the local file system.

func (*LocalFileDataStore) ConfigPath

func (fs *LocalFileDataStore) ConfigPath(env *Environment) string

ConfigPath returns the path to the config.json file for the given environment

func (*LocalFileDataStore) Delete

func (fs *LocalFileDataStore) Delete(ctx context.Context, name string) error

func (*LocalFileDataStore) EnvPath

func (fs *LocalFileDataStore) EnvPath(env *Environment) string

Path returns the path to the .env file for the given environment

func (*LocalFileDataStore) Get

func (fs *LocalFileDataStore) Get(ctx context.Context, name string) (*Environment, error)

Get returns the environment instance for the specified environment name

func (*LocalFileDataStore) List

List returns a list of all environments within the data store

func (*LocalFileDataStore) Reload

func (fs *LocalFileDataStore) Reload(ctx context.Context, env *Environment) error

Reload reloads the environment from the persistent data store

func (*LocalFileDataStore) Save

func (fs *LocalFileDataStore) Save(ctx context.Context, env *Environment, options *SaveOptions) error

Save saves the environment to the persistent data store

type Manager

type Manager interface {
	Create(ctx context.Context, spec Spec) (*Environment, error)

	// Loads the environment with the given name.
	// If the name is empty, the user is prompted to select or create an environment.
	// If the environment does not exist, the user is prompted to create it.
	LoadOrInitInteractive(ctx context.Context, name string) (*Environment, error)
	List(ctx context.Context) ([]*Description, error)

	// Get returns the existing environment with the given name.
	// If the environment specified by the given name does not exist, ErrNotFound is returned.
	Get(ctx context.Context, name string) (*Environment, error)

	Save(ctx context.Context, env *Environment) error
	SaveWithOptions(ctx context.Context, env *Environment, options *SaveOptions) error
	Reload(ctx context.Context, env *Environment) error

	// Delete deletes the environment from local storage.
	Delete(ctx context.Context, name string) error

	EnvPath(env *Environment) string
	ConfigPath(env *Environment) string
}

Manager is the interface used for managing instances of environments

func NewManager

func NewManager(
	serviceLocator ioc.ServiceLocator,
	azdContext *azdcontext.AzdContext,
	console input.Console,
	local LocalDataStore,
	remoteConfig *state.RemoteConfig,
) (Manager, error)

NewManager creates a new Manager instance

type RemoteDataStore

type RemoteDataStore DataStore

func NewStorageBlobDataStore

func NewStorageBlobDataStore(configManager config.Manager, blobClient storage.BlobClient) RemoteDataStore

type RemoteKind

type RemoteKind string
const (
	RemoteKindAzureBlobStorage RemoteKind = "AzureBlobStorage"
)

type SaveOptions

type SaveOptions struct {
	// Whether or not the environment is new
	IsNew bool
}

SaveOptions provide additional metadata for the save operation

type Spec

type Spec struct {
	Name         string
	Subscription string
	Location     string
	// suggest is the name that is offered as a suggestion if we need to prompt the user for an environment name.
	Examples []string
}

Spec is the specification for creating a new environment

type StorageBlobDataStore

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

func (*StorageBlobDataStore) ConfigPath

func (fs *StorageBlobDataStore) ConfigPath(env *Environment) string

ConfigPath returns the path to the config.json file for the given environment

func (*StorageBlobDataStore) Delete

func (sbd *StorageBlobDataStore) Delete(ctx context.Context, name string) error

func (*StorageBlobDataStore) EnvPath

func (fs *StorageBlobDataStore) EnvPath(env *Environment) string

EnvPath returns the path to the .env file for the given environment

func (*StorageBlobDataStore) Get

func (sbd *StorageBlobDataStore) Get(ctx context.Context, name string) (*Environment, error)

func (*StorageBlobDataStore) List

func (*StorageBlobDataStore) Reload

func (sbd *StorageBlobDataStore) Reload(ctx context.Context, env *Environment) error

func (*StorageBlobDataStore) Save

func (sbd *StorageBlobDataStore) Save(ctx context.Context, env *Environment, options *SaveOptions) error

type TargetResource

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

func NewTargetResource

func NewTargetResource(
	subscriptionId string,
	resourceGroupName string,
	resourceName string,
	resourceType string,
) *TargetResource

func (*TargetResource) ResourceGroupName

func (ds *TargetResource) ResourceGroupName() string

func (*TargetResource) ResourceName

func (ds *TargetResource) ResourceName() string

func (*TargetResource) ResourceType

func (ds *TargetResource) ResourceType() string

func (*TargetResource) SubscriptionId

func (ds *TargetResource) SubscriptionId() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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