Skip to content

Commit

Permalink
bump dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Jul 4, 2022
1 parent 2570041 commit e88d387
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 132 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
- uses: actions/checkout@v2

- name: install go
uses: actions/setup-go@v1
uses: actions/setup-go@v3
with:
go-version: 1.14
go-version: 1.18
- name: build and test
run: go test -timeout=60s -covermode=count -coverprofile=$GITHUB_WORKSPACE/profile.cov ./...
- name: install golangci-lint
run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.24.0
run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.46.1
- name: run linters
run: $GITHUB_WORKSPACE/golangci-lint run ./... ;
- name: build docker image
Expand Down
5 changes: 2 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ linters:
- gocyclo
- gofmt
- goimports
- golint
- revive
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- misspell
- nakedret
- rowserrcheck
- scopelint
- exportloopref
- staticcheck
- structcheck
- stylecheck
Expand Down
25 changes: 13 additions & 12 deletions connectors/detective.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
package connectors

import (
"fmt"

"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/service/detective"
"github.com/pkg/errors"
)

// DetectiveInviter is a per-region structure which contains all information
Expand Down Expand Up @@ -58,25 +59,25 @@ func NewDetectiveInviter(masterSess, memberSess client.ConfigProvider) *Detectiv
func (d DetectiveInviter) AddMember(accountID, accountEmail, masterAccountID string) error {
graphARN, err := getGraphARN(d.masterSvc)
if err != nil {
return errors.Wrap(err, "can't get graphARN of master account")
return fmt.Errorf("can't get graphARN of master account: %w", err)
}

connected, err := ifDetectiveMemberAlreadyEnabled(d.masterSvc, graphARN, &accountID)
if err != nil {
return errors.Wrap(err, "error retrieving information about existing member account")
return fmt.Errorf("error retrieving information about existing member account: %w", err)
}
if connected {
return nil
}

err = setUpDetectiveMaster(d.masterSvc, graphARN, &accountID, &accountEmail)
if err != nil {
return errors.Wrap(err, "error setting up master account")
return fmt.Errorf("error setting up master account: %w", err)
}

err = acceptDetectiveMemberInvitation(d.memberSvc, &masterAccountID)
if err != nil {
return errors.Wrap(err, "error accepting invitation in member account")
return fmt.Errorf("error accepting invitation in member account: %w", err)
}

return nil
Expand All @@ -90,7 +91,7 @@ func ifDetectiveMemberAlreadyEnabled(d DetectiveMasterClient, graphARN, memberAc
GraphArn: graphARN,
})
if err != nil {
return false, errors.Wrap(err, "error getting existing members")
return false, fmt.Errorf("error getting existing members: %w", err)
}

// Search conditions looking for particular account and we expect to get either zero results
Expand All @@ -116,7 +117,7 @@ func setUpDetectiveMaster(d DetectiveMasterClient, graphARN, memberAccountID, em
GraphArn: graphARN,
})
if err != nil {
return errors.Wrap(err, "error creating member account")
return fmt.Errorf("error creating member account: %w", err)
}

return nil
Expand All @@ -126,7 +127,7 @@ func setUpDetectiveMaster(d DetectiveMasterClient, graphARN, memberAccountID, em
func acceptDetectiveMemberInvitation(d DetectiveMemberClient, masterAccountID *string) error {
invitations, err := d.ListInvitations(nil)
if err != nil {
return errors.Wrap(err, "error retrieving list of invitations")
return fmt.Errorf("error retrieving list of invitations: %w", err)
}
var graphArn *string
for _, inv := range invitations.Invitations {
Expand All @@ -136,14 +137,14 @@ func acceptDetectiveMemberInvitation(d DetectiveMemberClient, masterAccountID *s
}
}
if graphArn == nil {
return errors.New("can't find invitation from master account")
return fmt.Errorf("can't find invitation from master account")
}

_, err = d.AcceptInvitation(&detective.AcceptInvitationInput{
GraphArn: graphArn,
})
if err != nil {
return errors.Wrap(err, "error accepting invitation")
return fmt.Errorf("error accepting invitation: %w", err)
}

return nil
Expand All @@ -153,10 +154,10 @@ func acceptDetectiveMemberInvitation(d DetectiveMemberClient, masterAccountID *s
func getGraphARN(d DetectiveMasterClient) (*string, error) {
graphs, err := d.ListGraphs(nil)
if err != nil {
return nil, errors.Wrap(err, "error listing graphs")
return nil, fmt.Errorf("error listing graphs: %w", err)
}
if len(graphs.GraphList) != 1 {
return nil, errors.Errorf(
return nil, fmt.Errorf(
"%d graphs found instead of one",
len(graphs.GraphList),
)
Expand Down
12 changes: 6 additions & 6 deletions connectors/detective_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package connectors

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/detective"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

Expand All @@ -30,19 +30,19 @@ func TestDetectiveInviter_AddMember(t *testing.T) {
memberAccID = "112233445566"
masterAccID = "665544332211"
testEmail = "[email protected]"
badGMReq = dGetMembersReq{err: errors.New("mock err")}
badGMReq = dGetMembersReq{err: fmt.Errorf("mock err")}
emptyGMReq = dGetMembersReq{output: &detective.GetMembersOutput{}}
associatedGMReq = dGetMembersReq{output: &detective.GetMembersOutput{
MemberDetails: []*detective.MemberDetail{{Status: aws.String("Enabled")}}}}
invitedGMReq = dGetMembersReq{output: &detective.GetMembersOutput{
MemberDetails: []*detective.MemberDetail{{Status: aws.String("Invited")}}}}
badCMReq = dCreateMembersReq{err: errors.New("mock err")}
badLIReq = dListInvitationsReq{err: errors.New("mock err")}
badCMReq = dCreateMembersReq{err: fmt.Errorf("mock err")}
badLIReq = dListInvitationsReq{err: fmt.Errorf("mock err")}
emptyLIReq = dListInvitationsReq{output: &detective.ListInvitationsOutput{}}
goodLIReq = dListInvitationsReq{output: &detective.ListInvitationsOutput{
Invitations: []*detective.MemberDetail{{AccountId: &masterAccID, GraphArn: &graphARN}}}}
badAIReq = dAcceptInvitationReq{err: errors.New("mock err")}
badDReq = dGraphReq{err: errors.New("mock err")}
badAIReq = dAcceptInvitationReq{err: fmt.Errorf("mock err")}
badDReq = dGraphReq{err: fmt.Errorf("mock err")}
emptyDReq = dGraphReq{output: &detective.ListGraphsOutput{}}
goodDReq = dGraphReq{output: &detective.ListGraphsOutput{GraphList: []*detective.Graph{{Arn: &graphARN}}}}
)
Expand Down
41 changes: 21 additions & 20 deletions connectors/guardduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package connectors

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/client"
"github.com/aws/aws-sdk-go/service/guardduty"
"github.com/pkg/errors"
)

// GuardDutyInviter is a per-region structure which contains all information
Expand Down Expand Up @@ -47,7 +48,7 @@ type GuardDutyMasterClient interface {
type GuardDutyMemberClient interface {
GuardDutyListDetectors
ListInvitations(*guardduty.ListInvitationsInput) (*guardduty.ListInvitationsOutput, error)
AcceptInvitation(*guardduty.AcceptInvitationInput) (*guardduty.AcceptInvitationOutput, error)
AcceptAdministratorInvitation(*guardduty.AcceptAdministratorInvitationInput) (*guardduty.AcceptAdministratorInvitationOutput, error)
}

// NewGuardDutyInviter creates new instance of GuardDutyInviter which is capable of inviting
Expand All @@ -66,25 +67,25 @@ func NewGuardDutyInviter(masterSess, memberSess client.ConfigProvider) *GuardDut
func (g GuardDutyInviter) AddMember(accountID, accountEmail, masterAccountID string) error {
detectorID, err := getDetectorID(g.masterSvc)
if err != nil {
return errors.Wrap(err, "can't get detectorID of master account")
return fmt.Errorf("can't get detectorID of master account: %w", err)
}

connected, err := ifGuardDutyMemberAlreadyEnabled(g.masterSvc, detectorID, &accountID)
if err != nil {
return errors.Wrap(err, "error retrieving information about existing member account")
return fmt.Errorf("error retrieving information about existing member account: %w", err)
}
if connected {
return nil
}

err = setUpGuardDutyMaster(g.masterSvc, detectorID, &accountID, &accountEmail)
if err != nil {
return errors.Wrap(err, "error setting up master account")
return fmt.Errorf("error setting up master account: %w", err)
}

err = acceptGuardDutyMemberInvitation(g.memberSvc, &masterAccountID)
if err != nil {
return errors.Wrap(err, "error accepting invitation in member account")
return fmt.Errorf("error accepting invitation in member account: %w", err)
}

return nil
Expand All @@ -98,7 +99,7 @@ func ifGuardDutyMemberAlreadyEnabled(g GuardDutyMasterClient, detectorID, member
AccountIds: []*string{memberAccountID},
})
if err != nil {
return false, errors.Wrap(err, "error getting existing members")
return false, fmt.Errorf("error getting existing members: %w", err)
}

// Search conditions looking for particular account and we expect to get either zero results
Expand All @@ -124,7 +125,7 @@ func setUpGuardDutyMaster(g GuardDutyMasterClient, detectorID, memberAccountID,
}},
})
if err != nil {
return errors.Wrap(err, "error creating member account")
return fmt.Errorf("error creating member account: %w", err)
}

_, err = g.InviteMembers(&guardduty.InviteMembersInput{
Expand All @@ -133,7 +134,7 @@ func setUpGuardDutyMaster(g GuardDutyMasterClient, detectorID, memberAccountID,
DisableEmailNotification: aws.Bool(true),
})
if err != nil {
return errors.Wrap(err, "error sending invitation")
return fmt.Errorf("error sending invitation: %w", err)
}

return nil
Expand All @@ -143,7 +144,7 @@ func setUpGuardDutyMaster(g GuardDutyMasterClient, detectorID, memberAccountID,
func acceptGuardDutyMemberInvitation(g GuardDutyMemberClient, masterAccountID *string) error {
invitations, err := g.ListInvitations(nil)
if err != nil {
return errors.Wrap(err, "error retrieving list of invitations")
return fmt.Errorf("error retrieving list of invitations: %w", err)
}
var invitationID *string
for _, inv := range invitations.Invitations {
Expand All @@ -153,22 +154,22 @@ func acceptGuardDutyMemberInvitation(g GuardDutyMemberClient, masterAccountID *s
}
}
if invitationID == nil {
return errors.New("can't find invitation from master account")
return fmt.Errorf("can't find invitation from master account")
}

detector, err := getDetectorID(g)
if err != nil {
return errors.Wrap(err, "can't get detectorID to accept invitation")
return fmt.Errorf("can't get detectorID to accept invitation: %w", err)
}

_, err = g.AcceptInvitation(
&guardduty.AcceptInvitationInput{
DetectorId: detector,
InvitationId: invitationID,
MasterId: masterAccountID,
_, err = g.AcceptAdministratorInvitation(
&guardduty.AcceptAdministratorInvitationInput{
DetectorId: detector,
InvitationId: invitationID,
AdministratorId: masterAccountID,
})
if err != nil {
return errors.Wrap(err, "error accepting invitation")
return fmt.Errorf("error accepting invitation: %w", err)
}

return nil
Expand All @@ -178,10 +179,10 @@ func acceptGuardDutyMemberInvitation(g GuardDutyMemberClient, masterAccountID *s
func getDetectorID(g GuardDutyListDetectors) (*string, error) {
detectors, err := g.ListDetectors(nil)
if err != nil {
return nil, errors.Wrap(err, "error listing detectors")
return nil, fmt.Errorf("error listing detectors: %w", err)
}
if len(detectors.DetectorIds) != 1 {
return nil, errors.Errorf(
return nil, fmt.Errorf(
"%d detectors found instead of one",
len(detectors.DetectorIds),
)
Expand Down
18 changes: 9 additions & 9 deletions connectors/guardduty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
package connectors

import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/guardduty"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

Expand All @@ -31,20 +31,20 @@ func TestGuardDutyInviter_AddMember(t *testing.T) {
memberAccID = "112233445566"
masterAccID = "665544332211"
testEmail = "[email protected]"
badGMReq = gdGetMembersReq{err: errors.New("mock err")}
badGMReq = gdGetMembersReq{err: fmt.Errorf("mock err")}
emptyGMReq = gdGetMembersReq{output: &guardduty.GetMembersOutput{}}
associatedGMReq = gdGetMembersReq{output: &guardduty.GetMembersOutput{
Members: []*guardduty.Member{{RelationshipStatus: aws.String("Enabled")}}}}
invitedGMReq = gdGetMembersReq{output: &guardduty.GetMembersOutput{
Members: []*guardduty.Member{{RelationshipStatus: aws.String("Invited")}}}}
badCMReq = gdCreateMembersReq{err: errors.New("mock err")}
badIMReq = gdInviteMembersReq{err: errors.New("mock err")}
badLIReq = gdListInvitationsReq{err: errors.New("mock err")}
badCMReq = gdCreateMembersReq{err: fmt.Errorf("mock err")}
badIMReq = gdInviteMembersReq{err: fmt.Errorf("mock err")}
badLIReq = gdListInvitationsReq{err: fmt.Errorf("mock err")}
emptyLIReq = gdListInvitationsReq{output: &guardduty.ListInvitationsOutput{}}
goodLIReq = gdListInvitationsReq{output: &guardduty.ListInvitationsOutput{
Invitations: []*guardduty.Invitation{{AccountId: &masterAccID, InvitationId: &invitationID}}}}
badAIReq = gdAcceptInvitationReq{err: errors.New("mock err")}
badDReq = gdDetectorReq{err: errors.New("mock err")}
badAIReq = gdAcceptInvitationReq{err: fmt.Errorf("mock err")}
badDReq = gdDetectorReq{err: fmt.Errorf("mock err")}
emptyDReq = gdDetectorReq{output: &guardduty.ListDetectorsOutput{}}
goodDReq = gdDetectorReq{output: &guardduty.ListDetectorsOutput{DetectorIds: []*string{&detectorID}}}
)
Expand Down Expand Up @@ -238,7 +238,7 @@ func (s mockGDMemberClient) ListInvitations(input *guardduty.ListInvitationsInpu
return s.liReq.output, s.liReq.err
}

func (s mockGDMemberClient) AcceptInvitation(input *guardduty.AcceptInvitationInput) (*guardduty.AcceptInvitationOutput, error) {
assert.Equal(s.t, &guardduty.AcceptInvitationInput{InvitationId: s.invitationID, MasterId: s.masterAccountID, DetectorId: s.detectorID}, input)
func (s mockGDMemberClient) AcceptAdministratorInvitation(input *guardduty.AcceptAdministratorInvitationInput) (*guardduty.AcceptAdministratorInvitationOutput, error) {
assert.Equal(s.t, &guardduty.AcceptAdministratorInvitationInput{InvitationId: s.invitationID, AdministratorId: s.masterAccountID, DetectorId: s.detectorID}, input)
return nil, s.aiReq.err
}
Loading

0 comments on commit e88d387

Please sign in to comment.