|
1 | 1 | package org.gitlab4j.api;
|
2 | 2 |
|
3 | 3 | import java.io.File;
|
| 4 | +import java.util.Arrays; |
4 | 5 | import java.util.Date;
|
5 | 6 | import java.util.List;
|
6 | 7 | import java.util.Objects;
|
|
20 | 21 | import org.gitlab4j.api.models.Badge;
|
21 | 22 | import org.gitlab4j.api.models.CustomAttribute;
|
22 | 23 | import org.gitlab4j.api.models.Group;
|
| 24 | +import org.gitlab4j.api.models.GroupAccessToken; |
23 | 25 | import org.gitlab4j.api.models.GroupFilter;
|
24 | 26 | import org.gitlab4j.api.models.GroupParams;
|
25 | 27 | import org.gitlab4j.api.models.GroupProjectsFilter;
|
| 28 | +import org.gitlab4j.api.models.ImpersonationToken; |
| 29 | +import org.gitlab4j.api.models.ImpersonationToken.Scope; |
26 | 30 | import org.gitlab4j.api.models.Iteration;
|
27 | 31 | import org.gitlab4j.api.models.IterationFilter;
|
28 | 32 | import org.gitlab4j.api.models.LdapGroupLink;
|
@@ -2046,4 +2050,89 @@ public List<Iteration> listGroupIterations(Object groupIdOrPath, IterationFilter
|
2046 | 2050 | Response response = get(Response.Status.OK, queryParams, "groups", getGroupIdOrPath(groupIdOrPath), "iterations");
|
2047 | 2051 | return (response.readEntity(new GenericType<List<Iteration>>() { }));
|
2048 | 2052 | }
|
| 2053 | + |
| 2054 | + /** |
| 2055 | + * Get a list of group access tokens. |
| 2056 | + * |
| 2057 | + * <pre><code>GitLab Endpoint: GET /groups/:id/access_tokens</code></pre> |
| 2058 | + * |
| 2059 | + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance |
| 2060 | + * @return the list of GroupAccessToken instances |
| 2061 | + * @throws GitLabApiException if any exception occurs |
| 2062 | + */ |
| 2063 | + public List<GroupAccessToken> getGroupAccessTokens(Object groupIdOrPath) throws GitLabApiException { |
| 2064 | + Response response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens"); |
| 2065 | + return (response.readEntity(new GenericType<List<GroupAccessToken>>() { })); |
| 2066 | + } |
| 2067 | + |
| 2068 | + /** |
| 2069 | + * Get a group access token by ID. |
| 2070 | + * |
| 2071 | + * <pre><code>GitLab Endpoint: GET /groups/:id/access_tokens/:token_id</code></pre> |
| 2072 | + * |
| 2073 | + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance |
| 2074 | + * @param tokenId ID of the group access token |
| 2075 | + * @return the GroupAccessToken instance |
| 2076 | + * @throws GitLabApiException if any exception occurs |
| 2077 | + */ |
| 2078 | + public GroupAccessToken getGroupAccessToken(Object groupIdOrPath, Long tokenId) throws GitLabApiException { |
| 2079 | + Response response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens", tokenId); |
| 2080 | + return (response.readEntity(GroupAccessToken.class)); |
| 2081 | + } |
| 2082 | + |
| 2083 | + /** |
| 2084 | + * Create a group access token. You must have the Owner role for the group to create group access tokens. |
| 2085 | + * |
| 2086 | + * <pre><code>GitLab Endpoint: POST /groups/:id/access_tokens</code></pre> |
| 2087 | + * |
| 2088 | + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance |
| 2089 | + * @param name the name of the group access token, required |
| 2090 | + * @param expiresAt the expiration date of the group access token, optional |
| 2091 | + * @param scopes an array of scopes of the group access token |
| 2092 | + * @param accessLevel Access level. Valid values are {@link AccessLevel#GUEST}, {@link AccessLevel#REPORTER}, {@link AccessLevel#DEVELOPER}, {@link AccessLevel#MAINTAINER}, and {@link AccessLevel#OWNER}. |
| 2093 | + * @return the created GroupAccessToken instance |
| 2094 | + * @throws GitLabApiException if any exception occurs |
| 2095 | + */ |
| 2096 | + public GroupAccessToken createGroupAccessToken(Object groupIdOrPath, String name, Date expiresAt, Scope[] scopes, AccessLevel accessLevel) throws GitLabApiException { |
| 2097 | + if (scopes == null || scopes.length == 0) { |
| 2098 | + throw new RuntimeException("scopes cannot be null or empty"); |
| 2099 | + } |
| 2100 | + |
| 2101 | + GitLabApiForm formData = new GitLabApiForm() |
| 2102 | + .withParam("name", name, true) |
| 2103 | + .withParam("scopes", Arrays.asList(scopes)) |
| 2104 | + .withParam("expires_at", expiresAt) |
| 2105 | + .withParam("access_level", accessLevel); |
| 2106 | + |
| 2107 | + Response response = post(Response.Status.CREATED, formData, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens"); |
| 2108 | + return (response.readEntity(GroupAccessToken.class)); |
| 2109 | + } |
| 2110 | + |
| 2111 | + /** |
| 2112 | + * Rotate a group access token. Revokes the previous token and creates a new token that expires in one week. |
| 2113 | + * |
| 2114 | + * <pre><code>GitLab Endpoint: POST /groups/:id/access_tokens/:token_id/rotate</code></pre> |
| 2115 | + * |
| 2116 | + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance |
| 2117 | + * @param tokenId ID of the group access token |
| 2118 | + * @return the updated GroupAccessToken instance |
| 2119 | + * @throws GitLabApiException if any exception occurs |
| 2120 | + */ |
| 2121 | + public GroupAccessToken rotateGroupAccessToken(Object groupIdOrPath, Long tokenId) throws GitLabApiException { |
| 2122 | + Response response = post(Response.Status.OK, (Form)null, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens", tokenId, "rotate"); |
| 2123 | + return (response.readEntity(GroupAccessToken.class)); |
| 2124 | + } |
| 2125 | + |
| 2126 | + /** |
| 2127 | + * Revoke a group access token. |
| 2128 | + * |
| 2129 | + * <pre><code>GitLab Endpoint: DELETE /groups/:id/access_tokens/:token_id</code></pre> |
| 2130 | + * |
| 2131 | + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance |
| 2132 | + * @param tokenId ID of the group access token |
| 2133 | + * @throws GitLabApiException if any exception occurs |
| 2134 | + */ |
| 2135 | + public void revokeGroupAccessToken(Object groupIdOrPath, Long tokenId) throws GitLabApiException { |
| 2136 | + delete(Response.Status.NO_CONTENT, null, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens", tokenId); |
| 2137 | + } |
2049 | 2138 | }
|
0 commit comments