-
Notifications
You must be signed in to change notification settings - Fork 0
/
attributesync_types.go
115 lines (92 loc) · 3.44 KB
/
attributesync_types.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
105
106
107
108
109
110
111
112
113
114
115
package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// AttributeSyncSpec defines the desired state of AttributeSync
type AttributeSyncSpec struct {
// CaSecret is a reference to a secret containing a CA certificate to communicate to the Keycloak server
// +kubebuilder:validation:Optional
CaSecret *corev1.SecretReference `json:"caSecret,omitempty"`
// CredentialsSecret is a reference to a secret containing authentication details for the Keycloak server
// +kubebuilder:validation:Required
CredentialsSecret corev1.SecretReference `json:"credentialsSecret"`
// LoginRealm is the Keycloak realm to authenticate against
// +kubebuilder:validation:Optional
LoginRealm string `json:"loginRealm,omitempty"`
// Realm is the realm containing the groups to synchronize against
// +kubebuilder:validation:Required
Realm string `json:"realm"`
// URL is the location of the Keycloak server
// +kubebuilder:validation:Required
URL string `json:"url"`
// Attribute specifies the attribute to sync
// +kubebuilder:validation:Required
Attribute string `json:"attribute"`
// TargetLabel specifies the label to sync the attribute to
// +kubebuilder:validation:Optional
TargetLabel string `json:"targetLabel,omitempty"`
// TargetAnnotation specifies the label to sync the attribute to
// +kubebuilder:validation:Optional
TargetAnnotation string `json:"targetAnnotation,omitempty"`
// Schedule represents a cron based configuration for synchronization
// +kubebuilder:validation:Optional
Schedule string `json:"schedule,omitempty"`
}
// AttributeSyncStatus defines the observed state of AttributeSync
type AttributeSyncStatus struct {
// +kubebuilder:validation:Optional
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
}
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// AttributeSync is the Schema for the attributesyncs API
type AttributeSync struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec AttributeSyncSpec `json:"spec,omitempty"`
Status AttributeSyncStatus `json:"status,omitempty"`
}
//+kubebuilder:object:root=true
// AttributeSyncList contains a list of AttributeSync
type AttributeSyncList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AttributeSync `json:"items"`
}
func (a *AttributeSync) GetCaSecret() *corev1.SecretReference {
ref := a.Spec.CaSecret
if ref == nil {
return nil
}
ns := ref.Namespace
if ns == "" {
ns = a.ObjectMeta.Namespace
}
return &corev1.SecretReference{Name: ref.Name, Namespace: ns}
}
func (a *AttributeSync) GetCredentialsSecret() corev1.SecretReference {
ref := a.Spec.CredentialsSecret
ns := ref.Namespace
if ns == "" {
ns = a.ObjectMeta.Namespace
}
return corev1.SecretReference{Name: ref.Name, Namespace: ns}
}
func (a *AttributeSync) GetLoginRealm() string {
if a.Spec.LoginRealm == "" {
return "master"
}
return a.Spec.LoginRealm
}
func (a *AttributeSync) GetConditions() []metav1.Condition {
return a.Status.Conditions
}
func (a *AttributeSync) SetConditions(conditions []metav1.Condition) {
a.Status.Conditions = conditions
}
func init() {
SchemeBuilder.Register(&AttributeSync{}, &AttributeSyncList{})
}