Skip to content

Commit

Permalink
feat: add support for custom secret provider define in api.kusion.io
Browse files Browse the repository at this point in the history
  • Loading branch information
Liuxingyu1111111 committed Jun 24, 2024
1 parent 1da8b5c commit f91dd69
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/apis/api.kusion.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions pkg/secrets/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions pkg/secrets/providers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit f91dd69

Please sign in to comment.