Skip to content

Add DOKU credential validation and normalization - #439

Merged
mnindrazaka merged 1 commit into
mainfrom
claude/zen-cray-js6d6k
Sep 11, 2026
Merged

Add DOKU credential validation and normalization#439
mnindrazaka merged 1 commit into
mainfrom
claude/zen-cray-js6d6k

Conversation

@mnindrazaka

Copy link
Copy Markdown
Collaborator

Summary

Adds comprehensive validation and normalization for DOKU payment gateway credentials to catch configuration errors early and handle environment variable quirks from .env files and systemd EnvironmentFile.

Key Changes

  • Config validation: New Config.Validate() method checks all required DOKU configuration fields are present and non-empty
  • Credential normalization:
    • normalizePrivateKeyPEM() handles PEM keys that arrive quoted or with escaped newlines from environment sources
    • getCredential() trims and unquotes credential strings from environment variables
  • Credential masking: New maskCredential() function masks sensitive values in logs while preserving last 4 characters for debugging
  • Verification tool: New dokucheck CLI command validates credentials by attempting to fetch an access token from DOKU
  • Enhanced error messages: Token request failures now include response code and masked client ID for better diagnostics
  • Main startup validation: Application now validates DOKU config at startup and panics if invalid

Implementation Details

  • Private key normalization handles both escaped newlines (\n strings) and literal newlines, plus surrounding quotes
  • Credential environment variables are trimmed of whitespace and quotes to handle CI/systemd quirks
  • Error messages include response codes to help distinguish between configuration issues (e.g., wrong environment) and other failures
  • The dokucheck tool provides helpful guidance for common configuration mistakes like using Checkout instead of SNAP client ID

https://claude.ai/code/session_01TXdAv9tEdEFQtLYSRcRoUB

DOKU answers the access token request with "Unauthorized. Unknown Client"
when it does not recognise the client id in X-CLIENT-KEY. Nothing in the
API made that diagnosable: a blank or mangled credential booted fine and
only surfaced as a 500 at the customer's checkout.

- Trim whitespace and surrounding quotes off the DOKU credentials, so a
  .env written by the deploy workflow cannot corrupt them.
- Accept a newline-escaped or quoted DOKU_PRIVATE_KEY, the format
  .env.example documents and the one systemd may pass through verbatim.
- Validate the whole DOKU config at boot and name every missing variable
  instead of failing later on a checkout.
- Log the rejection with its response code, base URL and a masked client
  id, and carry the response code into the error message.
- Add `make doku-check`, which asks DOKU for an access token with the
  configured credentials and prints what to check when it is refused.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TXdAv9tEdEFQtLYSRcRoUB
@vercel

vercel Bot commented Sep 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
gatherloop-order Ready Ready Preview Sep 11, 2026 1:52am UTC
gatherloop-pos Ready Ready Preview Sep 11, 2026 1:52am UTC

@mnindrazaka
mnindrazaka merged commit fd0fd0a into main Sep 11, 2026
6 of 7 checks passed
@mnindrazaka
mnindrazaka deleted the claude/zen-cray-js6d6k branch September 11, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants