@@ -653,6 +653,65 @@ def download(
653653 )
654654
655655
656+ class RotateMixin (_RestManagerBase ):
657+ _computed_path :Optional [str ]
658+ _from_parent_attrs :Dict [str ,Any ]
659+ _obj_cls :Optional [Type [base .RESTObject ]]
660+ _parent :Optional [base .RESTObject ]
661+ _parent_attrs :Dict [str ,Any ]
662+ _path :Optional [str ]
663+ gitlab :gitlab .Gitlab
664+
665+ @exc .on_http_error (exc .GitlabRotateError )
666+ def rotate (
667+ self ,id :Union [str ,int ],expires_at :Optional [str ]= None ,** kwargs :Any
668+ )-> Dict [str ,Any ]:
669+ """Rotate an access token.
670+
671+ Args:
672+ id: ID of the token to rotate
673+ **kwargs: Extra options to send to the server (e.g. sudo)
674+
675+ Raises:
676+ GitlabAuthenticationError: If authentication is not correct
677+ GitlabRotateError: If the server cannot perform the request
678+ """
679+ path = f"{ self .path } /{ utils .EncodedId (id )} /rotate"
680+ data :Dict [str ,Any ]= {}
681+ if expires_at is not None :
682+ data = {"expires_at" :expires_at }
683+
684+ server_data = self .gitlab .http_post (path ,post_data = data ,** kwargs )
685+ if TYPE_CHECKING :
686+ assert not isinstance (server_data ,requests .Response )
687+ return server_data
688+
689+
690+ class ObjectRotateMixin (_RestObjectBase ):
691+ _id_attr :Optional [str ]
692+ _attrs :Dict [str ,Any ]
693+ _module :ModuleType
694+ _parent_attrs :Dict [str ,Any ]
695+ _updated_attrs :Dict [str ,Any ]
696+ manager :base .RESTManager
697+
698+ def rotate (self ,** kwargs :Any )-> None :
699+ """Rotate the current access token object.
700+
701+ Args:
702+ **kwargs: Extra options to send to the server (e.g. sudo)
703+
704+ Raises:
705+ GitlabAuthenticationError: If authentication is not correct
706+ GitlabRotateError: If the server cannot perform the request
707+ """
708+ if TYPE_CHECKING :
709+ assert isinstance (self .manager ,RotateMixin )
710+ assert self .encoded_id is not None
711+ server_data = self .manager .rotate (self .encoded_id ,** kwargs )
712+ self ._update_attrs (server_data )
713+
714+
656715class SubscribableMixin (_RestObjectBase ):
657716_id_attr :Optional [str ]
658717_attrs :Dict [str ,Any ]