From de5be23d98393e0da1c881e3761db33e49a049b3 Mon Sep 17 00:00:00 2001 From: Bastian Doetsch Date: Wed, 31 Jul 2024 09:22:20 +0200 Subject: [PATCH] chore: improve scrubbing in logs (#609) --- application/config/config.go | 19 +++++++++++++------ application/server/notification.go | 14 +++++++------- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/application/config/config.go b/application/config/config.go index 08ef6b109..0031b0f06 100644 --- a/application/config/config.go +++ b/application/config/config.go @@ -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) @@ -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: diff --git a/application/server/notification.go b/application/server/notification.go index d24d7783b..39528e5c4 100644 --- a/application/server/notification.go +++ b/application/server/notification.go @@ -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") @@ -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)). @@ -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(). diff --git a/go.mod b/go.mod index 8933b2ced..3d6926371 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index e921fab95..1e0148a2a 100644 --- a/go.sum +++ b/go.sum @@ -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=