Skip to content

Commit

Permalink
netdeploy: Add AdminAPIToken to network templates (#5473)
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy authored Jun 22, 2023
1 parent 227df93 commit 7a282c8
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 195 deletions.
1 change: 1 addition & 0 deletions netdeploy/remote/buildConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type BuildConfig struct {
APIEndpoint2 string
APIEndpoint3 string
APIEndpoint4 string
AdminAPIToken string
APIToken string
EnableTelemetry bool
TelemetryURI string
Expand Down
1 change: 1 addition & 0 deletions netdeploy/remote/deployedNetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func replaceTokens(original string, buildConfig BuildConfig) (expanded string, e
tokenPairs = append(tokenPairs, "{{APIEndpoint3}}", buildConfig.APIEndpoint3)
tokenPairs = append(tokenPairs, "{{APIEndpoint4}}", buildConfig.APIEndpoint4)
tokenPairs = append(tokenPairs, "{{APIToken}}", buildConfig.APIToken)
tokenPairs = append(tokenPairs, "{{AdminAPIToken}}", buildConfig.AdminAPIToken)
tokenPairs = append(tokenPairs, "{{EnableTelemetry}}", strconv.FormatBool(buildConfig.EnableTelemetry))
tokenPairs = append(tokenPairs, "{{TelemetryURI}}", buildConfig.TelemetryURI)
tokenPairs = append(tokenPairs, "{{MetricsURI}}", buildConfig.MetricsURI)
Expand Down
1 change: 1 addition & 0 deletions netdeploy/remote/nodeConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type NodeConfig struct {
NetAddress string `json:",omitempty"`
APIEndpoint string `json:",omitempty"`
APIToken string `json:",omitempty"`
AdminAPIToken string `json:",omitempty"`
EnableTelemetry bool // Needs to also be configured host-wide (assign logging host name)
TelemetryURI string `json:",omitempty"` // Needs to be HostConfig
EnableMetrics bool // Needs to also be configured host-wide (register DNS entry)
Expand Down
19 changes: 19 additions & 0 deletions netdeploy/remote/nodecfg/nodeDir.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (nd *nodeDir) configure() (err error) {
fmt.Fprintf(os.Stdout, "Error during configureAPIToken: %s\n", err)
return
}
if err = nd.configureAdminAPIToken(nd.AdminAPIToken); err != nil {
fmt.Fprintf(os.Stdout, "Error during configureAdminAPIToken: %s\n", err)
return
}
if err = nd.configureTelemetry(nd.EnableTelemetry); err != nil {
fmt.Fprintf(os.Stdout, "Error during configureTelemetry: %s\n", err)
return
Expand Down Expand Up @@ -181,6 +185,21 @@ func (nd *nodeDir) configureAPIToken(token string) (err error) {
return nd.saveConfig()
}

func (nd *nodeDir) configureAdminAPIToken(token string) (err error) {
if token == "" {
return
}
if err = nd.ensureConfig(); err != nil {
return
}
fmt.Fprintf(os.Stdout, " - Assigning AdminAPIToken: %s\n", token)
err = os.WriteFile(filepath.Join(nd.dataDir, tokens.AlgodAdminTokenFilename), []byte(token), 0600)
if err != nil {
return err
}
return nd.saveConfig()
}

func (nd *nodeDir) configureTelemetry(enable bool) (err error) {
cfg, created, cfgErr := logging.EnsureTelemetryConfigCreated(nil, "")
if cfgErr != nil {
Expand Down
1 change: 1 addition & 0 deletions test/testdata/deployednettemplates/configs/reference.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"APIEndpoint3": ":8582",
"APIEndpoint4": ":8583",
"APIToken": "19b3fa5fd63074f3ec7d7052f417c423986472d253eaf275704cbc07adfe64ff",
"AdminAPIToken": "19b3fa5fd63074f3ec7d7052f417c423986472d253eaf275704cbc07adfe64ff",
"EnableTelemetry": true,
"TelemetryURI": "telemetry.<network>.algodev.network:9105",
"MetricsURI": "<network>.algodev.network:9106",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"APIEndpoint3": ":8582",
"APIEndpoint4": ":8583",
"APIToken": "19b3fa5fd63074f3ec7d7052f417c423986472d253eaf275704cbc07adfe64ff",
"AdminAPIToken": "19b3fa5fd63074f3ec7d7052f417c423986472d253eaf275704cbc07adfe64ff",
"EnableTelemetry": true,
"TelemetryURI": "telemetry.<network>.algodev.network:9105",
"MetricsURI": "<network>.algodev.network:9106",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"APIEndpoint": "{{APIEndpoint}}",
"APIToken": "{{APIToken}}",
"AdminAPIToken": "{{AdminAPIToken}}",
"EnableBlockStats": false,
"EnableTelemetry": false,
"TelemetryURI": "{{TelemetryURI}}",
Expand All @@ -11,6 +12,7 @@
{
"APIEndpoint": "{{APIEndpoint}}",
"APIToken": "{{APIToken}}",
"AdminAPIToken": "{{AdminAPIToken}}",
"EnableBlockStats": true,
"EnableTelemetry": true,
"TelemetryURI": "{{TelemetryURI}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"NetAddress": "{{NetworkPort}}",
"APIEndpoint": "{{APIEndpoint}}",
"APIToken": "{{APIToken}}",
"AdminAPIToken": "{{AdminAPIToken}}",
"EnableBlockStats": true,
"EnableTelemetry": true,
"TelemetryURI": "{{TelemetryURI}}",
"EnableMetrics": true,
"MetricsURI": "{{MetricsURI}}",
"ConfigJSONOverride": "{ \"TxPoolExponentialIncreaseFactor\": 1, \"DNSBootstrapID\": \"<network>.algodev.network\", \"DeadlockDetection\": -1, \"EnableIncomingMessageFilter\": true, \"EnableRuntimeMetrics\": true, \"CadaverSizeTarget\": 0, \"PeerPingPeriodSeconds\": 30, \"EnableAgreementReporting\": true, \"EnableAgreementTimeMetrics\": true, \"EnableAssembleStats\": true, \"EnableProcessBlockStats\": true, \"BaseLoggerDebugLevel\": 4, \"EnableProfiler\": true }"
"ConfigJSONOverride": "{ \"TxPoolExponentialIncreaseFactor\": 1, \"DNSBootstrapID\": \"<network>.algodev.network\", \"DeadlockDetection\": -1, \"EnableRuntimeMetrics\": true, \"CadaverSizeTarget\": 0, \"PeerPingPeriodSeconds\": 30, \"EnableAgreementReporting\": true, \"EnableAgreementTimeMetrics\": true, \"EnableAssembleStats\": true, \"EnableProcessBlockStats\": true, \"BaseLoggerDebugLevel\": 4, \"EnableProfiler\": true }"
}
Loading

0 comments on commit 7a282c8

Please sign in to comment.