Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commit4117dc8

Browse files
authored
feat: add additional config methods to coder sdk (#419)
1 parent59cae56 commit4117dc8

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 ofcredential, 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
Tokenstring
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
Emailstring
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
Passwordstring
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
AuthProviderOIDCAuthProviderType="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
typeConfigAuthstruct {
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
typeConfigOIDCstruct {
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
typeConfigOAuthBitbucketServerstruct {
4346
BaseURLstring`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
typeConfigOAuthGitHubstruct {
4852
BaseURLstring`json:"base_url"`
4953
ClientIDstring`json:"client_id"`
5054
ClientSecretstring`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
typeConfigOAuthGitLabstruct {
5560
BaseURLstring`json:"base_url"`
5661
ClientIDstring`json:"client_id" `
5762
ClientSecretstring`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
typeConfigOAuthstruct {
6268
BitbucketServerConfigOAuthBitbucketServer`json:"bitbucket_server"`
6369
GitHubConfigOAuthGitHub`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
typeConfigWorkspacesstruct {
143-
GPUVendorstring`json:"gpu_vendor,omitempty" valid:"in(nvidia|amd)"`
144-
EnableContainerVMsbool`json:"enable_container_vms,omitempty"`
145-
EnableWorkspacesAsCodebool`json:"enable_workspaces_as_code,omitempty"`
146-
EnableP2Pbool`json:"enable_p2p,omitempty"`
149+
GPUVendorstring`json:"gpu_vendor"`
150+
EnableContainerVMsbool`json:"enable_container_vms"`
151+
EnableWorkspacesAsCodebool`json:"enable_workspaces_as_code"`
147152
}
148153

149154
// SiteConfigWorkspaces fetches the workspace configuration.
150155
func (c*DefaultClient)SiteConfigWorkspaces(ctx context.Context) (*ConfigWorkspaces,error) {
151156
varconfConfigWorkspaces
152-
// TODO: use the `/api/v0/workspaces/config route once we migrate from using general config
153-
iferr:=c.requestBody(ctx,http.MethodGet,"/api/private/config",nil,&conf);err!=nil {
157+
iferr:=c.requestBody(ctx,http.MethodGet,"/api/v0/workspaces/config",nil,&conf);err!=nil {
154158
returnnil,err
155159
}
156160
return&conf,nil
157161
}
162+
163+
// PutSiteConfigWorkspaces sets the workspace configuration.
164+
func (c*DefaultClient)PutSiteConfigWorkspaces(ctx context.Context,reqConfigWorkspaces)error {
165+
returnc.requestBody(ctx,http.MethodPut,"/api/v0/workspaces/config",req,nil)
166+
}
167+
168+
typeConfigDormancystruct {
169+
// UserDormancyThresholdDays is not currently updatable.
170+
// UserDormancyThresholdDays int `json:"user_dormancy_threshold_days"`
171+
UserDeletionThresholdDaysint`json:"user_deletion_threshold_days"`
172+
}
173+
174+
// SiteConfigDormancy fetches the dormancy configuration.
175+
func (c*DefaultClient)SiteConfigDormancy(ctx context.Context) (*ConfigDormancy,error) {
176+
varconfConfigDormancy
177+
iferr:=c.requestBody(ctx,http.MethodGet,"/api/private/dormancy/config",nil,&conf);err!=nil {
178+
returnnil,err
179+
}
180+
return&conf,nil
181+
}
182+
183+
// PutSiteConfigDormancy sets the dormancy configuration.
184+
func (c*DefaultClient)PutSiteConfigDormancy(ctx context.Context,reqConfigDormancy)error {
185+
returnc.requestBody(ctx,http.MethodPut,"/api/private/dormancy/config",req,nil)
186+
}
187+
188+
typeConfigDevURLAccessstruct {
189+
Privatebool`json:"private"`
190+
Orgbool`json:"org"`
191+
Authedbool`json:"authed"`
192+
Publicbool`json:"public"`
193+
}
194+
195+
// SiteConfigDevURLAccess fetches the DevURL access configuration.
196+
func (c*DefaultClient)SiteConfigDevURLAccess(ctx context.Context) (*ConfigDevURLAccess,error) {
197+
varconfConfigDevURLAccess
198+
iferr:=c.requestBody(ctx,http.MethodGet,"/api/private/devurls/config",nil,&conf);err!=nil {
199+
returnnil,err
200+
}
201+
return&conf,nil
202+
}
203+
204+
// PutSiteConfigDevURLAccess sets the DevURL access configuration.
205+
func (c*DefaultClient)PutSiteConfigDevURLAccess(ctx context.Context,reqConfigDevURLAccess)error {
206+
returnc.requestBody(ctx,http.MethodPut,"/api/private/devurls/config",req,nil)
207+
}
208+
209+
// ConfigSSHSettings is the site configuration for SSH.
210+
typeConfigSSHSettingsstruct {
211+
KeygenAlgorithmstring`json:"keygen_algorithm"`
212+
}
213+
214+
// SiteConfigSSHSettings fetches the SSH configuration.
215+
func (c*DefaultClient)SiteConfigSSHSettings(ctx context.Context) (*ConfigSSHSettings,error) {
216+
varconfConfigSSHSettings
217+
iferr:=c.requestBody(ctx,http.MethodGet,"/api/private/ssh/config",nil,&conf);err!=nil {
218+
returnnil,err
219+
}
220+
return&conf,nil
221+
}
222+
223+
// PutSiteConfigSSHSettings sets the SSH configuration.
224+
func (c*DefaultClient)PutSiteConfigSSHSettings(ctx context.Context,reqConfigSSHSettings)error {
225+
returnc.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
funcassertAdmin(t*testing.T,users []coder.User) {
2626
for_,u:=rangeusers {
27-
ifu.Username=="admin" {
27+
ifu.Username=="kyle" {
2828
return
2929
}
3030
}
31-
slogtest.Fatal(t,"did not findadmin user",slog.F("users",users))
31+
slogtest.Fatal(t,"did not findkyle user",slog.F("users",users))
3232
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp