Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVPROD-10531 add redact keys to admin page #8581

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions config_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package evergreen
import (
"context"

"github.com/mongodb/anser/bsonutil"
"github.com/mongodb/grip"
"github.com/mongodb/grip/level"
"github.com/mongodb/grip/send"
Expand All @@ -18,6 +19,14 @@ type LoggerConfig struct {
RedactKeys []string `bson:"redact_keys" json:"redact_keys" yaml:"redact_keys"`
}

var (
bufferKey = bsonutil.MustHaveTag(LoggerConfig{}, "Buffer")
defaultLevelKey = bsonutil.MustHaveTag(LoggerConfig{}, "DefaultLevel")
thresholdLevelKey = bsonutil.MustHaveTag(LoggerConfig{}, "ThresholdLevel")
logkeeperURLKey = bsonutil.MustHaveTag(LoggerConfig{}, "LogkeeperURL")
redactKeysKey = bsonutil.MustHaveTag(LoggerConfig{}, "RedactKeys")
)

func (c LoggerConfig) Info() send.LevelInfo {
return send.LevelInfo{
Default: level.FromString(c.DefaultLevel),
Expand All @@ -34,10 +43,11 @@ func (c *LoggerConfig) Get(ctx context.Context) error {
func (c *LoggerConfig) Set(ctx context.Context) error {
return errors.Wrapf(setConfigSection(ctx, c.SectionId(), bson.M{
"$set": bson.M{
"buffer": c.Buffer,
"default_level": c.DefaultLevel,
"threshold_level": c.ThresholdLevel,
"logkeeper_url": c.LogkeeperURL,
bufferKey: c.Buffer,
defaultLevelKey: c.DefaultLevel,
thresholdLevelKey: c.ThresholdLevel,
logkeeperURLKey: c.LogkeeperURL,
redactKeysKey: c.RedactKeys,
}}), "updating config section '%s'", c.SectionId(),
)
}
Expand Down
18 changes: 18 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,24 @@ func (s *AdminSuite) TestNotifyConfig() {
s.Equal(config, settings.Notify)
}

func (s *AdminSuite) TestLoggerConfig() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

config := LoggerConfig{
RedactKeys: []string{
"secret",
"github token",
},
}
err := config.Set(ctx)
s.NoError(err)
settings, err := GetConfig(ctx)
s.NoError(err)
s.NotNil(settings)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: require

s.Equal(config, settings.LoggerConfig)
}

func (s *AdminSuite) TestContainerPoolsConfig() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
3 changes: 3 additions & 0 deletions rest/model/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,7 @@ type APILoggerConfig struct {
DefaultLevel *string `json:"default_level"`
ThresholdLevel *string `json:"threshold_level"`
LogkeeperURL *string `json:"logkeeper_url"`
RedactKeys []*string `json:"redact_keys"`
}

func (a *APILoggerConfig) BuildFromService(h interface{}) error {
Expand All @@ -1090,6 +1091,7 @@ func (a *APILoggerConfig) BuildFromService(h interface{}) error {
a.DefaultLevel = utility.ToStringPtr(v.DefaultLevel)
a.ThresholdLevel = utility.ToStringPtr(v.ThresholdLevel)
a.LogkeeperURL = utility.ToStringPtr(v.LogkeeperURL)
a.RedactKeys = utility.ToStringPtrSlice(v.RedactKeys)
a.Buffer = &APILogBuffering{}
if err := a.Buffer.BuildFromService(v.Buffer); err != nil {
return err
Expand All @@ -1105,6 +1107,7 @@ func (a *APILoggerConfig) ToService() (interface{}, error) {
DefaultLevel: utility.FromStringPtr(a.DefaultLevel),
ThresholdLevel: utility.FromStringPtr(a.ThresholdLevel),
LogkeeperURL: utility.FromStringPtr(a.LogkeeperURL),
RedactKeys: utility.FromStringPtrSlice(a.RedactKeys),
}
i, err := a.Buffer.ToService()
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions service/templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -1738,9 +1738,15 @@ <h2 class="modal-title">[[modalTitle]]</h2>
<input type="number" ng-disabled="!Settings.logger_config.buffer.use_async" ng-model="Settings.logger_config.buffer.incoming_buffer_factor">
</md-input-container>
<md-input-container class="control" style="width:45%;">
<label>Redact Keys</label>
<textarea ng-model="Settings.logger_config.redact_keys" ng-list="&#10;"
ng-trim="false" rows="3" md-select-on-focus></textarea>
</md-input-container>
<md-input-container class="control" style="width:45%; margin-left:50px;">
<label>Logkeeper URL</label>
<input type="text" ng-model="Settings.logger_config.logkeeper_url">
</md-input-container>

</md-card-content>
</md-card>
</section>
Expand Down
Loading