Skip to content

Commit

Permalink
Merge pull request #256 from malinthaprasan/master
Browse files Browse the repository at this point in the history
Cleanup empty production/sandbox URLs
  • Loading branch information
npamudika authored Apr 2, 2020
2 parents cf97275 + a9c91df commit 8d360e8
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions import-export-cli/specs/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ type APIEndpointConfig struct {
EPConfig string `json:"endpointConfig"`
}

// LoadApiParams loads an configuration from a reader. It returns an error or a valid ApiParams
func LoadApiParams(r io.Reader) (*ApiParams, error) {
// loadApiParams loads an configuration from a reader. It returns an error or a valid ApiParams
func loadApiParams(r io.Reader) (*ApiParams, error) {
data, err := ioutil.ReadAll(r)
if err != nil {
return nil, err
Expand All @@ -104,16 +104,32 @@ func LoadApiParams(r io.Reader) (*ApiParams, error) {
return nil, err
}

// Cleanup empty URLs
cleanEmptyEnvironmentURLs(apiParams.Environments)
return apiParams, nil
}

// Remove whole production/sandbox endpoint sections of each environment when corresponding urls are empty
func cleanEmptyEnvironmentURLs (envs []Environment) {
for _, env := range envs {
if env.Endpoints != nil {
if env.Endpoints.Production != nil && env.Endpoints.Production.Url == nil {
env.Endpoints.Production = nil
}
if env.Endpoints.Sandbox != nil && env.Endpoints.Sandbox.Url == nil {
env.Endpoints.Sandbox = nil
}
}
}
}

// LoadApiParamsFromFile loads a configuration YAML file located in path. It returns an error or a valid ApiParams
func LoadApiParamsFromFile(path string) (*ApiParams, error) {
r, err := os.Open(path)
if err != nil {
return nil, err
}
apiConfig, err := LoadApiParams(r)
apiConfig, err := loadApiParams(r)
_ = r.Close()

return apiConfig, err
Expand Down

0 comments on commit 8d360e8

Please sign in to comment.