mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
This reverts commit 372fb1f345
.
This commit is contained in:
@ -92,7 +92,7 @@ type Options struct {
|
||||
MetricsCacheRefreshInterval time.Duration
|
||||
AgentStatsRefreshInterval time.Duration
|
||||
Experimental bool
|
||||
DeploymentConfig *codersdk.DeploymentConfig
|
||||
DeploymentFlags *codersdk.DeploymentFlags
|
||||
}
|
||||
|
||||
// New constructs a Coder API handler.
|
||||
@ -286,9 +286,9 @@ func New(options *Options) *API {
|
||||
})
|
||||
})
|
||||
})
|
||||
r.Route("/config", func(r chi.Router) {
|
||||
r.Route("/flags", func(r chi.Router) {
|
||||
r.Use(apiKeyMiddleware)
|
||||
r.Get("/deployment", api.deploymentConfig)
|
||||
r.Get("/deployment", api.deploymentFlags)
|
||||
})
|
||||
r.Route("/audit", func(r chi.Router) {
|
||||
r.Use(
|
||||
|
@ -91,7 +91,7 @@ type Options struct {
|
||||
IncludeProvisionerDaemon bool
|
||||
MetricsCacheRefreshInterval time.Duration
|
||||
AgentStatsRefreshInterval time.Duration
|
||||
DeploymentConfig *codersdk.DeploymentConfig
|
||||
DeploymentFlags *codersdk.DeploymentFlags
|
||||
|
||||
// Overriding the database is heavily discouraged.
|
||||
// It should only be used in cases where multiple Coder
|
||||
@ -268,7 +268,7 @@ func NewOptions(t *testing.T, options *Options) (func(http.Handler), context.Can
|
||||
AutoImportTemplates: options.AutoImportTemplates,
|
||||
MetricsCacheRefreshInterval: options.MetricsCacheRefreshInterval,
|
||||
AgentStatsRefreshInterval: options.AgentStatsRefreshInterval,
|
||||
DeploymentConfig: options.DeploymentConfig,
|
||||
DeploymentFlags: options.DeploymentFlags,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
package coderd
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/coder/coder/coderd/httpapi"
|
||||
"github.com/coder/coder/coderd/rbac"
|
||||
)
|
||||
|
||||
func (api *API) deploymentConfig(rw http.ResponseWriter, r *http.Request) {
|
||||
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceDeploymentConfig) {
|
||||
httpapi.Forbidden(rw)
|
||||
return
|
||||
}
|
||||
|
||||
httpapi.Write(r.Context(), rw, http.StatusOK, api.DeploymentConfig)
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package coderd_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/cli/config"
|
||||
"github.com/coder/coder/cli/deployment"
|
||||
"github.com/coder/coder/coderd/coderdtest"
|
||||
"github.com/coder/coder/testutil"
|
||||
)
|
||||
|
||||
func TestDeploymentConfig(t *testing.T) {
|
||||
t.Parallel()
|
||||
hi := "hi"
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
|
||||
defer cancel()
|
||||
vip := deployment.NewViper()
|
||||
fs := pflag.NewFlagSet("test", pflag.ContinueOnError)
|
||||
fs.String(config.FlagName, hi, "usage")
|
||||
cfg, err := deployment.Config(fs, vip)
|
||||
require.NoError(t, err)
|
||||
// values should be returned
|
||||
cfg.AccessURL.Value = hi
|
||||
// values should not be returned
|
||||
cfg.OAuth2GithubClientSecret.Value = hi
|
||||
cfg.OIDCClientSecret.Value = hi
|
||||
cfg.PostgresURL.Value = hi
|
||||
cfg.SCIMAPIKey.Value = hi
|
||||
|
||||
client := coderdtest.New(t, &coderdtest.Options{
|
||||
DeploymentConfig: &cfg,
|
||||
})
|
||||
_ = coderdtest.CreateFirstUser(t, client)
|
||||
scrubbed, err := client.DeploymentConfig(ctx)
|
||||
require.NoError(t, err)
|
||||
// ensure normal values pass through
|
||||
require.EqualValues(t, hi, scrubbed.AccessURL.Value)
|
||||
// ensure secrets are removed
|
||||
require.Empty(t, scrubbed.OAuth2GithubClientSecret.Value)
|
||||
require.Empty(t, scrubbed.OIDCClientSecret.Value)
|
||||
require.Empty(t, scrubbed.PostgresURL.Value)
|
||||
require.Empty(t, scrubbed.SCIMAPIKey.Value)
|
||||
}
|
18
coderd/flags.go
Normal file
18
coderd/flags.go
Normal file
@ -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))
|
||||
}
|
47
coderd/flags_test.go
Normal file
47
coderd/flags_test.go
Normal file
@ -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)
|
||||
}
|
@ -142,9 +142,9 @@ var (
|
||||
Type: "license",
|
||||
}
|
||||
|
||||
// ResourceDeploymentConfig
|
||||
ResourceDeploymentConfig = Object{
|
||||
Type: "deployment_config",
|
||||
// ResourceDeploymentFlags
|
||||
ResourceDeploymentFlags = Object{
|
||||
Type: "deployment_flags",
|
||||
}
|
||||
|
||||
ResourceReplicas = Object{
|
||||
|
Reference in New Issue
Block a user