MCPcopy Index your code
hub / github.com/hasura/graphql-engine / Validate

Method Validate

cli/cli.go:610–787  ·  view source on GitHub ↗

Validate prepares the ExecutionContext ec and then validates the ExecutionDirectory to see if all the required files and directories are in place.

()

Source from the content-addressed store, hash-verified

608// ExecutionDirectory to see if all the required files and directories are in
609// place.
610func (ec *ExecutionContext) Validate() error {
611 var op errors.Op = "cli.ExecutionContext.Validate"
612 // validate execution directory
613 err := ec.validateDirectory()
614 if err != nil {
615 return errors.E(op, fmt.Errorf("validating current directory failed: %w", err))
616 }
617
618 // load .env file
619 err = ec.loadEnvfile()
620 if err != nil {
621 return errors.E(op, fmt.Errorf("loading .env file failed: %w", err))
622 }
623
624 // set names of config file
625 ec.ConfigFile = filepath.Join(ec.ExecutionDirectory, "config.yaml")
626
627 // read config and parse the values into Config
628 err = ec.readConfig()
629 if err != nil {
630 return errors.E(op, fmt.Errorf("cannot read config: %w", err))
631 }
632
633 // initialize HTTP client
634 // CLI uses a common http client defined in internal/httpc.Client
635 // get TLS Config
636 tlsConfig, err := httpc.GenerateTLSConfig(ec.Config.CAPath, ec.Config.InsecureSkipTLSVerify)
637 if err != nil || tlsConfig == nil {
638 return errors.E(op, fmt.Errorf("error while getting TLS config"))
639 }
640
641 // create a net/http.Client with TLS Config
642 standardHttpClient, err := httpc.NewHttpClientWithTLSConfig(tlsConfig)
643 if err != nil || standardHttpClient == nil {
644 return errors.E(op, fmt.Errorf("error while creating http client with TLS configuration %w", err))
645 }
646
647 // create httpc.Client
648 httpClient, err := httpc.New(standardHttpClient, ec.Config.Endpoint, ec.HGEHeaders)
649 if err != nil || httpClient == nil {
650 return errors.E(op, err)
651 }
652 ec.Config.HTTPClient = httpClient
653
654 err = util.GetServerStatus(ec.Config.GetVersionEndpoint(), ec.Config.HTTPClient)
655 if err != nil {
656 ec.Logger.Error("connecting to graphql-engine server failed")
657 ec.Logger.Info("possible reasons:")
658 ec.Logger.Info("1) Provided root endpoint of graphql-engine server is wrong. Verify endpoint key in config.yaml or/and value of --endpoint flag")
659 ec.Logger.Info("2) Endpoint should NOT be your GraphQL API, ie endpoint is NOT https://hasura-cloud-app.io/v1/graphql it should be: https://hasura-cloud-app.io")
660 ec.Logger.Info("3) Server might be unhealthy and is not running/accepting API requests")
661 ec.Logger.Info("4) Admin secret is not correct/set")
662 ec.Logger.Infoln()
663 return errors.E(op, err)
664 }
665
666 // get version from the server and match with the cli version
667 err = ec.checkServerVersion()

Callers 3

NewProjectDeployFunction · 0.95
NewProjectMigrateFunction · 0.95
NewProjectMetadataFunction · 0.95

Calls 15

validateDirectoryMethod · 0.95
loadEnvfileMethod · 0.95
readConfigMethod · 0.95
checkServerVersionMethod · 0.95
AddRequestHeadersMethod · 0.95
GetAdminSecretHeaderNameFunction · 0.85
GetVersionEndpointMethod · 0.80
GetServerFeatureFlagsMethod · 0.80
GetAdminSecretMethod · 0.80
SetHeadersMethod · 0.80
GetV1MetadataEndpointMethod · 0.80

Tested by

no test coverage detected