@@ -4,32 +4,37 @@ import (
44 "context"
55 "errors"
66 "fmt"
7+ "slices"
8+
79 policyManager "github.com/compliance-framework/agent/policy-manager"
810 "github.com/compliance-framework/agent/runner"
911 "github.com/compliance-framework/agent/runner/proto"
1012 "github.com/google/go-github/v71/github"
1113 "github.com/hashicorp/go-hclog"
1214 goplugin "github.com/hashicorp/go-plugin"
1315 "github.com/mitchellh/mapstructure"
14- "slices"
1516)
1617
1718type PluginConfig struct {
18- Token string `mapstructure:"token"`
19- Organization * string `mapstructure:"organization"`
20- User * string `mapstructure:"user"`
19+ Token string `mapstructure:"token"`
20+ Organization * string `mapstructure:"organization"`
21+ User * string `mapstructure:"user"`
22+ SecurityTeamName * string `mapstructure:"security-team-name"`
2123}
2224
2325type DependabotPlugin struct {
2426 logger hclog.Logger
25- data map [string ]interface {}
26- config * PluginConfig
2727
28+ config * PluginConfig
2829 githubClient * github.Client
2930}
3031
32+ type DependabotData struct {
33+ Alerts []* github.DependabotAlert
34+ SecurityTeamMembers []* github.User
35+ }
36+
3137func (l * DependabotPlugin ) Configure (req * proto.ConfigureRequest ) (* proto.ConfigureResponse , error ) {
32- //l.config = req.GetConfig()
3338 config := & PluginConfig {}
3439 mapstructure .Decode (req .GetConfig (), config )
3540 l .config = config
@@ -42,7 +47,20 @@ func (l *DependabotPlugin) Configure(req *proto.ConfigureRequest) (*proto.Config
4247func (l * DependabotPlugin ) Eval (req * proto.EvalRequest , apiHelper runner.ApiHelper ) (* proto.EvalResponse , error ) {
4348 ctx := context .TODO ()
4449 repochan , errchan := l .FetchRepositories (ctx )
50+
51+ var securityTeamMembers []* github.User
52+ if l .config .SecurityTeamName != nil && * l .config .SecurityTeamName != "" {
53+ var err error
54+ securityTeamMembers , err = l .FetchSecurityTeamMembers (ctx )
55+ if err != nil {
56+ return & proto.EvalResponse {
57+ Status : proto .ExecutionStatus_FAILURE ,
58+ }, err
59+ }
60+ }
61+
4562 done := false
63+
4664 for ! done {
4765 select {
4866 case err , ok := <- errchan :
@@ -66,7 +84,14 @@ func (l *DependabotPlugin) Eval(req *proto.EvalRequest, apiHelper runner.ApiHelp
6684 }, err
6785 }
6886
69- evidences , err := l .EvaluatePolicies (ctx , repo , alerts , req )
87+ data := & DependabotData {
88+ Alerts : alerts ,
89+ }
90+ if securityTeamMembers != nil {
91+ data .SecurityTeamMembers = securityTeamMembers
92+ }
93+
94+ evidences , err := l .EvaluatePolicies (ctx , repo , data , req )
7095 if err != nil {
7196 return & proto.EvalResponse {
7297 Status : proto .ExecutionStatus_FAILURE ,
@@ -87,6 +112,14 @@ func (l *DependabotPlugin) Eval(req *proto.EvalRequest, apiHelper runner.ApiHelp
87112 }, nil
88113}
89114
115+ func (l * DependabotPlugin ) FetchSecurityTeamMembers (ctx context.Context ) ([]* github.User , error ) {
116+ members , _ , err := l .githubClient .Teams .ListTeamMembersBySlug (ctx , * l .config .Organization , * l .config .SecurityTeamName , nil )
117+ if err != nil {
118+ return nil , err
119+ }
120+ return members , nil
121+ }
122+
90123func (l * DependabotPlugin ) FetchRepositoryDependabotAlerts (ctx context.Context , repo * github.Repository ) ([]* github.DependabotAlert , error ) {
91124 alerts , _ , err := l .githubClient .Dependabot .ListRepoAlerts (ctx , repo .GetOwner ().GetLogin (), repo .GetName (), & github.ListAlertsOptions {
92125 ListOptions : github.ListOptions {
@@ -140,7 +173,7 @@ func (l *DependabotPlugin) FetchRepositories(ctx context.Context) (<-chan *githu
140173 return repositories , errs
141174}
142175
143- func (l * DependabotPlugin ) EvaluatePolicies (ctx context.Context , repo * github.Repository , alerts [] * github. DependabotAlert , req * proto.EvalRequest ) ([]* proto.Evidence , error ) {
176+ func (l * DependabotPlugin ) EvaluatePolicies (ctx context.Context , repo * github.Repository , data * DependabotData , req * proto.EvalRequest ) ([]* proto.Evidence , error ) {
144177 var accumulatedErrors error
145178
146179 activities := make ([]* proto.Activity , 0 )
@@ -260,7 +293,7 @@ func (l *DependabotPlugin) EvaluatePolicies(ctx context.Context, repo *github.Re
260293 actors ,
261294 activities ,
262295 )
263- evidence , err := processor .GenerateResults (ctx , policyPath , alerts )
296+ evidence , err := processor .GenerateResults (ctx , policyPath , data )
264297 evidences = slices .Concat (evidences , evidence )
265298 if err != nil {
266299 accumulatedErrors = errors .Join (accumulatedErrors , err )
0 commit comments