File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
src/main/java/org/gitlab4j/api Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff 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 *
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments