Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetWorkspaceClient for GCP #803

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,14 @@ func (c *Config) NewWithWorkspaceHost(host string) (*Config, error) {
}

res.Host = host
// We can reuse the same OAuth token refresh client and context. The
// reuseTokenSource internally locks.
res.refreshClient = c.refreshClient
res.refreshCtx = c.refreshCtx
// The config does not need to be re-resolved, as we reuse all attributes
// from the original config.
res.resolved = c.resolved
res.auth = c.auth
res.isTesting = c.isTesting
// We need to reresolve the config with the updated host in general. For
// example, the audience for OAuth tokens provided by GCP is derived from
// the host, so account-level tokens cannot be used at workspace-level or
// vice-versa.
//
// In the future, when unified login is widely available, we may be able to
// reuse the authentication visitor specifically for in-house OAuth.
return res, nil
}

Expand Down
3 changes: 2 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ func TestNewWithWorkspaceHost(t *testing.T) {
// Other fields should be preserved
assert.Equal(t, "client-id", c2.ClientID)
assert.Equal(t, "http://", c2.MetadataServiceURL)
assert.True(t, c2.resolved)
// The new config will not be automatically resolved.
assert.False(t, c2.resolved)
}
12 changes: 3 additions & 9 deletions internal/account_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@ import (

func TestMwsAccAccountClient_GetWorkspaceClient_NoTranspile(t *testing.T) {
ctx, a := accountTest(t)
if !a.Config.IsAws() {
skipf(t)("Only works on AWS")
}
wss, err := a.Workspaces.List(ctx)
workspaceId := MustParseInt64(GetEnvOrSkipTest(t, "TEST_WORKSPACE_ID"))
ws, err := a.Workspaces.GetByWorkspaceId(ctx, int64(workspaceId))
require.NoError(t, err)

if len(wss) == 0 {
t.Skip("No workspaces found")
}
w, err := a.GetWorkspaceClient(wss[0])
w, err := a.GetWorkspaceClient(*ws)
assert.NoError(t, err)
me, err := w.CurrentUser.Me(ctx)
assert.NoError(t, err)
Expand Down
Loading