Skip to content

Default api_url, auth_url, network, chain_id so boilerplate can omit them - #12

Merged
CryptoFewka merged 1 commit into
mainfrom
feat/default-urls-network-chain
Jun 25, 2026
Merged

Default api_url, auth_url, network, chain_id so boilerplate can omit them#12
CryptoFewka merged 1 commit into
mainfrom
feat/default-urls-network-chain

Conversation

@CryptoFewka

@CryptoFewka CryptoFewka commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

What

Defaults the four config values that are identical for every mainnet customer, so the dashboard's API-key boilerplate can drop them:

Var Default
KEYSYNC_API_URL https://console.getoptimum.io
KEYSYNC_AUTH_URL https://auth.getoptimum.io
KEYSYNC_NETWORK mainnet
KEYSYNC_CHAIN_ID 0x1

An explicit env var or flag still wins. Resolved in from_env via or <default> and mirrored as pydantic model field defaults, so both the env path and direct construction get them.

After this, the minimal config is just KEYSYNC_API_KEY, KEYSYNC_OWNER_NAME, and one validator source (+ KEYSYNC_BEACON_URL when using pubkeys/index input).

Notes

  • Testnet: network and chain_id default to mainnet, so a testnet user must set both together (e.g. KEYSYNC_NETWORK=hoodi with its chain id). Documented in the README and flag help. A wrong/forgotten value here scopes reads/writes to the wrong network rather than failing loudly, which is the one tradeoff of defaulting these.
  • No change to KEYSYNC_API_KEY (required secret) or KEYSYNC_OWNER_NAME (handled separately).

Tests

  • test_url_network_chain_defaults_applied_when_unset (clears env, omits the four, asserts the defaults)
  • test_explicit_url_network_chain_override_defaults
  • pytest: 79 passed; ruff clean; mypy clean.

Written with Claude Code

Summary by CodeRabbit

  • New Features
    • Configuration now uses sensible defaults for API/auth endpoints, network, and chain ID, so fewer settings are needed to get started.
  • Documentation
    • Updated the quickstart and configuration guide to show which settings are optional and what defaults are used.
  • Bug Fixes
    • Improved CLI help text to clearly display default values for connection and network-related options.
  • Tests
    • Added coverage for default configuration behavior and for overriding those defaults when needed.

These four are the same for every mainnet customer, so default them to the
public Optimum endpoints and Ethereum mainnet and let the dashboard
boilerplate omit them. An explicit env var or flag still wins (resolved in
from_env via 'or DEFAULT', mirrored as model field defaults).

  api_url   -> https://console.getoptimum.io
  auth_url  -> https://auth.getoptimum.io
  network   -> mainnet
  chain_id  -> 0x1

Updates the README config table + quickstart and the CLI flag help, and adds
tests for defaults-applied-when-unset and explicit-override. A testnet user
must still set network + chain_id together (documented).
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds default values for KEYSYNC_API_URL, KEYSYNC_AUTH_URL, KEYSYNC_NETWORK, and KEYSYNC_CHAIN_ID in config, and updates from_env() to use those defaults when unset. README content and CLI help text were updated to describe the defaults, and tests were added for unset and explicit override cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title is relevant, but it does not use the required type(domain/pkg): summary format and exceeds the 72-character limit. Rename it to feat(optimum_keysync): default mainnet config values or another ≤72-char title with the required prefix.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/optimum_keysync/config.py`:
- Around line 90-93: The config fields `network` and `chain_id` in `config.py`
are currently independently overridable, which allows mixed-chain values like
`network="hoodi"` with the default `chain_id`. Update the validation logic in
the `Config` model so partial overrides are rejected and only the pair is
accepted together; keep the default behavior unchanged when neither is provided.
Use the existing `network`/`chain_id` fields and the related config-building
logic around the cited lines to enforce the coupled override rule.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: getoptimum/coderabbit/.coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d7880e57-7bb9-4bf3-96fb-13f66a974ae9

📥 Commits

Reviewing files that changed from the base of the PR and between 247c6fb and 162dca4.

📒 Files selected for processing (4)
  • README.md
  • src/optimum_keysync/cli.py
  • src/optimum_keysync/config.py
  • tests/test_config.py

Comment on lines +90 to +93
# network/chain_id default to Ethereum mainnet. Override both together for
# a testnet (e.g. network=hoodi with its chain_id).
network: Annotated[str, Field(min_length=1)] = _DEFAULT_NETWORK
chain_id: Annotated[str, Field(min_length=1)] = _DEFAULT_CHAIN_ID

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Enforce network/chain_id as a coupled override to prevent mixed-chain configs.

Line 177/Line 178 can produce network="hoodi" with chain_id="0x1" when only one is set, which silently creates an inconsistent target chain config. Please reject partial overrides and require both values together when overriding defaults.

Suggested minimal fix
 def from_env(overrides: dict[str, str | Path | None] | None = None) -> KeysyncConfig:
@@
-    return KeysyncConfig(
+    network_override = pick("network")
+    chain_id_override = pick("chain_id")
+    if (network_override is None) ^ (chain_id_override is None):
+        raise ValueError(
+            "KEYSYNC_NETWORK and KEYSYNC_CHAIN_ID must be set together when overriding defaults"
+        )
+
+    return KeysyncConfig(
         api_url=pick("api_url") or _DEFAULT_API_URL,
         auth_url=pick("auth_url") or _DEFAULT_AUTH_URL,
@@
-        network=pick("network") or _DEFAULT_NETWORK,
-        chain_id=pick("chain_id") or _DEFAULT_CHAIN_ID,
+        network=network_override or _DEFAULT_NETWORK,
+        chain_id=chain_id_override or _DEFAULT_CHAIN_ID,

Also applies to: 173-178

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/optimum_keysync/config.py` around lines 90 - 93, The config fields
`network` and `chain_id` in `config.py` are currently independently overridable,
which allows mixed-chain values like `network="hoodi"` with the default
`chain_id`. Update the validation logic in the `Config` model so partial
overrides are rejected and only the pair is accepted together; keep the default
behavior unchanged when neither is provided. Use the existing
`network`/`chain_id` fields and the related config-building logic around the
cited lines to enforce the coupled override rule.

@CryptoFewka
CryptoFewka merged commit 6ebb4db into main Jun 25, 2026
3 checks passed
@CryptoFewka
CryptoFewka deleted the feat/default-urls-network-chain branch June 25, 2026 15:57
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.

1 participant