Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

chore: expose API Token and BaseURL #252

Merged
merged 2 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions coder-sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,13 @@ type DefaultClient struct {
// token is the API Token credential.
token string
}

// Token returns the API Token used to authenticate.
func (c *DefaultClient) Token() string {
return c.token
}

// BaseURL returns the BaseURL configured for this Client.
func (c *DefaultClient) BaseURL() url.URL {
return *c.baseURL
}
4 changes: 4 additions & 0 deletions coder-sdk/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ func TestAuthentication(t *testing.T) {
})
require.NoError(t, err, "failed to create coder.Client")

require.Equal(t, token, client.Token(), "expected Token to match")
require.EqualValues(t, *u, client.BaseURL(), "expected BaseURL to match")

_, err = client.APIVersion(context.Background())
require.NoError(t, err, "failed to get API version information")
}
Expand Down Expand Up @@ -103,6 +106,7 @@ func TestPasswordAuthentication(t *testing.T) {
Password: "coder4all",
})
require.NoError(t, err, "failed to create Client")
require.Equal(t, "g4mtIPUaKt-pPl9Q0xmgKs7acSypHt4Jf", client.Token(), "expected token to match")

user, err := client.Me(context.Background())
require.NoError(t, err, "failed to get information about current user")
Expand Down
6 changes: 6 additions & 0 deletions coder-sdk/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,10 @@ type Client interface {

// DeleteWorkspaceProviderByID deletes a workspace provider entity from the Coder control plane.
DeleteWorkspaceProviderByID(ctx context.Context, id string) error

// Token returns the API Token used to authenticate.
Token() string

// BaseURL returns the BaseURL configured for this Client.
BaseURL() url.URL
}