Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch-libs command requires being logged into charmhub #1671

Open
lengau opened this issue May 7, 2024 · 2 comments
Open

fetch-libs command requires being logged into charmhub #1671

lengau opened this issue May 7, 2024 · 2 comments
Labels
Bug Something isn't working

Comments

@lengau
Copy link
Collaborator

lengau commented May 7, 2024

Bug Description

The fetch-libs command uses a logged in charmhub session, though it doesn't need to.

To Reproduce

  1. Create a fresh VM/container
  2. Add one or more libraries to a new charm
  3. Run charmcraft fetch-libs

Expected:

Libraries are collected

Actual:

Requests login

Environment

n/a

charmcraft.yaml

name: cc-1654

type: charm

bases:
  - build-on:
    - name: ubuntu
      channel: "22.04"
    run-on:
    - name: ubuntu
      channel: "22.04"

# (Required)
summary: A very short one-line summary of the flask application.

# (Required)
description: |
  A comprehensive overview of your Flask application.
]
charm-libs:
  - lib: mysql.mysql
    version: 0

Relevant log output

2024-05-07 10:17:58.552 Getting library metadata from charmhub
2024-05-07 10:17:58.552 Retrieving credentials for 'charmcraft' on 'api.charmhub.io' from keyring 'SecretService Keyring'.
2024-05-07 10:17:58.553 Credentials not found in the keyring 'SecretService Keyring'
2024-05-07 10:17:58.553 charmcraft internal error: CredentialsUnavailable("No credentials found for 'charmcraft' on 'api.charmhub.io'.")
2024-05-07 10:17:58.554 Traceback (most recent call last):
2024-05-07 10:17:58.554   File "/snap/charmcraft/3643/lib/python3.10/site-packages/craft_application/application.py", line 510, in run
2024-05-07 10:17:58.554     return_code = dispatcher.run() or 0
2024-05-07 10:17:58.554   File "/snap/charmcraft/3643/lib/python3.10/site-packages/craft_cli/dispatcher.py", line 487, in run
2024-05-07 10:17:58.554     return self._loaded_command.run(self._parsed_command_args)
2024-05-07 10:17:58.554   File "/snap/charmcraft/3643/lib/python3.10/site-packages/charmcraft/application/commands/store.py", line 1676, in run
2024-05-07 10:17:58.554     libs_metadata = store.get_libraries_metadata_by_name(charm_libs)
2024-05-07 10:17:58.554   File "/snap/charmcraft/3643/lib/python3.10/site-packages/charmcraft/services/store.py", line 220, in get_libraries_metadata_by_name
2024-05-07 10:17:58.554     for lib in self.get_libraries_metadata(libraries)
2024-05-07 10:17:58.554   File "/snap/charmcraft/3643/lib/python3.10/site-packages/charmcraft/services/store.py", line 212, in get_libraries_metadata
2024-05-07 10:17:58.554     return self.client.fetch_libraries_metadata(store_libs)
2024-05-07 10:17:58.554   File "/snap/charmcraft/3643/lib/python3.10/site-packages/charmcraft/store/client.py", line 202, in fetch_libraries_metadata
2024-05-07 10:17:58.554     response = self.request_urlpath_json("POST", "/v1/charm/libraries/bulk", json=libs)
2024-05-07 10:17:58.554   File "/snap/charmcraft/3643/lib/python3.10/site-packages/charmcraft/store/client.py", line 134, in request_urlpath_json
2024-05-07 10:17:58.554     response = super().request(method, self.api_base_url + urlpath, *args, **kwargs)
2024-05-07 10:17:58.554   File "/snap/charmcraft/3643/lib/python3.10/site-packages/craft_store/base_client.py", line 184, in request
2024-05-07 10:17:58.554     headers["Authorization"] = self._get_authorization_header()
2024-05-07 10:17:58.554   File "/snap/charmcraft/3643/lib/python3.10/site-packages/craft_store/store_client.py", line 108, in _get_authorization_header
2024-05-07 10:17:58.554     auth = creds.unmarshal_candid_credentials(self._auth.get_credentials())
2024-05-07 10:17:58.554   File "/snap/charmcraft/3643/lib/python3.10/site-packages/craft_store/auth.py", line 277, in get_credentials
2024-05-07 10:17:58.554     raise errors.CredentialsUnavailable(self.application_name, self.host)
2024-05-07 10:17:58.554 craft_store.errors.CredentialsUnavailable: No credentials found for 'charmcraft' on 'api.charmhub.io'.
@lengau lengau added the Bug Something isn't working label May 7, 2024
Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-2878.

This message was autogenerated

@gregory-schiano
Copy link
Contributor

While investigating this issue I also found out that the validation on the charm name in the libs, is in contradiction with what the charmhub API expects.

If I put the following in my charmcraft.yaml

charm-libs:
  - lib: traefik-k8s.ingress
    version: "2"

I get the following error:

- Invalid charm name in lib 'traefik-k8s.ingress'. Try replacing hyphens ('-') with underscores ('_'). (in field 'charm-libs[0].lib')

But if I use underscore instead the charmhub API doesn't recognize the charm-name

❯ curl -X POST 'https://api.charmhub.io/v1/charm/libraries/bulk' -H "Content-Type: application/json" --data '[{"charm-name": "traefik_k8s", "library-name": "ingress", "api": 2}]'
{"error-list":[{"code":null,"message":"Items need to include 'library_id' or 'package_id'"}]}

While using an hyphen:

❯ curl -X POST 'https://api.charmhub.io/v1/charm/libraries/bulk' -H "Content-Type: application/json" --data '[{"charm-name": "traefik-k8s", "library-name": "ingress", "api": 2}]'
{"libraries":[{"api":2,"charm-name":"traefik-k8s","created-at":"2024-05-02T11:09:33.567275","hash":"7410561327d3b8867651b6d664b7a5aab3a0f00aebac81a36911ec8dc11eb96d","library-id":"e6de2a5cd5b34422a204668f3b8f90d2","library-name":"ingress","patch":13}]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants