Skip to content

Commit a03cb91

Browse files
committed
reactor
1 parent 5294600 commit a03cb91

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,20 @@ public PersonalAccessToken getPersonalAccessToken(String id) throws GitLabApiExc
9393
Response response = get(Response.Status.OK, null, "personal_access_tokens", id);
9494
return (response.readEntity(PersonalAccessToken.class));
9595
}
96+
97+
/**
98+
* Revokes a personal access token. Available only for admin users.
99+
*
100+
* <pre><code>GitLab Endpoint: DELETE /personal_access_tokens/:token_id</code></pre>
101+
* @param tokenId the personal access token ID to revoke
102+
* @throws GitLabApiException if any exception occurs
103+
*/
104+
public void revokePersonalAccessToken(Long tokenId) throws GitLabApiException {
105+
if (tokenId == null) {
106+
throw new RuntimeException("tokenId cannot be null");
107+
}
108+
Response.Status expectedStatus =
109+
(isApiVersion(GitLabApi.ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
110+
delete(expectedStatus, null, "personal_access_tokens", tokenId);
111+
}
96112
}

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -805,19 +805,7 @@ public SshKey addSshKey(String title, String key) throws GitLabApiException {
805805
* @throws GitLabApiException if any exception occurs
806806
*/
807807
public SshKey addSshKey(Long userId, String title, String key) throws GitLabApiException {
808-
809-
if (userId == null) {
810-
throw new RuntimeException("userId cannot be null");
811-
}
812-
813-
GitLabApiForm formData = new GitLabApiForm().withParam("title", title).withParam("key", key);
814-
Response response = post(Response.Status.CREATED, formData, "users", userId, "keys");
815-
SshKey sshKey = response.readEntity(SshKey.class);
816-
if (sshKey != null) {
817-
sshKey.setUserId(userId);
818-
}
819-
820-
return (sshKey);
808+
return addSshKey(userId, title, key, null);
821809
}
822810

823811
/**
@@ -833,12 +821,20 @@ public SshKey addSshKey(Long userId, String title, String key) throws GitLabApiE
833821
* @throws GitLabApiException if any exception occurs
834822
*/
835823
public SshKey addSshKey(Long userId, String title, String key, Date expiresAt) throws GitLabApiException {
836-
GitLabApiForm formData = new GitLabApiForm()
837-
.withParam("title", title)
838-
.withParam("key", key)
839-
.withParam("expires_at", expiresAt);
840-
Response response = post(Response.Status.CREATED, formData, "user", "keys");
841-
return (response.readEntity(SshKey.class));
824+
if (userId == null) {
825+
throw new RuntimeException("userId cannot be null");
826+
}
827+
828+
GitLabApiForm formData = new GitLabApiForm().withParam("title", title).withParam("key", key);
829+
if (expiresAt != null) {
830+
formData.withParam("expires_at", expiresAt);
831+
}
832+
Response response = post(Response.Status.CREATED, formData, "users", userId, "keys");
833+
SshKey sshKey = response.readEntity(SshKey.class);
834+
if (sshKey != null) {
835+
sshKey.setUserId(userId);
836+
}
837+
return (sshKey);
842838
}
843839

844840
/**
@@ -1030,6 +1026,7 @@ public void revokePersonalAccessToken(Long tokenId) throws GitLabApiException {
10301026
(isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
10311027
delete(expectedStatus, null, "personal_access_tokens", tokenId);
10321028
}
1029+
10331030
// as per https://docs.gitlab.com/ee/api/README.html#impersonation-tokens, impersonation tokens are a type of
10341031
// personal access token
10351032
private ImpersonationToken createPersonalAccessTokenOrImpersonationToken(

0 commit comments

Comments
 (0)