mirror of
https://github.com/external-secrets/external-secrets.git
synced 2024-12-14 11:57:59 +00:00
feat(fake): deprecate ValueMap to use Value instead (#2884)
This commit is contained in:
parent
2441ad547b
commit
3599384660
12 changed files with 135 additions and 16 deletions
|
@ -113,6 +113,12 @@ issues:
|
||||||
linters:
|
linters:
|
||||||
- goheader
|
- goheader
|
||||||
|
|
||||||
|
# excluding deprecation check introduced on purpose in #2884
|
||||||
|
- path: pkg/provider/fake/fake.go
|
||||||
|
text: 'SA1019: data.ValueMap is deprecated: ValueMap is deprecated and is intended to be removed in the future, use the `value` field instead.'
|
||||||
|
- path: pkg/provider/fake/fake_test.go
|
||||||
|
text: 'SA1019: data.ValueMap is deprecated: ValueMap is deprecated and is intended to be removed in the future, use the `value` field instead.'
|
||||||
|
|
||||||
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
|
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
|
||||||
max-per-linter: 0
|
max-per-linter: 0
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,9 @@ type FakeProvider struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type FakeProviderData struct {
|
type FakeProviderData struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Value string `json:"value,omitempty"`
|
Value string `json:"value,omitempty"`
|
||||||
|
// Deprecated: ValueMap is deprecated and is intended to be removed in the future, use the `value` field instead.
|
||||||
ValueMap map[string]string `json:"valueMap,omitempty"`
|
ValueMap map[string]string `json:"valueMap,omitempty"`
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -2571,6 +2571,9 @@ spec:
|
||||||
valueMap:
|
valueMap:
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
type: string
|
type: string
|
||||||
|
description: 'Deprecated: ValueMap is deprecated and
|
||||||
|
is intended to be removed in the future, use the `value`
|
||||||
|
field instead.'
|
||||||
type: object
|
type: object
|
||||||
version:
|
version:
|
||||||
type: string
|
type: string
|
||||||
|
|
|
@ -2571,6 +2571,9 @@ spec:
|
||||||
valueMap:
|
valueMap:
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
type: string
|
type: string
|
||||||
|
description: 'Deprecated: ValueMap is deprecated and
|
||||||
|
is intended to be removed in the future, use the `value`
|
||||||
|
field instead.'
|
||||||
type: object
|
type: object
|
||||||
version:
|
version:
|
||||||
type: string
|
type: string
|
||||||
|
|
|
@ -2402,6 +2402,7 @@ spec:
|
||||||
valueMap:
|
valueMap:
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
type: string
|
type: string
|
||||||
|
description: 'Deprecated: ValueMap is deprecated and is intended to be removed in the future, use the `value` field instead.'
|
||||||
type: object
|
type: object
|
||||||
version:
|
version:
|
||||||
type: string
|
type: string
|
||||||
|
@ -6344,6 +6345,7 @@ spec:
|
||||||
valueMap:
|
valueMap:
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
type: string
|
type: string
|
||||||
|
description: 'Deprecated: ValueMap is deprecated and is intended to be removed in the future, use the `value` field instead.'
|
||||||
type: object
|
type: object
|
||||||
version:
|
version:
|
||||||
type: string
|
type: string
|
||||||
|
|
|
@ -3496,6 +3496,7 @@ map[string]string
|
||||||
</em>
|
</em>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
<p>Deprecated: ValueMap is deprecated and is intended to be removed in the future, use the <code>value</code> field instead.</p>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -2,13 +2,14 @@ We provide a `fake` implementation to help with testing. This provider returns s
|
||||||
To use the `fake` provider simply create a `SecretStore` or `ClusterSecretStore` and configure it like in the following example:
|
To use the `fake` provider simply create a `SecretStore` or `ClusterSecretStore` and configure it like in the following example:
|
||||||
|
|
||||||
!!! note inline end
|
!!! note inline end
|
||||||
The provider returns static data configured in `value` or `valueMap`. You can define a `version`, too. If set the `remoteRef` from an ExternalSecret must match otherwise no value is returned.
|
The provider returns static data configured in `value`. You can define a `version`, too. If set the `remoteRef` from an ExternalSecret must match otherwise no value is returned.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
{% include 'fake-provider-store.yaml' %}
|
{% include 'fake-provider-store.yaml' %}
|
||||||
```
|
```
|
||||||
|
|
||||||
Please note that `value` is intended for exclusive use with `data` and `valueMap` for `dataFrom`.
|
Please note that `value` is intended for exclusive use with `data` for `dataFrom`. You can use the `data` to set a `JSON` compliant value to be used as `dataFrom`.
|
||||||
|
|
||||||
Here is an example `ExternalSecret` that displays this behavior:
|
Here is an example `ExternalSecret` that displays this behavior:
|
||||||
|
|
||||||
!!! warning inline end
|
!!! warning inline end
|
||||||
|
|
|
@ -17,3 +17,4 @@ spec:
|
||||||
dataFrom:
|
dataFrom:
|
||||||
- extract:
|
- extract:
|
||||||
key: /foo/baz
|
key: /foo/baz
|
||||||
|
version: v1
|
|
@ -5,5 +5,4 @@ metadata:
|
||||||
namespace: default
|
namespace: default
|
||||||
data:
|
data:
|
||||||
foo_bar: SEVMTE8x # HELLO1 (via data)
|
foo_bar: SEVMTE8x # HELLO1 (via data)
|
||||||
foo: ZXhhbXBsZQ== # example (via dataFrom)
|
john: ZG9l #doe (via dataFrom)
|
||||||
other: dGhpbmc= # thing (via dataFrom)
|
|
|
@ -13,8 +13,5 @@ spec:
|
||||||
value: "HELLO2"
|
value: "HELLO2"
|
||||||
version: "v2"
|
version: "v2"
|
||||||
- key: "/foo/baz"
|
- key: "/foo/baz"
|
||||||
valueMap:
|
value: '{"john": "doe"}'
|
||||||
foo: example
|
version: "v1"
|
||||||
other: thing
|
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ package fake
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -182,12 +183,40 @@ func (p *Provider) GetSecret(_ context.Context, ref esv1beta1.ExternalSecretData
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSecretMap returns multiple k/v pairs from the provider.
|
// GetSecretMap returns multiple k/v pairs from the provider.
|
||||||
func (p *Provider) GetSecretMap(_ context.Context, ref esv1beta1.ExternalSecretDataRemoteRef) (map[string][]byte, error) {
|
func (p *Provider) GetSecretMap(ctx context.Context, ref esv1beta1.ExternalSecretDataRemoteRef) (map[string][]byte, error) {
|
||||||
data, ok := p.config[mapKey(ref.Key, ref.Version)]
|
ddata, ok := p.config[mapKey(ref.Key, ref.Version)]
|
||||||
if !ok || data.Version != ref.Version || data.ValueMap == nil {
|
if !ok || ddata.Version != ref.Version {
|
||||||
return nil, esv1beta1.NoSecretErr
|
return nil, esv1beta1.NoSecretErr
|
||||||
}
|
}
|
||||||
return convertMap(data.ValueMap), nil
|
|
||||||
|
// Due to backward compatibility valueMap will still be returned for now
|
||||||
|
if ddata.ValueMap != nil {
|
||||||
|
return convertMap(ddata.ValueMap), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := p.GetSecret(ctx, ref)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
secretData := make(map[string][]byte)
|
||||||
|
kv := make(map[string]json.RawMessage)
|
||||||
|
err = json.Unmarshal(data, &kv)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to unmarshal secret: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v := range kv {
|
||||||
|
var strVal string
|
||||||
|
err = json.Unmarshal(v, &strVal)
|
||||||
|
if err == nil {
|
||||||
|
secretData[k] = []byte(strVal)
|
||||||
|
} else {
|
||||||
|
secretData[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return secretData, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertMap(in map[string]string) map[string][]byte {
|
func convertMap(in map[string]string) map[string][]byte {
|
||||||
|
|
|
@ -413,9 +413,85 @@ func TestGetSecretMap(t *testing.T) {
|
||||||
},
|
},
|
||||||
expErr: esv1beta1.NoSecretErr.Error(),
|
expErr: esv1beta1.NoSecretErr.Error(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "get correct map from multiple versions by using Value only",
|
||||||
|
input: []esv1beta1.FakeProviderData{
|
||||||
|
{
|
||||||
|
Key: "/bar",
|
||||||
|
Version: "v1",
|
||||||
|
Value: `{"john":"doe"}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
request: esv1beta1.ExternalSecretDataRemoteRef{
|
||||||
|
Key: "/bar",
|
||||||
|
Version: "v1",
|
||||||
|
},
|
||||||
|
expValue: map[string][]byte{
|
||||||
|
"john": []byte("doe"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "get correct maps from multiple versions by using Value only",
|
||||||
|
input: []esv1beta1.FakeProviderData{
|
||||||
|
{
|
||||||
|
Key: "/bar",
|
||||||
|
Version: "v3",
|
||||||
|
Value: `{"john":"doe", "foo": "bar"}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
request: esv1beta1.ExternalSecretDataRemoteRef{
|
||||||
|
Key: "/bar",
|
||||||
|
Version: "v3",
|
||||||
|
},
|
||||||
|
expValue: map[string][]byte{
|
||||||
|
"john": []byte("doe"),
|
||||||
|
"foo": []byte("bar"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid marshal",
|
||||||
|
input: []esv1beta1.FakeProviderData{
|
||||||
|
{
|
||||||
|
Key: "/bar",
|
||||||
|
Version: "v3",
|
||||||
|
Value: `---------`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
request: esv1beta1.ExternalSecretDataRemoteRef{
|
||||||
|
Key: "/bar",
|
||||||
|
Version: "v3",
|
||||||
|
},
|
||||||
|
expErr: "unable to unmarshal secret: invalid character '-' in numeric literal",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "get correct value from ValueMap due to retrocompatibility",
|
||||||
|
input: []esv1beta1.FakeProviderData{
|
||||||
|
{
|
||||||
|
Key: "/foo/bar",
|
||||||
|
Version: "v3",
|
||||||
|
ValueMap: map[string]string{
|
||||||
|
"john": "doe",
|
||||||
|
"baz": "bang",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
request: esv1beta1.ExternalSecretDataRemoteRef{
|
||||||
|
Key: "/foo/bar",
|
||||||
|
Version: "v3",
|
||||||
|
},
|
||||||
|
expValue: map[string][]byte{
|
||||||
|
"john": []byte("doe"),
|
||||||
|
"baz": []byte("bang"),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "get correct value from multiple versions",
|
name: "get correct value from multiple versions",
|
||||||
input: []esv1beta1.FakeProviderData{
|
input: []esv1beta1.FakeProviderData{
|
||||||
|
{
|
||||||
|
Key: "john",
|
||||||
|
Value: "doe",
|
||||||
|
Version: "v2",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Key: "junk",
|
Key: "junk",
|
||||||
ValueMap: map[string]string{
|
ValueMap: map[string]string{
|
||||||
|
@ -467,7 +543,7 @@ func TestGetSecretMap(t *testing.T) {
|
||||||
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
||||||
out, err := cl.GetSecretMap(context.Background(), row.request)
|
out, err := cl.GetSecretMap(context.Background(), row.request)
|
||||||
if row.expErr != "" {
|
if row.expErr != "" {
|
||||||
gomega.Expect(err).To(gomega.MatchError(row.expErr))
|
gomega.Expect(err).To(gomega.MatchError(gomega.ContainSubstring(row.expErr)))
|
||||||
} else {
|
} else {
|
||||||
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue