@@ -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