|
@@ -16,19 +16,18 @@ import (
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
|
|
|
- corev1 "k8s.io/api/core/v1"
|
|
|
|
|
-
|
|
|
|
|
|
|
+ "github.com/oracle/oci-go-sdk/v45/common"
|
|
|
vault "github.com/oracle/oci-go-sdk/v45/vault"
|
|
vault "github.com/oracle/oci-go-sdk/v45/vault"
|
|
|
"github.com/tidwall/gjson"
|
|
"github.com/tidwall/gjson"
|
|
|
-
|
|
|
|
|
- "github.com/external-secrets/external-secrets/pkg/provider"
|
|
|
|
|
- "github.com/external-secrets/external-secrets/pkg/provider/aws/util"
|
|
|
|
|
- "github.com/external-secrets/external-secrets/pkg/provider/schema"
|
|
|
|
|
- "github.com/oracle/oci-go-sdk/v45/common"
|
|
|
|
|
|
|
+ corev1 "k8s.io/api/core/v1"
|
|
|
"k8s.io/apimachinery/pkg/types"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
|
kclient "sigs.k8s.io/controller-runtime/pkg/client"
|
|
kclient "sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
|
|
|
|
esv1alpha1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1alpha1"
|
|
esv1alpha1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1alpha1"
|
|
|
|
|
+ "github.com/external-secrets/external-secrets/pkg/provider"
|
|
|
|
|
+ "github.com/external-secrets/external-secrets/pkg/provider/aws/util"
|
|
|
|
|
+ "github.com/external-secrets/external-secrets/pkg/provider/schema"
|
|
|
|
|
+ "github.com/external-secrets/external-secrets/pkg/utils"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
const (
|
|
@@ -47,6 +46,8 @@ const (
|
|
|
errMissingRegion = "missing Region"
|
|
errMissingRegion = "missing Region"
|
|
|
errMissingFingerprint = "missing Fingerprint"
|
|
errMissingFingerprint = "missing Fingerprint"
|
|
|
errJSONSecretUnmarshal = "unable to unmarshal secret: %w"
|
|
errJSONSecretUnmarshal = "unable to unmarshal secret: %w"
|
|
|
|
|
+ errMissingKey = "missing Key in secret: %s"
|
|
|
|
|
+ errInvalidSecret = "invalid secret received. no secret string nor binary for key: %s"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
type client struct {
|
|
type client struct {
|
|
@@ -63,16 +64,6 @@ type client struct {
|
|
|
privateKey string
|
|
privateKey string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// // Oracle struct with values for *oracle.Client and projectID.
|
|
|
|
|
-// type providerOracle struct {
|
|
|
|
|
-// OracleClient identity.IdentityClient
|
|
|
|
|
-// projectID interface{}
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// type OracleCredentials struct {
|
|
|
|
|
-// Token string `json:"token"`
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
type KeyManagementService struct {
|
|
type KeyManagementService struct {
|
|
|
Client SMInterface
|
|
Client SMInterface
|
|
|
}
|
|
}
|
|
@@ -134,8 +125,9 @@ func (c *client) setAuth(ctx context.Context) error {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (kms *KeyManagementService) GetSecret(ctx context.Context, ref esv1alpha1.ExternalSecretDataRemoteRef) ([]byte, error) {
|
|
func (kms *KeyManagementService) GetSecret(ctx context.Context, ref esv1alpha1.ExternalSecretDataRemoteRef) ([]byte, error) {
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+ if utils.IsNil(kms.Client) {
|
|
|
|
|
+ return nil, fmt.Errorf(errUninitalizedOracleProvider)
|
|
|
|
|
+ }
|
|
|
kmsRequest := vault.GetSecretRequest{
|
|
kmsRequest := vault.GetSecretRequest{
|
|
|
SecretId: &ref.Key,
|
|
SecretId: &ref.Key,
|
|
|
}
|
|
}
|
|
@@ -147,7 +139,7 @@ func (kms *KeyManagementService) GetSecret(ctx context.Context, ref esv1alpha1.E
|
|
|
if *secretOut.SecretName != "" {
|
|
if *secretOut.SecretName != "" {
|
|
|
return []byte(*secretOut.SecretName), nil
|
|
return []byte(*secretOut.SecretName), nil
|
|
|
}
|
|
}
|
|
|
- return nil, fmt.Errorf("invalid secret received. no secret string nor binary for key: %s", ref.Key)
|
|
|
|
|
|
|
+ return nil, fmt.Errorf(errInvalidSecret, ref.Key)
|
|
|
}
|
|
}
|
|
|
var payload *string
|
|
var payload *string
|
|
|
if secretOut.SecretName != nil {
|
|
if secretOut.SecretName != nil {
|
|
@@ -158,7 +150,7 @@ func (kms *KeyManagementService) GetSecret(ctx context.Context, ref esv1alpha1.E
|
|
|
|
|
|
|
|
val := gjson.Get(payloadval, ref.Property)
|
|
val := gjson.Get(payloadval, ref.Property)
|
|
|
if !val.Exists() {
|
|
if !val.Exists() {
|
|
|
- return nil, fmt.Errorf("key %s does not exist in secret %s", ref.Property, ref.Key)
|
|
|
|
|
|
|
+ return nil, fmt.Errorf(errMissingKey, ref.Key)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return []byte(val.String()), nil
|
|
return []byte(val.String()), nil
|
|
@@ -172,7 +164,7 @@ func (kms *KeyManagementService) GetSecretMap(ctx context.Context, ref esv1alpha
|
|
|
kv := make(map[string]string)
|
|
kv := make(map[string]string)
|
|
|
err = json.Unmarshal(data, &kv)
|
|
err = json.Unmarshal(data, &kv)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- return nil, fmt.Errorf("unable to unmarshal secret %s: %w", ref.Key, err)
|
|
|
|
|
|
|
+ return nil, fmt.Errorf(errJSONSecretUnmarshal, err)
|
|
|
}
|
|
}
|
|
|
secretData := make(map[string][]byte)
|
|
secretData := make(map[string][]byte)
|
|
|
for k, v := range kv {
|
|
for k, v := range kv {
|
|
@@ -212,11 +204,6 @@ func (kms *KeyManagementService) NewClient(ctx context.Context, store esv1alpha1
|
|
|
return kms, nil
|
|
return kms, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// // Function newOracleProvider returns a reference to a new Oracle struct 'instance'.
|
|
|
|
|
-// func NewOracleProvider() *providerOracle {
|
|
|
|
|
-// return &providerOracle{}
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
func (kms *KeyManagementService) Close() error {
|
|
func (kms *KeyManagementService) Close() error {
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
@@ -226,72 +213,3 @@ func init() {
|
|
|
Oracle: &esv1alpha1.OracleProvider{},
|
|
Oracle: &esv1alpha1.OracleProvider{},
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-// func fakeMain(kms *KeyManagementService) {
|
|
|
|
|
-
|
|
|
|
|
-// configurationProvider := common.NewRawConfigurationProvider("", "", "", "", "", nil)
|
|
|
|
|
-
|
|
|
|
|
-// c, err := identity.NewIdentityClientWithConfigurationProvider(common.DefaultConfigProvider())
|
|
|
|
|
-// o.client = c
|
|
|
|
|
-// fmt.Println("Client:", o.client)
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// fmt.Println("Error:", err)
|
|
|
|
|
-// return
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // The OCID of the tenancy containing the compartment.
|
|
|
|
|
-// // tenancyID, err := common.DefaultConfigProvider().TenancyOCID()
|
|
|
|
|
-// // if err != nil {
|
|
|
|
|
-// // fmt.Println("Error:", err)
|
|
|
|
|
-// // return
|
|
|
|
|
-// // }
|
|
|
|
|
-
|
|
|
|
|
-// // The OCID of the tenancy containing the compartment.
|
|
|
|
|
-// userID, err := common.DefaultConfigProvider().UserOCID()
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// fmt.Println("Error:", err)
|
|
|
|
|
-// return
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // request := identity.ListAvailabilityDomainsRequest{
|
|
|
|
|
-// // CompartmentId: &tenancyID,
|
|
|
|
|
-// // }
|
|
|
|
|
-
|
|
|
|
|
-// // request2 := identity.ListCustomerSecretKeysRequest{
|
|
|
|
|
-// // UserId: &TF_VAR_user_ocid,
|
|
|
|
|
-// // }
|
|
|
|
|
-
|
|
|
|
|
-// request2 := identity.ListCustomerSecretKeysRequest{
|
|
|
|
|
-// UserId: &userID,
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// // r, err := c.ListAvailabilityDomains(context.Background(), request)
|
|
|
|
|
-// // if err != nil {
|
|
|
|
|
-// // fmt.Println("Error:", err)
|
|
|
|
|
-// // return
|
|
|
|
|
-// // }
|
|
|
|
|
-
|
|
|
|
|
-// r, err := c.ListCustomerSecretKeys(context.Background(), request2)
|
|
|
|
|
-// if err != nil {
|
|
|
|
|
-// fmt.Println("Error:", err)
|
|
|
|
|
-// return
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// //c.list
|
|
|
|
|
-
|
|
|
|
|
-// //z, err := c.ListCustomerSecretKeys(context.Background(), identity.ListCustomerSecretKeysRequest{})
|
|
|
|
|
-
|
|
|
|
|
-// fmt.Printf("List of available Secret Keys: %v", r.Items)
|
|
|
|
|
-// return
|
|
|
|
|
-// }
|
|
|
|
|
-
|
|
|
|
|
-// var TF_VAR_user_ocid = os.Getenv("OCI_USER")
|
|
|
|
|
-// var TF_VAR_region = os.Getenv("OCI_REGION")
|
|
|
|
|
-
|
|
|
|
|
-// //var TF_VAR_fingerprint = os.Getenv("OCI_CLI_FINGERPRINT").
|
|
|
|
|
-// var TF_VAR_private_key = os.Getenv("OCI_PRIVATE_KEY")
|
|
|
|
|
-
|
|
|
|
|
-// // var TF_VAR_tenancy_ocid = os.Getenv("OCI_TENANCY")
|
|
|
|
|
-
|
|
|
|
|
-// // Requires a token to be set in environment variablego.
|
|
|
|
|
-// var ORACLETOKEN = os.Getenv("ORACLETOKEN")
|
|
|