forked from gitlab4j/gitlab4j-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request gitlab4j#814 from dren-dk/implement-keys-api
Implement keys api
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |