From b9bb986b8a24ebb9607f63f3954511cb66b47888 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Sat, 23 Mar 2019 23:53:03 +0200 Subject: [PATCH] storj-sim network env (#1560) * add storj-sim environment flags * don't try to connect to console --- cmd/storj-sim/main.go | 8 ++++++++ cmd/storj-sim/network.go | 29 ++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/cmd/storj-sim/main.go b/cmd/storj-sim/main.go index a51992758..4b5bded9b 100644 --- a/cmd/storj-sim/main.go +++ b/cmd/storj-sim/main.go @@ -21,6 +21,8 @@ type Flags struct { Identities int IsDev bool + + OnlyEnv bool // only do things necessary for loading env vars } var printCommands bool @@ -63,6 +65,12 @@ func main() { RunE: func(cmd *cobra.Command, args []string) (err error) { return networkExec(&flags, args, "run") }, + }, &cobra.Command{ + Use: "env", + Short: "print environment variables", + RunE: func(cmd *cobra.Command, args []string) (err error) { + return networkEnv(&flags, args) + }, }, &cobra.Command{ Use: "setup", Short: "setup network", diff --git a/cmd/storj-sim/network.go b/cmd/storj-sim/network.go index 9726f8213..075b3c906 100644 --- a/cmd/storj-sim/network.go +++ b/cmd/storj-sim/network.go @@ -54,6 +54,29 @@ func networkExec(flags *Flags, args []string, command string) error { return errs.Combine(err, closeErr) } +func networkEnv(flags *Flags, args []string) error { + flags.OnlyEnv = true + processes, err := newNetwork(flags) + if err != nil { + return err + } + + // run exec before, since it will load env vars from configs + for _, process := range processes.List { + if exec := process.ExecBefore["run"]; exec != nil { + if err := exec(process); err != nil { + return err + } + } + } + + for _, env := range processes.Env() { + fmt.Println(env) + } + + return nil +} + func networkTest(flags *Flags, command string, args []string) error { processes, err := newNetwork(flags) if err != nil { @@ -255,7 +278,7 @@ func newNetwork(flags *Flags) (*Processes, error) { // create example project with key and add it to the config // so that gateway can have access to the satellite apiKey := vip.GetString("api-key") - if apiKey == "" { + if !flags.OnlyEnv && apiKey == "" { var consoleAddress string satelliteConfigErr := readConfigString(&consoleAddress, satellite.Directory, "console.address") if satelliteConfigErr != nil { @@ -281,6 +304,10 @@ func newNetwork(flags *Flags) (*Processes, error) { } } + if apiKey != "" { + process.Extra = append(process.Extra, "API_KEY="+apiKey) + } + accessKey := vip.GetString("minio.access-key") secretKey := vip.GetString("minio.secret-key")