Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unittests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
run: python -m tox -e test

- name: Upload pytest html report
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
path: __pytest_reports/charon-unit-tests.html
Expand Down
26 changes: 22 additions & 4 deletions charon/cmd/cmd_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@
format of CF defining too, and each path should be in a single line.
"""
)
@option(
"--config",
"-c",
help="""
The charon configuration yaml file path. Default is
$HOME/.charon/charon.yaml
"""
)
@option(
"--debug",
"-D",
Expand All @@ -79,6 +87,7 @@ def invalidate(
target: str,
paths: List[str],
path_file: str,
config: str = None,
quiet: bool = False,
debug: bool = False
):
Expand Down Expand Up @@ -110,7 +119,7 @@ def invalidate(
break

try:
(buckets, aws_profile) = _init_cmd(target)
(buckets, aws_profile) = _init_cmd(target, config)

for b in buckets:
cf_client = CFClient(aws_profile=aws_profile)
Expand Down Expand Up @@ -144,6 +153,14 @@ def invalidate(
""",
required=True
)
@option(
"--config",
"-c",
help="""
The charon configuration yaml file path. Default is
$HOME/.charon/charon.yaml
"""
)
@option(
"--debug",
"-D",
Expand All @@ -164,6 +181,7 @@ def invalidate(
def check(
invalidation_id: str,
target: str,
config: str = None,
quiet: bool = False,
debug: bool = False
):
Expand All @@ -175,7 +193,7 @@ def check(
is_quiet=quiet, is_debug=debug, use_log_file=False
)
try:
(buckets, aws_profile) = _init_cmd(target)
(buckets, aws_profile) = _init_cmd(target, config)
if not buckets:
sys.exit(1)

Expand Down Expand Up @@ -203,8 +221,8 @@ def check(
sys.exit(2)


def _init_cmd(target: str) -> Tuple[List[Tuple[str, str, str, str, str]], str]:
conf = get_config()
def _init_cmd(target: str, config: str) -> Tuple[List[Tuple[str, str, str, str, str]], str]:
conf = get_config(config)
if not conf:
sys.exit(1)

Expand Down
11 changes: 10 additions & 1 deletion charon/cmd/cmd_checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,20 @@ def validate(
""",
required=True
)
@option(
"--config",
"-c",
help="""
The charon configuration yaml file path. Default is
$HOME/.charon/charon.yaml
"""
)
@command()
def refresh(
target: str,
paths: List[str],
path_file: str,
config: str = None,
quiet: bool = False,
debug: bool = False
):
Expand All @@ -219,7 +228,7 @@ def refresh(
if paths:
work_paths.extend(paths)

conf = get_config()
conf = get_config(config)
aws_profile = os.getenv("AWS_PROFILE") or conf.get_aws_profile()
if not aws_profile:
logger.error("No AWS profile specified!")
Expand Down
11 changes: 10 additions & 1 deletion charon/cmd/cmd_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@
be extracted, when needed.
""",
)
@option(
"--config",
"-c",
help="""
The charon configuration yaml file path. Default is
$HOME/.charon/charon.yaml
"""
)
@option(
"--debug",
"-D",
Expand All @@ -120,6 +128,7 @@ def delete(
root_path="maven-repository",
ignore_patterns: List[str] = None,
work_dir: str = None,
config: str = None,
debug=False,
quiet=False,
dryrun=False
Expand All @@ -136,7 +145,7 @@ def delete(
"no files will be deleted.")
if not _validate_prod_key(product, version):
return
conf = get_config()
conf = get_config(config)
if not conf:
sys.exit(1)

Expand Down
11 changes: 10 additions & 1 deletion charon/cmd/cmd_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
""",
required=True
)
@option(
"--config",
"-c",
help="""
The charon configuration yaml file path. Default is
$HOME/.charon/charon.yaml
"""
)
@option(
"--debug",
"-D",
Expand All @@ -61,6 +69,7 @@
def index(
path: str,
target: str,
config: str = None,
debug: bool = False,
quiet: bool = False,
dryrun: bool = False
Expand All @@ -73,7 +82,7 @@ def index(
is_quiet=quiet, is_debug=debug, use_log_file=False
)
try:
conf = get_config()
conf = get_config(config)
if not conf:
sys.exit(1)

Expand Down
14 changes: 12 additions & 2 deletions charon/cmd/cmd_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@
be extracted, when needed.
""",
)
@option(
"--config",
"-c",
help="""
The charon configuration yaml file path. Default is
$HOME/.charon/charon.yaml
"""
)
@option(
"--contain_signature",
"-s",
Expand Down Expand Up @@ -137,6 +145,7 @@ def upload(
root_path="maven-repository",
ignore_patterns: List[str] = None,
work_dir: str = None,
config: str = None,
contain_signature: bool = False,
sign_key: str = "redhatdevel",
debug=False,
Expand All @@ -155,7 +164,7 @@ def upload(
"no files will be uploaded.")
if not _validate_prod_key(product, version):
return
conf = get_config()
conf = get_config(config)
if not conf:
sys.exit(1)

Expand Down Expand Up @@ -211,7 +220,8 @@ def upload(
cf_enable=conf.is_aws_cf_enable(),
key=sign_key,
dry_run=dryrun,
manifest_bucket_name=manifest_bucket_name
manifest_bucket_name=manifest_bucket_name,
config=config
)
if not succeeded:
sys.exit(1)
Expand Down
6 changes: 4 additions & 2 deletions charon/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ def is_aws_cf_enable(self) -> bool:
return self.__aws_cf_enable


def get_config() -> Optional[CharonConfig]:
config_file_path = os.path.join(os.getenv("HOME"), ".charon", CONFIG_FILE)
def get_config(cfgPath=None) -> Optional[CharonConfig]:
config_file_path = cfgPath
if not config_file_path or not os.path.isfile(config_file_path):
config_file_path = os.path.join(os.getenv("HOME"), ".charon", CONFIG_FILE)
data = read_yaml_from_file_path(config_file_path, 'schemas/charon.json')
return CharonConfig(data)

Expand Down
5 changes: 3 additions & 2 deletions charon/pkgs/maven.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def handle_maven_uploading(
cf_enable=False,
key=None,
dry_run=False,
manifest_bucket_name=None
manifest_bucket_name=None,
config=None
) -> Tuple[str, bool]:
""" Handle the maven product release tarball uploading process.
* repo is the location of the tarball in filesystem
Expand Down Expand Up @@ -406,7 +407,7 @@ def handle_maven_uploading(

# 10. Generate signature file if contain_signature is set to True
if gen_sign:
conf = get_config()
conf = get_config(config)
if not conf:
sys.exit(1)
suffix_list = __get_suffix(PACKAGE_TYPE_MAVEN, conf)
Expand Down
5 changes: 3 additions & 2 deletions charon/pkgs/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def handle_npm_uploading(
cf_enable=False,
key=None,
dry_run=False,
manifest_bucket_name=None
manifest_bucket_name=None,
config=None
) -> Tuple[str, bool]:
""" Handle the npm product release tarball uploading process.
For NPM uploading, tgz file and version metadata will be relocated based
Expand Down Expand Up @@ -189,7 +190,7 @@ def handle_npm_uploading(
logger.info("package.json uploading done")

if gen_sign:
conf = get_config()
conf = get_config(config)
if not conf:
sys.exit(1)
suffix_list = __get_suffix(PACKAGE_TYPE_NPM, conf)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

import charon.config as config
import re
import tempfile

from charon.constants import DEFAULT_REGISTRY
from charon.utils.files import overwrite_file
from tests.base import BaseTest


Expand All @@ -49,6 +51,26 @@ def test_no_config(self):
with pytest.raises(FileNotFoundError):
config.get_config()

def test_non_default_config(self):
self.__base.setUp()
config_content = """
ignore_patterns:
- ".*^(redhat).*"

targets:
changed:
- bucket: changed-bucket
prefix: changed-prefix
"""
_, tmp_config_file = tempfile.mkstemp(prefix="charon-test-config", suffix=".yaml")
overwrite_file(tmp_config_file, config_content)
conf = config.get_config(tmp_config_file)
self.assertIsNotNone(conf)
self.assertEqual("changed-bucket", conf.get_target("changed")[0].get('bucket', ''))
self.assertEqual("changed-prefix", conf.get_target("changed")[0].get('prefix', ''))
self.assertEqual([], conf.get_target("ga"))
os.remove(tmp_config_file)

def test_config_missing_targets(self):
content_missing_targets = """
ignore_patterns:
Expand Down