From f91dd693d87ee9b6024c3504173422658e3d8b2a Mon Sep 17 00:00:00 2001 From: liuxingyu9574 <841528039@qq.com> Date: Sat, 22 Jun 2024 11:51:57 +0800 Subject: [PATCH] feat: add support for custom secret provider define in api.kusion.io --- pkg/apis/api.kusion.io/v1/types.go | 11 +++++++++++ pkg/secrets/providers.go | 4 ++++ pkg/secrets/providers_test.go | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/pkg/apis/api.kusion.io/v1/types.go b/pkg/apis/api.kusion.io/v1/types.go index f33ac38d6..9bb66f960 100644 --- a/pkg/apis/api.kusion.io/v1/types.go +++ b/pkg/apis/api.kusion.io/v1/types.go @@ -721,6 +721,9 @@ type ProviderSpec struct { // Fake configures a store with static key/value pairs Fake *FakeProvider `yaml:"fake,omitempty" json:"fake,omitempty"` + + // custom configures a store with custom define attributes + Custom *CustomSecretProvider `yaml:"custom,omitempty" json:"custom,omitempty"` } // AlicloudProvider configures a store to retrieve secrets from Alicloud Secrets Manager. @@ -798,6 +801,14 @@ type FakeProviderData struct { Version string `json:"version,omitempty"` } +// CustomSecretProvider configures a secret provider with custom define attributes +type CustomSecretProvider struct { + // platform name of the provider + Name string `json:"name"` + // attributes of the provider + Attributes map[string]string `json:"attributes,omitempty"` +} + type Type string const ( diff --git a/pkg/secrets/providers.go b/pkg/secrets/providers.go index 46bad127e..a56c1b423 100644 --- a/pkg/secrets/providers.go +++ b/pkg/secrets/providers.go @@ -100,5 +100,9 @@ func getProviderName(spec *v1.ProviderSpec) (string, error) { return "", fmt.Errorf("secret stores must only have exactly one provider specified, found %d", len(specMap)) } + if maps.Keys(specMap)[0] == "custom" { + return specMap["custom"].(map[string]interface{})["name"].(string), nil + } + return maps.Keys(specMap)[0], nil } diff --git a/pkg/secrets/providers_test.go b/pkg/secrets/providers_test.go index 01506972e..6d2f92ae8 100644 --- a/pkg/secrets/providers_test.go +++ b/pkg/secrets/providers_test.go @@ -47,6 +47,17 @@ func TestRegister(t *testing.T) { AWS: &v1.AWSProvider{}, }, }, + { + name: "should register a valid provider", + providerName: "customplaform", + shouldPanic: false, + expExists: true, + spec: &v1.ProviderSpec{ + Custom: &v1.CustomSecretProvider{ + Name: "customplaform", + }, + }, + }, } fsp := &FakeSecretStoreProvider{}