client

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2021 License: MPL-2.0, MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCloudEnvironmentName = "Public"

Variables

View Source
var DefaultMetadataClient = NewMetadataClient()

DefaultMetadataClient is the default instance metadata client for Azure. Replace this variable for testing purposes only

Functions

func Authenticate added in v1.4.5

func Authenticate(env azure.Environment, tenantID string, say func(string), scope string) (*adal.ServicePrincipalToken, error)

Authenticate fetches a token from the local file cache or initiates a consent flow and waits for token to be obtained.

func FindTenantID added in v1.4.5

func FindTenantID(env azure.Environment, subscriptionID string) (string, error)

FindTenantID figures out the AAD tenant ID of the subscription by making an unauthenticated request to the Get Subscription Details endpoint and parses the value from WWW-Authenticate header.

func IsAzure added in v1.4.5

func IsAzure() bool

IsAzure returns true if Packer is running on Azure

func NewCertOAuthTokenProvider

func NewCertOAuthTokenProvider(env azure.Environment, clientID, clientCertPath, tenantID string, certExpireTimeout time.Duration) (oAuthTokenProvider, error)

func NewCliOAuthTokenProvider added in v1.6.6

func NewCliOAuthTokenProvider(env azure.Environment, say func(string), tenantID string) oAuthTokenProvider

func NewDeviceFlowOAuthTokenProvider

func NewDeviceFlowOAuthTokenProvider(env azure.Environment, say func(string), tenantID string) oAuthTokenProvider

func NewJWTOAuthTokenProvider

func NewJWTOAuthTokenProvider(env azure.Environment, clientID, clientJWT, tenantID string) oAuthTokenProvider

func NewMSIOAuthTokenProvider

func NewMSIOAuthTokenProvider(env azure.Environment) oAuthTokenProvider

func NewSecretOAuthTokenProvider

func NewSecretOAuthTokenProvider(env azure.Environment, clientID, clientSecret, tenantID string) oAuthTokenProvider

func NormalizeLocation added in v1.5.6

func NormalizeLocation(loc string) string

NormalizeLocation returns a normalized location string. Strings are converted to lower case and spaces are removed.

Types

type AzureClientSet added in v1.4.5

type AzureClientSet interface {
	MetadataClient() MetadataClientAPI

	DisksClient() computeapi.DisksClientAPI
	SnapshotsClient() computeapi.SnapshotsClientAPI
	ImagesClient() computeapi.ImagesClientAPI

	GalleryImagesClient() computeapi.GalleryImagesClientAPI
	GalleryImageVersionsClient() computeapi.GalleryImageVersionsClientAPI

	VirtualMachinesClient() computeapi.VirtualMachinesClientAPI
	VirtualMachineImagesClient() VirtualMachineImagesClientAPI

	PollClient() autorest.Client

	// SubscriptionID returns the subscription ID that this client set was created for
	SubscriptionID() string
}

func GetTestClientSet added in v1.4.5

func GetTestClientSet(t *testing.T) (AzureClientSet, error)

func New added in v1.4.5

func New(c Config, say func(string)) (AzureClientSet, error)

type AzureClientSetMock added in v1.4.5

type AzureClientSetMock struct {
	DisksClientMock                computeapi.DisksClientAPI
	SnapshotsClientMock            computeapi.SnapshotsClientAPI
	ImagesClientMock               computeapi.ImagesClientAPI
	VirtualMachineImagesClientMock VirtualMachineImagesClientAPI
	VirtualMachinesClientMock      computeapi.VirtualMachinesClientAPI
	GalleryImagesClientMock        computeapi.GalleryImagesClientAPI
	GalleryImageVersionsClientMock computeapi.GalleryImageVersionsClientAPI
	PollClientMock                 autorest.Client
	MetadataClientMock             MetadataClientAPI
	SubscriptionIDMock             string
}

AzureClientSetMock provides a generic mock for AzureClientSet

func (*AzureClientSetMock) DisksClient added in v1.4.5

func (m *AzureClientSetMock) DisksClient() computeapi.DisksClientAPI

DisksClient returns a DisksClientAPI

func (*AzureClientSetMock) GalleryImageVersionsClient added in v1.5.6

func (m *AzureClientSetMock) GalleryImageVersionsClient() computeapi.GalleryImageVersionsClientAPI

GalleryImageVersionsClient returns a GalleryImageVersionsClientAPI

func (*AzureClientSetMock) GalleryImagesClient added in v1.5.6

func (m *AzureClientSetMock) GalleryImagesClient() computeapi.GalleryImagesClientAPI

GalleryImagesClient returns a GalleryImagesClientAPI

func (*AzureClientSetMock) ImagesClient added in v1.4.5

func (m *AzureClientSetMock) ImagesClient() computeapi.ImagesClientAPI

ImagesClient returns a ImagesClientAPI

func (*AzureClientSetMock) MetadataClient added in v1.4.5

func (m *AzureClientSetMock) MetadataClient() MetadataClientAPI

MetadataClient returns a MetadataClientAPI

func (*AzureClientSetMock) PollClient added in v1.4.5

func (m *AzureClientSetMock) PollClient() autorest.Client

PollClient returns an autorest Client that can be used for polling async requests

func (*AzureClientSetMock) SnapshotsClient added in v1.5.6

func (m *AzureClientSetMock) SnapshotsClient() computeapi.SnapshotsClientAPI

SnapshotsClient returns a SnapshotsClientAPI

func (*AzureClientSetMock) SubscriptionID added in v1.5.6

func (m *AzureClientSetMock) SubscriptionID() string

SubscriptionID returns SubscriptionIDMock

func (*AzureClientSetMock) VirtualMachineImagesClient added in v1.4.5

func (m *AzureClientSetMock) VirtualMachineImagesClient() VirtualMachineImagesClientAPI

VirtualMachineImagesClient returns a VirtualMachineImagesClientAPI

func (*AzureClientSetMock) VirtualMachinesClient added in v1.4.5

func (m *AzureClientSetMock) VirtualMachinesClient() computeapi.VirtualMachinesClientAPI

VirtualMachinesClient returns a VirtualMachinesClientAPI

type CompoundName added in v1.5.6

type CompoundName []string

func (CompoundName) String added in v1.5.6

func (n CompoundName) String() string

type ComputeInfo added in v1.4.5

type ComputeInfo struct {
	Name              string
	ResourceGroupName string
	SubscriptionID    string
	Location          string
}

ComputeInfo defines the Azure VM metadata that is used in Packer

func (ComputeInfo) ResourceID added in v1.4.5

func (ci ComputeInfo) ResourceID() string

type Config

type Config struct {
	// One of Public, China, Germany, or
	// USGovernment. Defaults to Public. Long forms such as
	// USGovernmentCloud and AzureUSGovernmentCloud are also supported.
	CloudEnvironmentName string `mapstructure:"cloud_environment_name" required:"false"`

	// The application ID of the AAD Service Principal.
	// Requires either `client_secret`, `client_cert_path` or `client_jwt` to be set as well.
	ClientID string `mapstructure:"client_id"`
	// A password/secret registered for the AAD SP.
	ClientSecret string `mapstructure:"client_secret"`
	// The path to a pem-encoded certificate that will be used to authenticate
	// as the specified AAD SP.
	ClientCertPath string `mapstructure:"client_cert_path"`
	// The timeout for the JWT Token when using a [client certificate](#client_cert_path). Defaults to 1 hour.
	ClientCertExpireTimeout time.Duration `mapstructure:"client_cert_token_timeout" required:"false"`
	// A JWT bearer token for client auth (RFC 7523, Sec. 2.2) that will be used
	// to authenticate the AAD SP. Provides more control over token the expiration
	// when using certificate authentication than when using `client_cert_path`.
	ClientJWT string `mapstructure:"client_jwt"`
	// The object ID for the AAD SP. Optional, will be derived from the oAuth token if left empty.
	ObjectID string `mapstructure:"object_id"`

	// The Active Directory tenant identifier with which your `client_id` and
	// `subscription_id` are associated. If not specified, `tenant_id` will be
	// looked up using `subscription_id`.
	TenantID string `mapstructure:"tenant_id" required:"false"`
	// The subscription to use.
	SubscriptionID string `mapstructure:"subscription_id"`

	// Flag to use Azure CLI authentication. Defaults to false.
	// CLI auth will use the information from an active `az login` session to connect to Azure and set the subscription id and tenant id associated to the signed in account.
	// If enabled, it will use the authentication provided by the `az` CLI.
	// Azure CLI authentication will use the credential marked as `isDefault` and can be verified using `az account show`.
	// Works with normal authentication (`az login`) and service principals (`az login --service-principal --username APP_ID --password PASSWORD --tenant TENANT_ID`).
	// Ignores all other configurations if enabled.
	UseAzureCLIAuth bool `mapstructure:"use_azure_cli_auth" required:"false"`
	// contains filtered or unexported fields
}

Config allows for various ways to authenticate Azure clients. When `client_id` and `subscription_id` are specified, Packer will use the specified Azure Active Directory (AAD) Service Principal (SP). If only `subscription_id` is specified, Packer will try to interactively log on the current user (tokens will be cached). If none of these options are specified, Packer will attempt to use the Managed Identity and subscription of the VM that Packer is running on. This will only work if Packer is running on an Azure VM.

func (*Config) CloudEnvironment

func (c *Config) CloudEnvironment() *azure.Environment

func (*Config) FillParameters

func (c *Config) FillParameters() error

FillParameters capture the user intent from the supplied parameter set in authType, retrieves the TenantID and CloudEnvironment if not specified. The SubscriptionID is also retrieved in case MSI auth is requested.

func (Config) GetServicePrincipalToken added in v1.4.5

func (c Config) GetServicePrincipalToken(
	say func(string), forResource string) (
	servicePrincipalToken *adal.ServicePrincipalToken,
	err error)

func (Config) GetServicePrincipalTokens

func (c Config) GetServicePrincipalTokens(say func(string)) (
	servicePrincipalToken *adal.ServicePrincipalToken,
	servicePrincipalTokenVault *adal.ServicePrincipalToken,
	err error)

func (*Config) SetDefaultValues

func (c *Config) SetDefaultValues() error

func (Config) UseCLI added in v1.6.6

func (c Config) UseCLI() bool

func (Config) UseMSI

func (c Config) UseMSI() bool

func (Config) Validate

func (c Config) Validate(errs *packersdk.MultiError)

type MetadataClientAPI added in v1.4.5

type MetadataClientAPI interface {
	GetComputeInfo() (*ComputeInfo, error)
}

MetadataClientAPI holds methods that Packer uses to get information about the current VM

func NewMetadataClient added in v1.4.5

func NewMetadataClient() MetadataClientAPI

NewMetadataClient creates a new instance metadata client

type MetadataClientStub added in v1.5.6

type MetadataClientStub struct {
	ComputeInfo
}

MetadataClientStub is an easy way to put a test hook in DefaultMetadataClient

func (MetadataClientStub) GetComputeInfo added in v1.5.6

func (s MetadataClientStub) GetComputeInfo() (*ComputeInfo, error)

GetComputeInfo implements MetadataClientAPI

type PlatformImage added in v1.4.5

type PlatformImage struct {
	Publisher, Offer, Sku, Version string
}

func ParsePlatformImageURN added in v1.4.5

func ParsePlatformImageURN(urn string) (image *PlatformImage, err error)

func (PlatformImage) URN added in v1.4.5

func (pi PlatformImage) URN() string

type Resource added in v1.5.6

type Resource struct {
	Subscription  string
	ResourceGroup string
	Provider      string
	ResourceType  CompoundName
	ResourceName  CompoundName
}

func ParseResourceID added in v1.5.6

func ParseResourceID(resourceID string) (Resource, error)

ParseResourceID parses an Azure resource ID

func (Resource) Parent added in v1.5.6

func (r Resource) Parent() (Resource, error)

Parent produces a resource ID representing the parent resource if this is a child resource

func (Resource) String added in v1.5.6

func (r Resource) String() string

func (Resource) Validate added in v1.5.6

func (r Resource) Validate() error

type VirtualMachineImagesClient added in v1.5.6

type VirtualMachineImagesClient struct {
	computeapi.VirtualMachineImagesClientAPI
}

func (VirtualMachineImagesClient) GetLatest added in v1.5.6

func (c VirtualMachineImagesClient) GetLatest(ctx context.Context, publisher, offer, sku, location string) (*compute.VirtualMachineImageResource, error)

type VirtualMachineImagesClientAPI added in v1.4.5

type VirtualMachineImagesClientAPI interface {
	computeapi.VirtualMachineImagesClientAPI
	// extensions
	GetLatest(ctx context.Context, publisher, offer, sku, location string) (*compute.VirtualMachineImageResource, error)
}

Jump to

Keyboard shortcuts

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