Skip to content

feat: add equinix init to configure API credentials - #69

Open
displague wants to merge 4 commits into
mainfrom
feat/init-command
Open

displague wants to merge 4 commits into
mainfrom
feat/init-command

Conversation

@displague

@displague displague commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds equinix init, an interactive way to set up API credentials:

$ equinix init
Config file: ~/.config/equinix/equinix.yaml
Create a new API credential? [Y/n]:

Open https://portal.equinix.com/developer-settings/apps
Follow https://docs.equinix.com/equinix-api/developer-settings to create an app,
then enter its client ID and secret below.

Client ID: …
Client Secret:
Checking credentials... ok
Saved credentials to ~/.config/equinix/equinix.yaml
  • Y (default) opens the Portal apps page in a browser. The link is always printed too, for SSH or headless sessions. n skips straight to the prompts.
  • Hidden secret: when stdin is a terminal, the client secret isn't shown as it's typed (golang.org/x/term). Ctrl-C at that prompt turns echo back on before exiting.
  • Token check before save: the ID and secret must get an OAuth2 token before anything is written. If the check fails, the command exits non-zero and the config file isn't touched.
  • Leaving the config alone: a blank ID or secret, EOF, or Ctrl-C leaves the file unchanged. When the file is saved, other keys are kept and the mode is 0600. The file is edited as YAML directly rather than through viper.WriteConfig, so values from env vars aren't written out.
  • --config is supported, and its file doesn't need to exist yet when running init.

API and STS endpoints

Related: equinix-labs/equinix-docs-mcp-server#54, which proposes the same variable names for the MCP server.

There was no base URL setting. cobra doesn't add env vars for flags, and the equinix-sdk-go library reads no env vars (only its examples do). Each service's configuration.go hardcodes https://api.equinix.com, or https://sts.eqix.equinix.com for stsv1alpha. So this PR adds the Terraform provider's names, read through viper AutomaticEnv like the client ID and secret:

Env var Config key Default Flag on init
EQUINIX_API_ENDPOINT equinix_api_endpoint https://api.equinix.com --api-endpoint
EQUINIX_STS_ENDPOINT equinix_sts_endpoint https://sts.eqix.equinix.com --sts-endpoint
  • api.NewStandardClient uses the API endpoint for the token request. It rewrites SDK requests for either production host to the configured endpoint, so every service follows the setting without changing its server list.
  • With init --api-endpoint https://mockapi.example.com, or any host other than api.equinix.com, init asks the same questions but leaves out the Portal link and docs, which only apply to api.equinix.com.

CI

The e2e workflow only ran go test -run '^TestE2E_' ./cmd/..., so the other tests never ran in CI, including the existing internal/casing ones. A new test workflow runs go test -skip '^TestE2E_' ./..., and there's a make test target.

Test plan

  • go test ./... (in CI: e2e workflow for TestE2E_*, test workflow for the rest)
    • init: create, decline, blank/EOF, a failed token check, both endpoint flags, and the env var.
    • e2e: runs init against the fake API with the blanket redirect removed, then confirms a fabricv4 command uses the saved endpoint.
    • internal/api: host rewrite for both endpoints, plus rejection of an endpoint without a scheme.
  • make lint: 0 issues
  • make docs regenerated
  • Manual, through a pty: the secret isn't echoed. Ctrl-C at the secret prompt exits 130 with echo restored and no config written.

🤖 Generated with Claude Code

displague and others added 3 commits November 11, 2026 01:23
`equinix init` asks whether to create a new API credential. On yes it
opens the developer-settings apps page in Portal (printing the link in
case no browser opens), points at the developer-settings docs, then
prompts for the client ID and secret. The credentials are checked by
requesting an OAuth2 token before anything is written; a blank answer,
EOF, Ctrl-C, or a failed token check leaves the config file unchanged.

Add EQUINIX_API_ENDPOINT (config key equinix_api_endpoint) to point the
CLI at a non-production API. `init --api-endpoint` saves it, and skips
the Portal instructions when the host isn't api.equinix.com. Every SDK
service hardcodes https://api.equinix.com, so the standard client
rewrites requests for that host to the configured endpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When stdin is a terminal, the client secret is read without echo
(golang.org/x/term). Ctrl-C at that prompt restores the terminal before
exiting.

Add EQUINIX_STS_ENDPOINT (config key equinix_sts_endpoint), as in the
Terraform provider, to replace https://sts.eqix.equinix.com for stsv1alpha
requests. `init --sts-endpoint` saves it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The e2e workflow only runs `TestE2E_` tests in ./cmd, so the other tests
(cmd init tests, internal/api, internal/casing) never ran in CI. Add a
test workflow that runs the rest, and a `make test` target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ctreatma
ctreatma previously approved these changes Nov 11, 2026
With a non-production endpoint, still ask whether to create a new
credential, and only leave out the Portal link and docs, which apply to
api.equinix.com.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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