From 237770e90a4204431a4541bf8caf1a7ba6fee713 Mon Sep 17 00:00:00 2001 From: Bruno Ferreira Date: Tue, 27 Feb 2018 13:40:42 +0000 Subject: [PATCH 1/3] Added a new method to create a new SSH key Added a new method to create a new SSH key for the current user (https://docs.gitlab.com/ce/api/users.html#add-ssh-key) because the other method already available doesn't work if the user is not admin (https://docs.gitlab.com/ce/api/users.html#add-ssh-key-for-user) and wants to add a new SSH key for him. --- src/main/java/org/gitlab/api/GitlabAPI.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index f5414136..878f7175 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -319,6 +319,26 @@ public GitlabSSHKey createSSHKey(Integer targetUserId, String title, String key) return dispatch().to(tailUrl, GitlabSSHKey.class); } + + /** + * Create a new ssh key for the authenticated user. + * + * @param targetUserId The id of the Gitlab user + * @param title The title of the ssh key + * @param key The public key + * @return The new GitlabSSHKey + * @throws IOException on gitlab api call error + */ + public GitlabSSHKey createSSHKey(String title, String key) throws IOException { + + Query query = new Query() + .append("title", title) + .append("key", key); + + String tailUrl = GitlabUser.USERS_URL + "/" + GitlabSSHKey.KEYS_URL + query.toString(); + + return dispatch().to(tailUrl, GitlabSSHKey.class); + } /** * Delete user's ssh key From 22d3372a173d4d1e2cf3a8dd848c46fb5bca544f Mon Sep 17 00:00:00 2001 From: Bruno Ferreira Date: Tue, 27 Feb 2018 13:46:41 +0000 Subject: [PATCH 2/3] Updated docs and removed extra "/" --- src/main/java/org/gitlab/api/GitlabAPI.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index 878f7175..4d0683ca 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -323,7 +323,6 @@ public GitlabSSHKey createSSHKey(Integer targetUserId, String title, String key) /** * Create a new ssh key for the authenticated user. * - * @param targetUserId The id of the Gitlab user * @param title The title of the ssh key * @param key The public key * @return The new GitlabSSHKey @@ -335,7 +334,7 @@ public GitlabSSHKey createSSHKey(String title, String key) throws IOException { .append("title", title) .append("key", key); - String tailUrl = GitlabUser.USERS_URL + "/" + GitlabSSHKey.KEYS_URL + query.toString(); + String tailUrl = GitlabUser.USERS_URL + GitlabSSHKey.KEYS_URL + query.toString(); return dispatch().to(tailUrl, GitlabSSHKey.class); } From 8fa396dac3702b5bfce77917ed816abadb25a213 Mon Sep 17 00:00:00 2001 From: Bruno Ferreira Date: Tue, 27 Feb 2018 13:51:47 +0000 Subject: [PATCH 3/3] Removed extra "s" from the tailURL formation --- src/main/java/org/gitlab/api/GitlabAPI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/gitlab/api/GitlabAPI.java b/src/main/java/org/gitlab/api/GitlabAPI.java index 4d0683ca..a558d56c 100644 --- a/src/main/java/org/gitlab/api/GitlabAPI.java +++ b/src/main/java/org/gitlab/api/GitlabAPI.java @@ -334,7 +334,7 @@ public GitlabSSHKey createSSHKey(String title, String key) throws IOException { .append("title", title) .append("key", key); - String tailUrl = GitlabUser.USERS_URL + GitlabSSHKey.KEYS_URL + query.toString(); + String tailUrl = GitlabUser.USER_URL + GitlabSSHKey.KEYS_URL + query.toString(); return dispatch().to(tailUrl, GitlabSSHKey.class); }