Skip to content

Commit

Permalink
fix: update URLs (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop authored Dec 11, 2024
1 parent b62cfbd commit 58b8ba7
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 37 deletions.
25 changes: 17 additions & 8 deletions clienv/clienv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -43,7 +45,8 @@ func New(
stdout: stdout,
stderr: stderr,
Path: path,
domain: domain,
authURL: authURL,
graphqlURL: graphqlURL,
branch: branch,
nhclient: nil,
nhpublicclient: nil,
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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),
)
}
Expand All @@ -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
}
18 changes: 13 additions & 5 deletions clienv/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (
)

const (
flagDomain = "domain"
flagAuthURL = "auth-url"
flagGraphqlURL = "graphql-url"
flagBranch = "branch"
flagProjectName = "project-name"
flagRootFolder = "root-folder"
Expand Down Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions clienv/wf_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: ")
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion clienv/wf_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cmd/config/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 17 additions & 8 deletions cmd/dockercredentials/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
)

const (
flagDomain = "domain"
flagAuthURL = "auth-url"
flagGraphqlURL = "graphql-url"
)

func CommandGet() *cli.Command {
Expand All @@ -23,23 +24,31 @@ 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,
},
},
Action: actionGet,
}
}

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",
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/project/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion get_access_token.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion gqlgenc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion nhostclient/graphql/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions nhostclient/nhostclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...,
),
Expand Down

0 comments on commit 58b8ba7

Please sign in to comment.