Commit 907f86dd authored by Lars Avery's avatar Lars Avery

adding user ssh key api calls and ssh key model

parent a6c11767
......@@ -212,6 +212,50 @@ public class GitlabAPI {
return retrieve().method("PUT").to(tailUrl, GitlabUser.class);
}
/**
* Create a new ssh key for the 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
*/
public GitlabSSHKey createSSHKey(Integer targetUserId, String title, String key) throws IOException {
Query query = new Query()
.append("title", title)
.append("key", key);
String tailUrl = GitlabUser.USERS_URL + "/" + targetUserId + GitlabSSHKey.KEYS_URL + query.toString();
return dispatch().to(tailUrl, GitlabSSHKey.class);
}
/**
* Delete user's ssh key
*
* @param targetUserId The id of the Gitlab user
* @param targetKeyId The id of the Gitlab ssh key
* @throws IOException
*/
public void deleteSSHKey(Integer targetUserId, Integer targetKeyId) throws IOException {
String tailUrl = GitlabUser.USERS_URL + "/" + targetUserId + GitlabSSHKey.KEYS_URL + "/" + targetKeyId;
retrieve().method("DELETE").to(tailUrl, Void.class);
}
/**
* Gets all ssh keys for a user
*
* @param targetUserId The id of the GitLab User
* @return The list of user ssh keys
*/
public List<GitlabSSHKey> getSSHKeys(Integer targetUserId) throws IOException {
String tailUrl = GitlabUser.USERS_URL + "/" + targetUserId + GitlabSSHKey.KEYS_URL;
return Arrays.asList(retrieve().to(tailUrl, GitlabSSHKey[].class));
}
/**
* Delete a user
*
......
package org.gitlab.api.models;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.Date;
public class GitlabSSHKey {
public static String KEYS_URL = "/keys";
private Integer _id;
private String _title;
private String _key;
public Integer getId() {
return _id;
}
public void setId(Integer id) {
_id = id;
}
public String getTitle() {
return _title;
}
public void setTitle(String title) {
_title = title;
}
public String getKey() {
return _key;
}
public void setKey(String key) {
_key = key;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment