@@ -786,9 +786,30 @@ public Optional<SshKey> getOptionalSshKey(Long keyId) {
786
786
* @param key the new SSH key
787
787
* @return an SshKey instance with info on the added SSH key
788
788
* @throws GitLabApiException if any exception occurs
789
+ * @deprecated use {@link #addSshKey(String, String, Date)} instead
789
790
*/
791
+ @ Deprecated
790
792
public SshKey addSshKey (String title , String key ) throws GitLabApiException {
791
- GitLabApiForm formData = new GitLabApiForm ().withParam ("title" , title ).withParam ("key" , key );
793
+ return addSshKey (title , key , null );
794
+ }
795
+
796
+ /**
797
+ * Creates a new key owned by the currently authenticated user.
798
+ *
799
+ * <pre><code>GitLab Endpoint: POST /user/keys</code></pre>
800
+ *
801
+ * @param title the new SSH Key's title
802
+ * @param key the new SSH key
803
+ * @param expiresAt the expiration date of the ssh key, optional
804
+ * @return an SshKey instance with info on the added SSH key
805
+ * @throws GitLabApiException if any exception occurs
806
+ */
807
+ public SshKey addSshKey (String title , String key , Date expiresAt ) throws GitLabApiException {
808
+ GitLabApiForm formData = new GitLabApiForm ()
809
+ .withParam ("title" , title )
810
+ .withParam ("key" , key )
811
+ .withParam ("expires_at" , expiresAt );
812
+
792
813
Response response = post (Response .Status .CREATED , formData , "user" , "keys" );
793
814
return (response .readEntity (SshKey .class ));
794
815
}
@@ -803,20 +824,40 @@ public SshKey addSshKey(String title, String key) throws GitLabApiException {
803
824
* @param key the new SSH key
804
825
* @return an SshKey instance with info on the added SSH key
805
826
* @throws GitLabApiException if any exception occurs
827
+ * @deprecated use {@link #addSshKey(Long, String, String, Date)} instead
806
828
*/
829
+ @ Deprecated
807
830
public SshKey addSshKey (Long userId , String title , String key ) throws GitLabApiException {
831
+ return addSshKey (userId , title , key , null );
832
+ }
808
833
834
+ /**
835
+ * Create new key owned by specified user. Available only for admin users.
836
+ *
837
+ * <pre><code>GitLab Endpoint: POST /users/:id/keys</code></pre>
838
+ *
839
+ * @param userId the ID of the user to add the SSH key for
840
+ * @param title the new SSH Key's title
841
+ * @param key the new SSH key
842
+ * @param expiresAt the expiration date of the ssh key, optional
843
+ * @return an SshKey instance with info on the added SSH key
844
+ * @throws GitLabApiException if any exception occurs
845
+ */
846
+ public SshKey addSshKey (Long userId , String title , String key , Date expiresAt ) throws GitLabApiException {
809
847
if (userId == null ) {
810
848
throw new RuntimeException ("userId cannot be null" );
811
849
}
812
850
813
- GitLabApiForm formData = new GitLabApiForm ().withParam ("title" , title ).withParam ("key" , key );
851
+ GitLabApiForm formData = new GitLabApiForm ()
852
+ .withParam ("title" , title )
853
+ .withParam ("key" , key )
854
+ .withParam ("expires_at" , expiresAt );
855
+
814
856
Response response = post (Response .Status .CREATED , formData , "users" , userId , "keys" );
815
857
SshKey sshKey = response .readEntity (SshKey .class );
816
858
if (sshKey != null ) {
817
859
sshKey .setUserId (userId );
818
860
}
819
-
820
861
return (sshKey );
821
862
}
822
863
@@ -993,6 +1034,23 @@ public ImpersonationToken createPersonalAccessToken(
993
1034
return createPersonalAccessTokenOrImpersonationToken (userIdOrUsername , name , expiresAt , scopes , false );
994
1035
}
995
1036
1037
+ /**
1038
+ * Revokes a personal access token. Available only for admin users.
1039
+ *
1040
+ * <pre><code>GitLab Endpoint: DELETE /personal_access_tokens/:token_id</code></pre>
1041
+ * @param tokenId the personal access token ID to revoke
1042
+ * @throws GitLabApiException if any exception occurs
1043
+ */
1044
+ public void revokePersonalAccessToken (Long tokenId ) throws GitLabApiException {
1045
+ if (tokenId == null ) {
1046
+ throw new RuntimeException ("tokenId cannot be null" );
1047
+ }
1048
+
1049
+ Response .Status expectedStatus =
1050
+ (isApiVersion (ApiVersion .V3 ) ? Response .Status .OK : Response .Status .NO_CONTENT );
1051
+ delete (expectedStatus , null , "personal_access_tokens" , tokenId );
1052
+ }
1053
+
996
1054
// as per https://docs.gitlab.com/ee/api/README.html#impersonation-tokens, impersonation tokens are a type of
997
1055
// personal access token
998
1056
private ImpersonationToken createPersonalAccessTokenOrImpersonationToken (
0 commit comments