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

Commit 4117dc8

Browse files
authored
feat: add additional config methods to coder sdk (#419)
1 parent 59cae56 commit 4117dc8

File tree

4 files changed

+97
-29
lines changed

4 files changed

+97
-29
lines changed

coder-sdk/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# coder-sdk
22

3-
`coder-sdk` is a Go client library for [Coder](https://coder.com).
4-
It is not yet stable and therefore we do not recommend depending on the current state of its public APIs.
3+
`coder-sdk` is a Go client library for [Coder](https://coder.com).
4+
It is not yet stable and therefore we do not recommend depending on the current
5+
state of its public APIs.
56

67
## Usage
78

coder-sdk/client.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,25 @@ type ClientOptions struct {
2828

2929
// Token is the API Token used to authenticate (optional).
3030
//
31-
// If Token is provided, the DefaultClient will use it to
32-
// authenticate. If it is not provided, the client requires
33-
// another type of credential, such as an Email/Password pair.
31+
// If Token is provided, the DefaultClient will use it to authenticate.
32+
// If it is not provided, the client requires another type of
33+
// credential, such as an Email/Password pair.
3434
Token string
3535

3636
// Email used to authenticate with Coder.
3737
//
38-
// If you supply an Email and Password pair, NewClient will
39-
// exchange these credentials for a Token during initialization.
40-
// This is only applicable for the built-in authentication
41-
// provider. The client will not retain these credentials in
42-
// memory after NewClient returns.
38+
// If you supply an Email and Password pair, NewClient will exchange
39+
// these credentials for a Token during initialization. This is only
40+
// applicable for the built-in authentication provider. The client will
41+
// not retain these credentials in memory after NewClient returns.
4342
Email string
4443

4544
// Password used to authenticate with Coder.
4645
//
47-
// If you supply an Email and Password pair, NewClient will
48-
// exchange these credentials for a Token during initialization.
49-
// This is only applicable for the built-in authentication
50-
// provider. The client will not retain these credentials in
51-
// memory after NewClient returns.
46+
// If you supply an Email and Password pair, NewClient will exchange
47+
// these credentials for a Token during initialization. This is only
48+
// applicable for the built-in authentication provider. The client will
49+
// not retain these credentials in memory after NewClient returns.
5250
Password string
5351
}
5452

coder-sdk/config.go

Lines changed: 81 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ const (
1515
AuthProviderOIDC AuthProviderType = "oidc"
1616
)
1717

18-
// ConfigAuth describes the authentication configuration for a Coder deployment.
18+
// ConfigAuth describes the authentication configuration for a Coder
19+
// deployment.
1920
type ConfigAuth struct {
2021
ProviderType *AuthProviderType `json:"provider_type"`
2122
OIDC *ConfigOIDC `json:"oidc"`
2223
SAML *ConfigSAML `json:"saml"`
2324
}
2425

25-
// ConfigOIDC describes the OIDC configuration for single-signon support in Coder.
26+
// ConfigOIDC describes the OIDC configuration for single-signon support in
27+
// Coder.
2628
type ConfigOIDC struct {
2729
ClientID *string `json:"client_id"`
2830
ClientSecret *string `json:"client_secret"`
@@ -38,26 +40,30 @@ type ConfigSAML struct {
3840
PublicKeyCertificate *string `json:"public_key_certificate"`
3941
}
4042

41-
// ConfigOAuthBitbucketServer describes the Bitbucket integration configuration for a Coder deployment.
43+
// ConfigOAuthBitbucketServer describes the Bitbucket integration configuration
44+
// for a Coder deployment.
4245
type ConfigOAuthBitbucketServer struct {
4346
BaseURL string `json:"base_url" diff:"oauth.bitbucket_server.base_url"`
4447
}
4548

46-
// ConfigOAuthGitHub describes the Github integration configuration for a Coder deployment.
49+
// ConfigOAuthGitHub describes the Github integration configuration for a Coder
50+
// deployment.
4751
type ConfigOAuthGitHub struct {
4852
BaseURL string `json:"base_url"`
4953
ClientID string `json:"client_id"`
5054
ClientSecret string `json:"client_secret"`
5155
}
5256

53-
// ConfigOAuthGitLab describes the GitLab integration configuration for a Coder deployment.
57+
// ConfigOAuthGitLab describes the GitLab integration configuration for a Coder
58+
// deployment.
5459
type ConfigOAuthGitLab struct {
5560
BaseURL string `json:"base_url"`
5661
ClientID string `json:"client_id" `
5762
ClientSecret string `json:"client_secret"`
5863
}
5964

60-
// ConfigOAuth describes the aggregate git integration configuration for a Coder deployment.
65+
// ConfigOAuth describes the aggregate git integration configuration for a
66+
// Coder deployment.
6167
type ConfigOAuth struct {
6268
BitbucketServer ConfigOAuthBitbucketServer `json:"bitbucket_server"`
6369
GitHub ConfigOAuthGitHub `json:"github"`
@@ -140,18 +146,81 @@ func (c *DefaultClient) PutSiteConfigExtensionMarketplace(ctx context.Context, r
140146

141147
// ConfigWorkspaces is the site configuration for workspace attributes.
142148
type ConfigWorkspaces struct {
143-
GPUVendor string `json:"gpu_vendor,omitempty" valid:"in(nvidia|amd)"`
144-
EnableContainerVMs bool `json:"enable_container_vms,omitempty"`
145-
EnableWorkspacesAsCode bool `json:"enable_workspaces_as_code,omitempty"`
146-
EnableP2P bool `json:"enable_p2p,omitempty"`
149+
GPUVendor string `json:"gpu_vendor"`
150+
EnableContainerVMs bool `json:"enable_container_vms"`
151+
EnableWorkspacesAsCode bool `json:"enable_workspaces_as_code"`
147152
}
148153

149154
// SiteConfigWorkspaces fetches the workspace configuration.
150155
func (c *DefaultClient) SiteConfigWorkspaces(ctx context.Context) (*ConfigWorkspaces, error) {
151156
var conf ConfigWorkspaces
152-
// TODO: use the `/api/v0/workspaces/config route once we migrate from using general config
153-
if err := c.requestBody(ctx, http.MethodGet, "/api/private/config", nil, &conf); err != nil {
157+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/workspaces/config", nil, &conf); err != nil {
154158
return nil, err
155159
}
156160
return &conf, nil
157161
}
162+
163+
// PutSiteConfigWorkspaces sets the workspace configuration.
164+
func (c *DefaultClient) PutSiteConfigWorkspaces(ctx context.Context, req ConfigWorkspaces) error {
165+
return c.requestBody(ctx, http.MethodPut, "/api/v0/workspaces/config", req, nil)
166+
}
167+
168+
type ConfigDormancy struct {
169+
// UserDormancyThresholdDays is not currently updatable.
170+
// UserDormancyThresholdDays int `json:"user_dormancy_threshold_days"`
171+
UserDeletionThresholdDays int `json:"user_deletion_threshold_days"`
172+
}
173+
174+
// SiteConfigDormancy fetches the dormancy configuration.
175+
func (c *DefaultClient) SiteConfigDormancy(ctx context.Context) (*ConfigDormancy, error) {
176+
var conf ConfigDormancy
177+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/dormancy/config", nil, &conf); err != nil {
178+
return nil, err
179+
}
180+
return &conf, nil
181+
}
182+
183+
// PutSiteConfigDormancy sets the dormancy configuration.
184+
func (c *DefaultClient) PutSiteConfigDormancy(ctx context.Context, req ConfigDormancy) error {
185+
return c.requestBody(ctx, http.MethodPut, "/api/private/dormancy/config", req, nil)
186+
}
187+
188+
type ConfigDevURLAccess struct {
189+
Private bool `json:"private"`
190+
Org bool `json:"org"`
191+
Authed bool `json:"authed"`
192+
Public bool `json:"public"`
193+
}
194+
195+
// SiteConfigDevURLAccess fetches the DevURL access configuration.
196+
func (c *DefaultClient) SiteConfigDevURLAccess(ctx context.Context) (*ConfigDevURLAccess, error) {
197+
var conf ConfigDevURLAccess
198+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/devurls/config", nil, &conf); err != nil {
199+
return nil, err
200+
}
201+
return &conf, nil
202+
}
203+
204+
// PutSiteConfigDevURLAccess sets the DevURL access configuration.
205+
func (c *DefaultClient) PutSiteConfigDevURLAccess(ctx context.Context, req ConfigDevURLAccess) error {
206+
return c.requestBody(ctx, http.MethodPut, "/api/private/devurls/config", req, nil)
207+
}
208+
209+
// ConfigSSHSettings is the site configuration for SSH.
210+
type ConfigSSHSettings struct {
211+
KeygenAlgorithm string `json:"keygen_algorithm"`
212+
}
213+
214+
// SiteConfigSSHSettings fetches the SSH configuration.
215+
func (c *DefaultClient) SiteConfigSSHSettings(ctx context.Context) (*ConfigSSHSettings, error) {
216+
var conf ConfigSSHSettings
217+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/ssh/config", nil, &conf); err != nil {
218+
return nil, err
219+
}
220+
return &conf, nil
221+
}
222+
223+
// PutSiteConfigSSHSettings sets the SSH configuration.
224+
func (c *DefaultClient) PutSiteConfigSSHSettings(ctx context.Context, req ConfigSSHSettings) error {
225+
return c.requestBody(ctx, http.MethodPut, "/api/private/ssh/config", req, nil)
226+
}

internal/cmd/users_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ func Test_users(t *testing.T) {
2424

2525
func assertAdmin(t *testing.T, users []coder.User) {
2626
for _, u := range users {
27-
if u.Username == "admin" {
27+
if u.Username == "kyle" {
2828
return
2929
}
3030
}
31-
slogtest.Fatal(t, "did not find admin user", slog.F("users", users))
31+
slogtest.Fatal(t, "did not find kyle user", slog.F("users", users))
3232
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy