Skip to content
Merged
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
40 changes: 23 additions & 17 deletions cmd/register/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,23 @@ var (
// Replaced by the linker with the current version at build time.
Version = "0.0.0"

endpoint = flag.String("endpoint", defaultRegisterJWTEndpoint, "Endpoint of the autojoin service")
tkEndpoint = flag.String("token-endpoint", defaultTokenEndpoint, "Token-exchange endpoint")
apiKey = flag.String("key", "", "API key for the autojoin service")
service = flag.String("service", "ndt", "Service name to register with the autojoin service")
iata = flagx.StringFile{}
ipv4 = flagx.StringFile{}
ipv6 = flagx.StringFile{}
machineType = flag.String("type", "", "The type of machine: physical or virtual")
uplink = flag.String("uplink", "", "The speed of the uplink e.g., 1g, 10g, etc.")
interval = flag.Duration("interval.expected", 1*time.Hour, "Expected registration interval")
intervalMin = flag.Duration("interval.min", 55*time.Minute, "Minimum registration interval")
intervalMax = flag.Duration("interval.max", 65*time.Minute, "Maximum registration interval")
outputPath = flag.String("output", "", "Output folder")
siteProb = flagx.StringFile{}
defaultProb = 1.0
ports = flagx.StringArray{}
endpoint = flag.String("endpoint", defaultRegisterJWTEndpoint, "Endpoint of the autojoin service")
tkEndpoint = flag.String("token-endpoint", defaultTokenEndpoint, "Token-exchange endpoint")
apiKey = flag.String("key", "", "API key for the autojoin service")
service = flag.String("service", "ndt", "Service name to register with the autojoin service")
iata = flagx.StringFile{}
ipv4 = flagx.StringFile{}
ipv6 = flagx.StringFile{}
machineType = flag.String("type", "", "The type of machine: physical or virtual")
uplink = flag.String("uplink", "", "The speed of the uplink e.g., 1g, 10g, etc.")
interval = flag.Duration("interval.expected", 1*time.Hour, "Expected registration interval")
intervalMin = flag.Duration("interval.min", 55*time.Minute, "Minimum registration interval")
intervalMax = flag.Duration("interval.max", 65*time.Minute, "Maximum registration interval")
outputPath = flag.String("output", "", "Output directory for public files (default: current directory)")
outputSecurePath = flag.String("output-secure", "", "Output directory for credentials (default: use '-output' value)")
siteProb = flagx.StringFile{}
defaultProb = 1.0
ports = flagx.StringArray{}

hcAddr = flag.String("healthcheck-addr", "localhost:8001", "Address to serve the /ready endpoint on")
registerSuccess atomic.Bool
Expand Down Expand Up @@ -170,6 +171,7 @@ func register() {
os.Exit(1)
}

// TODO(bassosimone): `json.Unmarshal` can fail.
Comment thread
robertodauria marked this conversation as resolved.
var r v0.RegisterResponse
json.Unmarshal(body, &r)
if r.Error != nil {
Expand Down Expand Up @@ -201,9 +203,13 @@ func register() {
if r.Registration.Credentials == nil {
log.Fatalf("Registration credentials are nil:\n%s", body)
}
actualSecPath := *outputSecurePath
if actualSecPath == "" {
actualSecPath = *outputPath // keep backward compatibility
}
key, err := base64.StdEncoding.DecodeString(r.Registration.Credentials.ServiceAccountKey)
rtx.Must(err, "Failed to base64-decode the service-account credentials string")
serviceAccountFilePath := path.Join(*outputPath, serviceAccountFilename)
serviceAccountFilePath := path.Join(actualSecPath, serviceAccountFilename)
rtx.Must(
os.WriteFile(serviceAccountFilePath, key, 0600),
"Failed to write the service-account-key file",
Expand Down
Loading