mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
489835eb36
- modified the `dry-run` flag of metadata apply command. - added new flag `o` which takes "json" or "yaml" as parameters for metadata apply command. - added new flag `o` which takes "json" or "yaml" as parameters for metadata export command. It outputs the metadata from server to stdout in form of json or yaml and won't change the project's metadata. - added deprecation warnings for `--from-file` flag - added info message for describing change of behavior of `--dry-run` flag - v3 metadata objects like `rest_endpoints` was also added to list of metadata objects in config v2 (fix) - the order in which metadata objects are appended to metadata objects list matter when using `--dry-run` flag, refactored this order to match server metadata. - `metadata apply` command can now accept json/yaml metadata from io pipe - config v3 `metadata apply` didn't show any information to user when applied metadata is inconsistent, this is addressed. - removed `github.com/ghodss/yaml` dependency from repo - version metadata object was added twice during intialization (fix) Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com> GitOrigin-RevId: 2316f519eb40645efd86ffee2a85d3c90543ec17
42 lines
1014 B
Go
42 lines
1014 B
Go
package version
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"net/http"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type serverVersionResponse struct {
|
|
Version string `json:"version"`
|
|
}
|
|
|
|
// FetchServerVersion reads the version from server.
|
|
func FetchServerVersion(endpoint string, client *http.Client) (version string, err error) {
|
|
response, err := client.Get(endpoint)
|
|
if err != nil {
|
|
return "", errors.Wrap(err, "failed making version api call")
|
|
}
|
|
if response.StatusCode != http.StatusOK {
|
|
switch response.StatusCode {
|
|
case http.StatusNotFound:
|
|
return "", nil
|
|
default:
|
|
return "", errors.Errorf("GET %s failed - [%d]", endpoint, response.StatusCode)
|
|
}
|
|
} else {
|
|
defer response.Body.Close()
|
|
data, err := ioutil.ReadAll(response.Body)
|
|
if err != nil {
|
|
return "", errors.Wrap(err, "cannot read version api response")
|
|
}
|
|
var v serverVersionResponse
|
|
err = json.Unmarshal(data, &v)
|
|
if err != nil {
|
|
return "", errors.Wrap(err, "failed to parse version api response")
|
|
}
|
|
return v.Version, nil
|
|
}
|
|
}
|