|
| 1 | +package codersdk |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + "net/http" |
| 7 | + "time" |
| 8 | + |
| 9 | + "golang.org/x/xerrors" |
| 10 | +) |
| 11 | + |
| 12 | +// DeploymentConfig is the central configuration for the coder server. |
| 13 | +// Secret values should specify `json:"-"` to prevent them from being returned by the API. |
| 14 | +type DeploymentConfig struct { |
| 15 | + AccessURL DeploymentConfigField[string] `json:"access_url"` |
| 16 | + WildcardAccessURL DeploymentConfigField[string] `json:"wildcard_access_url"` |
| 17 | + Address DeploymentConfigField[string] `json:"address"` |
| 18 | + AutobuildPollInterval DeploymentConfigField[time.Duration] `json:"autobuild_poll_interval"` |
| 19 | + DERPServerEnable DeploymentConfigField[bool] `json:"derp_server_enabled"` |
| 20 | + DERPServerRegionID DeploymentConfigField[int] `json:"derp_server_region_id"` |
| 21 | + DERPServerRegionCode DeploymentConfigField[string] `json:"derp_server_region_code"` |
| 22 | + DERPServerRegionName DeploymentConfigField[string] `json:"derp_server_region_name"` |
| 23 | + DERPServerSTUNAddresses DeploymentConfigField[[]string] `json:"derp_server_stun_address"` |
| 24 | + DERPServerRelayAddress DeploymentConfigField[string] `json:"derp_server_relay_address"` |
| 25 | + DERPConfigURL DeploymentConfigField[string] `json:"derp_config_url"` |
| 26 | + DERPConfigPath DeploymentConfigField[string] `json:"derp_config_path"` |
| 27 | + PrometheusEnable DeploymentConfigField[bool] `json:"prometheus_enabled"` |
| 28 | + PrometheusAddress DeploymentConfigField[string] `json:"prometheus_address"` |
| 29 | + PprofEnable DeploymentConfigField[bool] `json:"pprof_enabled"` |
| 30 | + PprofAddress DeploymentConfigField[string] `json:"pprof_address"` |
| 31 | + CacheDir DeploymentConfigField[string] `json:"cache_dir"` |
| 32 | + InMemoryDatabase DeploymentConfigField[bool] `json:"in_memory_database"` |
| 33 | + ProvisionerDaemonCount DeploymentConfigField[int] `json:"provisioner_daemon_count"` |
| 34 | + PostgresURL DeploymentConfigField[string] `json:"-"` |
| 35 | + OAuth2GithubClientID DeploymentConfigField[string] `json:"oauth2_github_client_id"` |
| 36 | + OAuth2GithubClientSecret DeploymentConfigField[string] `json:"-"` |
| 37 | + OAuth2GithubAllowedOrganizations DeploymentConfigField[[]string] `json:"oauth2_github_allowed_organizations"` |
| 38 | + OAuth2GithubAllowedTeams DeploymentConfigField[[]string] `json:"oauth2_github_allowed_teams"` |
| 39 | + OAuth2GithubAllowSignups DeploymentConfigField[bool] `json:"oauth2_github_allow_signups"` |
| 40 | + OAuth2GithubEnterpriseBaseURL DeploymentConfigField[string] `json:"oauth2_github_enterprise_base_url"` |
| 41 | + OIDCAllowSignups DeploymentConfigField[bool] `json:"oidc_allow_signups"` |
| 42 | + OIDCClientID DeploymentConfigField[string] `json:"oidc_client_id"` |
| 43 | + OIDCClientSecret DeploymentConfigField[string] `json:"-"` |
| 44 | + OIDCEmailDomain DeploymentConfigField[string] `json:"oidc_email_domain"` |
| 45 | + OIDCIssuerURL DeploymentConfigField[string] `json:"oidc_issuer_url"` |
| 46 | + OIDCScopes DeploymentConfigField[[]string] `json:"oidc_scopes"` |
| 47 | + TelemetryEnable DeploymentConfigField[bool] `json:"telemetry_enable"` |
| 48 | + TelemetryTraceEnable DeploymentConfigField[bool] `json:"telemetry_trace_enable"` |
| 49 | + TelemetryURL DeploymentConfigField[string] `json:"telemetry_url"` |
| 50 | + TLSEnable DeploymentConfigField[bool] `json:"tls_enable"` |
| 51 | + TLSCertFiles DeploymentConfigField[[]string] `json:"tls_cert_files"` |
| 52 | + TLSClientCAFile DeploymentConfigField[string] `json:"tls_client_ca_file"` |
| 53 | + TLSClientAuth DeploymentConfigField[string] `json:"tls_client_auth"` |
| 54 | + TLSKeyFiles DeploymentConfigField[[]string] `json:"tls_key_files"` |
| 55 | + TLSMinVersion DeploymentConfigField[string] `json:"tls_min_version"` |
| 56 | + TraceEnable DeploymentConfigField[bool] `json:"trace_enable"` |
| 57 | + SecureAuthCookie DeploymentConfigField[bool] `json:"secure_auth_cookie"` |
| 58 | + SSHKeygenAlgorithm DeploymentConfigField[string] `json:"ssh_keygen_algorithm"` |
| 59 | + AutoImportTemplates DeploymentConfigField[[]string] `json:"auto_import_templates"` |
| 60 | + MetricsCacheRefreshInterval DeploymentConfigField[time.Duration] `json:"metrics_cache_refresh_interval"` |
| 61 | + AgentStatRefreshInterval DeploymentConfigField[time.Duration] `json:"agent_stat_refresh_interval"` |
| 62 | + Verbose DeploymentConfigField[bool] `json:"verbose"` |
| 63 | + AuditLogging DeploymentConfigField[bool] `json:"audit_logging"` |
| 64 | + BrowserOnly DeploymentConfigField[bool] `json:"browser_only"` |
| 65 | + SCIMAuthHeader DeploymentConfigField[string] `json:"-"` |
| 66 | + UserWorkspaceQuota DeploymentConfigField[int] `json:"user_workspace_quota"` |
| 67 | +} |
| 68 | + |
| 69 | +type Flaggable interface { |
| 70 | + string | bool | int | time.Duration | []string |
| 71 | +} |
| 72 | + |
| 73 | +type DeploymentConfigField[T Flaggable] struct { |
| 74 | + Key string |
| 75 | + Name string |
| 76 | + Usage string |
| 77 | + Flag string |
| 78 | + Shorthand string |
| 79 | + Enterprise bool |
| 80 | + Hidden bool |
| 81 | + Value T |
| 82 | +} |
| 83 | + |
| 84 | +// DeploymentConfig returns the deployment config for the coder server. |
| 85 | +func (c *Client) DeploymentConfig(ctx context.Context) (DeploymentConfig, error) { |
| 86 | + res, err := c.Request(ctx, http.MethodGet, "/api/v2/config/deployment", nil) |
| 87 | + if err != nil { |
| 88 | + return DeploymentConfig{}, xerrors.Errorf("execute request: %w", err) |
| 89 | + } |
| 90 | + defer res.Body.Close() |
| 91 | + |
| 92 | + if res.StatusCode != http.StatusOK { |
| 93 | + return DeploymentConfig{}, readBodyAsError(res) |
| 94 | + } |
| 95 | + |
| 96 | + var df DeploymentConfig |
| 97 | + return df, json.NewDecoder(res.Body).Decode(&df) |
| 98 | +} |
0 commit comments