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:
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:
validate_api_key(key: str, environment: Environment)function inconfig.py.test_key is used withPRODUCTIONor alive_key withSANDBOX.ShadeClientconstructor and in the global setter.Acceptance Criteria:
AuthenticationErrorat configuration time, not at request time.pk_test_key used withenvironment="production"emits aUserWarning.sk_live_key passes validation without error.Noneor empty string raisesAuthenticationErrorimmediately.