- Notifications
You must be signed in to change notification settings - Fork928
feat: deployment flags#4426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
03a77ae
091b754
3d02a4f
815f678
972c0ba
7e73583
2889c2d
9343f84
4780a5a
ea8c73f
bfdf859
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Uh oh!
There was an error while loading.Please reload this page.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package coderd | ||
import ( | ||
"net/http" | ||
"github.com/coder/coder/cli/deployment" | ||
"github.com/coder/coder/coderd/httpapi" | ||
"github.com/coder/coder/coderd/rbac" | ||
) | ||
func (api *API) deploymentFlags(rw http.ResponseWriter, r *http.Request) { | ||
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceDeploymentFlags) { | ||
httpapi.Forbidden(rw) | ||
return | ||
} | ||
httpapi.Write(r.Context(), rw, http.StatusOK, deployment.RemoveSensitiveValues(*api.DeploymentFlags)) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package coderd_test | ||
import ( | ||
"context" | ||
"testing" | ||
"github.com/stretchr/testify/require" | ||
"github.com/coder/coder/cli/deployment" | ||
"github.com/coder/coder/coderd/coderdtest" | ||
"github.com/coder/coder/testutil" | ||
) | ||
const ( | ||
secretValue = "********" | ||
) | ||
func TestDeploymentFlagSecrets(t *testing.T) { | ||
t.Parallel() | ||
hi := "hi" | ||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) | ||
defer cancel() | ||
df := deployment.Flags() | ||
// check if copy works for non-secret values | ||
df.AccessURL.Value = hi | ||
// check if secrets are removed | ||
df.OAuth2GithubClientSecret.Value = hi | ||
df.OIDCClientSecret.Value = hi | ||
df.PostgresURL.Value = hi | ||
df.SCIMAuthHeader.Value = hi | ||
client := coderdtest.New(t, &coderdtest.Options{ | ||
DeploymentFlags: &df, | ||
}) | ||
_ = coderdtest.CreateFirstUser(t, client) | ||
scrubbed, err := client.DeploymentFlags(ctx) | ||
require.NoError(t, err) | ||
// ensure df is unchanged | ||
require.EqualValues(t, hi, df.OAuth2GithubClientSecret.Value) | ||
// ensure normal values pass through | ||
require.EqualValues(t, hi, scrubbed.AccessURL.Value) | ||
// ensure secrets are removed | ||
require.EqualValues(t, secretValue, scrubbed.OAuth2GithubClientSecret.Value) | ||
require.EqualValues(t, secretValue, scrubbed.OIDCClientSecret.Value) | ||
require.EqualValues(t, secretValue, scrubbed.PostgresURL.Value) | ||
require.EqualValues(t, secretValue, scrubbed.SCIMAuthHeader.Value) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package codersdk | ||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"time" | ||
"golang.org/x/xerrors" | ||
) | ||
type DeploymentFlags struct { | ||
AccessURL StringFlag `json:"access_url"` | ||
WildcardAccessURL StringFlag `json:"wildcard_access_url"` | ||
Address StringFlag `json:"address"` | ||
AutobuildPollInterval DurationFlag `json:"autobuild_poll_interval"` | ||
DerpServerEnable BoolFlag `json:"derp_server_enabled"` | ||
DerpServerRegionID IntFlag `json:"derp_server_region_id"` | ||
DerpServerRegionCode StringFlag `json:"derp_server_region_code"` | ||
DerpServerRegionName StringFlag `json:"derp_server_region_name"` | ||
DerpServerSTUNAddresses StringArrayFlag `json:"derp_server_stun_address"` | ||
DerpConfigURL StringFlag `json:"derp_config_url"` | ||
DerpConfigPath StringFlag `json:"derp_config_path"` | ||
PromEnabled BoolFlag `json:"prom_enabled"` | ||
PromAddress StringFlag `json:"prom_address"` | ||
PprofEnabled BoolFlag `json:"pprof_enabled"` | ||
PprofAddress StringFlag `json:"pprof_address"` | ||
CacheDir StringFlag `json:"cache_dir"` | ||
InMemoryDatabase BoolFlag `json:"in_memory_database"` | ||
ProvisionerDaemonCount IntFlag `json:"provisioner_daemon_count"` | ||
PostgresURL StringFlag `json:"postgres_url"` | ||
OAuth2GithubClientID StringFlag `json:"oauth2_github_client_id"` | ||
OAuth2GithubClientSecret StringFlag `json:"oauth2_github_client_secret"` | ||
OAuth2GithubAllowedOrganizations StringArrayFlag `json:"oauth2_github_allowed_organizations"` | ||
OAuth2GithubAllowedTeams StringArrayFlag `json:"oauth2_github_allowed_teams"` | ||
OAuth2GithubAllowSignups BoolFlag `json:"oauth2_github_allow_signups"` | ||
OAuth2GithubEnterpriseBaseURL StringFlag `json:"oauth2_github_enterprise_base_url"` | ||
OIDCAllowSignups BoolFlag `json:"oidc_allow_signups"` | ||
OIDCClientID StringFlag `json:"oidc_client_id"` | ||
OIDCClientSecret StringFlag `json:"oidc_cliet_secret"` | ||
OIDCEmailDomain StringFlag `json:"oidc_email_domain"` | ||
OIDCIssuerURL StringFlag `json:"oidc_issuer_url"` | ||
OIDCScopes StringArrayFlag `json:"oidc_scopes"` | ||
TelemetryEnable BoolFlag `json:"telemetry_enable"` | ||
TelemetryTraceEnable BoolFlag `json:"telemetry_trace_enable"` | ||
TelemetryURL StringFlag `json:"telemetry_url"` | ||
TLSEnable BoolFlag `json:"tls_enable"` | ||
TLSCertFiles StringArrayFlag `json:"tls_cert_files"` | ||
TLSClientCAFile StringFlag `json:"tls_client_ca_file"` | ||
TLSClientAuth StringFlag `json:"tls_client_auth"` | ||
TLSKeyFiles StringArrayFlag `json:"tls_key_tiles"` | ||
TLSMinVersion StringFlag `json:"tls_min_version"` | ||
TraceEnable BoolFlag `json:"trace_enable"` | ||
SecureAuthCookie BoolFlag `json:"secure_auth_cookie"` | ||
SSHKeygenAlgorithm StringFlag `json:"ssh_keygen_algorithm"` | ||
AutoImportTemplates StringArrayFlag `json:"auto_import_templates"` | ||
MetricsCacheRefreshInterval DurationFlag `json:"metrics_cache_refresh_interval"` | ||
AgentStatRefreshInterval DurationFlag `json:"agent_stat_refresh_interval"` | ||
Verbose BoolFlag `json:"verbose"` | ||
AuditLogging BoolFlag `json:"audit_logging"` | ||
BrowserOnly BoolFlag `json:"browser_only"` | ||
SCIMAuthHeader StringFlag `json:"scim_auth_header"` | ||
UserWorkspaceQuota IntFlag `json:"user_workspace_quota"` | ||
} | ||
type StringFlag struct { | ||
Name string `json:"name"` | ||
Flag string `json:"flag"` | ||
EnvVar string `json:"env_var"` | ||
Shorthand string `json:"shorthand"` | ||
Description string `json:"description"` | ||
Enterprise bool `json:"enterprise"` | ||
Secret bool `json:"secret"` | ||
Default string `json:"default"` | ||
Value string `json:"value"` | ||
} | ||
type BoolFlag struct { | ||
Name string `json:"name"` | ||
Flag string `json:"flag"` | ||
EnvVar string `json:"env_var"` | ||
Shorthand string `json:"shorthand"` | ||
Description string `json:"description"` | ||
Enterprise bool `json:"enterprise"` | ||
Default bool `json:"default"` | ||
Value bool `json:"value"` | ||
} | ||
f0ssel marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
type IntFlag struct { | ||
Name string `json:"name"` | ||
Flag string `json:"flag"` | ||
EnvVar string `json:"env_var"` | ||
Shorthand string `json:"shorthand"` | ||
Description string `json:"description"` | ||
Enterprise bool `json:"enterprise"` | ||
Default int `json:"default"` | ||
Value int `json:"value"` | ||
} | ||
type DurationFlag struct { | ||
Name string `json:"name"` | ||
Flag string `json:"flag"` | ||
EnvVar string `json:"env_var"` | ||
Shorthand string `json:"shorthand"` | ||
Description string `json:"description"` | ||
Enterprise bool `json:"enterprise"` | ||
Default time.Duration `json:"default"` | ||
Value time.Duration `json:"value"` | ||
} | ||
type StringArrayFlag struct { | ||
Name string `json:"name"` | ||
Flag string `json:"flag"` | ||
EnvVar string `json:"env_var"` | ||
Shorthand string `json:"shorthand"` | ||
Description string `json:"description"` | ||
Enterprise bool `json:"enterprise"` | ||
Default []string `json:"default"` | ||
Value []string `json:"value"` | ||
} | ||
// DeploymentFlags returns the deployment level flags for the coder server. | ||
func (c *Client) DeploymentFlags(ctx context.Context) (DeploymentFlags, error) { | ||
res, err := c.Request(ctx, http.MethodGet, "/api/v2/flags/deployment", nil) | ||
if err != nil { | ||
return DeploymentFlags{}, xerrors.Errorf("execute request: %w", err) | ||
} | ||
defer res.Body.Close() | ||
if res.StatusCode != http.StatusOK { | ||
return DeploymentFlags{}, readBodyAsError(res) | ||
} | ||
var df DeploymentFlags | ||
return df, json.NewDecoder(res.Body).Decode(&df) | ||
} |
Uh oh!
There was an error while loading.Please reload this page.