ocep

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

README

OCI CLI Environment Variable Config Provider

Latest Tag CLA assistant Build Status Go Report Card GoDoc

Implements a common.ConfigurationProvider from oracle/oci-go-sdk that uses the standard environment variables from the OCI CLI.

See GoDocs for example code.

Copyright 2025 Finvi, Ontario Systems

Licensed under the Apache License, Version 2.0

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

Examples

Constants

View Source
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

View Source
const (
	ApiKeyType        common.AuthenticationType = "api_key"
	SecurityTokenType common.AuthenticationType = "security_token"
)

Variables

View Source
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)

Types

type EnvError

type EnvError struct {
	EnvVar string
}

func (EnvError) Error

func (e EnvError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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