88import java .net .URL ;
99import java .net .URLConnection ;
1010import java .net .URLEncoder ;
11+ import java .util .Arrays ;
1112import java .util .List ;
1213import java .util .StringJoiner ;
1314import java .util .regex .Matcher ;
@@ -39,7 +40,9 @@ public enum Scope {
3940
4041 /**
4142 * Allows to read (pull) container registry images if a project is private and
42- * authorization is required (introduced in GitLab 9.3).
43+ * authorization is required (introduced in GitLab 9.3). If the GitLab server you
44+ * are using does not have the Registry properly configured, using this scope will
45+ * result in an exception.
4346 */
4447 READ_REGISTRY ,
4548
@@ -58,7 +61,12 @@ public enum Scope {
5861 * Allows performing API actions as any user in the system,
5962 * if the authenticated user is an admin (introduced in GitLab 10.2).
6063 */
61- SUDO ;
64+ SUDO ,
65+
66+ /**
67+ * Grants read-write access to repositories on private projects using Git-over-HTTP (not using the API).
68+ */
69+ WRITE_REPOSITORY ;
6270
6371 private static JacksonJsonEnumHelper <Scope > enumHelper = new JacksonJsonEnumHelper <>(Scope .class );
6472
@@ -99,6 +107,27 @@ public String toString() {
99107 protected static final String HEALTH_CHECK_ACCESS_TOKEN_REGEX = "id=\" health-check-token\" >([^<]*)<\\ /code>" ;
100108 protected static final Pattern HEALTH_CHECK_ACCESS_TOKEN_PATTERN = Pattern .compile (HEALTH_CHECK_ACCESS_TOKEN_REGEX );
101109
110+ /**
111+ * Create a GitLab personal access token with the provided configuration.
112+ *
113+ * @param baseUrl the GitLab server base URL
114+ * @param username the user name to create the personal access token for
115+ * @param password the password of the user to create the personal access token for
116+ * @param tokenName the name for the new personal access token
117+ * @param scopes an array of scopes for the new personal access token
118+ * @return the created personal access token
119+ * @throws GitLabApiException if any exception occurs
120+ */
121+ public static final String createPersonalAccessToken (final String baseUrl , final String username ,
122+ final String password , final String tokenName , final Scope [] scopes ) throws GitLabApiException {
123+
124+ if (scopes == null || scopes .length == 0 ) {
125+ throw new RuntimeException ("scopes cannot be null or empty" );
126+ }
127+
128+ return (createPersonalAccessToken (baseUrl , username , password , tokenName , Arrays .asList (scopes )));
129+ }
130+
102131 /**
103132 * Create a GitLab personal access token with the provided configuration.
104133 *
@@ -232,6 +261,26 @@ public static final String createPersonalAccessToken(final String baseUrl, final
232261 }
233262 }
234263
264+ /**
265+ * Revoke the first matching GitLab personal access token.
266+ *
267+ * @param baseUrl the GitLab server base URL
268+ * @param username the user name to revoke the personal access token for
269+ * @param password the password of the user to revoke the personal access token for
270+ * @param tokenName the name of the personal access token to revoke
271+ * @param scopes an array of scopes of the personal access token to revoke
272+ * @throws GitLabApiException if any exception occurs
273+ */
274+ public static final void revokePersonalAccessToken (final String baseUrl , final String username ,
275+ final String password , final String tokenName , final Scope [] scopes ) throws GitLabApiException {
276+
277+ if (scopes == null || scopes .length == 0 ) {
278+ throw new RuntimeException ("scopes cannot be null or empty" );
279+ }
280+
281+ revokePersonalAccessToken (baseUrl , username , password , tokenName , Arrays .asList (scopes ));
282+ }
283+
235284 /**
236285 * Revoke the first matching GitLab personal access token.
237286 *
0 commit comments