diff --git a/coder-sdk/README.md b/coder-sdk/README.md index 75ffd8dd..b5fbec97 100644 --- a/coder-sdk/README.md +++ b/coder-sdk/README.md @@ -1,7 +1,8 @@ # coder-sdk -`coder-sdk` is a Go client library for [Coder](https://coder.com). -It is not yet stable and therefore we do not recommend depending on the current state of its public APIs. +`coder-sdk` is a Go client library for [Coder](https://coder.com). +It is not yet stable and therefore we do not recommend depending on the current +state of its public APIs. ## Usage diff --git a/coder-sdk/client.go b/coder-sdk/client.go index 6d172126..1cba0fcb 100644 --- a/coder-sdk/client.go +++ b/coder-sdk/client.go @@ -28,27 +28,25 @@ type ClientOptions struct { // Token is the API Token used to authenticate (optional). // - // If Token is provided, the DefaultClient will use it to - // authenticate. If it is not provided, the client requires - // another type of credential, such as an Email/Password pair. + // If Token is provided, the DefaultClient will use it to authenticate. + // If it is not provided, the client requires another type of + // credential, such as an Email/Password pair. Token string // Email used to authenticate with Coder. // - // If you supply an Email and Password pair, NewClient will - // exchange these credentials for a Token during initialization. - // This is only applicable for the built-in authentication - // provider. The client will not retain these credentials in - // memory after NewClient returns. + // If you supply an Email and Password pair, NewClient will exchange + // these credentials for a Token during initialization. This is only + // applicable for the built-in authentication provider. The client will + // not retain these credentials in memory after NewClient returns. Email string // Password used to authenticate with Coder. // - // If you supply an Email and Password pair, NewClient will - // exchange these credentials for a Token during initialization. - // This is only applicable for the built-in authentication - // provider. The client will not retain these credentials in - // memory after NewClient returns. + // If you supply an Email and Password pair, NewClient will exchange + // these credentials for a Token during initialization. This is only + // applicable for the built-in authentication provider. The client will + // not retain these credentials in memory after NewClient returns. Password string } diff --git a/coder-sdk/config.go b/coder-sdk/config.go index c43ddf2c..a38f2357 100644 --- a/coder-sdk/config.go +++ b/coder-sdk/config.go @@ -15,14 +15,16 @@ const ( AuthProviderOIDC AuthProviderType = "oidc" ) -// ConfigAuth describes the authentication configuration for a Coder deployment. +// ConfigAuth describes the authentication configuration for a Coder +// deployment. type ConfigAuth struct { ProviderType *AuthProviderType `json:"provider_type"` OIDC *ConfigOIDC `json:"oidc"` SAML *ConfigSAML `json:"saml"` } -// ConfigOIDC describes the OIDC configuration for single-signon support in Coder. +// ConfigOIDC describes the OIDC configuration for single-signon support in +// Coder. type ConfigOIDC struct { ClientID *string `json:"client_id"` ClientSecret *string `json:"client_secret"` @@ -38,26 +40,30 @@ type ConfigSAML struct { PublicKeyCertificate *string `json:"public_key_certificate"` } -// ConfigOAuthBitbucketServer describes the Bitbucket integration configuration for a Coder deployment. +// ConfigOAuthBitbucketServer describes the Bitbucket integration configuration +// for a Coder deployment. type ConfigOAuthBitbucketServer struct { BaseURL string `json:"base_url" diff:"oauth.bitbucket_server.base_url"` } -// ConfigOAuthGitHub describes the Github integration configuration for a Coder deployment. +// ConfigOAuthGitHub describes the Github integration configuration for a Coder +// deployment. type ConfigOAuthGitHub struct { BaseURL string `json:"base_url"` ClientID string `json:"client_id"` ClientSecret string `json:"client_secret"` } -// ConfigOAuthGitLab describes the GitLab integration configuration for a Coder deployment. +// ConfigOAuthGitLab describes the GitLab integration configuration for a Coder +// deployment. type ConfigOAuthGitLab struct { BaseURL string `json:"base_url"` ClientID string `json:"client_id" ` ClientSecret string `json:"client_secret"` } -// ConfigOAuth describes the aggregate git integration configuration for a Coder deployment. +// ConfigOAuth describes the aggregate git integration configuration for a +// Coder deployment. type ConfigOAuth struct { BitbucketServer ConfigOAuthBitbucketServer `json:"bitbucket_server"` GitHub ConfigOAuthGitHub `json:"github"` @@ -140,18 +146,81 @@ func (c *DefaultClient) PutSiteConfigExtensionMarketplace(ctx context.Context, r // ConfigWorkspaces is the site configuration for workspace attributes. type ConfigWorkspaces struct { - GPUVendor string `json:"gpu_vendor,omitempty" valid:"in(nvidia|amd)"` - EnableContainerVMs bool `json:"enable_container_vms,omitempty"` - EnableWorkspacesAsCode bool `json:"enable_workspaces_as_code,omitempty"` - EnableP2P bool `json:"enable_p2p,omitempty"` + GPUVendor string `json:"gpu_vendor"` + EnableContainerVMs bool `json:"enable_container_vms"` + EnableWorkspacesAsCode bool `json:"enable_workspaces_as_code"` } // SiteConfigWorkspaces fetches the workspace configuration. func (c *DefaultClient) SiteConfigWorkspaces(ctx context.Context) (*ConfigWorkspaces, error) { var conf ConfigWorkspaces - // TODO: use the `/api/v0/workspaces/config route once we migrate from using general config - if err := c.requestBody(ctx, http.MethodGet, "/api/private/config", nil, &conf); err != nil { + if err := c.requestBody(ctx, http.MethodGet, "/api/v0/workspaces/config", nil, &conf); err != nil { return nil, err } return &conf, nil } + +// PutSiteConfigWorkspaces sets the workspace configuration. +func (c *DefaultClient) PutSiteConfigWorkspaces(ctx context.Context, req ConfigWorkspaces) error { + return c.requestBody(ctx, http.MethodPut, "/api/v0/workspaces/config", req, nil) +} + +type ConfigDormancy struct { + // UserDormancyThresholdDays is not currently updatable. + // UserDormancyThresholdDays int `json:"user_dormancy_threshold_days"` + UserDeletionThresholdDays int `json:"user_deletion_threshold_days"` +} + +// SiteConfigDormancy fetches the dormancy configuration. +func (c *DefaultClient) SiteConfigDormancy(ctx context.Context) (*ConfigDormancy, error) { + var conf ConfigDormancy + if err := c.requestBody(ctx, http.MethodGet, "/api/private/dormancy/config", nil, &conf); err != nil { + return nil, err + } + return &conf, nil +} + +// PutSiteConfigDormancy sets the dormancy configuration. +func (c *DefaultClient) PutSiteConfigDormancy(ctx context.Context, req ConfigDormancy) error { + return c.requestBody(ctx, http.MethodPut, "/api/private/dormancy/config", req, nil) +} + +type ConfigDevURLAccess struct { + Private bool `json:"private"` + Org bool `json:"org"` + Authed bool `json:"authed"` + Public bool `json:"public"` +} + +// SiteConfigDevURLAccess fetches the DevURL access configuration. +func (c *DefaultClient) SiteConfigDevURLAccess(ctx context.Context) (*ConfigDevURLAccess, error) { + var conf ConfigDevURLAccess + if err := c.requestBody(ctx, http.MethodGet, "/api/private/devurls/config", nil, &conf); err != nil { + return nil, err + } + return &conf, nil +} + +// PutSiteConfigDevURLAccess sets the DevURL access configuration. +func (c *DefaultClient) PutSiteConfigDevURLAccess(ctx context.Context, req ConfigDevURLAccess) error { + return c.requestBody(ctx, http.MethodPut, "/api/private/devurls/config", req, nil) +} + +// ConfigSSHSettings is the site configuration for SSH. +type ConfigSSHSettings struct { + KeygenAlgorithm string `json:"keygen_algorithm"` +} + +// SiteConfigSSHSettings fetches the SSH configuration. +func (c *DefaultClient) SiteConfigSSHSettings(ctx context.Context) (*ConfigSSHSettings, error) { + var conf ConfigSSHSettings + if err := c.requestBody(ctx, http.MethodGet, "/api/private/ssh/config", nil, &conf); err != nil { + return nil, err + } + return &conf, nil +} + +// PutSiteConfigSSHSettings sets the SSH configuration. +func (c *DefaultClient) PutSiteConfigSSHSettings(ctx context.Context, req ConfigSSHSettings) error { + return c.requestBody(ctx, http.MethodPut, "/api/private/ssh/config", req, nil) +} diff --git a/internal/cmd/users_test.go b/internal/cmd/users_test.go index a82f4607..dad57ed9 100644 --- a/internal/cmd/users_test.go +++ b/internal/cmd/users_test.go @@ -24,9 +24,9 @@ func Test_users(t *testing.T) { func assertAdmin(t *testing.T, users []coder.User) { for _, u := range users { - if u.Username == "admin" { + if u.Username == "kyle" { return } } - slogtest.Fatal(t, "did not find admin user", slog.F("users", users)) + slogtest.Fatal(t, "did not find kyle user", slog.F("users", users)) } 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