diff --git a/Makefile b/Makefile index 7f31eb2d5..d4b5abbc9 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,7 @@ install-sim: ## install storj-sim ## install exact version of storj/gateway mkdir -p .build/gateway-tmp -cd .build/gateway-tmp && go mod init gatewaybuild - cd .build/gateway-tmp && go mod edit -replace github.com/minio/minio=github.com/storj/minio@storj && GO111MODULE=on go get storj.io/gateway@master + cd .build/gateway-tmp && GO111MODULE=on go get storj.io/gateway@latest ##@ Test diff --git a/cmd/storj-sim/network.go b/cmd/storj-sim/network.go index c870740c1..5ef59ee6d 100644 --- a/cmd/storj-sim/network.go +++ b/cmd/storj-sim/network.go @@ -8,7 +8,6 @@ import ( "errors" "fmt" "io/ioutil" - "log" "net" "net/url" "os" @@ -41,6 +40,10 @@ const ( folderPermissions = 0744 ) +var ( + defaultAccess = "17jgVrPRktsquJQFzpT533WHmZnF6QDkuv8w3Ry5XPzAkh3vj7D1dbJ5MatQRiyRE2ZEiA1Y6fYnhoWqr2n7VgycdXSUPz1QzhthBsHqGXCrRcjSp8RbbVE1VJqDej9nLgB5YDPh3Q5JrVjQeMe9saHAL5rE5tUYJAeynVdre8HeTJMXcwau5" +) + const ( // The following values of peer class and endpoints are used // to create a port with a consistent format for storj-sim services. @@ -434,7 +437,6 @@ func newNetwork(flags *Flags) (*Processes, error) { // Create gateways for each satellite for i, satellite := range satellites { - i := i satellite := satellite process := processes.New(Info{ Name: fmt.Sprintf("gateway/%d", i), @@ -446,9 +448,15 @@ func newNetwork(flags *Flags) (*Processes, error) { // gateway must wait for the corresponding satellite to start up process.WaitForStart(satellite) + accessData := defaultAccess + process.Arguments = withCommon(process.Directory, Arguments{ "setup": { + "--non-interactive", + + "--access", accessData, "--server.address", process.Address, + "--debug.addr", net.JoinHostPort(host, port(gatewayPeer, i, debugHTTP)), }, @@ -461,42 +469,65 @@ func newNetwork(flags *Flags) (*Processes, error) { return err } - var consoleAddress string - err = readConfigString(&consoleAddress, satellite.Directory, "console.address") - if err != nil { + vip := viper.New() + vip.AddConfigPath(process.Directory) + if err := vip.ReadInConfig(); err != nil { return err } - // try with 100ms delays until we hit 3s - apiKey, start := "", time.Now() - for apiKey == "" { - apiKey, err = newConsoleEndpoints(consoleAddress).createOrGetAPIKey() - if err != nil && time.Since(start) > 3*time.Second { - log.Printf("Failed retrieving GATEWAY_%d_ACCESS: %s\n", i, err.Error()) - return nil + // TODO: maybe all the config flags should be exposed for all processes? + + // check if gateway config has an api key, if it's not + // create example project with key and add it to the config + // so that gateway can have access to the satellite + if runAccessData := vip.GetString("access"); !flags.OnlyEnv && runAccessData == accessData { + var consoleAddress string + err := readConfigString(&consoleAddress, satellite.Directory, "console.address") + if err != nil { + return err + } + + // try with 100ms delays until we hit 3s + apiKey, start := "", time.Now() + for apiKey == "" { + apiKey, err = newConsoleEndpoints(consoleAddress).createOrGetAPIKey() + if err != nil && time.Since(start) > 3*time.Second { + return err + } + time.Sleep(100 * time.Millisecond) + } + + satNodeID, err := identity.NodeIDFromCertPath(filepath.Join(satellite.Directory, "identity.cert")) + if err != nil { + return err + } + nodeURL := storj.NodeURL{ + ID: satNodeID, + Address: satellite.Address, + } + + access, err := uplink.RequestAccessWithPassphrase(context.Background(), nodeURL.String(), apiKey, "") + if err != nil { + return err + } + + accessData, err := access.Serialize() + if err != nil { + return err + } + vip.Set("access", accessData) + + if err := vip.WriteConfig(); err != nil { + return err } - time.Sleep(100 * time.Millisecond) } - satNodeID, err := identity.NodeIDFromCertPath(filepath.Join(satellite.Directory, "identity.cert")) - if err != nil { - return err - } - nodeURL := storj.NodeURL{ - ID: satNodeID, - Address: satellite.Address, + if runAccessData := vip.GetString("access"); runAccessData != accessData { + process.AddExtra("ACCESS", runAccessData) } - access, err := uplink.RequestAccessWithPassphrase(context.Background(), nodeURL.String(), apiKey, "") - if err != nil { - return err - } - - accessData, err := access.Serialize() - if err != nil { - return err - } - process.AddExtra("ACCESS", accessData) + process.AddExtra("ACCESS_KEY", vip.GetString("minio.access-key")) + process.AddExtra("SECRET_KEY", vip.GetString("minio.secret-key")) return nil } diff --git a/scripts/tests/rollingupgrade/test-sim-rolling-upgrade.sh b/scripts/tests/rollingupgrade/test-sim-rolling-upgrade.sh index f880bacb4..f30b2d81b 100755 --- a/scripts/tests/rollingupgrade/test-sim-rolling-upgrade.sh +++ b/scripts/tests/rollingupgrade/test-sim-rolling-upgrade.sh @@ -117,7 +117,7 @@ install_sim(){ rm -rf .build/gateway-tmp mkdir -p .build/gateway-tmp pushd .build/gateway-tmp - go mod init gatewaybuild && go mod edit -replace github.com/minio/minio=github.com/storj/minio@storj && GOBIN=${bin_dir} GO111MODULE=on go get storj.io/gateway@master + go mod init gatewaybuild && GOBIN=${bin_dir} GO111MODULE=on go get storj.io/gateway@latest popd fi }