Skip to content

Commit f74d413

Browse files
authored
OCI Vault fix (#131)
* OCI Vault fix
1 parent 77ab337 commit f74d413

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,10 @@ The following example puts the logfile in the current location with the filename
662662

663663
The exporter will read the password from a secret stored in OCI Vault if you set these two environment variables:
664664

665-
- `VAULT_ID` should be set to the OCID of the OCI vault that you wish to use
666-
- `VAULT_SECRET_NAME` should be set to the name of the secret in the OCI vault which contains the database password
665+
- `OCI_VAULT_ID` should be set to the OCID of the OCI vault that you wish to use
666+
- `OCI_VAULT_SECRET_NAME` should be set to the name of the secret in the OCI vault which contains the database password
667667

668-
Note that the process must be running under a user that has the OCI CLI installed and configured correctly to access the desired tenancy and region.
668+
> Note that the process must be running under a user that has the OCI CLI installed and configured correctly to access the desired tenancy and region. The OCI Profile used is `DEFAULT`.
669669

670670
## Custom metrics
671671

Diff for: main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ func main() {
6060
connectString := os.Getenv("DB_CONNECT_STRING")
6161
dbrole := os.Getenv("DB_ROLE")
6262

63-
vaultName, useVault := os.LookupEnv("VAULT_ID")
63+
vaultID, useVault := os.LookupEnv("OCI_VAULT_ID")
6464
if useVault {
65-
level.Info(logger).Log("msg", "VAULT_ID env var is present so using OCI Vault", "vault_name", vaultName)
66-
password = vault.GetVaultSecret(vaultName, os.Getenv("VAULT_SECRET_NAME"))
65+
level.Info(logger).Log("msg", "OCI_VAULT_ID env var is present so using OCI Vault", "vaultOCID", vaultID)
66+
password = vault.GetVaultSecret(vaultID, os.Getenv("OCI_VAULT_SECRET_NAME"))
6767
}
6868

6969
freeOSMemInterval, enableFree := os.LookupEnv("FREE_INTERVAL")

Diff for: vault/vault.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,27 @@ import (
88
b64 "encoding/base64"
99
"strings"
1010

11+
"github.com/go-kit/log/level"
1112
"github.com/oracle/oci-go-sdk/v65/common"
1213
"github.com/oracle/oci-go-sdk/v65/example/helpers"
1314
"github.com/oracle/oci-go-sdk/v65/secrets"
15+
"github.com/prometheus/common/promlog"
1416
)
1517

1618
func GetVaultSecret(vaultId string, secretName string) string {
17-
configProvider := common.ConfigurationProviderEnvironmentVariables("vault", "")
19+
promLogConfig := &promlog.Config{}
20+
logger := promlog.New(promLogConfig)
1821

19-
client, err := secrets.NewSecretsClientWithConfigurationProvider(configProvider)
22+
client, err := secrets.NewSecretsClientWithConfigurationProvider(common.DefaultConfigProvider())
2023
helpers.FatalIfError(err)
2124

25+
tenancyID, err := common.DefaultConfigProvider().TenancyOCID()
26+
helpers.FatalIfError(err)
27+
region, err := common.DefaultConfigProvider().Region()
28+
helpers.FatalIfError(err)
29+
level.Info(logger).Log("msg", "OCI_VAULT_ID env var is present so using OCI Vault", "Region", region)
30+
level.Info(logger).Log("msg", "OCI_VAULT_ID env var is present so using OCI Vault", "tenancyOCID", tenancyID)
31+
2232
req := secrets.GetSecretBundleByNameRequest{
2333
SecretName: common.String(secretName),
2434
VaultId: common.String(vaultId)}

0 commit comments

Comments
 (0)