token

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 34 Imported by: 0

README

Instruction for recording response using GO-VCR for unit test

Things to know if you want to record new recording

  • All the recorded responses have been saved under folder /testdata

  • Highly recommand using RecordOnly if you want completely new recording, otherwise, current recordings have been modified without the sensitive contents

  • Here's the variable you need to input for recording Modify these variables modify authorizer clientID AZURE_CLIENT_ID="<specify with real value>" modify authorizer clientSecret AAD_SERVICE_PRINCIPAL_CLIENT_SECRET="<specify with real value>" modify authorizer clientCert AZURE_CLIENT_CER="<specify with real value>" modify authorizer clientCertPass AZURE_CLIENT_CERTIFICATE_PASSWORD="<specify with real value>" modify authorizer resourceID AZURE_RESOURCE_ID="<specify with real value>" modify authorizer tenantID AZURE_TENANT_ID="<specify with real value>" modify go-vcr record mode VCR_MODE="<specify vcr mode>" you can set to record mode by setting vcr mode to RecordOnly VCR_MODE="RecordOnly" To return to replay mode, simply unset the enviroment variable by unset VCR_MODE

Examples:

Recording Mode

  • Navigate to pkg/token folder in terminal
  • Setup your enviroment variables
export AZURE_CLIENT_ID="<specify with real value>"
export AAD_SERVICE_PRINCIPAL_CLIENT_SECRET="<specify with real value>"
export AZURE_CLIENT_CER="<specify with real value>"
export AZURE_CLIENT_CERTIFICATE_PASSWORD="<specify with real value>"
export AZURE_RESOURCE_ID="<specify with real value>"
export AZURE_TENANT_ID="<specify with real value>"
export VCR_MODE="RecordOnly"
go test

Replay Mode

unset VCR_MODE
go test

Documentation

Index

Constants

View Source
const (
	DeviceCodeLogin        = "devicecode"
	InteractiveLogin       = "interactive"
	ServicePrincipalLogin  = "spn"
	ROPCLogin              = "ropc"
	MSILogin               = "msi"
	AzureCLILogin          = "azurecli"
	AzureDeveloperCLILogin = "azd"
	WorkloadIdentityLogin  = "workloadidentity"
)

Variables

View Source
var (
	DefaultTokenCacheDir = homedir.HomeDir() + "/.kube/cache/kubelogin/"
)

Functions

func GetSupportedLogins

func GetSupportedLogins() string

Types

type AzureCLIToken

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

func (*AzureCLIToken) Token

func (p *AzureCLIToken) Token(ctx context.Context) (adal.Token, error)

Token fetches an azcore.AccessToken from the Azure CLI SDK and converts it to an adal.Token for use with kubelogin.

type AzureDeveloperCLIToken added in v0.1.1

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

func (*AzureDeveloperCLIToken) Token added in v0.1.1

Token fetches an azcore.AccessToken from the Azure Developer CLI SDK and converts it to an adal.Token for use with kubelogin.

type ExecCredentialPlugin

type ExecCredentialPlugin interface {
	Do(ctx context.Context) error
}

func New

type ExecCredentialWriter

type ExecCredentialWriter interface {
	Write(token adal.Token, writer io.Writer) error
}

type InteractiveToken

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

func (*InteractiveToken) Token

func (p *InteractiveToken) Token(ctx context.Context) (adal.Token, error)

Token fetches an azcore.AccessToken from the interactive browser SDK and converts it to an adal.Token for use with kubelogin.

func (*InteractiveToken) TokenWithOptions

func (p *InteractiveToken) TokenWithOptions(ctx context.Context, options *azcore.ClientOptions) (adal.Token, error)

type Options

type Options struct {
	LoginMethod        string
	ClientID           string
	ClientSecret       string
	ClientCert         string
	ClientCertPassword string
	Username           string
	Password           string
	ServerID           string
	TenantID           string
	Environment        string
	IsLegacy           bool
	Timeout            time.Duration
	TokenCacheDir      string

	IdentityResourceID     string
	FederatedTokenFile     string
	AuthorityHost          string
	UseAzureRMTerraformEnv bool
	IsPoPTokenEnabled      bool
	PoPTokenClaims         string
	// contains filtered or unexported fields
}

func NewOptions

func NewOptions() Options

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

func (*Options) ToString

func (o *Options) ToString() string

func (*Options) UpdateFromEnv

func (o *Options) UpdateFromEnv()

func (*Options) Validate

func (o *Options) Validate() error

type TokenCache

type TokenCache interface {
	Read(string) (adal.Token, error)
	Write(string, adal.Token) error
}

type TokenProvider

type TokenProvider interface {
	Token(ctx context.Context) (adal.Token, error)
}

func NewTokenProvider

func NewTokenProvider(o *Options) (TokenProvider, error)

NewTokenProvider creates the TokenProvider instance with giving options.

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

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