|
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;
|
@@ -1977,4 +1981,89 @@ public List<Iteration> listGroupIterations(Object groupIdOrPath, IterationFilter
|
1977 | 1981 | Response response = get(Response.Status.OK, queryParams, "groups", getGroupIdOrPath(groupIdOrPath), "iterations");
|
1978 | 1982 | return (response.readEntity(new GenericType<List<Iteration>>() { }));
|
1979 | 1983 | }
|
| 1984 | + |
| 1985 | + /** |
| 1986 | + * Get a list of group access tokens. |
| 1987 | + * |
| 1988 | + * <pre><code>GitLab Endpoint: GET /groups/:id/access_tokens</code></pre> |
| 1989 | + * |
| 1990 | + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance |
| 1991 | + * @return the list of GroupAccessToken instances |
| 1992 | + * @throws GitLabApiException if any exception occurs |
| 1993 | + */ |
| 1994 | + public List<GroupAccessToken> getGroupAccessTokens(Object groupIdOrPath) throws GitLabApiException { |
| 1995 | + Response response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens"); |
| 1996 | + return (response.readEntity(new GenericType<List<GroupAccessToken>>() { })); |
| 1997 | + } |
| 1998 | + |
| 1999 | + /** |
| 2000 | + * Get a group access token by ID. |
| 2001 | + * |
| 2002 | + * <pre><code>GitLab Endpoint: GET /groups/:id/access_tokens/:token_id</code></pre> |
| 2003 | + * |
| 2004 | + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance |
| 2005 | + * @param tokenId ID of the group access token |
| 2006 | + * @return the GroupAccessToken instance |
| 2007 | + * @throws GitLabApiException if any exception occurs |
| 2008 | + */ |
| 2009 | + public GroupAccessToken getGroupAccessTokens(Object groupIdOrPath, Long tokenId) throws GitLabApiException { |
| 2010 | + Response response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens", tokenId); |
| 2011 | + return (response.readEntity(GroupAccessToken.class)); |
| 2012 | + } |
| 2013 | + |
| 2014 | + /** |
| 2015 | + * Create a group access token. You must have the Owner role for the group to create group access tokens. |
| 2016 | + * |
| 2017 | + * <pre><code>GitLab Endpoint: POST /groups/:id/access_tokens</code></pre> |
| 2018 | + * |
| 2019 | + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance |
| 2020 | + * @param name the name of the group access token, required |
| 2021 | + * @param expiresAt the expiration date of the group access token, optional |
| 2022 | + * @param scopes an array of scopes of the group access token |
| 2023 | + * @param accessLevel Access level. Valid values are {@link AccessLevel#GUEST}, {@link AccessLevel#REPORTER}, {@link AccessLevel#DEVELOPER}, {@link AccessLevel#MAINTAINER}, and {@link AccessLevel#OWNER}. |
| 2024 | + * @return the created GroupAccessToken instance |
| 2025 | + * @throws GitLabApiException if any exception occurs |
| 2026 | + */ |
| 2027 | + public GroupAccessToken createGroupAccessToken(Object groupIdOrPath, String name, Date expiresAt, Scope[] scopes, AccessLevel accessLevel) throws GitLabApiException { |
| 2028 | + if (scopes == null || scopes.length == 0) { |
| 2029 | + throw new RuntimeException("scopes cannot be null or empty"); |
| 2030 | + } |
| 2031 | + |
| 2032 | + GitLabApiForm formData = new GitLabApiForm() |
| 2033 | + .withParam("name", name, true) |
| 2034 | + .withParam("scopes", Arrays.asList(scopes)) |
| 2035 | + .withParam("expires_at", expiresAt) |
| 2036 | + .withParam("access_level", accessLevel); |
| 2037 | + |
| 2038 | + Response response = post(Response.Status.CREATED, formData, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens"); |
| 2039 | + return (response.readEntity(GroupAccessToken.class)); |
| 2040 | + } |
| 2041 | + |
| 2042 | + /** |
| 2043 | + * Rotate a group access token. Revokes the previous token and creates a new token that expires in one week. |
| 2044 | + * |
| 2045 | + * <pre><code>GitLab Endpoint: POST /groups/:id/access_tokens/:token_id/rotate</code></pre> |
| 2046 | + * |
| 2047 | + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance |
| 2048 | + * @param tokenId ID of the group access token |
| 2049 | + * @return the updated GroupAccessToken instance |
| 2050 | + * @throws GitLabApiException if any exception occurs |
| 2051 | + */ |
| 2052 | + public GroupAccessToken rotateGroupAccessToken(Object groupIdOrPath, Long tokenId) throws GitLabApiException { |
| 2053 | + Response response = post(Response.Status.OK, (Form)null, "groups", getGroupIdOrPath(groupIdOrPath), "access_tokens", tokenId, "rotate"); |
| 2054 | + return (response.readEntity(GroupAccessToken.class)); |
| 2055 | + } |
| 2056 | + |
| 2057 | + /** |
| 2058 | + * Revoke a group access token. |
| 2059 | + * |
| 2060 | + * <pre><code>GitLab Endpoint: DELETE /groups/:id/access_tokens/:token_id</code></pre> |
| 2061 | + * |
| 2062 | + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance |
| 2063 | + * @param tokenId ID of the group access token |
| 2064 | + * @throws GitLabApiException if any exception occurs |
| 2065 | + */ |
| 2066 | + public void revokeGroupAccessToken(Object groupIdOrPath, Long tokenId) throws GitLabApiException { |
| 2067 | + delete(Response.Status.NO_CONTENT, null, "groups", getGroupIdOrPath(groupIdOrPath)); |
| 2068 | + } |
1980 | 2069 | }
|
0 commit comments