Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: orgadm locate project & register missing credential abort #56

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions cmd/orgadm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions cmd/register/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down