github.com/codeready-toolchain/api@v0.0.0-20240507023248-73662d6db2c5/api/v1alpha1/usersignup_types.go (about) 1 package v1alpha1 2 3 import ( 4 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 5 ) 6 7 const ( 8 // These are valid conditions of a UserSignup 9 10 // UserSignupApproved reflects whether the signup request has been approved or not 11 UserSignupApproved ConditionType = "Approved" 12 // UserSignupComplete means provisioning is complete 13 UserSignupComplete ConditionType = "Complete" 14 // UserSignupUserDeactivatingNotificationCreated is used to track the status of the notification send to a user 15 // shortly before their account is due for deactivation 16 UserSignupUserDeactivatingNotificationCreated ConditionType = "UserDeactivatingNotificationCreated" 17 // UserSignupUserDeactivatedNotificationCreated means that the Notification CR was created so the user should be notified about their deactivated account 18 UserSignupUserDeactivatedNotificationCreated ConditionType = "UserDeactivatedNotificationCreated" 19 20 // UserSignupLastTargetClusterAnnotationKey is used for tracking the cluster for returning users 21 UserSignupLastTargetClusterAnnotationKey = LabelKeyPrefix + "last-target-cluster" 22 // UserSignupVerificationCodeAnnotationKey is used for the usersignup verification code annotation key 23 UserSignupVerificationCodeAnnotationKey = LabelKeyPrefix + "verification-code" 24 // UserSignupVerificationTimestampAnnotationKey is used for the usersignup verification timestamp annotation key 25 UserSignupVerificationTimestampAnnotationKey = LabelKeyPrefix + "verification-timestamp" 26 // UserSignupVerificationInitTimestampAnnotationKey is used for the usersignup verification code generated timestamp annotation key 27 UserSignupVerificationInitTimestampAnnotationKey = LabelKeyPrefix + "verification-init-timestamp" 28 // UserSignupVerificationCounterAnnotationKey is used for the usersignup verification counter annotation key 29 UserSignupVerificationCounterAnnotationKey = LabelKeyPrefix + "verification-counter" 30 // UserVerificationAttemptsAnnotationKey is used for the usersignup verification attempts annotation key 31 UserVerificationAttemptsAnnotationKey = LabelKeyPrefix + "verification-attempts" 32 // UserVerificationExpiryAnnotationKey is used for the usersignup verification expiry annotation key 33 UserVerificationExpiryAnnotationKey = LabelKeyPrefix + "verification-expiry" 34 // SkipAutoCreateSpaceAnnotationKey when true signals the usersignup controller to skip Space creation, otherwise a Space will be created by default 35 SkipAutoCreateSpaceAnnotationKey = LabelKeyPrefix + "skip-auto-create-space" 36 // UserSignupActivationCounterAnnotationKey is used for the usersignup activation counter annotation key 37 // Activations are counted after phone verification succeeded 38 UserSignupActivationCounterAnnotationKey = LabelKeyPrefix + "activation-counter" 39 // UserSignupCaptchaScoreAnnotationKey is set if captcha verification was used, and contains the last captcha assessment score for the user 40 UserSignupCaptchaScoreAnnotationKey = LabelKeyPrefix + "captcha-score" 41 42 // UserSignupUserEmailHashLabelKey is used for the usersignup email hash label key 43 UserSignupUserEmailHashLabelKey = LabelKeyPrefix + "email-hash" 44 // UserSignupUserPhoneHashLabelKey is used for the usersignup phone hash label key 45 UserSignupUserPhoneHashLabelKey = LabelKeyPrefix + "phone-hash" 46 47 // UserSignupSocialEventLabelKey is used to indicate that the user registered via an activation code, and contains 48 // the name of the SocialEvent that they signed up for 49 UserSignupSocialEventLabelKey = LabelKeyPrefix + "social-event" 50 51 // UserSignupStateLabelKey is used for setting the required/expected state of UserSignups (not-ready, pending, approved, banned, deactivated). 52 // The main purpose of the label is easy selecting the UserSignups based on the state - eg. get all UserSignup on the waiting list (state=pending). 53 // Another usage of the label is counting the UserSingups for and exposing it through metrics or ToolchainStatus CR. 54 // Every value is set before doing the action - approving/deactivating/banning. The only exception is the "not-ready" state which is used as an initial state 55 // for all UserSignups that were just created and are still not fully ready - eg. requires verification. 56 UserSignupStateLabelKey = StateLabelKey 57 // UserSignupStateLabelValueNotReady is used for identifying that the UserSignup is not ready for approval yet (eg. requires verification) 58 UserSignupStateLabelValueNotReady = "not-ready" 59 // UserSignupStateLabelValuePending is used for identifying that the UserSignup is pending approval 60 UserSignupStateLabelValuePending = StateLabelValuePending 61 // UserSignupStateLabelValueApproved is used for identifying that the UserSignup is approved 62 UserSignupStateLabelValueApproved = "approved" 63 // UserSignupStateLabelValueDeactivated is used for identifying that the UserSignup is deactivated 64 UserSignupStateLabelValueDeactivated = "deactivated" 65 // UserSignupStateLabelValueBanned is used for identifying that the UserSignup is banned 66 UserSignupStateLabelValueBanned = "banned" 67 68 // Status condition reasons 69 UnableToCreateSpaceBinding = "UnableToCreateSpaceBinding" 70 UserSignupNoClusterAvailableReason = "NoClusterAvailable" 71 UserSignupNoUserTierAvailableReason = "NoUserTierAvailable" 72 UserSignupNoTemplateTierAvailableReason = "NoTemplateTierAvailable" 73 UserSignupFailedToReadUserApprovalPolicyReason = "FailedToReadUserApprovalPolicy" 74 UserSignupUnableToCreateMURReason = "UnableToCreateMUR" 75 UserSignupUnableToUpdateAnnotationReason = "UnableToUpdateAnnotation" 76 UserSignupUnableToUpdateStateLabelReason = "UnableToUpdateStateLabel" 77 UserSignupUnableToDeleteMURReason = "UnableToDeleteMUR" 78 UserSignupUnableToCreateSpaceReason = "UnableToCreateSpace" 79 UserSignupUnableToCreateSpaceBindingReason = UnableToCreateSpaceBinding 80 UserSignupProvisioningSpaceReason = "ProvisioningSpace" 81 82 // The UserSignupUserDeactivatingReason constant will be replaced with UserSignupDeactivationInProgressReason 83 // in order to reduce ambiguity. The "Deactivating" state should only refer to the period of time before the 84 // user is deactivated (by default 3 days), not when the user is in the actual process of deactivation 85 UserSignupUserDeactivatingReason = "Deactivating" 86 UserSignupDeactivationInProgressReason = "DeactivationInProgress" 87 88 UserSignupUserDeactivatedReason = "Deactivated" 89 UserSignupInvalidMURStateReason = "InvalidMURState" 90 UserSignupApprovedAutomaticallyReason = "ApprovedAutomatically" 91 UserSignupApprovedByAdminReason = "ApprovedByAdmin" 92 UserSignupPendingApprovalReason = "PendingApproval" 93 UserSignupUserBanningReason = "Banning" 94 UserSignupUserBannedReason = "Banned" 95 UserSignupFailedToReadBannedUsersReason = "FailedToReadBannedUsers" 96 UserSignupMissingUserEmailReason = "MissingUserEmail" 97 UserSignupMissingUserEmailAnnotationReason = "MissingUserEmailAnnotation" 98 UserSignupMissingEmailHashLabelReason = "MissingEmailHashLabel" 99 UserSignupInvalidEmailHashLabelReason = "InvalidEmailHashLabel" 100 UserSignupVerificationRequiredReason = "VerificationRequired" 101 102 notificationCRCreated = "NotificationCRCreated" 103 userIsActive = "UserIsActive" 104 userNotInPreDeactivation = "UserNotInPreDeactivation" 105 notificationCRCreationFailed = "NotificationCRCreationFailed" 106 107 // ############################################################################### 108 // Deactivation Notification Status Reasons 109 // ############################################################################### 110 111 // UserSignupDeactivatedNotificationUserIsActiveReason is the value that the condition reason is set to when 112 // a previously deactivated user has been reactivated again (for example when a user signs up again after their 113 // sandbox has been deactivated) 114 UserSignupDeactivatedNotificationUserIsActiveReason = userIsActive 115 116 UserSignupDeactivatedNotificationCRCreatedReason = notificationCRCreated 117 118 UserSignupDeactivatedNotificationCRCreationFailedReason = notificationCRCreationFailed 119 120 // ############################################################################### 121 // Pre-Deactivation Notification Status Reasons 122 // ############################################################################### 123 124 // UserSignupDeactivatingNotificationUserNotInPreDeactivationReason is the value that the condition reason is set to 125 // for an active user, before entering the pre-deactivation period 126 UserSignupDeactivatingNotificationUserNotInPreDeactivationReason = userNotInPreDeactivation 127 128 UserSignupDeactivatingNotificationCRCreatedReason = notificationCRCreated 129 130 UserSignupDeactivatingNotificationCRCreationFailedReason = notificationCRCreationFailed 131 132 // ############################################################################### 133 // UserSignup States 134 // ############################################################################### 135 136 // UserSignupStateApproved - If set then the user has been manually approved. Otherwise, if not set then 137 // the user is subject of auto-approval (if enabled) 138 UserSignupStateApproved = UserSignupState("approved") 139 140 // UserSignupStateVerificationRequired - If set then the user must complete the phone verification process 141 UserSignupStateVerificationRequired = UserSignupState("verification-required") 142 143 // UserSignupStateDeactivating - If this state is set, it indicates that the user has entered the "pre-deactivation" 144 // phase and their account will be deactivated shortly. Setting this state triggers the sending of a notification 145 // to the user to warn them of their pending account deactivation. 146 UserSignupStateDeactivating = UserSignupState("deactivating") 147 148 // UserSignupStateDeactivated - If this state is set, it means the user has been deactivated and they may no 149 // longer use their account 150 UserSignupStateDeactivated = UserSignupState("deactivated") 151 152 // UserSignupStateBanned - If this state is set by an admin then the user's account will be banned. 153 UserSignupStateBanned = UserSignupState("banned") 154 ) 155 156 type UserSignupState string 157 158 // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. 159 160 // UserSignupSpec defines the desired state of UserSignup 161 // +k8s:openapi-gen=true 162 type UserSignupSpec struct { 163 // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file 164 // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html 165 166 // The cluster in which the user is provisioned in 167 // If not set then the target cluster will be picked automatically 168 // +optional 169 TargetCluster string `json:"targetCluster,omitempty"` 170 171 // States contains a number of values that reflect the desired state of the UserSignup. 172 // +optional 173 // +listType=atomic 174 States []UserSignupState `json:"states,omitempty"` 175 176 // IdentityClaims contains as-is claim values extracted from the user's access token 177 IdentityClaims IdentityClaimsEmbedded `json:"identityClaims"` 178 } 179 180 // IdentityClaimsEmbedded is used to define a set of SSO claim values that we are interested in storing 181 // +k8s:openapi-gen=true 182 type IdentityClaimsEmbedded struct { 183 184 // PropagatedClaims 185 PropagatedClaims `json:",inline"` 186 187 // PreferredUsername contains the user's username 188 PreferredUsername string `json:"preferredUsername"` 189 190 // GivenName contains the value of the 'given_name' claim 191 // +optional 192 GivenName string `json:"givenName,omitempty"` 193 194 // FamilyName contains the value of the 'family_name' claim 195 // +optional 196 FamilyName string `json:"familyName,omitempty"` 197 198 // Company contains the value of the 'company' claim 199 // +optional 200 Company string `json:"company,omitempty"` 201 } 202 203 // +k8s:openapi-gen=true 204 type PropagatedClaims struct { 205 // Sub contains the value of the 'sub' claim 206 Sub string `json:"sub"` 207 208 // UserID contains the value of the 'user_id' claim 209 // +optional 210 UserID string `json:"userID,omitempty"` 211 212 // AccountID contains the value of the 'account_id' claim 213 // +optional 214 AccountID string `json:"accountID,omitempty"` 215 216 // OriginalSub is an optional property temporarily introduced for the purpose of migrating the users to 217 // a new IdP provider client, and contains the user's "original-sub" claim 218 // +optional 219 OriginalSub string `json:"originalSub,omitempty"` 220 221 // Email contains the user's email address 222 Email string `json:"email"` 223 } 224 225 // UserSignupStatus defines the observed state of UserSignup 226 // +k8s:openapi-gen=true 227 type UserSignupStatus struct { 228 // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file 229 // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html 230 231 // Conditions is an array of current UserSignup conditions 232 // Supported condition types: 233 // PendingApproval, Provisioning, Complete 234 // +optional 235 // +patchMergeKey=type 236 // +patchStrategy=merge 237 // +listType=map 238 // +listMapKey=type 239 Conditions []Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"` 240 241 // CompliantUsername is used to store the transformed, DNS-1123 compliant username 242 // +optional 243 CompliantUsername string `json:"compliantUsername,omitempty"` 244 245 // HomeSpace is the name of the Space that is created for the user 246 // immediately after their account is approved. 247 // This is used by the proxy when no workspace context is provided. 248 // +optional 249 HomeSpace string `json:"homeSpace,omitempty"` 250 251 // ScheduledDeactivationTimestamp is the calculated timestamp after which the user's account will be deactivated, typically 252 // after the expiry of their trial and based on the term specific by their UserTier. This property may be used as 253 // a convenience to determine the amount of time an account has left before deactivation, without requiring a separate 254 // lookup for the UserTier and subsequent calculation. It is managed by the Deactivation controller in the host operator. 255 // +optional 256 ScheduledDeactivationTimestamp *metav1.Time `json:"scheduledDeactivationTimestamp,omitempty"` 257 } 258 259 //+kubebuilder:object:root=true 260 //+kubebuilder:subresource:status 261 262 // UserSignup registers a user in the CodeReady Toolchain 263 // +k8s:openapi-gen=true 264 // +kubebuilder:subresource:status 265 // +kubebuilder:resource:scope=Namespaced 266 // +kubebuilder:printcolumn:name="Username",type="string",JSONPath=`.spec.identityClaims.preferredUsername` 267 // +kubebuilder:printcolumn:name="First Name",type="string",JSONPath=`.spec.identityClaims.givenName`,priority=1 268 // +kubebuilder:printcolumn:name="Last Name",type="string",JSONPath=`.spec.identityClaims.familyName`,priority=1 269 // +kubebuilder:printcolumn:name="Company",type="string",JSONPath=`.spec.identityClaims.company`,priority=1 270 // +kubebuilder:printcolumn:name="TargetCluster",type="string",JSONPath=`.spec.targetCluster`,priority=1 271 // +kubebuilder:printcolumn:name="Complete",type="string",JSONPath=`.status.conditions[?(@.type=="Complete")].status` 272 // +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=`.status.conditions[?(@.type=="Complete")].reason` 273 // +kubebuilder:printcolumn:name="Approved",type="string",JSONPath=`.status.conditions[?(@.type=="Approved")].status`,priority=1 274 // +kubebuilder:printcolumn:name="ApprovedBy",type="string",JSONPath=`.status.conditions[?(@.type=="Approved")].reason`,priority=1 275 // +kubebuilder:printcolumn:name="States",type="string",JSONPath=`.spec.states`,priority=1 276 // +kubebuilder:printcolumn:name="CompliantUsername",type="string",JSONPath=`.status.compliantUsername` 277 // +kubebuilder:printcolumn:name="Email",type="string",JSONPath=`.spec.identityClaims.email` 278 // +kubebuilder:validation:XPreserveUnknownFields 279 // +operator-sdk:gen-csv:customresourcedefinitions.displayName="User Signup" 280 type UserSignup struct { 281 metav1.TypeMeta `json:",inline"` 282 metav1.ObjectMeta `json:"metadata,omitempty"` 283 284 Spec UserSignupSpec `json:"spec,omitempty"` 285 Status UserSignupStatus `json:"status,omitempty"` 286 } 287 288 //+kubebuilder:object:root=true 289 290 // UserSignupList contains a list of UserSignup 291 type UserSignupList struct { 292 metav1.TypeMeta `json:",inline"` 293 metav1.ListMeta `json:"metadata,omitempty"` 294 Items []UserSignup `json:"items"` 295 } 296 297 func init() { 298 SchemeBuilder.Register(&UserSignup{}, &UserSignupList{}) 299 }