Skip to content

Add API key format validation #4

Description

@codebestia

Description:

API keys must conform to a format (e.g. pk_live_, sk_live_, pk_test_, sk_test_ prefixes). Catching a malformed key before the first network call saves developers from cryptic 401 errors. Validation should also enforce that a live key is not accidentally used with the sandbox environment, and vice versa.

Proposed Steps:

  • Write a validate_api_key(key: str, environment: Environment) function in config.py.
  • Check prefix, minimum length, and character set.
  • Warn (but do not raise) when a test_ key is used with PRODUCTION or a live_ key with SANDBOX.
  • Call this in the ShadeClient constructor and in the global setter.

Acceptance Criteria:

  • A key not matching the expected format raises AuthenticationError at configuration time, not at request time.
  • A pk_test_ key used with environment="production" emits a UserWarning.
  • A valid sk_live_ key passes validation without error.
  • None or empty string raises AuthenticationError immediately.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions