storj-sim network env (#1560)

* add storj-sim environment flags

* don't try to connect to console
This commit is contained in:
Egon Elbre 2019-03-23 23:53:03 +02:00 committed by littleskunk
parent dbd97aaaf9
commit b9bb986b8a
2 changed files with 36 additions and 1 deletions

View File

@ -21,6 +21,8 @@ type Flags struct {
Identities int Identities int
IsDev bool IsDev bool
OnlyEnv bool // only do things necessary for loading env vars
} }
var printCommands bool var printCommands bool
@ -63,6 +65,12 @@ func main() {
RunE: func(cmd *cobra.Command, args []string) (err error) { RunE: func(cmd *cobra.Command, args []string) (err error) {
return networkExec(&flags, args, "run") 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{ }, &cobra.Command{
Use: "setup", Use: "setup",
Short: "setup network", Short: "setup network",

View File

@ -54,6 +54,29 @@ func networkExec(flags *Flags, args []string, command string) error {
return errs.Combine(err, closeErr) 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 { func networkTest(flags *Flags, command string, args []string) error {
processes, err := newNetwork(flags) processes, err := newNetwork(flags)
if err != nil { if err != nil {
@ -255,7 +278,7 @@ func newNetwork(flags *Flags) (*Processes, error) {
// create example project with key and add it to the config // create example project with key and add it to the config
// so that gateway can have access to the satellite // so that gateway can have access to the satellite
apiKey := vip.GetString("api-key") apiKey := vip.GetString("api-key")
if apiKey == "" { if !flags.OnlyEnv && apiKey == "" {
var consoleAddress string var consoleAddress string
satelliteConfigErr := readConfigString(&consoleAddress, satellite.Directory, "console.address") satelliteConfigErr := readConfigString(&consoleAddress, satellite.Directory, "console.address")
if satelliteConfigErr != nil { 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") accessKey := vip.GetString("minio.access-key")
secretKey := vip.GetString("minio.secret-key") secretKey := vip.GetString("minio.secret-key")