|
|
@@ -20,6 +20,7 @@ import (
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
|
|
|
+ "cloud.google.com/go/secretmanager/apiv1/secretmanagerpb"
|
|
|
"github.com/tidwall/sjson"
|
|
|
|
|
|
esv1beta1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
|
|
|
@@ -28,6 +29,7 @@ import (
|
|
|
type Metadata struct {
|
|
|
Annotations map[string]string `json:"annotations"`
|
|
|
Labels map[string]string `json:"labels"`
|
|
|
+ Topics []string `json:"topics,omitempty"`
|
|
|
}
|
|
|
|
|
|
func newPushSecretBuilder(payload []byte, data esv1beta1.PushSecretData) (pushSecretBuilder, error) {
|
|
|
@@ -49,7 +51,7 @@ func newPushSecretBuilder(payload []byte, data esv1beta1.PushSecretData) (pushSe
|
|
|
}
|
|
|
|
|
|
type pushSecretBuilder interface {
|
|
|
- buildMetadata(annotations, labels map[string]string) (map[string]string, map[string]string, error)
|
|
|
+ buildMetadata(annotations, labels map[string]string, topics []*secretmanagerpb.Topic) (map[string]string, map[string]string, []string, error)
|
|
|
needUpdate(original []byte) bool
|
|
|
buildData(original []byte) ([]byte, error)
|
|
|
}
|
|
|
@@ -59,9 +61,9 @@ type psBuilder struct {
|
|
|
pushSecretData esv1beta1.PushSecretData
|
|
|
}
|
|
|
|
|
|
-func (b *psBuilder) buildMetadata(_, labels map[string]string) (map[string]string, map[string]string, error) {
|
|
|
+func (b *psBuilder) buildMetadata(_, labels map[string]string, _ []*secretmanagerpb.Topic) (map[string]string, map[string]string, []string, error) {
|
|
|
if manager, ok := labels[managedByKey]; !ok || manager != managedByValue {
|
|
|
- return nil, nil, fmt.Errorf("secret %v is not managed by external secrets", b.pushSecretData.GetRemoteKey())
|
|
|
+ return nil, nil, nil, fmt.Errorf("secret %v is not managed by external secrets", b.pushSecretData.GetRemoteKey())
|
|
|
}
|
|
|
|
|
|
var metadata Metadata
|
|
|
@@ -71,7 +73,7 @@ func (b *psBuilder) buildMetadata(_, labels map[string]string) (map[string]strin
|
|
|
decoder.DisallowUnknownFields()
|
|
|
|
|
|
if err := decoder.Decode(&metadata); err != nil {
|
|
|
- return nil, nil, fmt.Errorf("failed to decode PushSecret metadata: %w", err)
|
|
|
+ return nil, nil, nil, fmt.Errorf("failed to decode PushSecret metadata: %w", err)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -81,7 +83,7 @@ func (b *psBuilder) buildMetadata(_, labels map[string]string) (map[string]strin
|
|
|
}
|
|
|
newLabels[managedByKey] = managedByValue
|
|
|
|
|
|
- return metadata.Annotations, newLabels, nil
|
|
|
+ return metadata.Annotations, newLabels, metadata.Topics, nil
|
|
|
}
|
|
|
|
|
|
func (b *psBuilder) needUpdate(original []byte) bool {
|
|
|
@@ -101,7 +103,7 @@ type propertyPSBuilder struct {
|
|
|
pushSecretData esv1beta1.PushSecretData
|
|
|
}
|
|
|
|
|
|
-func (b *propertyPSBuilder) buildMetadata(annotations, labels map[string]string) (map[string]string, map[string]string, error) {
|
|
|
+func (b *propertyPSBuilder) buildMetadata(annotations, labels map[string]string, topics []*secretmanagerpb.Topic) (map[string]string, map[string]string, []string, error) {
|
|
|
newAnnotations := map[string]string{}
|
|
|
newLabels := map[string]string{}
|
|
|
if annotations != nil {
|
|
|
@@ -112,7 +114,13 @@ func (b *propertyPSBuilder) buildMetadata(annotations, labels map[string]string)
|
|
|
}
|
|
|
|
|
|
newLabels[managedByKey] = managedByValue
|
|
|
- return newAnnotations, newLabels, nil
|
|
|
+
|
|
|
+ result := make([]string, 0, len(topics))
|
|
|
+ for _, t := range topics {
|
|
|
+ result = append(result, t.Name)
|
|
|
+ }
|
|
|
+
|
|
|
+ return newAnnotations, newLabels, result, nil
|
|
|
}
|
|
|
|
|
|
func (b *propertyPSBuilder) needUpdate(original []byte) bool {
|