From dac9d1a52fad685827302921120f8c61177cae50 Mon Sep 17 00:00:00 2001 From: Haim Kortovich Date: Tue, 21 May 2024 19:10:32 -0500 Subject: [PATCH] Add oidcappref [ZITADOPER-1] --- src/api/v1alpha1/ref_types.go | 7 +++++++ src/api/v1alpha1/refresolver.go | 21 +++++++++++++++++++++ src/api/v1alpha1/zz_generated.deepcopy.go | 16 ++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/src/api/v1alpha1/ref_types.go b/src/api/v1alpha1/ref_types.go index 2af0f2a..1eedd2b 100644 --- a/src/api/v1alpha1/ref_types.go +++ b/src/api/v1alpha1/ref_types.go @@ -4,6 +4,13 @@ import ( corev1 "k8s.io/api/core/v1" ) +type OIDCAppRef struct { + // ObjectReference is a reference to a object. + // +kubebuilder:validation:Required + // +operator-sdk:csv:customresourcedefinitions:type=spec + corev1.ObjectReference `json:",inline"` +} + type CrdbClusterRef struct { // ObjectReference is a reference to a object. // +kubebuilder:validation:Required diff --git a/src/api/v1alpha1/refresolver.go b/src/api/v1alpha1/refresolver.go index 3fe00b6..5dfa87c 100644 --- a/src/api/v1alpha1/refresolver.go +++ b/src/api/v1alpha1/refresolver.go @@ -42,6 +42,27 @@ func (r *RefResolver) ZitadelCluster(ctx context.Context, ref *ZitadelClusterRef return &zitadel, nil } +func (r *RefResolver) OIDCAppRef(ctx context.Context, ref *OIDCAppRef, + namespace string) (*OIDCApp, error) { + if ref.Kind != "" && ref.Kind != "OIDCApp" { + return nil, fmt.Errorf("Unsupported reference kind: '%s'", ref.Kind) + } + + key := types.NamespacedName{ + Name: ref.Name, + Namespace: namespace, + } + if ref.Namespace != "" { + key.Namespace = ref.Namespace + } + + var zitadel OIDCApp + if err := r.client.Get(ctx, key, &zitadel); err != nil { + return nil, err + } + return &zitadel, nil +} + func (r *RefResolver) ProjectRef(ctx context.Context, ref *ProjectRef, namespace string) (*Project, error) { if ref.Kind != "" && ref.Kind != "Project" { diff --git a/src/api/v1alpha1/zz_generated.deepcopy.go b/src/api/v1alpha1/zz_generated.deepcopy.go index 8c52878..c8a94a7 100644 --- a/src/api/v1alpha1/zz_generated.deepcopy.go +++ b/src/api/v1alpha1/zz_generated.deepcopy.go @@ -353,6 +353,22 @@ func (in *OIDCAppList) DeepCopyObject() runtime.Object { return nil } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OIDCAppRef) DeepCopyInto(out *OIDCAppRef) { + *out = *in + out.ObjectReference = in.ObjectReference +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OIDCAppRef. +func (in *OIDCAppRef) DeepCopy() *OIDCAppRef { + if in == nil { + return nil + } + out := new(OIDCAppRef) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OIDCAppSpec) DeepCopyInto(out *OIDCAppSpec) { *out = *in