Skip to content

Commit

Permalink
Fixes server version issue
Browse files Browse the repository at this point in the history
Signed-off-by: nagesh bansal <[email protected]>
  • Loading branch information
Nageshbansal committed Feb 7, 2024
1 parent 3bac6d7 commit 08e66d8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 52 deletions.
33 changes: 0 additions & 33 deletions pkg/apis/experiment/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,36 +346,3 @@ func DeleteChaosExperiment(projectID string, experimentID *string, cred types.Cr
return DeleteChaosExperimentData{}, errors.New("Error while deleting the Chaos Experiment")
}
}

// GetServerVersion fetches the GQL server version
func GetServerVersion(endpoint string) (ServerVersionResponse, error) {
query := `{"query":"query{\n getServerVersion{\n key value\n }\n}"}`
resp, err := apis.SendRequest(
apis.SendRequestParams{
Endpoint: endpoint + utils.GQLAPIPath,
},
[]byte(query),
string(types.Post),
)
if err != nil {
return ServerVersionResponse{}, err
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
return ServerVersionResponse{}, err
}
if resp.StatusCode == http.StatusOK {
var version ServerVersionResponse
err = json.Unmarshal(bodyBytes, &version)
if err != nil {
return ServerVersionResponse{}, err
}
if len(version.Errors) > 0 {
return ServerVersionResponse{}, errors.New(version.Errors[0].Message)
}
return version, nil
} else {
return ServerVersionResponse{}, errors.New(resp.Status)
}
}
17 changes: 0 additions & 17 deletions pkg/apis/experiment/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,3 @@ type DeleteChaosExperimentGraphQLRequest struct {
ExperimentRunID *string `json:"experimentRunID"`
} `json:"variables"`
}

type ServerVersionResponse struct {
Data ServerVersionData `json:"data"`
Errors []struct {
Message string `json:"message"`
Path []string `json:"path"`
} `json:"errors"`
}

type ServerVersionData struct {
GetServerVersion GetServerVersionData `json:"getServerVersion"`
}

type GetServerVersionData struct {
Key string `json:"key"`
Value string `json:"value"`
}
37 changes: 37 additions & 0 deletions pkg/apis/infrastructure/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,40 @@ func DisconnectInfra(projectID string, infraID string, cred types.Credentials) (
return DisconnectInfraData{}, err
}
}

// GetServerVersion fetches the GQL server version
func GetServerVersion(endpoint string) (ServerVersionResponse, error) {

query, err := json.Marshal(ServerVersionQuery)
if err != nil {
return ServerVersionResponse{}, err
}
resp, err := apis.SendRequest(
apis.SendRequestParams{
Endpoint: endpoint + utils.GQLAPIPath,
},
query,
string(types.Post),
)
if err != nil {
return ServerVersionResponse{}, err
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
return ServerVersionResponse{}, err
}
if resp.StatusCode == http.StatusOK {
var version ServerVersionResponse
err = json.Unmarshal(bodyBytes, &version)
if err != nil {
return ServerVersionResponse{}, err
}
if len(version.Errors) > 0 {
return ServerVersionResponse{}, errors.New(version.Errors[0].Message)
}
return version, nil
} else {
return ServerVersionResponse{}, errors.New(resp.Status)
}
}
7 changes: 7 additions & 0 deletions pkg/apis/infrastructure/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ const (
}
}
}`

ServerVersionQuery = `query getServerVersion{
getServerVersion{
key
value
}
}`
)
12 changes: 12 additions & 0 deletions pkg/apis/infrastructure/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,15 @@ type DisconnectInfraGraphQLRequest struct {
InfraID string `json:"infraID"`
} `json:"variables"`
}

type ServerVersionResponse struct {
Data ServerVersionData `json:"data"`
Errors []struct {
Message string `json:"message"`
Path []string `json:"path"`
} `json:"errors"`
}

type ServerVersionData struct {
GetServerVersion models.ServerVersionResponse `json:"getServerVersion"`
}
4 changes: 2 additions & 2 deletions pkg/cmd/config/setAccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"strings"
"time"

"github.com/litmuschaos/litmusctl/pkg/apis/experiment"
infra "github.com/litmuschaos/litmusctl/pkg/apis/infrastructure"

"github.com/golang-jwt/jwt"
"github.com/litmuschaos/litmusctl/pkg/apis"
Expand Down Expand Up @@ -177,7 +177,7 @@ var setAccountCmd = &cobra.Command{
utils.Red.Println("\nError: some flags are missing. Run 'litmusctl config set-account --help' for usage. ")
}

serverResp, err := experiment.GetServerVersion(authInput.Endpoint)
serverResp, err := infra.GetServerVersion(authInput.Endpoint)
var isCompatible bool
if err != nil {
utils.Red.Println("\nError: ", err)
Expand Down

0 comments on commit 08e66d8

Please sign in to comment.