Skip to content

Conversation

@markphelps
Copy link
Contributor

@markphelps markphelps commented Sep 30, 2025

Summary

Implements support for other registries besides hardcoded r8.im

Changes

  • Add COG_REGISTRY_HOST environment variable for persistent registry override
  • Add --registry global persistent flag (hidden) for one-off overrides
  • Implement credential fallback: when alternate registry has no credentials, automatically reuse r8.im credentials
  • Update API client to dynamically load registry authentication
  • Update login messages to show actual registry host being authenticated

Configuration Priority

--registry flag (highest - one-off overrides)
       ↓
COG_REGISTRY_HOST env var (session/testing)
       ↓
Default "r8.im" (lowest - production)

Usage

Internal teams can now test alternate registries:

# Set for current shell session
export COG_REGISTRY_HOST=x.r8.im
cog login
cog push x.r8.im/user/model

# Or use flag for one-off override
cog --registry x.r8.im login

Credential Fallback

Existing r8.im credentials are automatically reused for alternate registries, displaying:

Using existing r8.im credentials for x.r8.im

Testing

  • ✅ All Go tests pass
  • ✅ Code formatted and linted
  • ✅ No regressions - default r8.im behavior unchanged
  • ✅ Generic fallback works for any alternate registry, not just x.r8.im

Implements DP-682 to support registry migration testing for internal teams.

Changes:
- Add COG_REGISTRY_HOST environment variable support for persistent registry override
- Add --registry global persistent flag (hidden) for one-off overrides
- Implement credential fallback: when alternate registry has no credentials, automatically reuse r8.im credentials
- Update API client to dynamically load registry authentication
- Update login messages to show actual registry host being authenticated

Configuration priority:
1. --registry flag (highest - one-off overrides)
2. COG_REGISTRY_HOST env var (session/testing)
3. Default "r8.im" (lowest - production)

This enables internal testing workflows like:
  export COG_REGISTRY_HOST=registry.r8.im
  cog login
  cog push registry.r8.im/user/model

With credential fallback, existing r8.im credentials are automatically
reused for alternate registries, showing: "Using existing r8.im credentials for <host>"
@markphelps markphelps requested review from 8W9aG, michaeldwan and tempusfrangit and removed request for 8W9aG September 30, 2025 18:56
Copy link
Member

@tempusfrangit tempusfrangit left a comment

Choose a reason for hiding this comment

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

I don't see anything fundamentally wrong here but I'll be honest, I'm having a hard time following the some parts of the change, e.g. where some of the logging/defaults may have gone.

Can we add a test to show previous behavior[s] in absence of a config is maintained? It would make me feel a lot better about this change.

- Restore "you may need to authenticate using cog login" message in api_client.go
- Add comprehensive tests for credential fallback behavior in credentials_test.go
- Tests verify:
  - Direct credentials are used when available
  - Fallback to default registry credentials for alternate registries
  - No fallback occurs when requesting default registry
  - Direct credentials preferred over fallback
  - Proper error handling when no credentials available
Move ctx parameter to first position in tryLoadAuthForHost function signature
to follow Go convention (ctx should always be the first argument).
@markphelps markphelps merged commit 171b1d5 into main Oct 2, 2025
26 checks passed
@markphelps markphelps deleted the dp-682-implement-registry-migration-support-in-cog-credential branch October 2, 2025 00:14
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.

4 participants