1
0
Fork 0
mirror of https://github.com/external-secrets/external-secrets.git synced 2024-12-14 11:57:59 +00:00
external-secrets/pkg/utils/metadata/metadata.go
Daniel R. Dagfinrud 40a698dafd
feat: add ability to push expiration date to secret in azure key vault (#4149)
* feat: add ability to push expiration date of secret to azure key vault with annotation

Signed-off-by: deggja <danieldagfinrud@gmail.com>

* docs: set example annotation on secret in docs

Signed-off-by: deggja <danieldagfinrud@gmail.com>

* test: added test for updating to new expiration date

Signed-off-by: deggja <danieldagfinrud@gmail.com>

* chore: format

Signed-off-by: deggja <danieldagfinrud@gmail.com>

* chore: clean up go.mod

Signed-off-by: deggja <danieldagfinrud@gmail.com>

* feat: add expiration date for secret as field in metadata block in pushsecret

Signed-off-by: deggja <danieldagfinrud@gmail.com>

* extract the metadata from Kubernetes package and put it into its own package

Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>

---------

Signed-off-by: deggja <danieldagfinrud@gmail.com>
Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
Co-authored-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com>
2024-11-26 10:15:40 +01:00

55 lines
1.6 KiB
Go

/*
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 metadata
import (
"fmt"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"sigs.k8s.io/yaml"
)
const (
APIVersion = "kubernetes.external-secrets.io/v1alpha1"
Kind = "PushSecretMetadata"
)
type PushSecretMetadata[T any] struct {
Kind string `json:"kind"`
APIVersion string `json:"apiVersion"`
Spec T `json:"spec,omitempty"`
}
// ParseMetadataParameters parses metadata with an arbitrary Spec.
func ParseMetadataParameters[T any](data *apiextensionsv1.JSON) (*PushSecretMetadata[T], error) {
if data == nil {
return nil, nil
}
var metadata PushSecretMetadata[T]
err := yaml.Unmarshal(data.Raw, &metadata, yaml.DisallowUnknownFields)
if err != nil {
return nil, fmt.Errorf("failed to parse %s %s: %w", APIVersion, Kind, err)
}
if metadata.APIVersion != APIVersion {
return nil, fmt.Errorf("unexpected apiVersion %q, expected %q", metadata.APIVersion, APIVersion)
}
if metadata.Kind != Kind {
return nil, fmt.Errorf("unexpected kind %q, expected %q", metadata.Kind, Kind)
}
return &metadata, nil
}