|
8 | 8 | "io/ioutil" |
9 | 9 | "math" |
10 | 10 | "os" |
| 11 | + "path/filepath" |
11 | 12 | "regexp" |
12 | 13 | "strconv" |
13 | 14 | "strings" |
@@ -777,6 +778,18 @@ func checkIncompatibleAttrsForApiKeyAuth(d *schema.ResourceData) ([]string, bool |
777 | 778 | return apiKeyConfigAttributesToUnset, len(apiKeyConfigAttributesToUnset) == 0 |
778 | 779 | } |
779 | 780 |
|
| 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 | + |
780 | 793 | func ProviderConfig(d *schema.ResourceData) (interface{}, error) { |
781 | 794 | clients := &OracleClients{configuration: map[string]string{}} |
782 | 795 |
|
@@ -879,17 +892,34 @@ func getConfigProviders(d *schema.ResourceData, auth string) ([]oci_common.Confi |
879 | 892 | return nil, fmt.Errorf("can not get %s from Terraform configuration (InstancePrincipalWithCerts)", regionAttrName) |
880 | 893 | } |
881 | 894 |
|
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 | + } |
884 | 899 |
|
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 | + } |
887 | 905 |
|
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 | + } |
890 | 910 |
|
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 | + } |
893 | 923 |
|
894 | 924 | intermediateCertificatesBytes := [][]byte{ |
895 | 925 | intermediateCertificateBytes, |
|
0 commit comments