Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini committed Nov 10, 2024
2 parents b0e731a + 5805b41 commit eb66036
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/main/java/org/gitlab4j/api/PersonalAccessTokenApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public PersonalAccessToken rotatePersonalAccessToken() throws GitLabApiException
}

/**
* Rotates the given personal access token.
* The token is revoked and a new one which will expire in one week is created to replace it.
* Rotates the personal access token used in the request header.
* The token is revoked and a new one which will expire at the given expiresAt-date is created to replace it.
* Only working with GitLab 16.0 and above.
*
* <pre><code>GitLab Endpoint: POST /personal_access_tokens/self/rotate</code></pre>
Expand All @@ -48,12 +48,13 @@ public PersonalAccessToken rotatePersonalAccessToken(Date expiresAt) throws GitL
}

/**
* Rotates the given personal access token.
* The token is revoked and a new one which will expire in one week is created to replace it.
* Rotates a specific personal access token.
* The token is revoked and a new one which will expire at the given expiresAt-date is created to replace it.
* Only working with GitLab 16.0 and above.
*
* <pre><code>GitLab Endpoint: POST /personal_access_tokens/:id/rotate</code></pre>
*
* @param id ID of the personal access token
* @param expiresAt Expiration date of the access token
* @return the newly created PersonalAccessToken.
* @throws GitLabApiException if any exception occurs
Expand All @@ -64,4 +65,32 @@ public PersonalAccessToken rotatePersonalAccessToken(String id, Date expiresAt)
Response response = post(Response.Status.OK, formData, "personal_access_tokens", id, "rotate");
return (response.readEntity(PersonalAccessToken.class));
}

/**
* Get information about the personal access token used in the request header.
* Only working with GitLab 16.0 and above.
*
* <pre><code>GitLab Endpoint: GET /personal_access_tokens/self</code></pre>
*
* @return the specified PersonalAccessToken.
* @throws GitLabApiException if any exception occurs
*/
public PersonalAccessToken getPersonalAccessToken() throws GitLabApiException {
return getPersonalAccessToken("self");
}

/**
* Get a specific personal access token.
* Only working with GitLab 16.0 and above.
*
* <pre><code>GitLab Endpoint: GET /personal_access_tokens/:id</code></pre>
*
* @param id ID of the personal access token
* @return the specified PersonalAccessToken.
* @throws GitLabApiException if any exception occurs
*/
public PersonalAccessToken getPersonalAccessToken(String id) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "personal_access_tokens", id);
return (response.readEntity(PersonalAccessToken.class));
}
}

0 comments on commit eb66036

Please sign in to comment.