-
-
Notifications
You must be signed in to change notification settings - Fork 744
/
pulumi.go
104 lines (85 loc) · 3.19 KB
/
pulumi.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package pulumi
import (
"context"
"encoding/json"
"errors"
"fmt"
"time"
esc "github.com/pulumi/esc/cmd/esc/cli/client"
corev1 "k8s.io/api/core/v1"
esv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
"github.com/external-secrets/external-secrets/pkg/utils"
)
type client struct {
escClient esc.Client
environment string
organization string
}
const (
errPushSecretsNotSupported = "pushing secrets is currently not supported by Pulumi"
errDeleteSecretsNotSupported = "deleting secrets is currently not supported by Pulumi"
errGettingSecrets = "error getting secret %s: %w"
errUnmarshalSecret = "unable to unmarshal secret: %w"
errUnableToGetValues = "unable to get value for key %s: %w"
errGettingAllSecretsNotSupported = "getting all secrets is currently not supported by Pulumi"
)
var _ esv1beta1.SecretsClient = &client{}
func (c *client) GetSecret(ctx context.Context, ref esv1beta1.ExternalSecretDataRemoteRef) ([]byte, error) {
x, _, err := c.escClient.OpenEnvironment(ctx, c.organization, c.environment, 5*time.Minute)
if err != nil {
return nil, err
}
value, err := c.escClient.GetOpenProperty(ctx, c.organization, c.environment, x, ref.Key)
if err != nil {
return nil, err
}
return utils.GetByteValue(value.ToJSON(false))
}
func (c *client) PushSecret(_ context.Context, _ *corev1.Secret, _ esv1beta1.PushSecretData) error {
return errors.New(errPushSecretsNotSupported)
}
func (c *client) SecretExists(_ context.Context, _ esv1beta1.PushSecretRemoteRef) (bool, error) {
return false, errors.New(errPushSecretsNotSupported)
}
func (c *client) DeleteSecret(_ context.Context, _ esv1beta1.PushSecretRemoteRef) error {
return errors.New(errDeleteSecretsNotSupported)
}
func (c *client) Validate() (esv1beta1.ValidationResult, error) {
return esv1beta1.ValidationResultReady, nil
}
func (c *client) GetSecretMap(ctx context.Context, ref esv1beta1.ExternalSecretDataRemoteRef) (map[string][]byte, error) {
data, err := c.GetSecret(ctx, ref)
if err != nil {
return nil, fmt.Errorf(errGettingSecrets, ref.Key, err)
}
kv := make(map[string]any)
err = json.Unmarshal(data, &kv)
if err != nil {
return nil, fmt.Errorf(errUnmarshalSecret, err)
}
secretData := make(map[string][]byte)
for k, v := range kv {
secretData[k], err = utils.GetByteValue(v)
if err != nil {
return nil, fmt.Errorf(errUnableToGetValues, k, err)
}
}
return secretData, nil
}
func (c *client) GetAllSecrets(_ context.Context, _ esv1beta1.ExternalSecretFind) (map[string][]byte, error) {
return nil, errors.New(errGettingAllSecretsNotSupported)
}
func (c *client) Close(context.Context) error {
return nil
}