ocep

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 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")
)

Functions

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

Be aware that if you want AuthType to be set, it must be set with the EnvAuth environment variable. common.ComposingConfigurationProvider only calls AuthType on the first provider.

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