Skip to content

Commit ea2b541

Browse files
suggestions implemented
Signed-off-by: Kartikay <[email protected]>
1 parent fe822b9 commit ea2b541

File tree

12 files changed

+189
-101
lines changed

12 files changed

+189
-101
lines changed

DEVELOPMENT.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Litmusctl Local Development Setup Guide
2+
3+
## Introduction
4+
5+
Welcome to the local development setup guide for **`litmusctl`**. This guide will walk you through the steps required to set up and run **`litmusctl`** on your local machine.
6+
7+
## Important Note
8+
9+
Before running **`litmusctl`**, make sure you have a Chaos Centre running. Ensure that the Chaos Centre version is compatible with the **`litmusctl`** version you are using.
10+
11+
## Prerequisites
12+
13+
Before you begin, ensure that you have the following prerequisites installed on your machine:
14+
15+
- [Go programming language](https://golang.org/doc/install) (version or later)
16+
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
17+
- Kubeconfig - `litmusctl` needs the kubeconfig of the k8s cluster where we need to connect litmus Chaos Delegates. The CLI currently uses the default path of kubeconfig i.e. `~/.kube/config`.
18+
19+
## Clone the Repository
20+
21+
```bash
22+
git clone https://github.com/litmuschaos/litmusctl.git
23+
24+
cd litmusctl
25+
```
26+
27+
## **Install Dependencies**
28+
29+
```bash
30+
go mod download
31+
```
32+
33+
## **Configuration**
34+
35+
Before running **`litmusctl`**, update the following configuration paths in the **`pkg/utils/constants.go`**
36+
37+
From this
38+
39+
```go
40+
// Graphql server API path
41+
GQLAPIPath = "/api/query"
42+
43+
// Auth server API path
44+
AuthAPIPath = "/auth"
45+
```
46+
47+
To this
48+
49+
```go
50+
// Graphql server API path
51+
GQLAPIPath = "/query"
52+
53+
// Auth server API path
54+
AuthAPIPath = ""
55+
```
56+
57+
## **Running `litmusctl`**
58+
59+
Execute the following command to run **`litmusctl`** locally:
60+
61+
```bash
62+
go run main.go <command> <subcommand> <subcommand> [options and parameters]
63+
```
64+
65+
## **Testing `litmusctl`**
66+
67+
To run tests, use the following command:
68+
69+
```bash
70+
go test ./...
71+
```
72+
73+
## **Contributing Guidelines**
74+
75+
If you wish to contribute to **`litmusctl`**, please follow our [contributing guidelines](https://github.com/litmuschaos/litmus/blob/master/CONTRIBUTING.md). Your contributions are valuable, and adhering to these guidelines ensures a smooth and collaborative development process.
76+
77+
## **Troubleshooting**
78+
79+
If you encounter any issues during setup, refer to our [troubleshooting guide](https://docs.litmuschaos.io/docs/troubleshooting) or reach out to our community for assistance. We're here to help you overcome any obstacles and ensure a successful setup.
80+
81+
## **Additional Information**
82+
83+
For more details on using **`litmusctl`**, refer to our [official documentation](https://docs.litmuschaos.io/). This documentation provides comprehensive information to help you make the most out of **`litmusctl`**.
84+
85+
Thank you for setting up **`litmusctl`** locally! Feel free to explore and contribute to the project. Your involvement is crucial to the success of the **`litmusctl`** community.
86+
87+
Let the chaos begin! 🚀🔥

README.md

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Litmusctl
2+
23
[![BCH compliance](https://bettercodehub.com/edge/badge/litmuschaos/litmusctl?branch=master)](https://bettercodehub.com/)
34
![GitHub Workflow](https://github.com/litmuschaos/litmusctl/actions/workflows/push.yml/badge.svg?branch=master)
45
[![GitHub stars](https://img.shields.io/github/stars/litmuschaos/litmusctl?style=social)](https://github.com/litmuschaos/litmusctl/stargazers)
@@ -7,7 +8,9 @@
78
The Litmuschaos command-line tool, litmusctl, allows you to manage litmuschaos's agent plane. You can use litmusctl to connect Chaos Delegates, create project, schedule Chaos Scenarios, disconnect Chaos Delegates and manage multiple litmuschaos accounts.
89

910
## Usage
11+
1012
For more information including a complete list of litmusctl operations, see the litmusctl reference documentation.
13+
1114
* For 0.23.0 or latest: <a href="https://github.com/litmuschaos/litmusctl/blob/master/Usage_0.23.0.md">Click here</a>
1215
* For v0.12.0 to v0.22.0: <a href="https://github.com/litmuschaos/litmusctl/blob/master/Usage_interactive.md">Click here</a>
1316
* For v0.2.0 or earlier && compatible with Litmus-2.0.0-Beta8 or earlier: <a href="https://github.com/litmuschaos/litmusctl/blob/master/Usage_v0.2.0.md">Click here</a>
@@ -17,8 +20,7 @@ For more information including a complete list of litmusctl operations, see the
1720
The litmusctl CLI requires the following things:
1821

1922
- kubeconfig - litmusctl needs the kubeconfig of the k8s cluster where we need to connect litmus Chaos Delegates. The CLI currently uses the default path of kubeconfig i.e. `~/.kube/config`.
20-
- kubectl- litmusctl is using kubectl under the hood to apply the manifest. To install kubectl, follow: [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)
21-
23+
- kubectl- litmusctl is using kubectl under the hood to apply the manifest. To install kubectl, follow: [kubectl](https://kubernetes.io/docs/tasks/tools/#kubectl)
2224

2325
## Compatibility matrix
2426

@@ -185,44 +187,48 @@ To install the latest version of litmusctl follow the below steps:
185187

186188
### Linux/MacOS
187189

188-
* Extract the binary
190+
- Extract the binary
189191

190192
```shell
191193
tar -zxvf litmusctl-<OS>-<ARCH>-<VERSION>.tar.gz
192194
```
193195

194-
* Provide necessary permissions
196+
- Provide necessary permissions
195197

196198
```shell
197199
chmod +x litmusctl
198200
```
199201

200-
* Move the litmusctl binary to /usr/local/bin/litmusctl. Note: Make sure to use root user or use sudo as a prefix
202+
- Move the litmusctl binary to /usr/local/bin/litmusctl. Note: Make sure to use root user or use sudo as a prefix
201203

202204
```shell
203205
mv litmusctl /usr/local/bin/litmusctl
204206
```
205207

206-
* You can run the litmusctl command in Linux/macOS:
208+
- You can run the litmusctl command in Linux/macOS:
207209

208210
```shell
209211
litmusctl <command> <subcommand> <subcommand> [options and parameters]
210212
```
211213

212214
### Windows
213215

214-
* Extract the binary from the zip using WinZip or any other extraction tool.
216+
- Extract the binary from the zip using WinZip or any other extraction tool.
215217

216-
* You can run the litmusctl command in windows:
218+
- You can run the litmusctl command in windows:
217219

218220
```shell
219221
litmusctl.exe <command> <subcommand> <subcommand> [options and parameters]
220222
```
221223

222-
* To check the version of the litmusctl:
224+
- To check the version of the litmusctl:
223225

224226
```shell
225227
litmusctl version
226228
```
227229

228-
----
230+
## Development Guide
231+
232+
You can find the local setup guide for **`litmusctl`** [here](DEVELOPMENT.md).
233+
234+
---

go.sum

-36
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,10 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
139139
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
140140
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
141141
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
142-
github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=
143-
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
144-
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
145-
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
146142
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
147143
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
148-
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
149-
github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8=
150-
github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs=
151-
github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns=
152144
github.com/go-openapi/jsonreference v0.20.1 h1:FBLnyygC4/IZZr893oiomc9XaghoveYTrLC1F86HID8=
153145
github.com/go-openapi/jsonreference v0.20.1/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
154-
github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
155-
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
156-
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
157-
github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM=
158-
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
159146
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
160147
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
161148
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
@@ -919,36 +906,16 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
919906
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
920907
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
921908
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
922-
k8s.io/api v0.21.2 h1:vz7DqmRsXTCSa6pNxXwQ1IYeAZgdIsua+DZU+o+SX3Y=
923-
k8s.io/api v0.21.2/go.mod h1:Lv6UGJZ1rlMI1qusN8ruAp9PUBFyBwpEHAdG24vIsiU=
924909
k8s.io/api v0.27.3 h1:yR6oQXXnUEBWEWcvPWS0jQL575KoAboQPfJAuKNrw5Y=
925910
k8s.io/api v0.27.3/go.mod h1:C4BNvZnQOF7JA/0Xed2S+aUyJSfTGkGFxLXz9MnpIpg=
926-
k8s.io/apimachinery v0.21.2 h1:vezUc/BHqWlQDnZ+XkrpXSmnANSLbpnlpwo0Lhk0gpc=
927-
k8s.io/apimachinery v0.21.2/go.mod h1:CdTY8fU/BlvAbJ2z/8kBwimGki5Zp8/fbVuLY8gJumM=
928911
k8s.io/apimachinery v0.27.3 h1:Ubye8oBufD04l9QnNtW05idcOe9Z3GQN8+7PqmuVcUM=
929912
k8s.io/apimachinery v0.27.3/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E=
930-
k8s.io/client-go v0.21.2 h1:Q1j4L/iMN4pTw6Y4DWppBoUxgKO8LbffEMVEV00MUp0=
931-
k8s.io/client-go v0.21.2/go.mod h1:HdJ9iknWpbl3vMGtib6T2PyI/VYxiZfq936WNVHBRrA=
932913
k8s.io/client-go v0.27.3 h1:7dnEGHZEJld3lYwxvLl7WoehK6lAq7GvgjxpA3nv1E8=
933914
k8s.io/client-go v0.27.3/go.mod h1:2MBEKuTo6V1lbKy3z1euEGnhPfGZLKTS9tiJ2xodM48=
934-
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
935-
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
936-
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
937-
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
938-
k8s.io/klog/v2 v2.8.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec=
939-
k8s.io/klog/v2 v2.80.1 h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4=
940-
k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
941915
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
942916
k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
943-
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7/go.mod h1:wXW5VT87nVfh/iLV8FpR2uDvrFyomxbtb1KivDbvPTE=
944-
k8s.io/kube-openapi v0.0.0-20220124234850-424119656bbf h1:M9XBsiMslw2lb2ZzglC0TOkBPK5NQi0/noUrdnoFwUg=
945-
k8s.io/kube-openapi v0.0.0-20220124234850-424119656bbf/go.mod h1:sX9MT8g7NVZM5lVL/j8QyCCJe8YSMW30QvGZWaCIDIk=
946917
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f h1:2kWPakN3i/k81b0gvD5C5FJ2kxm1WrQFanWchyKuqGg=
947918
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f/go.mod h1:byini6yhqGC14c3ebc/QwanvYwhuMWF6yz2F8uwW8eg=
948-
k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
949-
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
950-
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d h1:0Smp/HP1OH4Rvhe+4B8nWGERtlqAGSftbSbbmm45oFs=
951-
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
952919
k8s.io/utils v0.0.0-20230209194617-a36077c30491 h1:r0BAOLElQnnFhE/ApUsg3iHdVYYPBjNSSOMowRZxxsY=
953920
k8s.io/utils v0.0.0-20230209194617-a36077c30491/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
954921
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
@@ -958,10 +925,7 @@ sigs.k8s.io/controller-runtime v0.11.1 h1:7YIHT2QnHJArj/dk9aUkYhfqfK5cIxPOX5gPEC
958925
sigs.k8s.io/controller-runtime v0.11.1/go.mod h1:KKwLiTooNGu+JmLZGn9Sl3Gjmfj66eMbCQznLP5zcqA=
959926
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
960927
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
961-
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
962-
sigs.k8s.io/structured-merge-diff/v4 v4.1.0/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
963928
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
964929
sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E=
965-
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
966930
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
967931
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

pkg/apis/environment/environment.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ func CreateEnvironment(pid string, request models.CreateEnvironmentRequest, cred
1919
gqlReq.Variables.ProjectId = pid
2020
gqlReq.Variables.Request = request
2121

22-
query, _ := json.Marshal(gqlReq)
22+
query, err := json.Marshal(gqlReq)
23+
if err != nil {
24+
return CreateEnvironmentResponse{}, errors.New("Error in Creating Chaos Infrastructure: " + err.Error())
25+
}
26+
2327
resp, err := apis.SendRequest(apis.SendRequestParams{Endpoint: cred.ServerEndpoint + utils.GQLAPIPath, Token: cred.Token}, query, string(types.Post))
2428
if err != nil {
2529
return CreateEnvironmentResponse{}, errors.New("Error in Creating Chaos Infrastructure: " + err.Error())

pkg/apis/experiment/experiment.go

-33
Original file line numberDiff line numberDiff line change
@@ -346,36 +346,3 @@ func DeleteChaosExperiment(projectID string, experimentID *string, cred types.Cr
346346
return DeleteChaosExperimentData{}, errors.New("Error while deleting the Chaos Experiment")
347347
}
348348
}
349-
350-
// GetServerVersion fetches the GQL server version
351-
func GetServerVersion(endpoint string) (ServerVersionResponse, error) {
352-
query := `{"query":"query{\n getServerVersion{\n key value\n }\n}"}`
353-
resp, err := apis.SendRequest(
354-
apis.SendRequestParams{
355-
Endpoint: endpoint + utils.GQLAPIPath,
356-
},
357-
[]byte(query),
358-
string(types.Post),
359-
)
360-
if err != nil {
361-
return ServerVersionResponse{}, err
362-
}
363-
bodyBytes, err := io.ReadAll(resp.Body)
364-
defer resp.Body.Close()
365-
if err != nil {
366-
return ServerVersionResponse{}, err
367-
}
368-
if resp.StatusCode == http.StatusOK {
369-
var version ServerVersionResponse
370-
err = json.Unmarshal(bodyBytes, &version)
371-
if err != nil {
372-
return ServerVersionResponse{}, err
373-
}
374-
if len(version.Errors) > 0 {
375-
return ServerVersionResponse{}, errors.New(version.Errors[0].Message)
376-
}
377-
return version, nil
378-
} else {
379-
return ServerVersionResponse{}, errors.New(resp.Status)
380-
}
381-
}

pkg/apis/experiment/types.go

-17
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,3 @@ type DeleteChaosExperimentGraphQLRequest struct {
9494
ExperimentRunID *string `json:"experimentRunID"`
9595
} `json:"variables"`
9696
}
97-
98-
type ServerVersionResponse struct {
99-
Data ServerVersionData `json:"data"`
100-
Errors []struct {
101-
Message string `json:"message"`
102-
Path []string `json:"path"`
103-
} `json:"errors"`
104-
}
105-
106-
type ServerVersionData struct {
107-
GetServerVersion GetServerVersionData `json:"getServerVersion"`
108-
}
109-
110-
type GetServerVersionData struct {
111-
Key string `json:"key"`
112-
Value string `json:"value"`
113-
}

pkg/apis/infrastructure/infra.go

+45-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ func ConnectInfra(infra types.Infra, cred types.Credentials) (InfraConnectionDat
9696
gqlReq.Variables.RegisterInfraRequest.Tolerations = toleration
9797
}
9898

99-
query, _ := json.Marshal(gqlReq)
99+
query, err := json.Marshal(gqlReq)
100+
if err != nil {
101+
return InfraConnectionData{}, errors.New("Error in registering Chaos Infrastructure: " + err.Error())
102+
}
103+
100104
resp, err := apis.SendRequest(apis.SendRequestParams{Endpoint: cred.ServerEndpoint + utils.GQLAPIPath, Token: cred.Token}, query, string(types.Post))
101105
if err != nil {
102106
return InfraConnectionData{}, errors.New("Error in registering Chaos Infrastructure: " + err.Error())
@@ -189,3 +193,43 @@ func DisconnectInfra(projectID string, infraID string, cred types.Credentials) (
189193
return DisconnectInfraData{}, err
190194
}
191195
}
196+
197+
// GetServerVersion fetches the GQL server version
198+
func GetServerVersion(endpoint string) (ServerVersionResponse, error) {
199+
var gqlReq ServerVersionRequest
200+
var err error
201+
202+
gqlReq.Query = ServerVersionQuery
203+
query, err := json.Marshal(gqlReq)
204+
if err != nil {
205+
return ServerVersionResponse{}, err
206+
}
207+
resp, err := apis.SendRequest(
208+
apis.SendRequestParams{
209+
Endpoint: endpoint + utils.GQLAPIPath,
210+
},
211+
query,
212+
string(types.Post),
213+
)
214+
if err != nil {
215+
return ServerVersionResponse{}, err
216+
}
217+
bodyBytes, err := ioutil.ReadAll(resp.Body)
218+
defer resp.Body.Close()
219+
if err != nil {
220+
return ServerVersionResponse{}, err
221+
}
222+
if resp.StatusCode == http.StatusOK {
223+
var version ServerVersionResponse
224+
err = json.Unmarshal(bodyBytes, &version)
225+
if err != nil {
226+
return ServerVersionResponse{}, err
227+
}
228+
if len(version.Errors) > 0 {
229+
return ServerVersionResponse{}, errors.New(version.Errors[0].Message)
230+
}
231+
return version, nil
232+
} else {
233+
return ServerVersionResponse{}, errors.New(resp.Status)
234+
}
235+
}

pkg/apis/infrastructure/query.go

+7
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ const (
3030
}
3131
}
3232
}`
33+
34+
ServerVersionQuery = `query getServerVersion{
35+
getServerVersion{
36+
key
37+
value
38+
}
39+
}`
3340
)

0 commit comments

Comments
 (0)