From 2551ba92173b175e13f2c32153eb82bd0d639809 Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Wed, 20 Nov 2024 13:00:06 -0500 Subject: [PATCH 1/2] Add flag for locate project, pass correct project for APIKeys --- cmd/orgadm/main.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/orgadm/main.go b/cmd/orgadm/main.go index 7de2dc2..06afa2f 100644 --- a/cmd/orgadm/main.go +++ b/cmd/orgadm/main.go @@ -21,14 +21,16 @@ import ( ) var ( - org string - project string - updateTables bool + org string + project string + locateProject string + updateTables bool ) func init() { flag.StringVar(&org, "org", "", "Organization name. Must match name assigned by M-Lab") flag.StringVar(&project, "project", "", "GCP project to create organization resources") + flag.StringVar(&locateProject, "locate-project", "", "GCP project for Locate API") flag.BoolVar(&updateTables, "update-tables", false, "Allow this org's service account to update table schemas") } @@ -57,7 +59,11 @@ func main() { d := dnsx.NewManager(dnsiface.NewCloudDNSService(ds), project, dnsname.ProjectZone(project)) ac, err := apikeys.NewClient(ctx) rtx.Must(err, "failed to create new apikey client") - k := adminx.NewAPIKeys(project, keysiface.NewKeys(ac), nn) + if project == "mlab-autojoin" && locateProject == "" { + locateProject = "mlab-ns" + } + // Local project names are taken from the namer. + k := adminx.NewAPIKeys(locateProject, keysiface.NewKeys(ac), nn) defer ac.Close() o := adminx.NewOrg(project, crmiface.NewCRM(project, crm), sa, sm, d, k, updateTables) From 06b05ad4680dc2fe5bed627f11522c592815d391 Mon Sep 17 00:00:00 2001 From: Stephen Soltesz Date: Wed, 20 Nov 2024 13:00:27 -0500 Subject: [PATCH 2/2] Fail if credentials are missing --- cmd/register/main.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/register/main.go b/cmd/register/main.go index 794a63b..4abbfb8 100644 --- a/cmd/register/main.go +++ b/cmd/register/main.go @@ -149,14 +149,14 @@ func register() { err = os.WriteFile(path.Join(*outputPath, annotationFilename), annotationJSON, 0644) rtx.Must(err, "Failed to write annotation file") - // Service account credentials. - if r.Registration.Credentials != nil { - // TODO(soltesz): abort on nil after deployment. - key, err := base64.StdEncoding.DecodeString(r.Registration.Credentials.ServiceAccountKey) - rtx.Must(err, "Failed to decode service account key") - err = os.WriteFile(path.Join(*outputPath, serviceAccountFilename), key, 0644) - rtx.Must(err, "Failed to write annotation file") + if r.Registration.Credentials == nil { + log.Fatalf("Registration credentials are nil:\n%s", body) } + // Service account credentials. + key, err := base64.StdEncoding.DecodeString(r.Registration.Credentials.ServiceAccountKey) + rtx.Must(err, "Failed to decode service account key") + err = os.WriteFile(path.Join(*outputPath, serviceAccountFilename), key, 0644) + rtx.Must(err, "Failed to write annotation file") log.Printf("Registration successful with hostname: %s", r.Registration.Hostname) registerSuccess.Store(true)