forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1fa35d
commit 31fcfe4
Showing
6 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package packer | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"sync" | ||
) | ||
|
||
type secretFilter struct { | ||
s map[string]struct{} | ||
m sync.Mutex | ||
w io.Writer | ||
} | ||
|
||
func (l *secretFilter) Set(secrets ...string) { | ||
l.m.Lock() | ||
defer l.m.Unlock() | ||
for _, s := range secrets { | ||
l.s[s] = struct{}{} | ||
} | ||
} | ||
|
||
func (l *secretFilter) SetOutput(output io.Writer) { | ||
l.m.Lock() | ||
defer l.m.Unlock() | ||
l.w = output | ||
} | ||
|
||
func (l *secretFilter) Write(p []byte) (n int, err error) { | ||
for s := range l.s { | ||
p = bytes.Replace(p, []byte(s), []byte("<filtered>"), -1) | ||
} | ||
return l.w.Write(p) | ||
// return l.w.Write([]byte("foobar")) | ||
} | ||
|
||
func (l *secretFilter) get() (s []string) { | ||
l.m.Lock() | ||
defer l.m.Unlock() | ||
for k := range l.s { | ||
s = append(s, k) | ||
} | ||
return | ||
} | ||
|
||
var LogSecretFilter secretFilter | ||
|
||
func init() { | ||
LogSecretFilter.s = make(map[string]struct{}) | ||
} |