config

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: MPL-2.0 Imports: 12 Imported by: 12

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

	// 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 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 WithSession added in v0.25.0

func WithSession(s auth.Session) HCPConfigOption

WithSession is an option that can be used to provide a custom Session struct.

A mock Session can be provided, if none is provided the default UserSession will be used.

This should only be necessary for testing purposes.

func WithoutBrowserLogin added in v0.42.0

func WithoutBrowserLogin() HCPConfigOption

WithoutBrowserLogin disables the automatic opening of the browser login if no valid auth method is found instead force the return of a typed error for users to catch

Jump to

Keyboard shortcuts

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