Skip to content

Commit

Permalink
[CI-1628] Use shared secret redacting (#885)
Browse files Browse the repository at this point in the history
* Update dependencies

* Remove old implementation

* Use shared secret redacting

* Use log adapter
  • Loading branch information
tothszabi authored Sep 14, 2023
1 parent ddd8706 commit 2527170
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 712 deletions.
47 changes: 0 additions & 47 deletions analytics/logger.go

This file was deleted.

3 changes: 2 additions & 1 deletion analytics/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/bitrise-io/bitrise/configs"
"github.com/bitrise-io/bitrise/log"
"github.com/bitrise-io/bitrise/models"
"github.com/bitrise-io/bitrise/version"
"github.com/bitrise-io/go-utils/v2/analytics"
Expand Down Expand Up @@ -123,7 +124,7 @@ func NewDefaultTracker() Tracker {
envRepository := env.NewRepository()
stateChecker := NewStateChecker(envRepository)

logger := newUtilsLogAdapter()
logger := log.NewUtilsLogAdapter()
tracker := analytics.NewDefaultTracker(&logger)
if stateChecker.UseAsync() {
tracker = analytics.NewDefaultTracker(&logger)
Expand Down
10 changes: 6 additions & 4 deletions cli/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"fmt"
"io"

"github.com/bitrise-io/bitrise/stepruncmd/filterwriter"
"github.com/bitrise-io/bitrise/log"
"github.com/bitrise-io/envman/models"
"github.com/bitrise-io/go-utils/v2/redactwriter"
)

func redactStepInputs(environment map[string]string, inputs []models.EnvironmentItemModel, secrets []string) (map[string]string, map[string]string, error) {
Expand Down Expand Up @@ -49,12 +50,13 @@ func redactStepInputs(environment map[string]string, inputs []models.Environment
func redactWithSecrets(inputValue string, secrets []string) (string, error) {
src := bytes.NewReader([]byte(inputValue))
dstBuf := new(bytes.Buffer)
secretFilterDst := filterwriter.New(secrets, dstBuf)
logger := log.NewUtilsLogAdapter()
redactWriterDst := redactwriter.New(secrets, dstBuf, &logger)

if _, err := io.Copy(secretFilterDst, src); err != nil {
if _, err := io.Copy(redactWriterDst, src); err != nil {
return "", fmt.Errorf("failed to redact secrets, stream copy failed: %s", err)
}
if err := secretFilterDst.Close(); err != nil {
if err := redactWriterDst.Close(); err != nil {
return "", fmt.Errorf("failed to redact secrets, closing the stream failed: %s", err)
}

Expand Down
3 changes: 2 additions & 1 deletion cli/run_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/bitrise-io/go-utils/pointers"
"github.com/bitrise-io/go-utils/retry"
coreanalytics "github.com/bitrise-io/go-utils/v2/analytics"
logV2 "github.com/bitrise-io/go-utils/v2/log"
"github.com/bitrise-io/go-utils/versions"
stepmanModels "github.com/bitrise-io/stepman/models"
)
Expand Down Expand Up @@ -433,7 +434,7 @@ func (r WorkflowRunner) executeStep(
return 1, fmt.Errorf("failed to read command environment: %w", err)
}

cmd := stepruncmd.New(name, args, bitriseSourceDir, envs, stepSecrets, timeout, noOutputTimeout, stdout)
cmd := stepruncmd.New(name, args, bitriseSourceDir, envs, stepSecrets, timeout, noOutputTimeout, stdout, logV2.NewLogger())
return cmd.Run()
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/bitrise-io/envman v0.0.0-20221010094751-a03ce30a5316
github.com/bitrise-io/go-steputils/v2 v2.0.0-alpha.19
github.com/bitrise-io/go-utils v1.0.8
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.16
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.19
github.com/bitrise-io/goinp v0.0.0-20211005113137-305e91b481f4
github.com/bitrise-io/gows v0.0.0-20211005113107-14f65e686b88
github.com/bitrise-io/stepman v0.0.0-20221010110437-a88e9a915b58
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ github.com/bitrise-io/go-utils v1.0.3/go.mod h1:ZY1DI+fEpZuFpO9szgDeICM4QbqoWVt0
github.com/bitrise-io/go-utils v1.0.8 h1:ekXH6FK5V8UxkyHm2FsQL8yk9Wqd5fjg1NGlD7jK2kc=
github.com/bitrise-io/go-utils v1.0.8/go.mod h1:ZY1DI+fEpZuFpO9szgDeICM4QbqoWVt0RSY3tRI1heY=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.13/go.mod h1:gZWtM7PLn1VOroa4gN1La/24aRVc0jg5R701jTsPaO8=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.16 h1:y+Yo0d8pYIjZiKhQuPM/Z5FY9/mu+wrWkyQlch8f9Po=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.16/go.mod h1:Laih4ji980SQkRgdnMCH0g4u2GZI/5nnbqmYT9UfKFQ=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.19 h1:55as5Iv0N4btuRP3YwRzN+BCMtKO210MnJ8mpxmeI7o=
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.19/go.mod h1:Laih4ji980SQkRgdnMCH0g4u2GZI/5nnbqmYT9UfKFQ=
github.com/bitrise-io/goinp v0.0.0-20210504152833-8559b0680ab1/go.mod h1:iRbd8zAXLeNy+0gic0eqNCxXvDGe8ZEY/uYX2CCeAoo=
github.com/bitrise-io/goinp v0.0.0-20211005113137-305e91b481f4 h1:ytUxnO7iSGHlNpbdjhDUefEM5WRy1kD2ElGfBA7r1PE=
github.com/bitrise-io/goinp v0.0.0-20211005113137-305e91b481f4/go.mod h1:iRbd8zAXLeNy+0gic0eqNCxXvDGe8ZEY/uYX2CCeAoo=
Expand Down
43 changes: 43 additions & 0 deletions log/adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package log

// UtilsLogAdapter extends the bitrise/log.Logger to meet the go-utils/v2/log.Logger interface.
type UtilsLogAdapter struct {
debug bool
Logger
}

func NewUtilsLogAdapter() UtilsLogAdapter {
opts := GetGlobalLoggerOpts()
return UtilsLogAdapter{
Logger: NewLogger(opts),
debug: opts.DebugLogEnabled,
}
}

func (l *UtilsLogAdapter) TInfof(format string, v ...interface{}) {
Infof(format, v...)
}
func (l *UtilsLogAdapter) TWarnf(format string, v ...interface{}) {
Warnf(format, v...)
}
func (l *UtilsLogAdapter) TPrintf(format string, v ...interface{}) {
Printf(format, v...)
}
func (l *UtilsLogAdapter) TDonef(format string, v ...interface{}) {
Donef(format, v...)
}
func (l *UtilsLogAdapter) TDebugf(format string, v ...interface{}) {
if !l.debug {
return
}
Debugf(format, v...)
}
func (l *UtilsLogAdapter) TErrorf(format string, v ...interface{}) {
Errorf(format, v...)
}
func (l *UtilsLogAdapter) Println() {
Print()
}
func (l *UtilsLogAdapter) EnableDebugLog(enable bool) {
l.debug = enable
}
Loading

0 comments on commit 2527170

Please sign in to comment.