Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
57889a34
Commit
57889a34
authored
Mar 09, 2022
by
Flemming Frandsen
Browse files
Implemented the keys api
parent
3efc1263
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/GitLabApi.java
View file @
57889a34
...
...
@@ -5,6 +5,7 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.WeakHashMap
;
import
java.util.function.Supplier
;
import
java.util.logging.Level
;
import
java.util.logging.Logger
;
...
...
@@ -95,6 +96,7 @@ public class GitLabApi implements AutoCloseable {
private
TodosApi
todosApi
;
private
UserApi
userApi
;
private
WikisApi
wikisApi
;
private
KeysApi
keysApi
;
/**
* Get the GitLab4J shared Logger instance.
...
...
@@ -711,6 +713,14 @@ public class GitLabApi implements AutoCloseable {
return
(
apiClient
.
getAuthToken
());
}
/**
* Set auth token supplier for gitlab api client.
* @param authTokenSupplier - supplier which provide actual auth token
*/
public
void
setAuthTokenSupplier
(
Supplier
<
String
>
authTokenSupplier
)
{
apiClient
.
setAuthTokenSupplier
(
authTokenSupplier
);
}
/**
* Get the secret token.
*
...
...
@@ -1674,6 +1684,21 @@ public class GitLabApi implements AutoCloseable {
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.
*
...
...
src/main/java/org/gitlab4j/api/KeysApi.java
0 → 100644
View file @
57889a34
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
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment