Skip to content

Commit 591ac69

Browse files
authored
Improve readability re: nesting; improve README; small regex fixes (#12)
This PR cleans up the heavy nesting in `logs.go` and allows either content or pattern to be specified when searching logs, rather than requiring both. The README has also been updated to reflect the new configuration options. Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
1 parent af89cd9 commit 591ac69

File tree

6 files changed

+326
-162
lines changed

6 files changed

+326
-162
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ permissions:
4545
Path to final CSV output file
4646
-end string
4747
End time for workflow run filtering (RFC3339) (default "2025-03-16T00:00:00Z")
48+
-ioc-content string
49+
Comma-separated string(s) to search for in logs
50+
-ioc-name string
51+
IOC Logs to scan for (e.g. tj-actions/changed-files (default "tj-actions/changed-files")
52+
-ioc-pattern string
53+
Regex pattern to search logs with
4854
-json string
4955
Path to final JSON output file
5056
-start string
@@ -62,4 +68,16 @@ $ chainctl auth octo-sts --scope chainguard-dev/tj-scan --identity ephemerality
6268
2025/03/18 11:27:59 INFO No existing cache found at cache.json, starting fresh
6369
```
6470

71+
Custom IOC configuration can be provided with the flags documented above or added to `config.yaml`:
72+
```yaml
73+
ioc:
74+
name: "custom-ioc-name"
75+
content: "0e58ed8671d6b60d0890c21b07f8835ace038e67,example-string,example-string2"
76+
pattern: "(?:^|\\s+)([A-Za-z0-9+/]{40,}={0,3})"
77+
```
78+
79+
`name` is a reference to the IOC
80+
`content` is the string or strings to search for in the Workflow logs
81+
`pattern` is an optional regex pattern to search for in the Workflow logs
82+
6583
Results will be saved in the `results/` directory.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/google/go-querystring v1.1.0 // indirect
2020
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
2121
github.com/rogpeppe/go-internal v1.10.0 // indirect
22-
github.com/sagikazarmark/locafero v0.8.0 // indirect
22+
github.com/sagikazarmark/locafero v0.9.0 // indirect
2323
github.com/sourcegraph/conc v0.3.0 // indirect
2424
github.com/spf13/afero v1.14.0 // indirect
2525
github.com/spf13/cast v1.7.1 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
3434
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3535
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
3636
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
37-
github.com/sagikazarmark/locafero v0.8.0 h1:mXaMVw7IqxNBxfv3LdWt9MDmcWDQ1fagDH918lOdVaQ=
38-
github.com/sagikazarmark/locafero v0.8.0/go.mod h1:UBUyz37V+EdMS3hDF3QWIiVr/2dPrx49OMO0Bn0hJqk=
37+
github.com/sagikazarmark/locafero v0.9.0 h1:GbgQGNtTrEmddYDSAH9QLRyfAHY12md+8YFTqyMTC9k=
38+
github.com/sagikazarmark/locafero v0.9.0/go.mod h1:UBUyz37V+EdMS3hDF3QWIiVr/2dPrx49OMO0Bn0hJqk=
3939
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
4040
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
4141
github.com/spf13/afero v1.14.0 h1:9tH6MapGnn/j0eb0yIXiLjERO8RB6xIVZRDCX7PtqWA=

pkg/ioc/ioc.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@ func NewIOC(config *Config) (*IOC, error) {
5353
return nil, fmt.Errorf("predefined IOC not found: %s", config.Name)
5454
}
5555

56-
if config.Pattern == "" {
57-
return nil, fmt.Errorf("pattern is required for novel IOC")
56+
if config.Pattern == "" && len(config.Content) == 0 {
57+
return nil, fmt.Errorf("either content or pattern is required for novel IOC")
5858
}
5959

60-
regex, err := regexp.Compile(config.Pattern)
61-
if err != nil {
62-
return nil, fmt.Errorf("invalid regex pattern: %w", err)
60+
var regex *regexp.Regexp
61+
var err error
62+
if config.Pattern != "" {
63+
regex, err = regexp.Compile(config.Pattern)
64+
if err != nil {
65+
return nil, fmt.Errorf("invalid regex pattern: %w", err)
66+
}
6367
}
6468

6569
name := config.Name

pkg/request/retry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func WithRetry(ctx context.Context, logger *clog.Logger, operation func() error)
1515
maxRetries := viper.GetInt("max_retries")
1616
attempt := 0
1717

18-
wrappedOperation := func() (interface{}, error) {
18+
wrappedOperation := func() (any, error) {
1919
if ctx.Err() != nil {
2020
return nil, backoff.Permanent(ctx.Err())
2121
}

0 commit comments

Comments
 (0)