11package org .gitlab4j .api ;
22
3- import jakarta .ws .rs .core .Response ;
3+ import javax .ws .rs .core .Response ;
44import org .gitlab4j .api .models .PersonalAccessToken ;
55import org .gitlab4j .api .utils .ISO8601 ;
66
@@ -17,12 +17,13 @@ public PersonalAccessTokenApi(GitLabApi gitLabApi) {
1717 super (gitLabApi );
1818 }
1919
20-
2120 /**
2221 * Rotates the given personal access token.
2322 * The token is revoked and a new one which will expire in one week is created to replace it.
2423 * Only working with GitLab 16.0 and above.
2524 *
25+ * <pre><code>GitLab Endpoint: POST /personal_access_tokens/self/rotate</code></pre>
26+ *
2627 * @return the newly created PersonalAccessToken.
2728 * @throws GitLabApiException if any exception occurs
2829 */
@@ -34,16 +35,33 @@ public PersonalAccessToken rotatePersonalAccessToken() throws GitLabApiException
3435 * Rotates the given personal access token.
3536 * The token is revoked and a new one which will expire in one week is created to replace it.
3637 * Only working with GitLab 16.0 and above.
38+ *
39+ * <pre><code>GitLab Endpoint: POST /personal_access_tokens/self/rotate</code></pre>
3740 *
3841 * @param expiresAt Expiration date of the access token
3942 * @return the newly created PersonalAccessToken.
4043 * @throws GitLabApiException if any exception occurs
4144 */
4245 public PersonalAccessToken rotatePersonalAccessToken (Date expiresAt ) throws GitLabApiException {
43- GitLabApiForm formData = new GitLabApiForm ()
44- . withParam ( "expires_at" , ISO8601 . dateOnly ( expiresAt ));
46+ return rotatePersonalAccessToken ( "self" , expiresAt );
47+ }
4548
46- Response response = post (Response .Status .OK , formData , "personal_access_tokens" , "self" , "rotate" );
49+ /**
50+ * Rotates the given personal access token.
51+ * The token is revoked and a new one which will expire in one week is created to replace it.
52+ * Only working with GitLab 16.0 and above.
53+ *
54+ * <pre><code>GitLab Endpoint: POST /personal_access_tokens/:id/rotate</code></pre>
55+ *
56+ * @param expiresAt Expiration date of the access token
57+ * @return the newly created PersonalAccessToken.
58+ * @throws GitLabApiException if any exception occurs
59+ */
60+ public PersonalAccessToken rotatePersonalAccessToken (String id , Date expiresAt ) throws GitLabApiException {
61+ GitLabApiForm formData = new GitLabApiForm ()
62+ .withParam ("expires_at" , ISO8601 .dateOnly (expiresAt ));
63+
64+ Response response = post (Response .Status .OK , formData , "personal_access_tokens" , id , "rotate" );
4765 return (response .readEntity (PersonalAccessToken .class ));
4866 }
4967}
0 commit comments