-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsearch.ts
52 lines (43 loc) · 1.22 KB
/
search.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { flags } from "@oclif/command";
import { Kommand } from "../../common";
import { kuzzleFlags } from "../../support/kuzzle";
class ApiKeySearch extends Kommand {
public static description = "Lists a user's API Keys.";
public static flags = {
help: flags.help(),
filter: flags.string({
description: "Filter to match the API Key descriptions",
}),
...kuzzleFlags,
};
static args = [{ name: "user", description: "User kuid", required: true }];
async runSafe() {
let query = {};
if (this.flags.filter) {
query = {
match: {
description: this.flags.filter,
},
};
}
const result = await this.sdk.security.searchApiKeys(
this.args.user,
query,
{
from: 0,
size: 100,
}
);
this.logOk(`${result.total} API Keys found for user ${this.args.user}`);
if (result.total !== 0) {
this.log("");
for (const { _id, _source } of result.hits) {
this.log(` - Key "${_id}"`);
this.log(` Description: ${_source.description}`);
this.log(` Fingerprint: ${_source.fingerprint}`);
this.log(` Expires at: ${_source.expiresAt}`);
}
}
}
}
export default ApiKeySearch;