@@ -696,3 +696,56 @@ func UserFromRequest(request *admissionv1.AdmissionRequest) (*v3.User, error) {
696696
697697 return object , nil
698698}
699+
700+ // AuthConfigOldAndNewFromRequest gets the old and new AuthConfig objects, respectively, from the webhook request.
701+ // If the request is a Delete operation, then the new object is the zero value for AuthConfig.
702+ // Similarly, if the request is a Create operation, then the old object is the zero value for AuthConfig.
703+ func AuthConfigOldAndNewFromRequest (request * admissionv1.AdmissionRequest ) (* v3.AuthConfig , * v3.AuthConfig , error ) {
704+ if request == nil {
705+ return nil , nil , fmt .Errorf ("nil request" )
706+ }
707+
708+ object := & v3.AuthConfig {}
709+ oldObject := & v3.AuthConfig {}
710+
711+ if request .Operation != admissionv1 .Delete {
712+ err := json .Unmarshal (request .Object .Raw , object )
713+ if err != nil {
714+ return nil , nil , fmt .Errorf ("failed to unmarshal request object: %w" , err )
715+ }
716+ }
717+
718+ if request .Operation == admissionv1 .Create {
719+ return oldObject , object , nil
720+ }
721+
722+ err := json .Unmarshal (request .OldObject .Raw , oldObject )
723+ if err != nil {
724+ return nil , nil , fmt .Errorf ("failed to unmarshal request oldObject: %w" , err )
725+ }
726+
727+ return oldObject , object , nil
728+ }
729+
730+ // AuthConfigFromRequest returns a AuthConfig object from the webhook request.
731+ // If the operation is a Delete operation, then the old object is returned.
732+ // Otherwise, the new object is returned.
733+ func AuthConfigFromRequest (request * admissionv1.AdmissionRequest ) (* v3.AuthConfig , error ) {
734+ if request == nil {
735+ return nil , fmt .Errorf ("nil request" )
736+ }
737+
738+ object := & v3.AuthConfig {}
739+ raw := request .Object .Raw
740+
741+ if request .Operation == admissionv1 .Delete {
742+ raw = request .OldObject .Raw
743+ }
744+
745+ err := json .Unmarshal (raw , object )
746+ if err != nil {
747+ return nil , fmt .Errorf ("failed to unmarshal request object: %w" , err )
748+ }
749+
750+ return object , nil
751+ }
0 commit comments