diff --git a/clienv/clienv.go b/clienv/clienv.go index f1af99ee..7e28cdee 100644 --- a/clienv/clienv.go +++ b/clienv/clienv.go @@ -22,7 +22,8 @@ type CliEnv struct { stdout io.Writer stderr io.Writer Path *PathStructure - domain string + authURL string + graphqlURL string branch string nhclient *nhostclient.Client nhpublicclient *nhostclient.Client @@ -34,7 +35,8 @@ func New( stdout io.Writer, stderr io.Writer, path *PathStructure, - domain string, + authURL string, + graphqlURL string, branch string, projectName string, localSubdomain string, @@ -43,7 +45,8 @@ func New( stdout: stdout, stderr: stderr, Path: path, - domain: domain, + authURL: authURL, + graphqlURL: graphqlURL, branch: branch, nhclient: nil, nhpublicclient: nil, @@ -67,7 +70,8 @@ func FromCLI(cCtx *cli.Context) *CliEnv { cCtx.String(flagDataFolder), cCtx.String(flagNhostFolder), ), - domain: cCtx.String(flagDomain), + authURL: cCtx.String(flagAuthURL), + graphqlURL: cCtx.String(flagGraphqlURL), branch: cCtx.String(flagBranch), projectName: sanitizeName(cCtx.String(flagProjectName)), nhclient: nil, @@ -84,8 +88,12 @@ func (ce *CliEnv) LocalSubdomain() string { return ce.localSubdomain } -func (ce *CliEnv) Domain() string { - return ce.domain +func (ce *CliEnv) AuthURL() string { + return ce.authURL +} + +func (ce *CliEnv) GraphqlURL() string { + return ce.graphqlURL } func (ce *CliEnv) Branch() string { @@ -99,7 +107,8 @@ func (ce *CliEnv) GetNhostClient(ctx context.Context) (*nhostclient.Client, erro return nil, fmt.Errorf("failed to load session: %w", err) } ce.nhclient = nhostclient.New( - ce.domain, + ce.authURL, + ce.graphqlURL, graphql.WithAccessToken(session.Session.AccessToken), ) } @@ -108,7 +117,7 @@ func (ce *CliEnv) GetNhostClient(ctx context.Context) (*nhostclient.Client, erro func (ce *CliEnv) GetNhostPublicClient() (*nhostclient.Client, error) { if ce.nhpublicclient == nil { - ce.nhpublicclient = nhostclient.New(ce.domain) + ce.nhpublicclient = nhostclient.New(ce.authURL, ce.graphqlURL) } return ce.nhpublicclient, nil } diff --git a/clienv/flags.go b/clienv/flags.go index 624d2daf..4969a4f0 100644 --- a/clienv/flags.go +++ b/clienv/flags.go @@ -10,7 +10,8 @@ import ( ) const ( - flagDomain = "domain" + flagAuthURL = "auth-url" + flagGraphqlURL = "graphql-url" flagBranch = "branch" flagProjectName = "project-name" flagRootFolder = "root-folder" @@ -52,10 +53,17 @@ func Flags() ([]cli.Flag, error) { //nolint:funlen return []cli.Flag{ &cli.StringFlag{ //nolint:exhaustruct - Name: flagDomain, - Usage: "Nhost domain", - EnvVars: []string{"NHOST_DOMAIN"}, - Value: "nhost.run", + Name: flagAuthURL, + Usage: "Nhost auth URL", + EnvVars: []string{"NHOST_CLI_AUTH_URL"}, + Value: "https://otsispdzcwxyqzbfntmj.auth.eu-central-1.nhost.run/v1", + Hidden: true, + }, + &cli.StringFlag{ //nolint:exhaustruct + Name: flagGraphqlURL, + Usage: "Nhost GraphQL URL", + EnvVars: []string{"NHOST_CLI_GRAPHQL_URL"}, + Value: "https://otsispdzcwxyqzbfntmj.graphql.eu-central-1.nhost.run/v1", Hidden: true, }, &cli.StringFlag{ //nolint:exhaustruct diff --git a/clienv/wf_login.go b/clienv/wf_login.go index 8fab202f..8e00ba3a 100644 --- a/clienv/wf_login.go +++ b/clienv/wf_login.go @@ -118,7 +118,7 @@ func (ce *CliEnv) loginEmailPassword( email string, password string, ) (credentials.Credentials, error) { - cl := nhostclient.New(ce.Domain()) + cl := nhostclient.New(ce.AuthURL(), ce.GraphqlURL()) var err error if email == "" { ce.PromptMessage("email: ") @@ -166,10 +166,7 @@ func (ce *CliEnv) loginGithub(ctx context.Context) (credentials.Credentials, err } }() - signinPage := fmt.Sprintf( - "https://%s/v1/auth/signin/provider/github/?redirectTo=https://local.dashboard.nhost.run:8099/signin", - ce.Domain(), - ) + signinPage := ce.AuthURL() + "/signin/provider/github/?redirectTo=https://local.dashboard.nhost.run:8099/signin" ce.Infoln("Opening browser to sign-in") if err := openBrowser(signinPage); err != nil { return credentials.Credentials{}, err @@ -178,7 +175,7 @@ func (ce *CliEnv) loginGithub(ctx context.Context) (credentials.Credentials, err refreshTokenValue := <-refreshToken - cl := nhostclient.New(ce.Domain()) + cl := nhostclient.New(ce.AuthURL(), ce.GraphqlURL()) refreshTokenResp, err := cl.RefreshToken(ctx, refreshTokenValue) if err != nil { return credentials.Credentials{}, fmt.Errorf("failed to get access token: %w", err) @@ -228,7 +225,7 @@ func (ce *CliEnv) verifyEmail( ) error { ce.Infoln("Your email address is not verified") - cl := nhostclient.New(ce.Domain()) + cl := nhostclient.New(ce.AuthURL(), ce.GraphqlURL()) if err := cl.VerifyEmail(ctx, email); err != nil { return fmt.Errorf("failed to send verification email: %w", err) } diff --git a/clienv/wf_session.go b/clienv/wf_session.go index fafeceb6..fbe0839a 100644 --- a/clienv/wf_session.go +++ b/clienv/wf_session.go @@ -20,7 +20,7 @@ func (ce *CliEnv) LoadSession( } } - cl := nhostclient.New(ce.Domain()) + cl := nhostclient.New(ce.AuthURL(), ce.GraphqlURL()) session, err := cl.LoginPAT(ctx, creds.PersonalAccessToken) if err != nil { return credentials.Session{}, fmt.Errorf("failed to login: %w", err) diff --git a/cmd/config/validate_test.go b/cmd/config/validate_test.go index ad52e7db..db8bfe32 100644 --- a/cmd/config/validate_test.go +++ b/cmd/config/validate_test.go @@ -250,7 +250,8 @@ func TestValidate(t *testing.T) { filepath.Join("testdata", "validate", tc.path, ".nhost", "data"), filepath.Join("testdata", "validate", tc.path, "nhost"), ), - "fakedomain", + "fakeauthurl", + "fakegraphqlurl", "fakebranch", "", "local", diff --git a/cmd/dockercredentials/get.go b/cmd/dockercredentials/get.go index 14643c4c..d4d26fc5 100644 --- a/cmd/dockercredentials/get.go +++ b/cmd/dockercredentials/get.go @@ -12,7 +12,8 @@ import ( ) const ( - flagDomain = "domain" + flagAuthURL = "auth-url" + flagGraphqlURL = "graphql-url" ) func CommandGet() *cli.Command { @@ -23,10 +24,17 @@ func CommandGet() *cli.Command { Hidden: true, Flags: []cli.Flag{ &cli.StringFlag{ //nolint:exhaustruct - Name: flagDomain, - Usage: "Nhost domain", - EnvVars: []string{"NHOST_DOMAIN"}, - Value: "nhost.run", + Name: flagAuthURL, + Usage: "Nhost auth URL", + EnvVars: []string{"NHOST_CLI_AUTH_URL"}, + Value: "https://otsispdzcwxyqzbfntmj.auth.eu-central-1.nhost.run/v1", + Hidden: true, + }, + &cli.StringFlag{ //nolint:exhaustruct + Name: flagGraphqlURL, + Usage: "Nhost GraphQL URL", + EnvVars: []string{"NHOST_CLI_GRAPHQL_URL"}, + Value: "https://otsispdzcwxyqzbfntmj.graphql.eu-central-1.nhost.run/v1", Hidden: true, }, }, @@ -34,12 +42,13 @@ func CommandGet() *cli.Command { } } -func getToken(ctx context.Context, domain string) (string, error) { +func getToken(ctx context.Context, authURL, graphqlURL string) (string, error) { ce := clienv.New( os.Stdout, os.Stderr, &clienv.PathStructure{}, - domain, + authURL, + graphqlURL, "unneeded", "unneeded", "unneeded", @@ -65,7 +74,7 @@ func actionGet(c *cli.Context) error { for scanner.Scan() { input += scanner.Text() } - token, err := getToken(c.Context, c.String(flagDomain)) + token, err := getToken(c.Context, c.String(flagAuthURL), c.String(flagGraphqlURL)) if err != nil { return err } diff --git a/cmd/project/init.go b/cmd/project/init.go index eda2b30a..ffea78e3 100644 --- a/cmd/project/init.go +++ b/cmd/project/init.go @@ -187,7 +187,7 @@ func InitRemote( } hasuraEndpoint := fmt.Sprintf( - "https://%s.hasura.%s.%s", proj.Subdomain, proj.Region.Name, ce.Domain(), + "https://%s.hasura.%s.nhost.run", proj.Subdomain, proj.Region.Name, ) if err := deploy( diff --git a/get_access_token.sh b/get_access_token.sh index df7044e4..6d7b0734 100644 --- a/get_access_token.sh +++ b/get_access_token.sh @@ -5,7 +5,7 @@ output=`curl \ --fail -s \ -H "Content-Type: application/json" \ -d "{\"personalAccessToken\":\"$NHOST_PAT\"}" \ - https://staging.nhost.run/v1/auth/signin/pat` + https://mytpiiwxeyrvlqrxuknp.auth.eu-central-1.nhost.run/v1/signin/pat` if [ $? -ne 0 ]; then echo "Error: Failed to get access token" diff --git a/gqlgenc.yaml b/gqlgenc.yaml index 88bbc755..b8d89f2c 100644 --- a/gqlgenc.yaml +++ b/gqlgenc.yaml @@ -25,7 +25,7 @@ models: - github.com/99designs/gqlgen/graphql.Uint32 endpoint: - url: https://staging.nhost.run/v1/graphql + url: https://mytpiiwxeyrvlqrxuknp.graphql.eu-central-1.nhost.run/v1 headers: Authorization: Bearer $NHOST_ACCESS_TOKEN # # support environment variables diff --git a/nhostclient/graphql/models_gen.go b/nhostclient/graphql/models_gen.go index 9a4bcdbf..4334b8ce 100644 --- a/nhostclient/graphql/models_gen.go +++ b/nhostclient/graphql/models_gen.go @@ -7950,7 +7950,7 @@ type SoftwareTypeEnum string const ( // Hasura Auth SoftwareTypeEnumAuth SoftwareTypeEnum = "Auth" - // Graphite + // Nhost AI service SoftwareTypeEnumGraphite SoftwareTypeEnum = "Graphite" // Hasura GraphQL Engine SoftwareTypeEnumHasura SoftwareTypeEnum = "Hasura" diff --git a/nhostclient/nhostclient.go b/nhostclient/nhostclient.go index 54549085..e04861f7 100644 --- a/nhostclient/nhostclient.go +++ b/nhostclient/nhostclient.go @@ -33,13 +33,13 @@ func (e *RequestError) Error() string { return fmt.Sprintf("status: %d, error: %s, message: %s", e.Status, e.ErrorCode, e.Message) } -func New(domain string, interceptors ...clientv2.RequestInterceptor) *Client { +func New(authURL, graphqlURL string, interceptors ...clientv2.RequestInterceptor) *Client { return &Client{ - baseURL: fmt.Sprintf("https://%s/v1/auth", domain), + baseURL: authURL, client: &http.Client{}, //nolint:exhaustruct Client: graphql.NewClient( &http.Client{}, //nolint:exhaustruct - fmt.Sprintf("https://%s/v1/graphql", domain), + graphqlURL, &clientv2.Options{}, //nolint:exhaustruct interceptors..., ),