Skip to content

Commit df21559

Browse files
committed
Merge branch 'release' into konflux
2 parents b995851 + c14663d commit df21559

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+603
-354
lines changed

.github/workflows/linters.yaml

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ jobs:
2929
- name: Run flake8 on python${{ matrix.python-version }}
3030
run: python -m tox -e flake8
3131

32-
# markdownlint:
33-
# name: Markdownlint
34-
# runs-on: ubuntu-latest
35-
36-
# steps:
37-
# - name: Check out repo
38-
# uses: actions/checkout@v2
39-
40-
# - name: Run markdownlint
41-
# uses: containerbuildsystem/actions/markdownlint@master
42-
4332
pylint:
4433
name: Pylint analyzer for Python ${{ matrix.python-version }}
4534
runs-on: ubuntu-latest
@@ -71,25 +60,25 @@ jobs:
7160
- name: Run ShellCheck
7261
uses: containerbuildsystem/actions/shellcheck@master
7362

74-
# mypy:
75-
# name: mypy type checker for Python ${{ matrix.python-version }}
76-
# runs-on: ubuntu-latest
77-
#
78-
# strategy:
79-
# matrix:
80-
# python-version: [ "3.8" ]
81-
#
82-
# steps:
83-
# - uses: actions/checkout@v3
84-
# - uses: actions/setup-python@v4
85-
# with:
86-
# python-version: ${{ matrix.python-version }}
87-
# - name: Install dependencies
88-
# run: |
89-
# python -m pip install --upgrade pip setuptools tox
90-
#
91-
# - name: Run mypy on python${{ matrix.python-version }}
92-
# run: python -m tox -e mypy
63+
mypy:
64+
name: mypy type checker for Python ${{ matrix.python-version }}
65+
runs-on: ubuntu-latest
66+
67+
strategy:
68+
matrix:
69+
python-version: [ "3.9" ]
70+
71+
steps:
72+
- uses: actions/checkout@v3
73+
- uses: actions/setup-python@v4
74+
with:
75+
python-version: ${{ matrix.python-version }}
76+
- name: Install dependencies
77+
run: |
78+
python -m pip install --upgrade pip setuptools tox
79+
80+
- name: Run mypy on python${{ matrix.python-version }}
81+
run: python -m tox -e mypy
9382

9483
# bandit:
9584
# name: Bandit analyzer for Python ${{ matrix.python-version }}

.github/workflows/unittests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: python -m tox -e test
3232

3333
- name: Upload pytest html report
34-
uses: actions/upload-artifact@v2
34+
uses: actions/upload-artifact@v4
3535
if: failure()
3636
with:
3737
path: __pytest_reports/charon-unit-tests.html

.pylintrc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ confidence=
2424
# --enable=similarities". If you want to run only the classes checker, but have
2525
# no Warning level messages displayed, use"--disable=all --enable=classes
2626
# --disable=W"
27-
enable=all,
28-
python3
27+
enable=all
2928
disable=I,
3029
R, # refactoring checks
3130
abstract-method, # nice to have
@@ -34,14 +33,14 @@ disable=I,
3433
bad-whitespace, # pep8, nice to have
3534
broad-except,
3635
comprehension-escape, # throws false positives on 1.9.0 (Fedora 29)
37-
deprecated-lambda, # nice to have
36+
; deprecated-lambda, # nice to have
3837
import-outside-toplevel,
3938
import-error, # requires to having all modules installed
4039
invalid-name,
4140
len-as-condition, # nice to have
4241
line-too-long, # pep8, should be enabled
4342
missing-docstring,
44-
misplaced-comparison-constant,
43+
; misplaced-comparison-constant,
4544
multiple-statements, # nice to have
4645
no-absolute-import, # it was required for py2
4746
no-init,
@@ -51,7 +50,7 @@ disable=I,
5150
old-division, # it was required for py2
5251
protected-access,
5352
redefined-outer-name, # nice to have
54-
relative-import, # nice to have
53+
; relative-import, # nice to have
5554
super-init-not-called, # nice to have
5655
superfluous-parens, # nice to have
5756
too-many-lines,

Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
init-venv:
2+
@pip install virtualenv
3+
@python -m virtualenv venv
4+
@source venv/bin/activate
5+
@pip install -r requirements.txt
6+
@pip install tox
7+
.PHONY: init, init-venv
8+
9+
lint:
10+
@python -m tox -e flake8
11+
@python -m tox -e pylint
12+
@python -m tox -e mypy
13+
.PHONY: lint
14+
15+
test-only:
16+
@python -m tox -e test
17+
.PHONY: test-only
18+
19+
test: lint test-only
20+
.PHONY: test
21+
22+
clean:
23+
rm -rf .coverage .tox .mypy_cache __pytest_reports htmlcov
24+
rm -rf build charon.egg-info dist local package
25+
.PHONY: clean
26+
27+
build:
28+
@pip install -r ./requirements.txt
29+
@pip install .
30+
.PHONY: build
31+
32+
sdist:
33+
@python3 setup.py sdist
34+
.PHONY: sdist
35+
36+
image-latest:
37+
@podman build . -f ./image/Containerfile -t localhost/charon:latest
38+
.PHONY: image-latest

charon.spec

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
%global owner Commonjava
22
%global modulename charon
33

4-
%global charon_version 1.2.2
4+
%global charon_version 1.3.3
55
%global sdist_tar_name %{modulename}-%{charon_version}
66

77
%global python3_pkgversion 3
@@ -23,33 +23,17 @@ BuildArch: x86_64
2323
BuildRequires: python%{python3_pkgversion}-setuptools
2424
BuildRequires: python%{python3_pkgversion}-devel
2525

26+
Requires: python%{python3_pkgversion}-jinja2
2627
Requires: python%{python3_pkgversion}-boto3
2728
Requires: python%{python3_pkgversion}-botocore
28-
Requires: python%{python3_pkgversion}-jinja2
29-
Requires: python%{python3_pkgversion}-markupsafe
30-
Requires: python%{python3_pkgversion}-dateutil
31-
Requires: python%{python3_pkgversion}-six
32-
Requires: python%{python3_pkgversion}-jmespath
33-
Requires: python%{python3_pkgversion}-urllib3
34-
Requires: python%{python3_pkgversion}-s3transfer
3529
Requires: python%{python3_pkgversion}-click
3630
Requires: python%{python3_pkgversion}-requests
37-
Requires: python%{python3_pkgversion}-idna
38-
Requires: python%{python3_pkgversion}-chardet
39-
Requires: python%{python3_pkgversion}-cryptography
40-
Requires: python%{python3_pkgversion}-cffi
41-
Requires: python%{python3_pkgversion}-pycparser
42-
Requires: python%{python3_pkgversion}-certifi
43-
Requires: python%{python3_pkgversion}-pyOpenSSL
44-
Requires: python%{python3_pkgversion}-ruamel-yaml
31+
Requires: python%{python3_pkgversion}-pyyaml
4532
Requires: python%{python3_pkgversion}-defusedxml
46-
Requires: python%{python3_pkgversion}-semantic-version
4733
Requires: python%{python3_pkgversion}-subresource-integrity
4834
Requires: python%{python3_pkgversion}-jsonschema
49-
Requires: python%{python3_pkgversion}-importlib-metadata
50-
Requires: python%{python3_pkgversion}-zipp
51-
Requires: python%{python3_pkgversion}-attrs
52-
Requires: python%{python3_pkgversion}-pyrsistent
35+
Requires: python%{python3_pkgversion}-urllib3
36+
Requires: python%{python3_pkgversion}-semantic-version
5337

5438
%description
5539
Simple Python tool with command line interface for charon init,

charon/cache.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from boto3 import session
22
from botocore.exceptions import ClientError
3-
from typing import Dict, List
3+
from typing import Dict, List, Optional
44
import os
55
import logging
66
import uuid
@@ -57,7 +57,7 @@ def __init_aws_client(
5757
endpoint_url=endpoint_url
5858
)
5959

60-
def __get_endpoint(self, extra_conf) -> str:
60+
def __get_endpoint(self, extra_conf) -> Optional[str]:
6161
endpoint_url = os.getenv(ENDPOINT_ENV)
6262
if not endpoint_url or not endpoint_url.strip():
6363
if isinstance(extra_conf, Dict):
@@ -97,14 +97,14 @@ def invalidate_paths(
9797
" will take more than %d seconds",
9898
len(real_paths), total_time_approx)
9999
results = []
100-
current_invalidation = {}
100+
current_invalidation: Dict[str, str] = {}
101101
processed_count = 0
102102
for batch_paths in real_paths:
103103
while (current_invalidation and
104104
INVALIDATION_STATUS_INPROGRESS == current_invalidation.get('Status', '')):
105105
time.sleep(INPRO_W_SECS)
106106
try:
107-
result = self.check_invalidation(distr_id, current_invalidation.get('Id'))
107+
result = self.check_invalidation(distr_id, current_invalidation.get('Id', ''))
108108
if result:
109109
current_invalidation = {
110110
'Id': result.get('Id', None),
@@ -159,7 +159,7 @@ def invalidate_paths(
159159
results.append(current_invalidation)
160160
return results
161161

162-
def check_invalidation(self, distr_id: str, invalidation_id: str) -> dict:
162+
def check_invalidation(self, distr_id: str, invalidation_id: str) -> Optional[dict]:
163163
try:
164164
response = self.__client.get_invalidation(
165165
DistributionId=distr_id,
@@ -177,8 +177,9 @@ def check_invalidation(self, distr_id: str, invalidation_id: str) -> dict:
177177
"[CloudFront] Error occurred while check invalidation of id %s, "
178178
"error: %s", invalidation_id, err
179179
)
180+
return None
180181

181-
def get_dist_id_by_domain(self, domain: str) -> str:
182+
def get_dist_id_by_domain(self, domain: str) -> Optional[str]:
182183
"""Get distribution id by a domain name. The id can be used to send invalidating
183184
request through #invalidate_paths function
184185
* Domain are Ronda domains, like "maven.repository.redhat.com"
@@ -200,5 +201,5 @@ def get_dist_id_by_domain(self, domain: str) -> str:
200201
)
201202
return None
202203

203-
def get_domain_by_bucket(self, bucket: str) -> str:
204+
def get_domain_by_bucket(self, bucket: str) -> Optional[str]:
204205
return DEFAULT_BUCKET_TO_DOMAIN.get(bucket, None)

charon/cmd/cmd_cache.py

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
"""
1616

1717
from charon.config import get_config
18-
from charon.cmd.internal import _decide_mode, _get_buckets
18+
from charon.cmd.internal import _decide_mode, _get_targets
1919
from charon.cache import CFClient
2020
from charon.pkgs.pkg_utils import invalidate_cf_paths
21+
from charon.types import TARGET_TYPE
2122
from click import command, option, argument, group
22-
from typing import List, Tuple
23+
from typing import List, Tuple, Optional
2324

2425
import traceback
2526
import logging
@@ -58,6 +59,14 @@
5859
format of CF defining too, and each path should be in a single line.
5960
"""
6061
)
62+
@option(
63+
"--config",
64+
"-c",
65+
help="""
66+
The charon configuration yaml file path. Default is
67+
$HOME/.charon/charon.yaml
68+
"""
69+
)
6170
@option(
6271
"--debug",
6372
"-D",
@@ -79,6 +88,7 @@ def invalidate(
7988
target: str,
8089
paths: List[str],
8190
path_file: str,
91+
config: str = "",
8292
quiet: bool = False,
8393
debug: bool = False
8494
):
@@ -110,20 +120,20 @@ def invalidate(
110120
break
111121

112122
try:
113-
(buckets, aws_profile) = _init_cmd(target)
123+
(targets, aws_profile) = _init_cmd(target, config)
114124

115-
for b in buckets:
125+
for t in targets:
116126
cf_client = CFClient(aws_profile=aws_profile)
117127
# Per aws official doc, if the paths contains wildcard, it is
118128
# limited to 15 as max items in one request. Otherwise it could
119129
# be 3000
120130
if use_wildcard:
121131
invalidate_cf_paths(
122-
cf_client, b, work_paths
132+
cf_client, t, work_paths
123133
)
124134
else:
125135
invalidate_cf_paths(
126-
cf_client, b, work_paths, batch_size=3000
136+
cf_client, t, work_paths, batch_size=3000
127137
)
128138
except Exception:
129139
print(traceback.format_exc())
@@ -144,6 +154,14 @@ def invalidate(
144154
""",
145155
required=True
146156
)
157+
@option(
158+
"--config",
159+
"-c",
160+
help="""
161+
The charon configuration yaml file path. Default is
162+
$HOME/.charon/charon.yaml
163+
"""
164+
)
147165
@option(
148166
"--debug",
149167
"-D",
@@ -164,6 +182,7 @@ def invalidate(
164182
def check(
165183
invalidation_id: str,
166184
target: str,
185+
config: str = "",
167186
quiet: bool = False,
168187
debug: bool = False
169188
):
@@ -175,14 +194,14 @@ def check(
175194
is_quiet=quiet, is_debug=debug, use_log_file=False
176195
)
177196
try:
178-
(buckets, aws_profile) = _init_cmd(target)
179-
if not buckets:
197+
(targets, aws_profile) = _init_cmd(target, config)
198+
if not targets:
180199
sys.exit(1)
181200

182-
for b in buckets:
201+
for t in targets:
183202
cf_client = CFClient(aws_profile=aws_profile)
184-
bucket_name = b[1]
185-
domain = b[4]
203+
bucket_name = t[1]
204+
domain: Optional[str] = t[4]
186205
if not domain:
187206
domain = cf_client.get_domain_by_bucket(bucket_name)
188207
if domain:
@@ -203,8 +222,8 @@ def check(
203222
sys.exit(2)
204223

205224

206-
def _init_cmd(target: str) -> Tuple[List[Tuple[str, str, str, str, str]], str]:
207-
conf = get_config()
225+
def _init_cmd(target: str, config: str) -> Tuple[List[TARGET_TYPE], str]:
226+
conf = get_config(config)
208227
if not conf:
209228
sys.exit(1)
210229

@@ -213,7 +232,7 @@ def _init_cmd(target: str) -> Tuple[List[Tuple[str, str, str, str, str]], str]:
213232
logger.error("No AWS profile specified!")
214233
sys.exit(1)
215234

216-
return (_get_buckets([target], conf), aws_profile)
235+
return (_get_targets([target], conf), aws_profile)
217236

218237

219238
@group()

0 commit comments

Comments
 (0)