Skip to content

Commit 62a8ae7

Browse files
committed
fix obo token fail in sweeper
1 parent 3e27c4d commit 62a8ae7

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

oci/provider.go

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io/ioutil"
99
"math"
1010
"os"
11+
"path/filepath"
1112
"regexp"
1213
"strconv"
1314
"strings"
@@ -777,6 +778,18 @@ func checkIncompatibleAttrsForApiKeyAuth(d *schema.ResourceData) ([]string, bool
777778
return apiKeyConfigAttributesToUnset, len(apiKeyConfigAttributesToUnset) == 0
778779
}
779780

781+
func getCertificateFileBytes(certificateFileFullPath string) (pemRaw []byte, err error) {
782+
absFile, err := filepath.Abs(certificateFileFullPath)
783+
if err != nil {
784+
return nil, fmt.Errorf("can't form absolute path of %s: %v", certificateFileFullPath, err)
785+
}
786+
787+
if pemRaw, err = ioutil.ReadFile(absFile); err != nil {
788+
return nil, fmt.Errorf("can't read %s: %v", certificateFileFullPath, err)
789+
}
790+
return
791+
}
792+
780793
func ProviderConfig(d *schema.ResourceData) (interface{}, error) {
781794
clients := &OracleClients{configuration: map[string]string{}}
782795

@@ -879,17 +892,34 @@ func getConfigProviders(d *schema.ResourceData, auth string) ([]oci_common.Confi
879892
return nil, fmt.Errorf("can not get %s from Terraform configuration (InstancePrincipalWithCerts)", regionAttrName)
880893
}
881894

882-
leafCertificate := getEnvSettingWithBlankDefault("ip_cert")
883-
leafCertificateBytes := []byte(leafCertificate)
895+
defaultCertsDir, err := os.Getwd()
896+
if err != nil {
897+
return nil, fmt.Errorf("can not get working directory for current os platform")
898+
}
884899

885-
leafPrivateKey := getEnvSettingWithBlankDefault("ip_key")
886-
leafPrivateKeyBytes := []byte(leafPrivateKey)
900+
certsDir := filepath.Clean(getEnvSettingWithDefault("test_certificates_location", defaultCertsDir))
901+
leafCertificateBytes, err := getCertificateFileBytes(filepath.Join(certsDir, "ip_cert.pem"))
902+
if err != nil {
903+
return nil, fmt.Errorf("can not read leaf certificate from %s", filepath.Join(certsDir, "ip_cert.pem"))
904+
}
887905

888-
leafPassphrase := getEnvSettingWithBlankDefault("INTEGRATION_PASS_PHRASE")
889-
leafPassphraseBytes := []byte(leafPassphrase)
906+
leafPrivateKeyBytes, err := getCertificateFileBytes(filepath.Join(certsDir, "ip_key.pem"))
907+
if err != nil {
908+
return nil, fmt.Errorf("can not read leaf private key from %s", filepath.Join(certsDir, "ip_key.pem"))
909+
}
890910

891-
intermediateCertificate := getEnvSettingWithBlankDefault("intermediate")
892-
intermediateCertificateBytes := []byte(intermediateCertificate)
911+
leafPassphraseBytes := []byte{}
912+
if _, err := os.Stat(certsDir + "/leaf_passphrase"); !os.IsNotExist(err) {
913+
leafPassphraseBytes, err = getCertificateFileBytes(filepath.Join(certsDir + "leaf_passphrase"))
914+
if err != nil {
915+
return nil, fmt.Errorf("can not read leafPassphraseBytes from %s", filepath.Join(certsDir+"leaf_passphrase"))
916+
}
917+
}
918+
919+
intermediateCertificateBytes, err := getCertificateFileBytes(filepath.Join(certsDir, "intermediate.pem"))
920+
if err != nil {
921+
return nil, fmt.Errorf("can not read intermediate certificate from %s", filepath.Join(certsDir, "intermediate.pem"))
922+
}
893923

894924
intermediateCertificatesBytes := [][]byte{
895925
intermediateCertificateBytes,

0 commit comments

Comments
 (0)