config

package
v0.93.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MPL-2.0 Imports: 17 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HCPConfig

type HCPConfig interface {

	// Profile will return the user's configured profile information
	Profile() *profile.UserProfile

	// TokenSource will return a token that can be used to authenticate to HCP.
	oauth2.TokenSource

	// Logout will discard the currently cached login credentials
	Logout() error

	// PortalURL will return the URL of the portal.
	//
	// The default portal URL will be the production portal, but the value may
	// be overwritten for development purposes.
	PortalURL() *url.URL

	// APIAddress will return the HCP API address (<hostname>[:port]).
	//
	// The default address will be the HCP production API, but it may be
	// overwritten for development purposes.
	APIAddress() string

	// APITLSConfig will return the API TLS configuration.
	//
	// TLS will be enabled by default but may be disabled for development
	// purposes.
	APITLSConfig() *tls.Config

	// SCADAAddress will return the SCADA address (<hostname>[:port]).
	//
	// The default address will be the HCP production SCADA endpoint, but it may
	// be overwritten for development purposes.
	SCADAAddress() string

	// SCADATLSConfig will return the SCADA TLS configuration.
	//
	// TLS will be enabled by default but may be disabled for development
	// purposes.
	SCADATLSConfig() *tls.Config
}

HCPConfig provides configuration values that are useful to interact with HCP.

func NewHCPConfig

func NewHCPConfig(opts ...HCPConfigOption) (HCPConfig, error)

NewHCPConfig will return a HCPConfig. The configuration will be constructed from default values and the passed options.

Based on the provided options the configuration values can be provided directly or will be read from other places (e.g. the environment).

The configuration will default to values for the HCP production environment, but can be overwritten for development purposes.

In addition to the default values the configuration requires client credentials to be provided through one of the passed options (e.g. by using WithCredentials or by using FromEnv and providing the client credentials via environment variables).

type HCPConfigOption

type HCPConfigOption = func(config *hcpConfig) error

HCPConfigOption are functions that modify the hcpConfig struct. They can be passed to NewHCPConfig.

func FromEnv

func FromEnv() HCPConfigOption

FromEnv will return a HCPConfigOption that will populate the configuration with values from the environment.

It will not fail if no or only part of the variables are present.

func WithAPI

func WithAPI(address string, tlsConfig *tls.Config) HCPConfigOption

WithAPI credentials is an option that can be used to provide a custom configuration for the API endpoint.

If nil is provided for the tlsConfig value, TLS will be disabled.

This should only be necessary for development purposes.

func WithAuth

func WithAuth(authURL string, tlsConfig *tls.Config) HCPConfigOption

WithAuth credentials is an option that can be used to provide a custom URL for the auth endpoint.

An alternative TLS configuration can be provided, if none is provided the default TLS configuration will be used. It is not possible to disable TLS for the auth endpoint.

This should only be necessary for development purposes.

func WithClientCredentials

func WithClientCredentials(clientID, clientSecret string) HCPConfigOption

WithClientCredentials credentials is an option that can be used to set HCP client credentials on the configuration.

func WithCredentialFile added in v0.57.0

func WithCredentialFile(cf *auth.CredentialFile) HCPConfigOption

WithCredentialFile sets the given credential file to be used as an authentication source.

func WithCredentialFilePath added in v0.57.0

func WithCredentialFilePath(p string) HCPConfigOption

WithCredentialFilePath will search for a credential file at the given path to be used as an authentication source.

func WithOAuth2ClientID added in v0.22.0

func WithOAuth2ClientID(oauth2ClientID string) HCPConfigOption

WithOAuth2ClientID credentials is an option that can be used to provide a custom OAuth2 Client ID.

An alternative OAuth2 ClientID can be provided, if none is provided the default OAuth2 Client ID will be used.

This should only be necessary for development purposes.

func WithPortalURL

func WithPortalURL(portalURL string) HCPConfigOption

WithPortalURL credentials is an option that can be used to provide a custom URL for the portal.

This should only be necessary for development purposes.

func WithProfile added in v0.27.0

func WithProfile(p *profile.UserProfile) HCPConfigOption

WithProfile is an option that can be used to provide a custom UserProfile struct.

func WithSCADA

func WithSCADA(address string, tlsConfig *tls.Config) HCPConfigOption

WithSCADA credentials is an option that can be used to provide a custom configuration for the SCADA endpoint.

If nil is provided for the tlsConfig value, TLS will be disabled.

This should only be necessary for development purposes.

func WithTokenSource added in v0.71.0

func WithTokenSource(tokenSource oauth2.TokenSource) HCPConfigOption

WithTokenSource can be used to set a token source. This should only be necessary for testing. Tokens from a custom token source will not be cached.

func WithWorkloadIdentity added in v0.57.0

func WithWorkloadIdentity(providerConfig *workload.IdentityProviderConfig) HCPConfigOption

WithWorkloadIdentity exchanges a workload identity provider credentials for an HCP Service Principal token. The Workload Identity Provider can be AWS or any OIDC based identity provider.

func WithoutBrowserLogin added in v0.42.0

func WithoutBrowserLogin() HCPConfigOption

WithoutBrowserLogin disables the automatic opening of the browser login.

func WithoutLogging added in v0.47.0

func WithoutLogging() HCPConfigOption

WithoutLogging disables this SDK from printing of any kind, this is necessary since there is not a consistent logger that is used throughout the project so a log level option is not sufficient.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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