Skip to content

Commit 66bf89d

Browse files
committed
kernelci.cli: add storage subcommand
Add implementation for `kci storage upload` subcommand using the new framework with Click. Signed-off-by: Guillaume Tucker <[email protected]>
1 parent 38189c2 commit 66bf89d

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

kci

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ https://kernelci.org/docs/api/.
1717
from kernelci.cli import kci
1818
from kernelci.cli import ( # pylint: disable=unused-import
1919
docker as kci_docker,
20+
storage as kci_storage,
2021
user as kci_user,
2122
)
2223

kernelci/cli/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ class Args: # pylint: disable=too-few-public-methods
3939
'-s', '--toml-settings', 'settings',
4040
help="Path to the TOML user settings"
4141
)
42+
storage = click.option(
43+
'--storage',
44+
help="Name of the storage config entry"
45+
)
4246
verbose = click.option(
4347
'-v', '--verbose/--no-verbose', default=None,
4448
help="Print more details output"

kernelci/cli/storage.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
#
3+
# Copyright (C) 2023 Collabora Limited
4+
# Author: Guillaume Tucker <[email protected]>
5+
6+
"""Tool to interact with storage services supported by KernelCI"""
7+
8+
import os
9+
10+
import click
11+
12+
import kernelci.config
13+
import kernelci.storage
14+
from . import Args, kci
15+
16+
17+
@kci.group(name='storage')
18+
def kci_storage():
19+
"""Interact with KernelCI storage services"""
20+
21+
22+
@kci_storage.command(secrets=True)
23+
@click.argument('filename', type=click.Path(exists=True))
24+
@click.argument('path', required=False)
25+
@Args.config
26+
@Args.storage
27+
def upload(filename, path, config, storage, secrets):
28+
"""Upload FILENAME to the designated storage service in PATH"""
29+
configs = kernelci.config.load(config)
30+
storage_config = configs['storage'][storage]
31+
storage = kernelci.storage.get_storage(
32+
storage_config, secrets.storage.credentials
33+
)
34+
url = storage.upload_single(
35+
(filename, os.path.basename(filename)),
36+
path or ''
37+
)
38+
click.echo(url)

0 commit comments

Comments
 (0)