Make default cluster jurisdiction-aware · Entire
Make default cluster jurisdiction-aware
6f7d464→main
is_default is per-jurisdiction (each of au/eu/us has its own default), so the single hardcoded "first default" was wrong. Resolve the caller's jurisdiction from /me and:
- one-shot
repo mirror create <url>(no cluster-host): pick the is_default cluster for that jurisdiction; - wizard: still list every cluster (so you can mirror into any), but pre-select only your jurisdiction's default instead of all three.
Errors asking for an explicit [cluster-host] when the jurisdiction is unknown or has no default. Surfaces the jurisdiction in the wizard's "Signed in as" line.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
Sessions
a03b61382aa9View transcript
Changes
5
cmd/entire/cli
Mauth.go+4
Mrepo_mirror.go+43/-15
Mrepo_mirror_create_wizard.go+30/-19
Mrepo_mirror_create_wizard_test.go+10/-3
Mrepo_mirror_test.go+31/-13
Cluster Choices
func clusterChoices(regions []regionChoice) (opts []huh.Option[string], defaults []string) {
opts = make([]huh.Option[string], 0, len(regions))
for _, r := range regions {
opts = append(opts, huh.NewOption(regionLabel(r), r.host))
if r.isDefault {
defaults = append(defaults, r.host)
}
}
return opts, defaults
}
Pick Default Region Host
func pickDefaultRegionHost(regions []regionChoice, jurisdiction string) (string, error) {
if len(regions) == 0 {
return "", errors.New("no clusters available to mirror into; pass [cluster-host] explicitly")
}
for _, r := range regions {
if r.isDefault && r.jurisdiction == jurisdiction {
return r.host, nil
}
}
return "", fmt.Errorf("no default cluster for your jurisdiction (%s); pass [cluster-host] explicitly", jurisdiction)
}
Tests
func TestClusterChoices(t *testing.T) {
t.Parallel()
regions := []regionChoice{
{slug: "us-east", jurisdiction: "us", host: "aws-us-east-2.entire.io", isDefault: true},
{slug: "eu-west", jurisdiction: "eu", host: "eu-west-1.entire.io", isDefault: true},
}
opts, defaults := clusterChoices(regions)
require.Len(t, opts, 2)
require.Equal(t, []string{"aws-us-east-2.entire.io", "eu-west-1.entire.io"}, defaults)
}
func TestPickDefaultRegionHost(t *testing.T) {
t.Parallel()
host, err := pickDefaultRegionHost([]regionChoice{
{host: "eu-west-1.entire.io"},
{host: "aws-us-east-2.entire.io", isDefault: true},
}, "eu")
require.NoError(t, err)
require.Equal(t, "aws-us-east-2.entire.io", host)
}