Skip to content

Commit

Permalink
support redacted config in dashboard (#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaoz authored Feb 25, 2023
1 parent 61c72ff commit bcc601b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type MasterConfig struct {
DashboardUserName string `mapstructure:"dashboard_user_name"` // dashboard user name
DashboardPassword string `mapstructure:"dashboard_password"` // dashboard password
DashboardAuthServer string `mapstructure:"dashboard_auth_server"` // dashboard auth server
DashboardRedacted bool `mapstructure:"dashboard_redacted"`
AdminAPIKey string `mapstructure:"admin_api_key"`
}

Expand Down Expand Up @@ -540,6 +541,7 @@ func LoadConfig(path string, oneModel bool) (*Config, error) {
{"master.dashboard_user_name", "GORSE_DASHBOARD_USER_NAME"},
{"master.dashboard_password", "GORSE_DASHBOARD_PASSWORD"},
{"master.dashboard_auth_server", "GORSE_DASHBOARD_AUTH_SERVER"},
{"master.dashboard_redacted", "GORSE_DASHBOARD_REDACTED"},
{"master.admin_api_key", "GORSE_ADMIN_API_KEY"},
{"server.api_key", "GORSE_SERVER_API_KEY"},
}
Expand Down
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func TestBindEnv(t *testing.T) {
{"GORSE_DASHBOARD_USER_NAME", "user_name"},
{"GORSE_DASHBOARD_PASSWORD", "password"},
{"GORSE_DASHBOARD_AUTH_SERVER", "http://127.0.0.1:8888"},
{"GORSE_DASHBOARD_REDACTED", "true"},
{"GORSE_ADMIN_API_KEY", "<admin_api_key>"},
{"GORSE_SERVER_API_KEY", "<server_api_key>"},
}
Expand All @@ -197,6 +198,7 @@ func TestBindEnv(t *testing.T) {
assert.Equal(t, "user_name", config.Master.DashboardUserName)
assert.Equal(t, "password", config.Master.DashboardPassword)
assert.Equal(t, "http://127.0.0.1:8888", config.Master.DashboardAuthServer)
assert.Equal(t, true, config.Master.DashboardRedacted)
assert.Equal(t, "<admin_api_key>", config.Master.AdminAPIKey)
assert.Equal(t, "<server_api_key>", config.Server.APIKey)

Expand Down
2 changes: 1 addition & 1 deletion master/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (m *Master) getConfig(_ *restful.Request, response *restful.Response) {
server.InternalServerError(response, err)
return
}
if m.managedMode {
if m.Config.Master.DashboardRedacted {
delete(configMap, "database")
}
server.Ok(response, formatConfig(configMap))
Expand Down
8 changes: 4 additions & 4 deletions master/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,16 +829,16 @@ func TestMaster_GetConfig(t *testing.T) {
Body(marshal(t, formatConfig(convertToMapStructure(t, s.Config)))).
End()

s.managedMode = true
managedConfig := formatConfig(convertToMapStructure(t, s.Config))
delete(managedConfig, "database")
s.Config.Master.DashboardRedacted = true
redactedConfig := formatConfig(convertToMapStructure(t, s.Config))
delete(redactedConfig, "database")
apitest.New().
Handler(s.handler).
Get("/api/dashboard/config").
Header("Cookie", cookie).
Expect(t).
Status(http.StatusOK).
Body(marshal(t, managedConfig)).
Body(marshal(t, redactedConfig)).
End()
}

Expand Down

0 comments on commit bcc601b

Please sign in to comment.