fix(controlplane): name a migrated connection for its host
The seeded root connection was called "Instance forge", which names two archie concepts an operator never chose. Name it for the host it points at instead.
This commit is contained in:
3 files changed
+20
-1
No files matched your search
@@ -3,6 +3,7 @@ package controlplane
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"net/url"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
@@ -41,7 +42,7 @@ func forgeConnectionsDefinition() Definition {
|
||||
// and is filled by a verification.
|
||||
func seedForgeConnections(cfg config.Config) any {
|
||||
out := []config.ForgeConnection{}
|
||||
if c, ok := connectionFromForge(rootConnectionID, "Instance forge", cfg.Forge); ok {
|
||||
if c, ok := connectionFromForge(rootConnectionID, connectionDisplayName(cfg.Forge), cfg.Forge); ok {
|
||||
// Root tasks act as the instance, not as an organisation execution
|
||||
// identity, so they take this connection without a permit entry. An
|
||||
// execution identity needs one, and the file granted it none.
|
||||
@@ -60,6 +61,21 @@ func seedForgeConnections(cfg config.Config) any {
|
||||
return out
|
||||
}
|
||||
|
||||
// connectionDisplayName is the label an operator sees, so it names the thing
|
||||
// that tells one connection from another -- the host it points at -- rather
|
||||
// than the archie concept it was migrated from. The file never named the
|
||||
// forge, so there is nothing better to carry over.
|
||||
func connectionDisplayName(cfg config.Forge) string {
|
||||
host := strings.TrimSpace(cfg.Host)
|
||||
if u, err := url.Parse(host); err == nil && u.Hostname() != "" {
|
||||
host = u.Hostname()
|
||||
}
|
||||
if host != "" {
|
||||
return host
|
||||
}
|
||||
return strings.TrimSpace(cfg.Type)
|
||||
}
|
||||
|
||||
// connectionFromForge reads one file forge section as a connection. A forge
|
||||
// with no type is not configured and seeds nothing.
|
||||
func connectionFromForge(id, name string, cfg config.Forge) (config.ForgeConnection, bool) {
|
||||
|
||||
@@ -112,6 +112,9 @@ func TestConnectionMigrationKeepsTheFilesGrants(t *testing.T) {
|
||||
if root.ID != rootConnectionID || len(root.Permits) != 0 {
|
||||
t.Fatalf("root connection = %+v, want the root's forge and no permitted execution identity", root)
|
||||
}
|
||||
if root.Name != "github.com" {
|
||||
t.Fatalf("root connection name = %q, want the host an operator recognises, not an internal label", root.Name)
|
||||
}
|
||||
if root.Token.Key != "ROOT_TOKEN" {
|
||||
t.Fatalf("root connection credential = %+v, want the file's reference", root.Token)
|
||||
}
|
||||
|
||||
File renamed without changes.
Reference in new issue
Block a user