-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add auth:searchApiKeys #39
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4532829
Add auth:searchApiKeys
Yoann-Abbes 4525836
fingerprint field
Yoann-Abbes 29651b7
Update doc/1/controllers/auth/search-api-keys/index.md
Yoann-Abbes 8f3de9e
Update doc/1/controllers/auth/search-api-keys/index.md
Yoann-Abbes cc07f07
Update doc/1/controllers/auth/search-api-keys/index.md
Yoann-Abbes 1096daa
Update doc/1/controllers/auth/search-api-keys/index.md
Yoann-Abbes 3c51b23
Update doc/1/controllers/auth/search-api-keys/index.md
Yoann-Abbes 520b57b
Update doc/1/controllers/auth/search-api-keys/index.md
Yoann-Abbes 585f180
Update doc/1/controllers/auth/search-api-keys/index.md
Yoann-Abbes c158ec5
Update doc/1/controllers/auth/search-api-keys/index.md
Yoann-Abbes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,92 @@ | ||
--- | ||
code: true | ||
type: page | ||
title: searchApiKeys | ||
description: Searches API keys for the currently logged user. | ||
--- | ||
|
||
# searchApiKeys | ||
|
||
<SinceBadge version="auto-version" /> | ||
|
||
<SinceBadge version="Kuzzle 2.1.0" /> | ||
|
||
Searches API keys for the currently logged user. | ||
|
||
:::: tabs | ||
::: tab Java | ||
|
||
## Arguments | ||
|
||
```java | ||
public CompletableFuture<SearchResult> searchApiKeys( | ||
ConcurrentHashMap<String, Object> query) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<SearchResult> searchApiKeys( | ||
ConcurrentHashMap<String, Object> query, | ||
Integer from) throws NotConnectedException, InternalException | ||
|
||
public CompletableFuture<SearchResult> searchApiKeys( | ||
ConcurrentHashMap<String, Object> query | ||
Integer from | ||
Integer size) throws NotConnectedException, InternalException | ||
``` | ||
|
||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| `query` | <pre>ConcurrentHashMap<String, Object></pre> | Search query | | ||
| `from` | <pre>Integer</pre><br/>(`0`) | (optional) Offset of the first document to fetch | | ||
| `size` | <pre>Integer</pre> | (optional) Maximum number of documents to retrieve per page | | ||
|
||
### query | ||
|
||
The search query to apply to API keys content, using the [ElasticSearch Query DSL](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/query-dsl.html) syntax. | ||
|
||
If left empty, the result will return all available API keys for the currently logged user. | ||
|
||
## Return | ||
|
||
Returns a [SearchResult](/sdk/jvm/1/core-classes/search-result) object. | ||
|
||
|
||
## Usage | ||
|
||
<<< ./snippets/search-api-keys-java.java | ||
|
||
::: | ||
::: tab Kotlin | ||
|
||
## Arguments | ||
|
||
```kotlin | ||
fun searchApiKeys( | ||
query: ConcurrentHashMap<String, Any?>, | ||
from: Int = 0, | ||
size: Int? = null): CompletableFuture<SearchResult> | ||
``` | ||
|
||
|
||
| Property | Type | Description | | ||
| --- | --- | --- | | ||
| `query` | <pre>ConcurrentHashMap<String, Any?></pre> | Search query | | ||
| `from` | <pre>Int</pre><br/>(`0`) | (optional) Offset of the first document to fetch | | ||
| `size` | <pre>Int</pre> | (optional) Maximum number of documents to retrieve per page | | ||
|
||
### query | ||
|
||
The search query to apply to API keys content, using the [ElasticSearch Query DSL](https://www.elastic.co/guide/en/elasticsearch/reference/7.3/query-dsl.html) syntax. | ||
|
||
If left empty, the result will return all available API keys of the currently logged user. | ||
|
||
## Return | ||
|
||
Returns a [SearchResult](/sdk/jvm/1/core-classes/search-result) object. | ||
|
||
|
||
## Usage | ||
|
||
<<< ./snippets/search-api-keys-kotlin.kt | ||
|
||
::: | ||
:::: |
68 changes: 68 additions & 0 deletions
68
doc/1/controllers/auth/search-api-keys/snippets/search-api-keys-java.java
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,68 @@ | ||
|
||
ConcurrentHashMap<String, Object> description = new ConcurrentHashMap<>(); | ||
description.put("description", "LoRa permanent API Key"); | ||
|
||
ConcurrentHashMap<String, Object> query = new ConcurrentHashMap<>(); | ||
query.put("controller", "security"); | ||
query.put("action", "createApiKey"); | ||
query.put("userId", "jared.doe"); | ||
query.put("refresh", "wait_for"); | ||
query.put("body", description); | ||
|
||
kuzzle.query(query).get(); | ||
|
||
description.put("description", "Sigfox API key"); | ||
query.put("body", description); | ||
kuzzle.query(query).get(); | ||
|
||
description.put("description", "LoRa 6 month API key"); | ||
query.put("body", description); | ||
query.put("expiresIn", 36000); | ||
kuzzle.query(query).get(); | ||
|
||
ConcurrentHashMap<String, Object> credentials = new ConcurrentHashMap<>(); | ||
credentials.put("username", "jared.doe"); | ||
credentials.put("password", "password"); | ||
|
||
kuzzle.getAuthController().login("local", credentials).get(); | ||
|
||
ConcurrentHashMap<String, Object> match = new ConcurrentHashMap<>(); | ||
match.put("description", "LoRa"); | ||
|
||
ConcurrentHashMap<String, Object> squery = new ConcurrentHashMap<>(); | ||
squery.put("match", match); | ||
|
||
SearchResult results = kuzzle.getAuthController() | ||
.searchApiKeys(squery).get(); | ||
|
||
String output = String.format("Found %d API keys matching 'LoRa'", results.total); | ||
|
||
System.out.println(output); | ||
|
||
/* | ||
{ | ||
"total"=2, | ||
"hits"=[ | ||
{ | ||
"_id"="znEwbG8BJASM_0-bWU-q", | ||
"_source"={ | ||
"description"="LoRa permanent API key", | ||
"userId"="jared.doe", | ||
"expiresAt"=-1, | ||
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6", | ||
"ttl"=-1 | ||
} | ||
}, | ||
{ | ||
"_id"="zXEwbG8BJASM_0-bWU-q", | ||
"_source"={ | ||
"description"="LoRa 6 month API key", | ||
"userId"="jared.doe", | ||
"expiresAt"=31557600000, | ||
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6", | ||
"ttl"=360000 | ||
} | ||
} | ||
] | ||
} | ||
*/ |
20 changes: 20 additions & 0 deletions
20
doc/1/controllers/auth/search-api-keys/snippets/search-api-keys-java.test.yml
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,20 @@ | ||
name: java-auth#searchApiKeys | ||
description: Searches API keys for the currently loggued user. | ||
hooks: | ||
before: > | ||
curl --fail -H "Content-type: application/json" -d '{ | ||
"content": { | ||
"profileIds": ["default"] | ||
}, | ||
"credentials": { | ||
"local": { | ||
"username": "jared.doe", | ||
"password": "password" | ||
} | ||
} | ||
}' "kuzzle:7512/users/jared.doe/_create?refresh=wait_for" | ||
after: | ||
curl -XDELETE kuzzle:7512/users/jared.doe | ||
template: default | ||
expected: | ||
- Found 2 API keys matching 'LoRa' |
72 changes: 72 additions & 0 deletions
72
doc/1/controllers/auth/search-api-keys/snippets/search-api-keys-kotlin.kt
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,72 @@ | ||
|
||
val description: ConcurrentHashMap<String?, Any?> = ConcurrentHashMap<String?, Any?>().apply { | ||
put("description", "LoRa permanent API Key") | ||
} | ||
|
||
val query: ConcurrentHashMap<String?, Any?> = ConcurrentHashMap<String?, Any?>().apply { | ||
put("controller", "security") | ||
put("action", "createApiKey") | ||
put("userId", "jared.doe") | ||
put("refresh", "wait_for") | ||
put("body", description) | ||
} | ||
|
||
kuzzle.query(query).get() | ||
|
||
description.put("description", "Sigfox API key") | ||
query.put("body", description); | ||
kuzzle.query(query).get() | ||
|
||
description.put("description", "LoRa 6 month API key") | ||
query.put("body", description); | ||
query.put("expiresIn", 36000); | ||
kuzzle.query(query).get() | ||
|
||
kuzzle.authController.login("local", ConcurrentHashMap<String, Any?>().apply { | ||
put("username", "jared.doe") | ||
put("password", "password") | ||
}).get() | ||
|
||
val match: ConcurrentHashMap<String, Any?> = | ||
ConcurrentHashMap<String, Any?>().apply { | ||
put("description", "LoRa") | ||
} | ||
|
||
val squery: ConcurrentHashMap<String, Any?> = | ||
ConcurrentHashMap<String, Any?>().apply { | ||
put("match", match) | ||
} | ||
|
||
val results = kuzzle | ||
.authController | ||
.searchApiKeys(squery).get(); | ||
|
||
print("Found ${results.total} API keys matching 'LoRa'"); | ||
|
||
/* | ||
{ | ||
"total"=2, | ||
"hits"=[ | ||
{ | ||
"_id"="znEwbG8BJASM_0-bWU-q", | ||
"_source"={ | ||
"description"="LoRa permanent API key", | ||
"userId"="jared.doe", | ||
"expiresAt"=-1, | ||
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6", | ||
"ttl"=-1 | ||
} | ||
}, | ||
{ | ||
"_id"="zXEwbG8BJASM_0-bWU-q", | ||
"_source"={ | ||
"description"="LoRa 6 month API key", | ||
"userId"="jared.doe", | ||
"expiresAt"=31557600000, | ||
"fingerprint": "4ee98cb8c614e99213e7695f822e42325d86c93cfaf39cb40e860939e784c8e6", | ||
"ttl"=360000 | ||
} | ||
} | ||
] | ||
} | ||
*/ |
20 changes: 20 additions & 0 deletions
20
doc/1/controllers/auth/search-api-keys/snippets/search-api-keys-kotlin.test.yml
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,20 @@ | ||
name: kotlin-auth#searchApiKeys | ||
description: Searches API keys for the currently loggued user. | ||
hooks: | ||
before: > | ||
curl --fail -H "Content-type: application/json" -d '{ | ||
"content": { | ||
"profileIds": ["default"] | ||
}, | ||
"credentials": { | ||
"local": { | ||
"username": "jared.doe", | ||
"password": "password" | ||
} | ||
} | ||
}' "kuzzle:7512/users/jared.doe/_create?refresh=wait_for" | ||
after: | ||
curl -XDELETE kuzzle:7512/users/jared.doe | ||
template: default | ||
expected: | ||
- Found 2 API keys matching 'LoRa' |
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
54 changes: 27 additions & 27 deletions
54
doc/1/controllers/document/update-by-query/snippets/update-by-query-java.java
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 |
---|---|---|
@@ -1,30 +1,30 @@ | ||
ConcurrentHashMap<String, Object> searchQuery = new ConcurrentHashMap<>(); | ||
ConcurrentHashMap<String, Object> match = new ConcurrentHashMap<>(); | ||
match.put("capacity", 4); | ||
searchQuery.put("match", match); | ||
ConcurrentHashMap<String, Object> searchQuery = new ConcurrentHashMap<>(); | ||
ConcurrentHashMap<String, Object> match = new ConcurrentHashMap<>(); | ||
match.put("capacity", 4); | ||
searchQuery.put("match", match); | ||
|
||
ConcurrentHashMap<String, Object> changes = new ConcurrentHashMap<>(); | ||
changes.put("capacity", 42); | ||
ConcurrentHashMap<String, Object> changes = new ConcurrentHashMap<>(); | ||
changes.put("capacity", 42); | ||
|
||
ConcurrentHashMap<String, ArrayList<Object>> result = kuzzle | ||
.getDocumentController() | ||
.updateByQuery("nyc-open-data", "yellow-taxi", searchQuery, changes) | ||
.get(); | ||
ConcurrentHashMap<String, ArrayList<Object>> result = kuzzle | ||
.getDocumentController() | ||
.updateByQuery("nyc-open-data", "yellow-taxi", searchQuery, changes) | ||
.get(); | ||
|
||
/* | ||
{ | ||
successes=[ | ||
{ | ||
_id=<document-id>, | ||
_source=<updated document> // if source set to true | ||
status=200 | ||
}, | ||
{ | ||
_id=<document id>, | ||
_source=<updated document> // if source set to true | ||
status=200 | ||
} | ||
], | ||
errors=[] | ||
} | ||
*/ | ||
/* | ||
{ | ||
successes=[ | ||
{ | ||
_id=<document-id>, | ||
_source=<updated document> // if source set to true | ||
status=200 | ||
}, | ||
{ | ||
_id=<document id>, | ||
_source=<updated document> // if source set to true | ||
status=200 | ||
} | ||
], | ||
errors=[] | ||
} | ||
*/ |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol.