Skip to content

Commit 33bf479

Browse files
committed
kci: rework using kernelci.cli and Click
Rework the kci entry point to use the new kernelci.cli module and Click. Only implement `kci whoami` for now which can be used to check that TOML settings and secrets are loaded correctly. Also drop "kci config validate" from the Makefile tests for now as this needs to be reimplemented. Signed-off-by: Guillaume Tucker <guillaume.tucker@collabora.com>
1 parent 74ff7ea commit 33bf479

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ unit-tests:
4747
python3 -m pytest tests
4848

4949
validate-yaml:
50-
./kci config validate
5150
./kci_build validate
5251
./kci_test validate
5352
./kci_data validate

kci

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,37 @@
22
#
33
# SPDX-License-Identifier: LGPL-2.1-or-later
44
#
5-
# Copyright (C) 2022 Collabora Limited
5+
# Copyright (C) 2022, 2023 Collabora Limited
66
# Author: Guillaume Tucker <guillaume.tucker@collabora.com>
77

88
"""KernelCI Command Line Tool
99
10-
This executable script is the entry point for all the new KernelCI command line
11-
tools which support the new API & Pipeline design. See the documentation for
12-
more details: https://kernelci.org/docs/api/.
10+
This executable module is the entry point for the kci command line tool. It
11+
provides a way to manually interact with the KernelCI API and its related
12+
features. See the online documentation for more details:
13+
https://kernelci.org/docs/api/.
1314
"""
1415

15-
import argparse
16-
import sys
16+
import json
1717

18-
import kernelci.legacy.cli
18+
import click
19+
20+
from kernelci.cli import Args, kci
21+
import kernelci.api
22+
import kernelci.config
23+
24+
25+
@kci.command(secrets=True)
26+
@Args.config
27+
@Args.api
28+
def whoami(config, api, secrets):
29+
"""Use whoami to get current user info with API authentication"""
30+
configs = kernelci.config.load(config)
31+
api_config = configs['api_configs'][api]
32+
api = kernelci.api.get_api(api_config, secrets.api.token)
33+
data = api.whoami()
34+
click.echo(json.dumps(data, indent=2))
1935

2036

2137
if __name__ == '__main__':
22-
parser = argparse.ArgumentParser("KernelCI Command Line Tools")
23-
parser.add_argument(
24-
'command',
25-
choices=kernelci.legacy.cli.list_command_names(),
26-
help="Command to run"
27-
)
28-
args = parser.parse_args(sys.argv[1:2])
29-
kernelci.legacy.cli.call(args.command, sys.argv[2:])
38+
kci() # pylint: disable=no-value-for-parameter

0 commit comments

Comments
 (0)