Skip to content

Commit

Permalink
chore: improve scrubbing in logs (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch authored Jul 31, 2024
1 parent 1194a9d commit de5be23
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
19 changes: 13 additions & 6 deletions application/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,17 @@ func (c *Config) SetSeverityFilter(severityFilter types.SeverityFilter) bool {

func (c *Config) SetToken(token string) {
c.m.Lock()

oldToken := c.token

// always update the token and auth method in the engine
c.token = token
c.m.Unlock()

_, err := c.TokenAsOAuthToken()
oauthToken, err := c.TokenAsOAuthToken()
isOauthToken := err == nil
conf := c.engine.GetConfiguration()

// propagate token to gaf
if !isOauthToken && conf.GetString(configuration.AUTHENTICATION_TOKEN) != token {
c.Logger().Info().Msg("Setting legacy authentication in GAF")
conf.Set(configuration.AUTHENTICATION_TOKEN, token)
Expand All @@ -492,16 +494,21 @@ func (c *Config) SetToken(token string) {
conf.Set(auth.CONFIG_KEY_OAUTH_TOKEN, token)
}

// ensure scrubbing of new token
if w, ok := c.scrubbingWriter.(frameworkLogging.ScrubbingLogWriter); ok {
w.AddTerm(token, 0)
if isOauthToken {
w.AddTerm(oauthToken.AccessToken, 0)
w.AddTerm(oauthToken.RefreshToken, 0)
}
}

// return if the token hasn't changed
if oldToken == token {
return
}

c.m.Lock()
if w, ok := c.scrubbingWriter.(frameworkLogging.ScrubbingLogWriter); ok {
w.AddTerm(token, 0)
}

for _, channel := range c.tokenChangeChannels {
select {
case channel <- token:
Expand Down
14 changes: 7 additions & 7 deletions application/server/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ func registerNotifier(c *config.Config, srv types.Server) {
switch params := params.(type) {
case types.FolderConfigsParam:
notifier(c, srv, "$/snyk.folderConfigs", params)
logger.Info().Any("folderConfig", params).Msg("sending folderConfig to client")
logger.Debug().Any("folderConfig", params).Msg("sending folderConfig to client")
case types.AuthenticationParams:
notifier(c, srv, "$/snyk.hasAuthenticated", params)
logger.Info().Msg("sending token")
logger.Debug().Msg("sending token")
case types.SnykIsAvailableCli:
notifier(c, srv, "$/snyk.isAvailableCli", params)
logger.Info().Msg("sending cli path")
logger.Debug().Msg("sending cli path")
case sglsp.ShowMessageParams:
notifier(c, srv, "window/showMessage", params)
logger.Info().Interface("message", params).Msg("showing message")
Expand All @@ -108,7 +108,7 @@ func registerNotifier(c *config.Config, srv types.Server) {
if len(params.Diagnostics) > 0 {
source = params.Diagnostics[0].Source
}
logger.Info().
logger.Debug().
Interface("documentURI", params.URI).
Interface("source", source).
Interface("diagnosticCount", len(params.Diagnostics)).
Expand All @@ -130,15 +130,15 @@ func registerNotifier(c *config.Config, srv types.Server) {
logger.Info().Msg("sending show message request to client")
case types.ApplyWorkspaceEditParams:
handleApplyWorkspaceEdit(srv, params, &logger)
logger.Info().
logger.Debug().
Msg("sending apply workspace edit request to client")
case types.CodeLensRefresh:
handleCodelensRefresh(srv, &logger)
logger.Info().
logger.Debug().
Msg("sending codelens refresh request to client")
case types.InlineValueRefresh:
handleInlineValueRefresh(srv, &logger)
logger.Info().
logger.Debug().
Msg("sending inline value refresh request to client")
default:
logger.Warn().
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/snyk/code-client-go v1.8.0
github.com/snyk/go-application-framework v0.0.0-20240726091718-6ffbf7a2bcd3
github.com/snyk/go-application-framework v0.0.0-20240730165042-1f5ebaba13a9
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ github.com/snyk/code-client-go v1.8.0 h1:6H883KAn7ybiSIxhvL2QR9yEyHgAwA2+9WVHMDN
github.com/snyk/code-client-go v1.8.0/go.mod h1:orU911flV1kJQOlxxx0InUQkAfpBrcERsb2olfnlI8s=
github.com/snyk/error-catalog-golang-public v0.0.0-20240724122202-c7d3fb545c88 h1:ZiFV5IDPI2p1wx1D3B2iSC/8nxTGvlKuyUekZlm1ptU=
github.com/snyk/error-catalog-golang-public v0.0.0-20240724122202-c7d3fb545c88/go.mod h1:Ytttq7Pw4vOCu9NtRQaOeDU2dhBYUyNBe6kX4+nIIQ4=
github.com/snyk/go-application-framework v0.0.0-20240726091718-6ffbf7a2bcd3 h1:gisnOktdqZYJLPIpKzNhm9UQIsuSQ0Ojded7XC5zI1E=
github.com/snyk/go-application-framework v0.0.0-20240726091718-6ffbf7a2bcd3/go.mod h1:3DhXDHbBbGWRRZESbYVZyunyIDaet9SOtuOZCK7AC3g=
github.com/snyk/go-application-framework v0.0.0-20240730165042-1f5ebaba13a9 h1:JmNcysYo2gESoSxU+mmhSUtHaTBEMEnvI6ZskaRHDQw=
github.com/snyk/go-application-framework v0.0.0-20240730165042-1f5ebaba13a9/go.mod h1:3DhXDHbBbGWRRZESbYVZyunyIDaet9SOtuOZCK7AC3g=
github.com/snyk/go-httpauth v0.0.0-20231117135515-eb445fea7530 h1:s9PHNkL6ueYRiAKNfd8OVxlUOqU3qY0VDbgCD1f6WQY=
github.com/snyk/go-httpauth v0.0.0-20231117135515-eb445fea7530/go.mod h1:88KbbvGYlmLgee4OcQ19yr0bNpXpOr2kciOthaSzCAg=
github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfd h1:Dq5WSzWsP1TbVi10zPWBI5LKEBDg4Y1OhWEph1wr5WQ=
Expand Down

0 comments on commit de5be23

Please sign in to comment.