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

Commit cfdde80

Browse files
committed
Add config sdk methods
1 parent 25ac3c3 commit cfdde80

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

coder-sdk/config.go

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package coder
2+
3+
import (
4+
"context"
5+
"net/http"
6+
)
7+
8+
type AuthProviderType string
9+
10+
// AuthProviderType enum.
11+
const (
12+
AuthProviderBuiltIn AuthProviderType = "built-in"
13+
AuthProviderSAML AuthProviderType = "saml"
14+
AuthProviderOIDC AuthProviderType = "oidc"
15+
)
16+
17+
type ConfigAuth struct {
18+
ProviderType *AuthProviderType `json:"provider_type"`
19+
OIDC *ConfigOIDC `json:"oidc"`
20+
SAML *ConfigSAML `json:"saml"`
21+
}
22+
23+
type ConfigOIDC struct {
24+
ClientID *string `json:"client_id"`
25+
ClientSecret *string `json:"client_secret"`
26+
Issuer *string `json:"issuer"`
27+
}
28+
29+
type ConfigSAML struct {
30+
IdentityProviderMetadataURL *string `json:"idp_metadata_url"`
31+
SignatureAlgorithm *string `json:"signature_algorithm"`
32+
NameIDFormat *string `json:"name_id_format"`
33+
PrivateKey *string `json:"private_key"`
34+
PublicKeyCertificate *string `json:"public_key_certificate"`
35+
}
36+
37+
type ConfigOAuthBitbucketServer struct {
38+
BaseURL string `json:"base_url" diff:"oauth.bitbucket_server.base_url"`
39+
}
40+
41+
type ConfigOAuthGitHub struct {
42+
BaseURL string `json:"base_url"`
43+
ClientID string `json:"client_id"`
44+
ClientSecret string `json:"client_secret"`
45+
}
46+
47+
type ConfigOAuthGitLab struct {
48+
BaseURL string `json:"base_url"`
49+
ClientID string `json:"client_id" `
50+
ClientSecret string `json:"client_secret"`
51+
}
52+
53+
type ConfigOAuth struct {
54+
BitbucketServer ConfigOAuthBitbucketServer `json:"bitbucket_server"`
55+
GitHub ConfigOAuthGitHub `json:"github"`
56+
GitLab ConfigOAuthGitLab `json:"gitlab"`
57+
}
58+
59+
func (c Client) SiteConfigAuth(ctx context.Context) (*ConfigAuth, error) {
60+
var conf ConfigAuth
61+
if err := c.requestBody(ctx, http.MethodGet, "/api/auth/config", nil, &c); err != nil {
62+
return nil, err
63+
}
64+
return &conf, nil
65+
}
66+
67+
func (c Client) PutSiteConfigAuth(ctx context.Context, req ConfigAuth) error {
68+
return c.requestBody(ctx, http.MethodPut, "/api/auth/config", req, nil)
69+
}
70+
71+
func (c Client) SiteConfigOAuth(ctx context.Context) (*ConfigOAuth, error) {
72+
var conf ConfigOAuth
73+
if err := c.requestBody(ctx, http.MethodGet, "/api/oauth/config", nil, &conf); err != nil {
74+
return nil, err
75+
}
76+
return &conf, nil
77+
}
78+
79+
func (c Client) PutSiteConfigOAuth(ctx context.Context, req ConfigOAuth) error {
80+
return c.requestBody(ctx, http.MethodPut, "/api/oauth/config", req, nil)
81+
}
82+
83+
type configSetupMode struct {
84+
SetupMode bool `json:"setup_mode"`
85+
}
86+
87+
func (c Client) SiteSetupModeEnabled(ctx context.Context) (bool, error) {
88+
var conf configSetupMode
89+
if err := c.requestBody(ctx, http.MethodGet, "/api/config/setup-mode", nil, &conf); err != nil {
90+
return false, nil
91+
}
92+
return conf.SetupMode, nil
93+
}
94+
95+
type ExtensionMarketplaceType string
96+
97+
// ExtensionMarketplaceType enum.
98+
const (
99+
ExtensionMarketplaceInternal ExtensionMarketplaceType = "internal"
100+
ExtensionMarketplaceCustom ExtensionMarketplaceType = "custom"
101+
ExtensionMarketplacePublic ExtensionMarketplaceType = "public"
102+
)
103+
104+
const MarketplaceExtensionPublicURL = "https://extensions.coder.com/api"
105+
106+
type ConfigExtensionMarketplace struct {
107+
URL string `json:"url"`
108+
Type ExtensionMarketplaceType `json:"type"`
109+
}
110+
111+
func (c Client) SiteConfigExtensionMarketplace(ctx context.Context) (*ConfigExtensionMarketplace, error) {
112+
var conf ConfigExtensionMarketplace
113+
if err := c.requestBody(ctx, http.MethodGet, "/api/extensions/config", nil, &conf); err != nil {
114+
return nil, err
115+
}
116+
return &conf, nil
117+
}
118+
119+
func (c Client) PutSiteConfigExtensionMarketplace(ctx context.Context, req ConfigExtensionMarketplace) error {
120+
return c.requestBody(ctx, http.MethodGet, "/api/extensions/config", req, nil)
121+
}

coder-sdk/users.go

+4
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,7 @@ type CreateUserReq struct {
125125
func (c Client) CreateUser(ctx context.Context, req CreateUserReq) error {
126126
return c.requestBody(ctx, http.MethodPost, "/api/users", req, nil)
127127
}
128+
129+
func (c Client) DeleteUser(ctx context.Context, userID string) error {
130+
return c.requestBody(ctx, http.MethodDelete, "/api/users/"+userID, nil, nil)
131+
}

0 commit comments

Comments
 (0)