Documentation
¶
Overview ¶
Package ocep creates a common.ConfigurationProvider which reads the configuration specified by oci-cli environment variables.
Example ¶
The most common use is to create a provider that can use the OCI CLI Environment variables as well as the providers from the sdk.
provider := ocep.DefaultConfigProvider()
client, _ := identity.NewIdentityClientWithConfigurationProvider(provider)
tenancyID, _ := provider.TenancyOCID()
req := identity.GetCompartmentRequest{
CompartmentId: common.String(tenancyID),
RequestMetadata: metadata,
}
resp, _ := client.GetCompartment(context.TODO(), req)
fmt.Printf("CompartmentId: %s\n", *resp.Id)
Index ¶
- Constants
- Variables
- func ComposingConfigProvider(providers ...common.ConfigurationProvider) common.ConfigurationProvider
- func DefaultConfigProvider() common.ConfigurationProvider
- func LazyConfigProvider(providerFunc func() (common.ConfigurationProvider, error)) common.ConfigurationProvider
- func OciCliEnvironmentConfigurationProvider() common.ConfigurationProvider
- type EnvError
Examples ¶
Constants ¶
const ( EnvAuth = "OCI_CLI_AUTH" EnvConfigFile = "OCI_CLI_CONFIG_FILE" EnvFingerprint = "OCI_CLI_FINGERPRINT" EnvKeyContent = "OCI_CLI_KEY_CONTENT" EnvKeyFile = "OCI_CLI_KEY_FILE" EnvPassphrase = "OCI_CLI_PASSPHRASE" EnvProfile = "OCI_CLI_PROFILE" EnvRegion = "OCI_CLI_REGION" EnvSecurityTokenFile = "OCI_CLI_SECURITY_TOKEN_FILE" EnvTenancy = "OCI_CLI_TENANCY" EnvUser = "OCI_CLI_USER" )
The standard oci-cli environment variables we use
const ( ApiKeyType common.AuthenticationType = "api_key" SecurityTokenType common.AuthenticationType = "security_token" )
Variables ¶
var ( ErrNoKeyId = errors.New("could not determine KeyID") ErrNoAuthType = errors.New("could not determine AuthType") )
Functions ¶
func ComposingConfigProvider ¶ added in v0.2.0
func ComposingConfigProvider(providers ...common.ConfigurationProvider) common.ConfigurationProvider
ComposingConfigProvider takes a list of providers and return a common.ConfigurationProvider that returns the configuration of the first non-error result
One key difference from common.ComposingConfigurationProvider is that this loops through all the providers in the list when determining AuthType.
func DefaultConfigProvider ¶
func DefaultConfigProvider() common.ConfigurationProvider
DefaultConfigProvider returns a common.ConfigurationProvider containing providers for oci cli environment variables, as well as those returned by common.DefaultConfigProvider
func LazyConfigProvider ¶ added in v0.2.0
func LazyConfigProvider(providerFunc func() (common.ConfigurationProvider, error)) common.ConfigurationProvider
LazyConfigProvider returns a common.ConfigurationProvider that is initialized one time by calling the func argument. The initialization func is only called if the provider methods are called.
Example ¶
The LazyConfigProvider can be used to wrap providers that can only be created under certain circumstances (such as on a compute instance).
Normally [auth.InstancePrincipalConfigurationProvider] will fail if not on a compute instance, but here it won't be called unless the other providers in the ComposingConfigProvider do not provide valid configuration
provider := ocep.ComposingConfigProvider(
ocep.DefaultConfigProvider(),
ocep.LazyConfigProvider(auth.InstancePrincipalConfigurationProvider),
)
client, _ := identity.NewIdentityClientWithConfigurationProvider(provider)
tenancyID, _ := provider.TenancyOCID()
req := identity.GetCompartmentRequest{
CompartmentId: common.String(tenancyID),
RequestMetadata: metadata,
}
resp, _ := client.GetCompartment(context.TODO(), req)
fmt.Printf("CompartmentId: %s\n", *resp.Id)
func OciCliEnvironmentConfigurationProvider ¶
func OciCliEnvironmentConfigurationProvider() common.ConfigurationProvider
OciCliEnvironmentConfigurationProvider returns a common.ConfigurationProvider that gets values from oci-cli environment variables
Example ¶
This example requires the OCI CLI environment variables to be set. The output will be your Tenancy OCID.
provider := ocep.OciCliEnvironmentConfigurationProvider()
client, _ := identity.NewIdentityClientWithConfigurationProvider(provider)
tenancyID, _ := provider.TenancyOCID()
req := identity.GetCompartmentRequest{
CompartmentId: common.String(tenancyID),
RequestMetadata: metadata,
}
resp, _ := client.GetCompartment(context.TODO(), req)
fmt.Printf("CompartmentId: %s\n", *resp.Id)