Skip to content

Commit

Permalink
Merge branch 'develop' into merged-apps
Browse files Browse the repository at this point in the history
  • Loading branch information
0pcom committed Feb 10, 2024
2 parents ace0494 + 945f786 commit 7ab4956
Showing 1 changed file with 69 additions and 47 deletions.
116 changes: 69 additions & 47 deletions cmd/skywire-cli/commands/config/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ var genConfigCmd = &cobra.Command{
if isUsrEnv {
isHypervisor = true
}
//use test deployment
if isTestEnv {
serviceConfURL = utilenv.TestServiceConfAddr
}
var err error
if isDmsgHTTP {
if isPkgEnv {
Expand Down Expand Up @@ -372,13 +376,33 @@ var genConfigCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {

log := logger
wasStdout := isStdout
var body []byte
var err error
// enable errors from service conf fetch from the combination of these flags
if isStdout && isHide {
isStdout = false
}

if !noFetch {
wasStdout := isStdout
var body []byte
var err error

if configServicePath != "" {
// create an http client to fetch the services
client := http.Client{
Timeout: time.Second * 15, // Timeout after 15 seconds
}
if serviceConfURL == "" {
serviceConfURL = utilenv.ServiceConfAddr
}
if !isStdout {
log.Infof("Fetching service endpoints from %s", serviceConfURL)
}
// Make the HTTP GET request
res, err := client.Get(fmt.Sprint(serviceConfURL))
if err != nil {
//silence errors for stdout
if !isStdout {
log.WithError(err).Error("Failed to fetch servers\n")
log.Warn("Falling back on services-config.json")
}
body, err = os.ReadFile(configServicePath)
if err != nil {
if !isStdout {
Expand All @@ -389,67 +413,65 @@ var genConfigCmd = &cobra.Command{
//fill in services struct with the response
err = json.Unmarshal(body, &servicesConfig)
if err != nil {
log.WithError(err).Fatal("Failed to unmarshal json response\n")
}
if !isStdout {
log.Infof("Fetched service endpoints from '%s'", serviceConfURL)
}
services = servicesConfig.Prod
if isTestEnv {
services = servicesConfig.Test
if !isStdout {
log.WithError(err).Error("Failed to unmarshal services-config.json file\n")
}
} else {
services = servicesConfig.Prod
if isTestEnv {
services = servicesConfig.Test
}
}
// reset the state of isStdout
isStdout = wasStdout

}
} else {
// set default service conf url if none is specified
if serviceConfURL == "" {
serviceConfURL = utilenv.ServiceConfAddr
}
//use test deployment
if isTestEnv {
serviceConfURL = utilenv.TestServiceConfAddr
}
// enable errors from service conf fetch from the combination of these flags

if isStdout && isHide {
isStdout = false
//nil error on service conf fetch
if res.Body != nil {
defer res.Body.Close() //nolint
}
// create an http client to fetch the services
client := http.Client{
Timeout: time.Second * 15, // Timeout after 15 seconds
body, err = io.ReadAll(res.Body)
if err != nil {
log.WithError(err).Error("Failed to read http response\n")
}
// Make the HTTP GET request
res, err := client.Get(fmt.Sprint(serviceConfURL))
//fill in services struct with the response
err = json.Unmarshal(body, &services)
if err != nil {
//silence errors for stdout
if !isStdout {
log.WithError(err).Error("Failed to fetch servers\n")
log.WithError(err).Error("Failed to unmarshal json response to services struct\n")
log.Warn("Falling back on hardcoded servers")
}
} else {
if res.Body != nil {
defer res.Body.Close() //nolint
}
body, err = io.ReadAll(res.Body)
if err != nil {
log.WithError(err).Fatal("Failed to read response\n")
if !isStdout {
log.Infof("Fetched service endpoints from '%s'", serviceConfURL)
}
}
}
} else {
body, err = os.ReadFile(configServicePath)
if err != nil {
if !isStdout {
log.WithError(err).Error("Failed to read config service from file\n")
log.Warn("Falling back on hardcoded servers")
}
} else {
//fill in services struct with the response
err = json.Unmarshal(body, &services)
err = json.Unmarshal(body, &servicesConfig)
if err != nil {
log.WithError(err).Fatal("Failed to unmarshal json response\n")
if !isStdout {
log.WithError(err).Error("Failed to unmarshal json response to services struct\n")
log.Warn("Falling back on hardcoded servers")
}
}
if !isStdout {
log.Infof("Fetched service endpoints from '%s'", serviceConfURL)
services = servicesConfig.Prod
if isTestEnv {
services = servicesConfig.Test
}

// reset the state of isStdout
isStdout = wasStdout
}

}

// reset the state of isStdout
isStdout = wasStdout
// Read in old config and obtain old secret key or generate a new random secret key
// and obtain old hypervisors (if any)
var oldConf visorconfig.V1
Expand Down

0 comments on commit 7ab4956

Please sign in to comment.