Skip to content

Commit 61e6411

Browse files
authored
Add "expires_at" to the rotate access token methods (#1124)
1 parent 346a02a commit 61e6411

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/main/java/org/gitlab4j/api/GroupApi.java

+22-2
Original file line numberDiff line numberDiff line change
@@ -2121,7 +2121,7 @@ public GroupAccessToken createGroupAccessToken(Object groupIdOrPath, String name
21212121
GitLabApiForm formData = new GitLabApiForm()
21222122
.withParam("name", name, true)
21232123
.withParam("scopes", Arrays.asList(scopes))
2124-
.withParam("expires_at", expiresAt)
2124+
.withParam("expires_at", ISO8601.dateOnly(expiresAt))
21252125
.withParam("access_level", accessLevel);
21262126

21272127
Response response = post(Response.Status.CREATED, formData, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens");
@@ -2139,10 +2139,30 @@ public GroupAccessToken createGroupAccessToken(Object groupIdOrPath, String name
21392139
* @throws GitLabApiException if any exception occurs
21402140
*/
21412141
public GroupAccessToken rotateGroupAccessToken(Object groupIdOrPath, Long tokenId) throws GitLabApiException {
2142-
Response response = post(Response.Status.OK, (Form)null, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens", tokenId, "rotate");
2142+
return rotateGroupAccessToken(groupIdOrPath, tokenId, null);
2143+
}
2144+
2145+
2146+
/**
2147+
* Rotate a group access token. Revokes the previous token and creates a new token that expires in one week.
2148+
*
2149+
* <pre><code>GitLab Endpoint: POST /groups/:id/access_tokens/:token_id/rotate</code></pre>
2150+
*
2151+
* @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance
2152+
* @param tokenId ID of the group access token
2153+
* @param expiresAt Expiration date of the access token
2154+
* @return the updated GroupAccessToken instance
2155+
* @throws GitLabApiException if any exception occurs
2156+
*/
2157+
public GroupAccessToken rotateGroupAccessToken(Object groupIdOrPath, Long tokenId, Date expiresAt) throws GitLabApiException {
2158+
GitLabApiForm formData = new GitLabApiForm()
2159+
.withParam("expires_at", ISO8601.dateOnly(expiresAt));
2160+
2161+
Response response = post(Response.Status.OK, formData, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens", tokenId, "rotate");
21432162
return (response.readEntity(GroupAccessToken.class));
21442163
}
21452164

2165+
21462166
/**
21472167
* Revoke a group access token.
21482168
*

src/main/java/org/gitlab4j/api/ProjectApi.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -4024,7 +4024,25 @@ public ProjectAccessToken createProjectAccessToken(Object projectIdOrPath, Strin
40244024
* @throws GitLabApiException if any exception occurs
40254025
*/
40264026
public ProjectAccessToken rotateProjectAccessToken(Object projectIdOrPath, Long tokenId) throws GitLabApiException {
4027-
Response response = post(Response.Status.OK, (Object) null, "projects", getProjectIdOrPath(projectIdOrPath), "access_tokens", tokenId, "rotate");
4027+
return rotateProjectAccessToken(projectIdOrPath, tokenId, null);
4028+
}
4029+
4030+
/**
4031+
* Rotates the given project access token.
4032+
* The token is revoked and a new one which will expire in one week is created to replace it.
4033+
* Only working with GitLab 16.0 and above.
4034+
*
4035+
* @param projectIdOrPath the project in the form of a Long(ID), String(path), or Project instance
4036+
* @param tokenId the id
4037+
* @param expiresAt Expiration date of the access token
4038+
* @return the newly created ProjectAccessToken.
4039+
* @throws GitLabApiException if any exception occurs
4040+
*/
4041+
public ProjectAccessToken rotateProjectAccessToken(Object projectIdOrPath, Long tokenId, Date expiresAt) throws GitLabApiException {
4042+
GitLabApiForm formData = new GitLabApiForm()
4043+
.withParam("expires_at", ISO8601.dateOnly(expiresAt));
4044+
4045+
Response response = post(Response.Status.OK, formData, "projects", getProjectIdOrPath(projectIdOrPath), "access_tokens", tokenId, "rotate");
40284046
return (response.readEntity(ProjectAccessToken.class));
40294047
}
40304048

0 commit comments

Comments
 (0)