Skip to content

Commit

Permalink
fix config not found bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfa committed Nov 20, 2022
1 parent 0f0cd80 commit 5fab397
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
13 changes: 4 additions & 9 deletions pkg/paas/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io"
"log"
"regexp"
"strconv"

Expand Down Expand Up @@ -43,10 +42,8 @@ func NewCmdLogin(in io.Reader, out, errout io.Writer) *cobra.Command {
utl.CheckErr(err)
apiKey := getApiKey(in, explainOut)

_, err = config.LoadConfigFile()
if err != nil {
log.Println(err)
}
_, _ = config.LoadConfigFile()

arvanConfig := config.GetConfigInfo()

arvanConfig.Initiate(apiKey, *region)
Expand Down Expand Up @@ -84,10 +81,8 @@ func NewCmdSwitchRegion(in io.Reader, out, errout io.Writer) *cobra.Command {
region, err := getSelectedRegion(in, explainOut)
utl.CheckErr(err)

_, err = config.LoadConfigFile()
if err != nil {
log.Println(err)
}
_, _ = config.LoadConfigFile()

arvanConfig := config.GetConfigInfo()

arvanConfig.Initiate(arvanConfig.GetApiKey(), *region)
Expand Down
27 changes: 12 additions & 15 deletions pkg/paas/paas.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,12 @@ func prepareConfigSwtichRegion(cmd *cobra.Command) error {
}

func prepareCommand(cmd *cobra.Command) error {
err := UpgradeConfigFile()
if err != nil {
return err
}
_ = UpgradeConfigFile()

arvanConfig := config.GetConfigInfo()
kubeConfigPath := paasConfigPath()

err = setConfigFlag(cmd, kubeConfigPath)
err := setConfigFlag(cmd, kubeConfigPath)
if err != nil {
return err
}
Expand All @@ -194,12 +191,12 @@ func UpgradeConfigFile() error {
if err != nil {
return err
}
if strings.Contains(configFileStruct.Clusters[0].Cluster.Server, "arvancloud.com") {
configFileStruct.Clusters[0].Cluster.Server = strings.Replace(configFileStruct.Clusters[0].Cluster.Server, "arvancloud.com", "arvancloud.ir", -1)
}

configFileStruct.Clusters[0].Cluster.Server = strings.Replace(configFileStruct.Clusters[0].Cluster.Server, "arvancloud.com", "arvancloud.ir", -1)

err = writeKubeConfig(configFileStruct, path)
if err != nil {
return err
return err
}

return nil
Expand Down Expand Up @@ -261,7 +258,7 @@ func whoAmI() (string, int, error) {
return "", httpResp.StatusCode, err
}
if kind != "User" {
return "", httpResp.StatusCode, errors.New("User kind not supported")
return "", httpResp.StatusCode, errors.New("user kind not supported")
}
var metadata map[string]*json.RawMessage
err = json.Unmarshal(*objmap["metadata"], &metadata)
Expand All @@ -278,7 +275,7 @@ func whoAmI() (string, int, error) {
}
}

return "", httpResp.StatusCode, errors.New("invalid authentication credentials.")
return "", httpResp.StatusCode, errors.New("invalid authentication credentials")
}

func projectList() ([]string, error) {
Expand Down Expand Up @@ -321,15 +318,15 @@ func projectList() ([]string, error) {
for i := 0; i < len(projects); i++ {
err = json.Unmarshal(*projects[i], &project)
if err != nil || project["metadata"] == nil {
return nil, errors.New("Invalid projects response")
return nil, errors.New("invalid projects response")
}
err = json.Unmarshal(*project["metadata"], &projectMetadata)
if err != nil || projectMetadata["name"] == nil {
return nil, errors.New("Invalid projects response")
return nil, errors.New("invalid projects response")
}
err = json.Unmarshal(*projectMetadata["name"], &projectName)
if err != nil || projectMetadata["name"] == nil {
return nil, errors.New("Invalid projects response")
return nil, errors.New("invalid projects response")
}
result = append(result, projectName)
}
Expand All @@ -338,7 +335,7 @@ func projectList() ([]string, error) {
return nil, nil
}
}
return nil, errors.New("Invalid projects response")
return nil, errors.New("invalid projects response")
}

func getArvanAuthorization() string {
Expand Down

0 comments on commit 5fab397

Please sign in to comment.