cli icon indicating copy to clipboard operation
cli copied to clipboard

Portal upload token (API key) format validation

Open vmasek opened this issue 9 months ago • 1 comments

User story

As a user, I want to be sure the token (API key) I set and use for uploading reports to portal is in correct format, so I will get quick and understandable feedback that my token is missing or missconfigured.

Acceptance criteria

  • [ ] validate the prefix cp_ should always be present
  • [ ] validate the hash lenght as it is always 64 hexadecimal characters
  • [ ] strip possible the unnecessary surrounding quotes
  • [ ] the logic for validation/stripping should live in the @code-pushup/portal-client package and be consumed by the CLI

Implementation details

A regex of /^cp_[0-9a-f]{64}$/ could be used. Additional pre-check if token is wrapped in " or ' quotes as this could be done if user copy pastes from code or assumes it needs to be in explicit string format. We could recover easily by stripping the quotes.

vmasek avatar Mar 04 '25 16:03 vmasek

the logic for validation/stripping should live in the @code-pushup/portal-client package and be consumed by the CLI

What it the reason we have it in portal-client instead of models? It would create a dependency from portal-client to models which I would avoid. model should not have dependencies.

Would it be OK to duplicate it? and have it in the API and the models?

BioPhoton avatar Oct 04 '25 11:10 BioPhoton