graphql-engine/cli/version/server.go
Kali Vara Purushotham Santhati 780d942fad cli: skip tls verfication for all API requests when insecure-skip-tls-verify flag is set
closes: https://github.com/hasura/graphql-engine/issues/4926

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3307
Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com>
GitOrigin-RevId: 90222fc2e5b176fbf5721fea3f5b2af929ca93f4
2022-02-04 11:11:37 +00:00

36 lines
900 B
Go

package version
import (
"context"
"fmt"
"net/http"
"github.com/hasura/graphql-engine/cli/v2/internal/httpc"
)
type serverVersionResponse struct {
Version string `json:"version"`
}
// FetchServerVersion reads the version from server.
func FetchServerVersion(endpoint string, client *httpc.Client) (version string, err error) {
req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
return "", fmt.Errorf("error while making http request to %s", endpoint)
}
var v serverVersionResponse
response, err := client.Do(context.Background(), req, &v)
if err != nil {
return "", fmt.Errorf("failed making version api call: %w", err)
}
if response.StatusCode != http.StatusOK {
switch response.StatusCode {
case http.StatusNotFound:
return "", nil
default:
return "", fmt.Errorf("GET %s failed - [%d]", endpoint, response.StatusCode)
}
}
return v.Version, nil
}