Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/java/org/gitlab4j/api/GitLabApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public String getApiNamespace() {
private TodosApi todosApi;
private UserApi userApi;
private WikisApi wikisApi;
private KeysApi keysApi;

/**
* Get the GitLab4J shared Logger instance.
Expand Down Expand Up @@ -1674,6 +1675,21 @@ public WikisApi getWikisApi() {
return wikisApi;
}

/**
* Gets the KeysApi instance owned by this GitLabApi instance. The KeysApi is used to look up users by their ssh key signatures
*
* @return the KeysApi instance owned by this GitLabApi instance
*/
public KeysApi getKeysAPI() {
synchronized (this) {
if (keysApi == null) {
keysApi = new KeysApi(this);
}
}
return keysApi;
}


/**
* Create and return an Optional instance associated with a GitLabApiException.
*
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/org/gitlab4j/api/KeysApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.gitlab4j.api;

import org.gitlab4j.api.models.Key;

import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import java.util.Collections;

/**
* See:
* https://docs.gitlab.com/ee/api/keys.html#get-user-by-fingerprint-of-ssh-key
*/
public class KeysApi extends AbstractApi {
public KeysApi(GitLabApi gitLabApi) {
super(gitLabApi);
}

/**
* @param fingerprint The md5 hash of a ssh public key with : separating the bytes Or SHA256:$base64hash
* @return The Key which includes the user who owns the key
* @throws GitLabApiException If anything goes wrong
*/
public Key getUserBySSHKeyFingerprint(String fingerprint) throws GitLabApiException {
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
queryParams.put("fingerprint", Collections.singletonList(fingerprint));
Response response = get(Response.Status.OK, queryParams, "keys");
return response.readEntity(Key.class);
}
}