@@ -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,7 +824,9 @@ 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 {
808
831
return addSshKey (userId , title , key , null );
809
832
}
@@ -825,10 +848,11 @@ public SshKey addSshKey(Long userId, String title, String key, Date expiresAt) t
825
848
throw new RuntimeException ("userId cannot be null" );
826
849
}
827
850
828
- GitLabApiForm formData = new GitLabApiForm ().withParam ("title" , title ).withParam ("key" , key );
829
- if (expiresAt != null ) {
830
- formData .withParam ("expires_at" , expiresAt );
831
- }
851
+ GitLabApiForm formData = new GitLabApiForm ()
852
+ .withParam ("title" , title )
853
+ .withParam ("key" , key )
854
+ .withParam ("expires_at" , expiresAt );
855
+
832
856
Response response = post (Response .Status .CREATED , formData , "users" , userId , "keys" );
833
857
SshKey sshKey = response .readEntity (SshKey .class );
834
858
if (sshKey != null ) {
0 commit comments