Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
61e64115
Unverified
Commit
61e64115
authored
May 16, 2024
by
Jérémie Bresson
Committed by
GitHub
May 16, 2024
Browse files
Add "expires_at" to the rotate access token methods (#1124)
parent
346a02a0
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/GroupApi.java
View file @
61e64115
...
...
@@ -2121,7 +2121,7 @@ public class GroupApi extends AbstractApi {
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"name"
,
name
,
true
)
.
withParam
(
"scopes"
,
Arrays
.
asList
(
scopes
))
.
withParam
(
"expires_at"
,
expiresAt
)
.
withParam
(
"expires_at"
,
ISO8601
.
dateOnly
(
expiresAt
)
)
.
withParam
(
"access_level"
,
accessLevel
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"groups"
,
getGroupIdOrPath
(
groupIdOrPath
),
"access_tokens"
);
...
...
@@ -2139,10 +2139,30 @@ public class GroupApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
public
GroupAccessToken
rotateGroupAccessToken
(
Object
groupIdOrPath
,
Long
tokenId
)
throws
GitLabApiException
{
Response
response
=
post
(
Response
.
Status
.
OK
,
(
Form
)
null
,
"groups"
,
getGroupIdOrPath
(
groupIdOrPath
),
"access_tokens"
,
tokenId
,
"rotate"
);
return
rotateGroupAccessToken
(
groupIdOrPath
,
tokenId
,
null
);
}
/**
* Rotate a group access token. Revokes the previous token and creates a new token that expires in one week.
*
* <pre><code>GitLab Endpoint: POST /groups/:id/access_tokens/:token_id/rotate</code></pre>
*
* @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance
* @param tokenId ID of the group access token
* @param expiresAt Expiration date of the access token
* @return the updated GroupAccessToken instance
* @throws GitLabApiException if any exception occurs
*/
public
GroupAccessToken
rotateGroupAccessToken
(
Object
groupIdOrPath
,
Long
tokenId
,
Date
expiresAt
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"expires_at"
,
ISO8601
.
dateOnly
(
expiresAt
));
Response
response
=
post
(
Response
.
Status
.
OK
,
formData
,
"groups"
,
getGroupIdOrPath
(
groupIdOrPath
),
"access_tokens"
,
tokenId
,
"rotate"
);
return
(
response
.
readEntity
(
GroupAccessToken
.
class
));
}
/**
* Revoke a group access token.
*
...
...
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
61e64115
...
...
@@ -4024,7 +4024,25 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs
*/
public
ProjectAccessToken
rotateProjectAccessToken
(
Object
projectIdOrPath
,
Long
tokenId
)
throws
GitLabApiException
{
Response
response
=
post
(
Response
.
Status
.
OK
,
(
Object
)
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"access_tokens"
,
tokenId
,
"rotate"
);
return
rotateProjectAccessToken
(
projectIdOrPath
,
tokenId
,
null
);
}
/**
* Rotates the given project access token.
* The token is revoked and a new one which will expire in one week is created to replace it.
* Only working with GitLab 16.0 and above.
*
* @param projectIdOrPath the project in the form of a Long(ID), String(path), or Project instance
* @param tokenId the id
* @param expiresAt Expiration date of the access token
* @return the newly created ProjectAccessToken.
* @throws GitLabApiException if any exception occurs
*/
public
ProjectAccessToken
rotateProjectAccessToken
(
Object
projectIdOrPath
,
Long
tokenId
,
Date
expiresAt
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"expires_at"
,
ISO8601
.
dateOnly
(
expiresAt
));
Response
response
=
post
(
Response
.
Status
.
OK
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"access_tokens"
,
tokenId
,
"rotate"
);
return
(
response
.
readEntity
(
ProjectAccessToken
.
class
));
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment