client

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: MIT Imports: 38 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

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

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

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

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, ClientID string) oAuthTokenProvider

func NewSecretOAuthTokenProvider

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

func NormalizeLocation

func NormalizeLocation(loc string) string

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

Types

type AzureClientSet

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
	VirtualMachineScaleSetVMsClient() computeapi.VirtualMachineScaleSetVMsClientAPI

	PollClient() autorest.Client

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

func GetTestClientSet

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

func New

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

type AzureClientSetMock

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

AzureClientSetMock provides a generic mock for AzureClientSet

func (*AzureClientSetMock) DisksClient

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

DisksClient returns a DisksClientAPI

func (*AzureClientSetMock) GalleryImageVersionsClient

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

GalleryImageVersionsClient returns a GalleryImageVersionsClientAPI

func (*AzureClientSetMock) GalleryImagesClient

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

GalleryImagesClient returns a GalleryImagesClientAPI

func (*AzureClientSetMock) ImagesClient

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

ImagesClient returns a ImagesClientAPI

func (*AzureClientSetMock) MetadataClient

func (m *AzureClientSetMock) MetadataClient() MetadataClientAPI

MetadataClient returns a MetadataClientAPI

func (*AzureClientSetMock) PollClient

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

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

func (*AzureClientSetMock) SnapshotsClient

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

SnapshotsClient returns a SnapshotsClientAPI

func (*AzureClientSetMock) SubscriptionID

func (m *AzureClientSetMock) SubscriptionID() string

SubscriptionID returns SubscriptionIDMock

func (*AzureClientSetMock) VirtualMachineImagesClient

func (m *AzureClientSetMock) VirtualMachineImagesClient() VirtualMachineImagesClientAPI

VirtualMachineImagesClient returns a VirtualMachineImagesClientAPI

func (*AzureClientSetMock) VirtualMachineScaleSetVMsClient

func (m *AzureClientSetMock) VirtualMachineScaleSetVMsClient() computeapi.VirtualMachineScaleSetVMsClientAPI

VirtualMachineScaleSetVMsClient returns a VirtualMachineScaleSetVMsClientAPI

func (*AzureClientSetMock) VirtualMachinesClient

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

VirtualMachinesClient returns a VirtualMachinesClientAPI

type CompoundName

type CompoundName []string

func (CompoundName) String

func (n CompoundName) String() string

type ComputeInfo

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

ComputeInfo defines the Azure VM metadata that is used in Packer

func (ComputeInfo) GetResourceID

func (ci ComputeInfo) GetResourceID() 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 Hostname of the Azure Metadata Service
	// (for example management.azure.com), used to obtain the Cloud Environment
	// when using a Custom Azure Environment. This can also be sourced from the
	// ARM_METADATA_HOST Environment Variable.
	// Note: CloudEnvironmentName must be set to the requested environment
	// name in the list of available environments held in the metadata_host.
	MetadataHost string `mapstructure:"metadata_host" 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

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

CloudEnvironmentName is deprecated in favor of MetadataHost. This is retained for now to preserve backward compatability, but should eventually be removed.

func (Config) UseCLI

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

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

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

func NewMetadataClient

func NewMetadataClient() MetadataClientAPI

NewMetadataClient creates a new instance metadata client

type MetadataClientStub

type MetadataClientStub struct {
	ComputeInfo
}

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

func (MetadataClientStub) GetComputeInfo

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

GetComputeInfo implements MetadataClientAPI

type PlatformImage

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

func ParsePlatformImageURN

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

func (PlatformImage) URN

func (pi PlatformImage) URN() string

type Resource

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

func ParseResourceID

func ParseResourceID(resourceID string) (Resource, error)

ParseResourceID parses an Azure resource ID

func (Resource) Parent

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

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

func (Resource) String

func (r Resource) String() string

func (Resource) Validate

func (r Resource) Validate() error

type VirtualMachineImagesClient

type VirtualMachineImagesClient struct {
	computeapi.VirtualMachineImagesClientAPI
}

func (VirtualMachineImagesClient) GetLatest

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

type VirtualMachineImagesClientAPI

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