Skip to content

Commit

Permalink
fix(cli): Don't require token for dry-run of version upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kumekay committed Aug 2, 2023
1 parent 7659e47 commit 488bf90
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Don't require token for `--dry-run` of `compote component upload` command
- Fix incorrect message suggestion to check upload status if non-default profile is used

## [1.3.2] - 2023-07-05
Expand Down
18 changes: 13 additions & 5 deletions idf_component_manager/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,13 @@ def upload_component(
dry_run=False, # type: bool
dest_dir=None,
): # type: (...) -> None
client, namespace = service_details(namespace, service_profile)
"""
Uploads a component version to the registry.
"""
token_required = not (check_only or dry_run)
client, namespace = service_details(
namespace, service_profile, token_required=token_required
)

if archive:
if not os.path.isfile(archive):
Expand Down Expand Up @@ -538,10 +544,12 @@ def upload_component(

# Uploading/validating the component
info_message = 'Uploading' if not dry_run else 'Validating'
print_info('%s archive %s' % (info_message, archive))
job_id = client.upload_version(
component_name=component_name, file_path=archive, validate_only=dry_run
)
print_info('{} archive {}'.format(info_message, archive))

if dry_run:
job_id = client.validate_version(file_path=archive)
else:
job_id = client.upload_version(component_name=component_name, file_path=archive)

# Wait for processing
profile_text = (
Expand Down
20 changes: 12 additions & 8 deletions idf_component_tools/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,7 @@ def component(self, request, component_name, version=None):
examples=examples,
)

@auth_required
@_request(cache=False)
def upload_version(self, request, component_name, file_path, validate_only=False):
def _upload_version_to_endpoint(self, request, file_path, endpoint):
with open(file_path, 'rb') as file:
filename = os.path.basename(file_path)

Expand All @@ -493,11 +491,6 @@ def callback(

data = MultipartEncoderMonitor(encoder, callback)

if validate_only:
endpoint = ['components', 'validate']
else:
endpoint = ['components', component_name.lower(), 'versions']

try:
return request(
'post',
Expand All @@ -509,6 +502,17 @@ def callback(
finally:
progress_bar.close()

@auth_required
@_request(cache=False)
def upload_version(self, request, component_name, file_path):
return self._upload_version_to_endpoint(
request, file_path, ['components', component_name.lower(), 'versions']
)

@_request(cache=False)
def validate_version(self, request, file_path):
return self._upload_version_to_endpoint(request, file_path, ['components', 'validate'])

@auth_required
@_request(cache=False)
def delete_version(self, request, component_name, component_version):
Expand Down
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,12 @@ def example_component_path(fixtures_path):


@pytest.fixture()
def mock_registry(monkeypatch):
def mock_registry_without_token(monkeypatch):
monkeypatch.setenv('IDF_COMPONENT_REGISTRY_URL', 'http://localhost:5000')


@pytest.fixture()
def mock_registry(mock_registry_without_token, monkeypatch):
monkeypatch.setenv('IDF_COMPONENT_API_TOKEN', 'test')


Expand Down
2 changes: 1 addition & 1 deletion tests/test_component_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_allow_existing_component(mock_registry, release_component_path, tmp_pat


@vcr.use_cassette('tests/fixtures/vcr_cassettes/test_validate_component.yaml')
def test_validate_component(mock_registry, pre_release_component_path):
def test_validate_component(mock_registry_without_token, pre_release_component_path):
manager = ComponentManager(path=pre_release_component_path)

manager.upload_component(
Expand Down

0 comments on commit 488bf90

Please sign in to comment.