-
Notifications
You must be signed in to change notification settings - Fork 95
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
Showing
45 changed files
with
1,224 additions
and
1,056 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
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,78 @@ | ||
package loader | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"slices" | ||
|
||
"github.com/bearer/bearer/internal/commands/process/settings" | ||
"github.com/bearer/bearer/internal/commands/process/settings/policies" | ||
"github.com/bearer/bearer/internal/commands/process/settings/rules" | ||
"github.com/bearer/bearer/internal/engine" | ||
"github.com/bearer/bearer/internal/flag" | ||
flagtypes "github.com/bearer/bearer/internal/flag/types" | ||
"github.com/bearer/bearer/internal/util/ignore" | ||
"github.com/bearer/bearer/internal/version_check" | ||
) | ||
|
||
func FromOptions( | ||
opts flagtypes.Options, | ||
versionMeta *version_check.VersionMeta, | ||
engine engine.Engine, | ||
) (settings.Config, error) { | ||
policies, err := policies.Load() | ||
if err != nil { | ||
return settings.Config{}, fmt.Errorf("failed to load policies: %w", err) | ||
} | ||
|
||
result, err := rules.Load( | ||
opts.ExternalRuleDir, | ||
opts.RuleOptions, | ||
versionMeta, | ||
engine, | ||
opts.ScanOptions.Force, | ||
) | ||
if err != nil { | ||
return settings.Config{}, err | ||
} | ||
|
||
ignoredFingerprints, _, _, err := ignore.GetIgnoredFingerprints(opts.GeneralOptions.IgnoreFile, &opts.ScanOptions.Target) | ||
if err != nil { | ||
return settings.Config{}, err | ||
} | ||
|
||
config := settings.Config{ | ||
Client: opts.Client, | ||
Worker: settings.WorkerOptions{ | ||
Timeout: settings.Timeout, | ||
TimeoutFileMinimum: settings.TimeoutFileMinimum, | ||
TimeoutFileMaximum: settings.TimeoutFileMaximum, | ||
TimeoutFileBytesPerSecond: settings.TimeoutFileBytesPerSecond, | ||
TimeoutWorkerOnline: settings.TimeoutWorkerOnline, | ||
FileSizeMaximum: settings.FileSizeMaximum, | ||
ExistingWorker: settings.ExistingWorker, | ||
}, | ||
Scan: opts.ScanOptions, | ||
Report: opts.ReportOptions, | ||
IgnoredFingerprints: ignoredFingerprints, | ||
NoColor: opts.GeneralOptions.NoColor || opts.ReportOptions.Output != "", | ||
DebugProfile: opts.GeneralOptions.DebugProfile, | ||
Debug: opts.GeneralOptions.Debug, | ||
LogLevel: opts.GeneralOptions.LogLevel, | ||
IgnoreFile: opts.GeneralOptions.IgnoreFile, | ||
IgnoreGit: opts.GeneralOptions.IgnoreGit, | ||
Policies: policies, | ||
Rules: result.Rules, | ||
BuiltInRules: result.BuiltInRules, | ||
CacheUsed: result.CacheUsed, | ||
BearerRulesVersion: result.BearerRulesVersion, | ||
} | ||
|
||
if config.Scan.Diff { | ||
if !slices.Contains([]string{flag.ReportSecurity, flag.ReportSaaS}, config.Report.Report) { | ||
return settings.Config{}, errors.New("diff base branch is only supported for the security report") | ||
} | ||
} | ||
|
||
return config, nil | ||
} |
Oops, something went wrong.