Skip to content

Commit bdc1f6d

Browse files
authored
Merge pull request #814 from dren-dk/implement-keys-api
Implement keys api
2 parents 116a2f5 + 55a9fb4 commit bdc1f6d

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/main/java/org/gitlab4j/api/GitLabApi.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public String getApiNamespace() {
9696
private TodosApi todosApi;
9797
private UserApi userApi;
9898
private WikisApi wikisApi;
99+
private KeysApi keysApi;
99100

100101
/**
101102
* Get the GitLab4J shared Logger instance.
@@ -1683,6 +1684,21 @@ public WikisApi getWikisApi() {
16831684
return wikisApi;
16841685
}
16851686

1687+
/**
1688+
* Gets the KeysApi instance owned by this GitLabApi instance. The KeysApi is used to look up users by their ssh key signatures
1689+
*
1690+
* @return the KeysApi instance owned by this GitLabApi instance
1691+
*/
1692+
public KeysApi getKeysAPI() {
1693+
synchronized (this) {
1694+
if (keysApi == null) {
1695+
keysApi = new KeysApi(this);
1696+
}
1697+
}
1698+
return keysApi;
1699+
}
1700+
1701+
16861702
/**
16871703
* Create and return an Optional instance associated with a GitLabApiException.
16881704
*
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.gitlab4j.api;
2+
3+
import org.gitlab4j.api.models.Key;
4+
5+
import javax.ws.rs.core.MultivaluedHashMap;
6+
import javax.ws.rs.core.MultivaluedMap;
7+
import javax.ws.rs.core.Response;
8+
import java.util.Collections;
9+
10+
/**
11+
* See:
12+
* https://docs.gitlab.com/ee/api/keys.html#get-user-by-fingerprint-of-ssh-key
13+
*/
14+
public class KeysApi extends AbstractApi {
15+
public KeysApi(GitLabApi gitLabApi) {
16+
super(gitLabApi);
17+
}
18+
19+
/**
20+
* @param fingerprint The md5 hash of a ssh public key with : separating the bytes Or SHA256:$base64hash
21+
* @return The Key which includes the user who owns the key
22+
* @throws GitLabApiException If anything goes wrong
23+
*/
24+
public Key getUserBySSHKeyFingerprint(String fingerprint) throws GitLabApiException {
25+
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
26+
queryParams.put("fingerprint", Collections.singletonList(fingerprint));
27+
Response response = get(Response.Status.OK, queryParams, "keys");
28+
return response.readEntity(Key.class);
29+
}
30+
}

0 commit comments

Comments
 (0)