Skip to content

Commit

Permalink
Merge pull request #213 from TxnLab/dev
Browse files Browse the repository at this point in the history
v0.9.3
  • Loading branch information
drichar authored Jun 3, 2024
2 parents d7612b0 + 577d84d commit 2567018
Show file tree
Hide file tree
Showing 25 changed files with 323 additions and 246 deletions.
2 changes: 1 addition & 1 deletion contracts/bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap",
"version": "0.9.2",
"version": "0.9.3",
"description": "",
"main": "index.ts",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reti-contracts",
"version": "0.9.2",
"version": "0.9.3",
"license": "MIT",
"scripts": {
"generate-client": "algokit generate client contracts/artifacts/ --language typescript --output contracts/clients/{contract_name}Client.ts && ./update_contract_artifacts.sh``",
Expand Down
5 changes: 4 additions & 1 deletion nodemgr/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func initApp() *RetiApp {
if os.Getenv("DEBUG") == "1" {
logLevel.Set(slog.LevelDebug)
}

misc.LoadEnvSettings(logger)

// We initialize our wrapper instance first, so we can call its methods in the 'Before' lambda func
// in initialization of cli App instance.
// signer will be set in the initClients method.
Expand Down Expand Up @@ -160,7 +163,7 @@ func (ac *RetiApp) initClients(ctx context.Context, cmd *cli.Command) error {

// Now load .env.{network} overrides -ie: .env.sandbox containing generated mnemonics
// by bootstrap testing script
misc.LoadEnvForNetwork(network)
misc.LoadEnvForNetwork(ac.logger, network)

// Initialize algod client / networks / reti validator app id (testing connectivity as well)
cfg := algo.GetNetworkConfig(network)
Expand Down
5 changes: 5 additions & 0 deletions nodemgr/internal/lib/algo/networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func GetNetworkConfig(network string) NetworkConfig {
if nodeToken != "" {
cfg.NodeToken = nodeToken
}
// ALGO_ALGOD_ADMIN_TOKEN is what we assume users will use, so it takes precedence for the node token
// (which is required to be an admin token)
if token := misc.GetSecret("ALGO_ALGOD_ADMIN_TOKEN"); token != "" {
cfg.NodeToken = token
}
NodeHeaders := misc.GetSecret("ALGO_ALGOD_HEADERS")
// parse NodeHeaders from key:value,[key:value...] pairs and put into cfg.NodeHeaders map
cfg.NodeHeaders = map[string]string{}
Expand Down
21 changes: 16 additions & 5 deletions nodemgr/internal/lib/misc/env.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
package misc

import (
"errors"
"log/slog"
"os"

"github.com/joho/godotenv"
)

func LoadEnvSettings() {
godotenv.Load(".env.local")
godotenv.Load() // .env
func LoadEnvSettings(log *slog.Logger) {
loadEnvFile(log, ".env.local")
loadEnvFile(log, ".env")
}

func LoadEnvForNetwork(log *slog.Logger, network string) {
loadEnvFile(log, ".env."+network)
}

func LoadEnvForNetwork(network string) {
godotenv.Load(".env." + network)
func loadEnvFile(log *slog.Logger, filename string) {
err := godotenv.Load(filename)
if !errors.Is(err, os.ErrNotExist) {
Warnf(log, "error loading %s, err: %v", filename, err)
}
}
5 changes: 5 additions & 0 deletions nodemgr/internal/lib/misc/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func SecretKeys() []string {
return retStrings
}

// GetSecret retrieves the value of a secret identified by the given key.
// If the secret is found in an environment variable, it returns the value.
// Otherwise, it return the value secretsMap if found.
// This abstraction is just an env abstraction at the moment but could easily
// be changed to fetch secrets other ways if necessary.
func GetSecret(key string) string {
if value := os.Getenv(key); value != "" {
return value
Expand Down
4 changes: 0 additions & 4 deletions nodemgr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ import (
"context"
"log/slog"
"os"

"github.com/TxnLab/reti/internal/lib/misc"
)

var App *RetiApp

func main() {
misc.LoadEnvSettings()

App = initApp()
err := App.cliCmd.Run(context.Background(), os.Args)
if err != nil {
Expand Down
Loading

0 comments on commit 2567018

Please sign in to comment.