Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 32555f5e87 | |||
| f3071aa46a | |||
| ea2de122be | |||
| 83e22d8b16 |
+1
-1
@@ -9,7 +9,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o trufflehog .
|
||||
|
||||
FROM alpine:3.15
|
||||
RUN apk add --no-cache bash git ca-certificates \
|
||||
RUN apk add --no-cache git ca-certificates \
|
||||
&& rm -rf /var/cache/apk/* && \
|
||||
update-ca-certificates
|
||||
COPY --from=builder /build/trufflehog /usr/bin/trufflehog
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
FROM alpine:3.15
|
||||
|
||||
RUN apk add --no-cache bash git ca-certificates \
|
||||
RUN apk add --no-cache git ca-certificates \
|
||||
&& rm -rf /var/cache/apk/* && \
|
||||
update-ca-certificates
|
||||
WORKDIR /usr/bin/
|
||||
|
||||
+3
-2
@@ -27,9 +27,10 @@ runs:
|
||||
- git
|
||||
- file://${{ inputs.path }}
|
||||
- --since-commit
|
||||
- ${{ inputs.base }}
|
||||
- ${{ inputs.base.default }}
|
||||
- --branch
|
||||
- ${{ inputs.head }}
|
||||
- --fail
|
||||
- --no-update
|
||||
- ${{ inputs.extra_args }}
|
||||
- ${{each arg in inputs.extra_args.split(' ')}}${{arg}}${{end}}
|
||||
- ${{ arg }}
|
||||
+3
-5
@@ -1,6 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
#!/usr/bin/env ash
|
||||
|
||||
# Parse the last argument into an array of extra_args.
|
||||
mapfile -t extra_args < <(bash -c "for arg in ${*: -1}; do echo \$arg; done")
|
||||
|
||||
/usr/bin/trufflehog "${@: 1: $#-1}" "${extra_args[@]}"
|
||||
# "$@" should expand all args in an 'array' as they were passed in
|
||||
/usr/bin/trufflehog "$@"
|
||||
+4
-3
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-retryablehttp"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var caCerts = []string{
|
||||
@@ -93,7 +94,7 @@ func NewCustomTransport(T http.RoundTripper) *CustomTransport {
|
||||
|
||||
func PinnedRetryableHttpClient() *http.Client {
|
||||
httpClient := retryablehttp.NewClient()
|
||||
httpClient.Logger = nil
|
||||
httpClient.Logger = logrus.WithField("name", "PinnedRetryableHttpClient").WithField("level", logrus.DebugLevel)
|
||||
httpClient.HTTPClient.Transport = NewCustomTransport(&http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
RootCAs: PinnedCertPool(),
|
||||
@@ -115,7 +116,7 @@ func PinnedRetryableHttpClient() *http.Client {
|
||||
func RetryableHttpClient() *http.Client {
|
||||
httpClient := retryablehttp.NewClient()
|
||||
httpClient.RetryMax = 3
|
||||
httpClient.Logger = nil
|
||||
httpClient.Logger = logrus.WithField("name", "RetryableHttpClient").WithField("level", logrus.DebugLevel)
|
||||
httpClient.HTTPClient.Timeout = 3 * time.Second
|
||||
httpClient.HTTPClient.Transport = NewCustomTransport(nil)
|
||||
return httpClient.StandardClient()
|
||||
@@ -124,7 +125,7 @@ func RetryableHttpClient() *http.Client {
|
||||
func RetryableHttpClientTimeout(timeOutSeconds int64) *http.Client {
|
||||
httpClient := retryablehttp.NewClient()
|
||||
httpClient.RetryMax = 3
|
||||
httpClient.Logger = nil
|
||||
httpClient.Logger = logrus.WithField("name", "RetryableHttpClientTimeout").WithField("level", logrus.DebugLevel)
|
||||
httpClient.HTTPClient.Timeout = time.Duration(timeOutSeconds) * time.Second
|
||||
httpClient.HTTPClient.Transport = NewCustomTransport(nil)
|
||||
return httpClient.StandardClient()
|
||||
|
||||
@@ -166,9 +166,6 @@ func captureCancelCallstack(ctx logCtx, f context.CancelFunc) (Context, context.
|
||||
}
|
||||
f()
|
||||
// Set the error with the stacktrace if the err pointer is non-nil.
|
||||
*ctx.err = fmt.Errorf(
|
||||
"%w (canceled at %v\n%s)",
|
||||
ctx.Err(), time.Now(), string(debug.Stack()),
|
||||
)
|
||||
*ctx.err = fmt.Errorf("%w (%s)", ctx.Err(), string(debug.Stack()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
|
||||
}
|
||||
|
||||
if verify {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.buildkite.com/v2/access-token", nil)
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.buildkite.com/v2/user", nil)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
+8
-17
@@ -9,7 +9,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
|
||||
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
|
||||
@@ -182,6 +181,7 @@ func (e *Engine) detectorWorker(ctx context.Context) {
|
||||
for originalChunk := range e.chunks {
|
||||
for chunk := range sources.Chunker(originalChunk) {
|
||||
atomic.AddUint64(&e.bytesScanned, uint64(len(chunk.Data)))
|
||||
fragStart, mdLine := FragmentFirstLine(chunk)
|
||||
for _, decoder := range e.decoders {
|
||||
var decoderType detectorspb.DecoderType
|
||||
switch decoder.(type) {
|
||||
@@ -230,19 +230,9 @@ func (e *Engine) detectorWorker(ctx context.Context) {
|
||||
results = detectors.CleanResults(results)
|
||||
}
|
||||
for _, result := range results {
|
||||
resultChunk := chunk
|
||||
if SupportsLineNumbers(chunk.SourceType) {
|
||||
copyChunk := *chunk
|
||||
copyMetaDataClone := proto.Clone(chunk.SourceMetadata)
|
||||
if copyMetaData, ok := copyMetaDataClone.(*source_metadatapb.MetaData); ok {
|
||||
copyChunk.SourceMetadata = copyMetaData
|
||||
}
|
||||
fragStart, mdLine := FragmentFirstLine(©Chunk)
|
||||
SetResultLineNumber(©Chunk, &result, fragStart, mdLine)
|
||||
resultChunk = ©Chunk
|
||||
}
|
||||
SetResultLineNumber(chunk, &result, fragStart, mdLine)
|
||||
result.DecoderType = decoderType
|
||||
e.results <- detectors.CopyMetadata(resultChunk, result)
|
||||
e.results <- detectors.CopyMetadata(chunk, result)
|
||||
|
||||
}
|
||||
if len(results) > 0 {
|
||||
@@ -281,8 +271,7 @@ func gitSources() []sourcespb.SourceType {
|
||||
}
|
||||
}
|
||||
|
||||
// SupportsLineNumbers determines if a line number can be found for a source type.
|
||||
func SupportsLineNumbers(sourceType sourcespb.SourceType) bool {
|
||||
func isGitSource(sourceType sourcespb.SourceType) bool {
|
||||
for _, i := range gitSources() {
|
||||
if i == sourceType {
|
||||
return true
|
||||
@@ -325,6 +314,8 @@ func FragmentFirstLine(chunk *sources.Chunk) (int64, *int64) {
|
||||
|
||||
// SetResultLineNumber sets the line number in the provided result.
|
||||
func SetResultLineNumber(chunk *sources.Chunk, result *detectors.Result, fragStart int64, mdLine *int64) {
|
||||
offset := FragmentLineOffset(chunk, result)
|
||||
*mdLine = fragStart + offset
|
||||
if isGitSource(chunk.SourceType) {
|
||||
offset := FragmentLineOffset(chunk, result)
|
||||
*mdLine = fragStart + offset
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user