Skip to content

Commit 672dc59

Browse files
committed
Addressing issues from golint
1 parent 2df0226 commit 672dc59

File tree

8 files changed

+68
-62
lines changed

8 files changed

+68
-62
lines changed

cmd/root.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func Execute() {
7777
}
7878
}
7979

80+
// Handler for when executing as a lambda
8081
func Handler(ctx context.Context, event events.CodePipelineEvent) (string, error) {
8182
log.Debug(event)
8283
err := rootCmd.Execute()
@@ -87,6 +88,7 @@ func Handler(ctx context.Context, event events.CodePipelineEvent) (string, error
8788

8889
if cfg.IsLambdaRunningInCodePipeline {
8990
log.Info("Lambda has been invoked by CodePipeline")
91+
rtnMessage := ""
9092

9193
if err != nil {
9294
// notify codepipeline and mark its job execution as Failure
@@ -107,7 +109,7 @@ func Handler(ctx context.Context, event events.CodePipelineEvent) (string, error
107109
if cplErr != nil {
108110
log.Fatalf(errors.Wrap(err, "Failed to update CodePipeline jobID status").Error())
109111
}
110-
return "Failure", err
112+
rtnMessage = "Failure"
111113
} else {
112114
log.Info("Notifying CodePipeline and mark its job execution as Success")
113115
jobID := event.CodePipelineJob.ID
@@ -122,16 +124,17 @@ func Handler(ctx context.Context, event events.CodePipelineEvent) (string, error
122124
if cplErr != nil {
123125
log.Fatalf(errors.Wrap(err, "Failed to update CodePipeline jobID status").Error())
124126
}
125-
return "Success", nil
127+
rtnMessage = "Success"
126128
}
127129
} else {
128130
if err != nil {
129131
log.Fatalf(errors.Wrap(err, "Notifying Lambda and mark this execution as Failure").Error())
130-
return "Failure", err
132+
rtnMessage = "Failure"
131133
} else {
132-
return "Success", nil
134+
rtnMessage = "Success"
133135
}
134136
}
137+
return rtnMessage, err
135138
}
136139

137140
func init() {

internal/aws/client.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@ import (
2828
)
2929

3030
var (
31+
// User not found error
3132
ErrUserNotFound = errors.New("user not found")
33+
// Group not found error
3234
ErrGroupNotFound = errors.New("group not found")
35+
// User not specified error
3336
ErrUserNotSpecified = errors.New("user not specified")
3437
)
3538

36-
type ErrHttpNotOK struct {
39+
type ErrHTTPNotOK struct {
3740
StatusCode int
3841
}
3942

40-
func (e *ErrHttpNotOK) Error() string {
43+
func (e *ErrHTTPNotOK) Error() string {
4144
return fmt.Sprintf("status of http response was %d", e.StatusCode)
4245
}
4346

@@ -62,15 +65,15 @@ type Client interface {
6265
}
6366

6467
type client struct {
65-
httpClient HttpClient
68+
httpClient HTTPClient
6669
endpointURL *url.URL
6770
bearerToken string
6871
}
6972

7073
// NewClient creates a new client to talk with AWS SSO's SCIM endpoint. It
7174
// requires a http.Client{} as well as the URL and bearer token from the
7275
// console. If the URL is not parsable, an error will be thrown.
73-
func NewClient(c HttpClient, config *Config) (Client, error) {
76+
func NewClient(c HTTPClient, config *Config) (Client, error) {
7477
u, err := url.Parse(config.Endpoint)
7578
if err != nil {
7679
return nil, err
@@ -118,7 +121,7 @@ func (c *client) sendRequestWithBody(method string, url string, body interface{}
118121

119122
// If we get a non-2xx status code, raise that via an error
120123
if resp.StatusCode < http.StatusOK || resp.StatusCode > http.StatusNoContent {
121-
err = &ErrHttpNotOK{resp.StatusCode}
124+
err = &ErrHTTPNotOK{resp.StatusCode}
122125
}
123126

124127
return

internal/aws/client_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestNewClient(t *testing.T) {
7272
ctrl := gomock.NewController(t)
7373
defer ctrl.Finish()
7474

75-
x := mock.NewMockIHttpClient(ctrl)
75+
x := mock.NewIHTTPClient(ctrl)
7676

7777
c, err := NewClient(x, &Config{
7878
Endpoint: ":foo",
@@ -86,7 +86,7 @@ func TestSendRequestBadUrl(t *testing.T) {
8686
ctrl := gomock.NewController(t)
8787
defer ctrl.Finish()
8888

89-
x := mock.NewMockIHttpClient(ctrl)
89+
x := mock.NewIHTTPClient(ctrl)
9090

9191
c, err := NewClient(x, &Config{
9292
Endpoint: "https://scim.example.com/",
@@ -104,7 +104,7 @@ func TestSendRequestBadStatusCode(t *testing.T) {
104104
ctrl := gomock.NewController(t)
105105
defer ctrl.Finish()
106106

107-
x := mock.NewMockIHttpClient(ctrl)
107+
x := mock.NewIHTTPClient(ctrl)
108108

109109
c, err := NewClient(x, &Config{
110110
Endpoint: "https://scim.example.com/",
@@ -134,7 +134,7 @@ func TestSendRequestCheckAuthHeader(t *testing.T) {
134134
ctrl := gomock.NewController(t)
135135
defer ctrl.Finish()
136136

137-
x := mock.NewMockIHttpClient(ctrl)
137+
x := mock.NewIHTTPClient(ctrl)
138138

139139
c, err := NewClient(x, &Config{
140140
Endpoint: "https://scim.example.com/",
@@ -169,7 +169,7 @@ func TestSendRequestWithBodyCheckHeaders(t *testing.T) {
169169
ctrl := gomock.NewController(t)
170170
defer ctrl.Finish()
171171

172-
x := mock.NewMockIHttpClient(ctrl)
172+
x := mock.NewIHTTPClient(ctrl)
173173

174174
c, err := NewClient(x, &Config{
175175
Endpoint: "https://scim.example.com/",
@@ -206,7 +206,7 @@ func TestClient_FindUserByEmail(t *testing.T) {
206206
ctrl := gomock.NewController(t)
207207
defer ctrl.Finish()
208208

209-
x := mock.NewMockIHttpClient(ctrl)
209+
x := mock.NewIHTTPClient(ctrl)
210210

211211
c, err := NewClient(x, &Config{
212212
Endpoint: "https://scim.example.com/",
@@ -282,7 +282,7 @@ func TestClient_FindGroupByDisplayName(t *testing.T) {
282282
ctrl := gomock.NewController(t)
283283
defer ctrl.Finish()
284284

285-
x := mock.NewMockIHttpClient(ctrl)
285+
x := mock.NewIHTTPClient(ctrl)
286286

287287
c, err := NewClient(x, &Config{
288288
Endpoint: "https://scim.example.com/",
@@ -362,7 +362,7 @@ func TestClient_CreateUser(t *testing.T) {
362362
ctrl := gomock.NewController(t)
363363
defer ctrl.Finish()
364364

365-
x := mock.NewMockIHttpClient(ctrl)
365+
x := mock.NewIHTTPClient(ctrl)
366366

367367
c, err := NewClient(x, &Config{
368368
Endpoint: "https://scim.example.com/",
@@ -407,7 +407,7 @@ func TestClient_UpdateUser(t *testing.T) {
407407
ctrl := gomock.NewController(t)
408408
defer ctrl.Finish()
409409

410-
x := mock.NewMockIHttpClient(ctrl)
410+
x := mock.NewIHTTPClient(ctrl)
411411

412412
c, err := NewClient(x, &Config{
413413
Endpoint: "https://scim.example.com/",

internal/aws/http.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package aws
1616

1717
import "net/http"
1818

19-
// HttpClient is a generic HTTP Do interface
20-
type HttpClient interface {
19+
// HTTPClient is a generic HTTP Do interface
20+
type HTTPClient interface {
2121
Do(req *http.Request) (*http.Response, error)
2222
}

internal/aws/mock/mock_http.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,31 @@ import (
2121
"github.com/golang/mock/gomock"
2222
)
2323

24-
// MockIHttpClient is a mock of IHttpClient interface
25-
type MockIHttpClient struct {
24+
// IHTTPClient is a mock of IHTTPClient interface
25+
type IHTTPClient struct {
2626
ctrl *gomock.Controller
27-
recorder *MockIHttpClientMockRecorder
27+
recorder *IHTTPClientMockRecorder
2828
}
2929

30-
// MockIHttpClientMockRecorder is the mock recorder for MockIHttpClient
31-
type MockIHttpClientMockRecorder struct {
32-
mock *MockIHttpClient
30+
// IHTTPClientMockRecorder is the mock recorder for IHTTPClient
31+
type IHTTPClientMockRecorder struct {
32+
mock *IHTTPClient
3333
}
3434

35-
// NewMockIHttpClient creates a new mock instance
36-
func NewMockIHttpClient(ctrl *gomock.Controller) *MockIHttpClient {
37-
mock := &MockIHttpClient{ctrl: ctrl}
38-
mock.recorder = &MockIHttpClientMockRecorder{mock}
35+
// NewIHTTPClient creates a new mock instance
36+
func NewIHTTPClient(ctrl *gomock.Controller) *IHTTPClient {
37+
mock := &IHTTPClient{ctrl: ctrl}
38+
mock.recorder = &IHTTPClientMockRecorder{mock}
3939
return mock
4040
}
4141

4242
// EXPECT returns an object that allows the caller to indicate expected use
43-
func (m *MockIHttpClient) EXPECT() *MockIHttpClientMockRecorder {
43+
func (m *IHTTPClient) EXPECT() *IHTTPClientMockRecorder {
4444
return m.recorder
4545
}
4646

4747
// Do mocks base method
48-
func (m *MockIHttpClient) Do(req *http.Request) (*http.Response, error) {
48+
func (m *IHTTPClient) Do(req *http.Request) (*http.Response, error) {
4949
m.ctrl.T.Helper()
5050
ret := m.ctrl.Call(m, "Do", req)
5151
ret0, _ := ret[0].(*http.Response)
@@ -54,7 +54,7 @@ func (m *MockIHttpClient) Do(req *http.Request) (*http.Response, error) {
5454
}
5555

5656
// Do indicates an expected call of Do
57-
func (mr *MockIHttpClientMockRecorder) Do(req interface{}) *gomock.Call {
57+
func (mr *IHTTPClientMockRecorder) Do(req interface{}) *gomock.Call {
5858
mr.mock.ctrl.T.Helper()
59-
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Do", reflect.TypeOf((*MockIHttpClient)(nil).Do), req)
59+
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Do", reflect.TypeOf((*IHTTPClient)(nil).Do), req)
6060
}

internal/config/secrets.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func (s *Secrets) SCIMAccessToken(secretArn string) (string, error) {
3434
return s.getSecret(secretArn)
3535
}
3636

37-
// SCIMEndpointUrl ...
38-
func (s *Secrets) SCIMEndpointUrl(secretArn string) (string, error) {
37+
// SCIMEndpointURL ...
38+
func (s *Secrets) SCIMEndpointURL(secretArn string) (string, error) {
3939
if len([]rune(secretArn)) == 0 {
40-
return s.getSecret("SSOSyncSCIMEndpointUrl")
40+
return s.getSecret("SSOSyncSCIMEndpointURL")
4141
}
4242
return s.getSecret(secretArn)
4343
}
@@ -58,7 +58,7 @@ func (s *Secrets) Region(secretArn string) (string, error) {
5858
return s.getSecret(secretArn)
5959
}
6060

61-
// Identity Store ID ...
61+
// IdentityStoreID ...
6262
func (s *Secrets) IdentityStoreID(secretArn string) (string, error) {
6363
if len([]rune(secretArn)) == 0 {
6464
return s.getSecret("IdentityStoreID")

internal/google/client.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,16 @@ func (c *client) GetGroups(query string) ([]*admin.Group, error) {
175175
return nil
176176
})
177177
return g, err
178-
} else {
179178

180-
// The Google api doesn't support multi-part queries, but we do so we need to split into an array of query strings
181-
queries := strings.Split(query, ",")
179+
// The Google api doesn't support multi-part queries, but we do so we need to split into an array of query strings
180+
queries := strings.Split(query, ",")
182181

183-
// Then call the api one query at a time, appending to our list
184-
for _, subQuery := range queries {
185-
err = c.service.Groups.List().Customer("my_customer").Query(subQuery).Pages(context.TODO(), func(groups *admin.Groups) error {
186-
g = append(g, groups.Groups...)
187-
return nil
188-
})
189-
}
182+
// Then call the api one query at a time, appending to our list
183+
for _, subQuery := range queries {
184+
err = c.service.Groups.List().Customer("my_customer").Query(subQuery).Pages(context.TODO(), func(groups *admin.Groups) error {
185+
g = append(g, groups.Groups...)
186+
return nil
187+
})
190188
}
191189

192190
// Check we've got some users otherwise something is wrong.

internal/sync.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ func (s *syncGSuite) SyncGroupsUsers(queryGroups string, queryUsers string) erro
393393
log.Info("creating user")
394394
_, err := s.aws.CreateUser(awsUser)
395395
if err != nil {
396-
errHttp := new(aws.ErrHttpNotOK)
397-
if errors.As(err, &errHttp) && errHttp.StatusCode == 409 {
396+
errHTTP := new(aws.ErrHttpNotOK)
397+
if errors.As(err, &errHTTP) && errHTTP.StatusCode == 409 {
398398
log.WithField("user", awsUser.Username).Warn("user already exists")
399399
continue
400400
}
@@ -805,10 +805,7 @@ func DoSync(ctx context.Context, cfg *config.Config) error {
805805
if err != nil {
806806
log.WithField("error", err).Warn("Problem performing test query against Identity Store")
807807
return err
808-
} else {
809-
log.WithField("Groups", response).Info("Test call for groups successful")
810-
811-
}
808+
log.WithField("Groups", response).Info("Test call for groups successful")
812809

813810
// Initialize sync client with
814811
// 1. SCIM API client
@@ -884,6 +881,7 @@ func (s *syncGSuite) GetGroups() ([]*aws.Group, error) {
884881
return awsGroups, nil
885882
}
886883

884+
// Callback handler for paginated List of Groups
887885
func ListGroupsPagesCallbackFn(page *identitystore.ListGroupsOutput, lastPage bool) bool {
888886
// Loop through each Group returned
889887
for _, group := range page.Groups {
@@ -916,6 +914,7 @@ func (s *syncGSuite) GetUsers() ([]*aws.User, error) {
916914
return awsUsers, nil
917915
}
918916

917+
// Callback handler for paginated List of Users
919918
func ListUsersPagesCallbackFn(page *identitystore.ListUsersOutput, lastPage bool) bool {
920919
// Loop through each User in ListUsersOutput and convert to native User object
921920
for _, user := range page.Users {
@@ -924,6 +923,7 @@ func ListUsersPagesCallbackFn(page *identitystore.ListUsersOutput, lastPage bool
924923
return !lastPage
925924
}
926925

926+
// Convert SDK user to native user object
927927
func ConvertSdkUserObjToNative(user *identitystore.User) *aws.User {
928928
// Convert emails into native Email object
929929
userEmails := make([]aws.UserEmail, 0)
@@ -968,6 +968,7 @@ func ConvertSdkUserObjToNative(user *identitystore.User) *aws.User {
968968
}
969969
}
970970

971+
// Create User ID for user object map
971972
func CreateUserIDtoUserObjMap(awsUsers []*aws.User) map[string]*aws.User {
972973
awsUsersMap := make(map[string]*aws.User)
973974

@@ -978,6 +979,7 @@ func CreateUserIDtoUserObjMap(awsUsers []*aws.User) map[string]*aws.User {
978979
return awsUsersMap
979980
}
980981

982+
// Handler for Paginated Group Membership List
981983
var ListGroupMembershipPagesCallbackFn func(page *identitystore.ListGroupMembershipsOutput, lastPage bool) bool
982984

983985
func (s *syncGSuite) GetGroupMembershipsLists(awsGroups []*aws.Group, awsUsersMap map[string]*aws.User) (map[string][]*aws.User, error) {
@@ -986,8 +988,8 @@ func (s *syncGSuite) GetGroupMembershipsLists(awsGroups []*aws.Group, awsUsersMa
986988

987989
ListGroupMembershipPagesCallbackFn = func(page *identitystore.ListGroupMembershipsOutput, lastPage bool) bool {
988990
for _, member := range page.GroupMemberships { // For every member in the group
989-
userId := member.MemberId.UserId
990-
user := awsUsersMap[*userId]
991+
userID := member.MemberId.UserId
992+
user := awsUsersMap[*userID]
991993

992994
// Append new user onto existing list of users
993995
awsGroupsUsers[curGroup.DisplayName] = append(awsGroupsUsers[curGroup.DisplayName], user)
@@ -1034,25 +1036,25 @@ func (s *syncGSuite) IsUserInGroup(user *aws.User, group *aws.Group) (*bool, err
10341036
return isUserInGroup, nil
10351037
}
10361038

1037-
func (s *syncGSuite) RemoveUserFromGroup(userId *string, groupId *string) error {
1038-
memberIdOutput, err := s.identityStoreClient.GetGroupMembershipId(
1039+
func (s *syncGSuite) RemoveUserFromGroup(userID *string, groupID *string) error {
1040+
memberIDOutput, err := s.identityStoreClient.GetGroupMembershipId(
10391041
&identitystore.GetGroupMembershipIdInput{
10401042
IdentityStoreId: &s.cfg.IdentityStoreID,
1041-
GroupId: groupId,
1042-
MemberId: &identitystore.MemberId{UserId: userId},
1043+
GroupId: groupID,
1044+
MemberId: &identitystore.MemberId{UserId: userID},
10431045
},
10441046
)
10451047

10461048
if err != nil {
10471049
return err
10481050
}
10491051

1050-
memberId := memberIdOutput.MembershipId
1052+
memberID := memberIDOutput.MembershipId
10511053

10521054
_, err = s.identityStoreClient.DeleteGroupMembership(
10531055
&identitystore.DeleteGroupMembershipInput{
10541056
IdentityStoreId: &s.cfg.IdentityStoreID,
1055-
MembershipId: memberId,
1057+
MembershipId: memberID,
10561058
},
10571059
)
10581060

0 commit comments

Comments
 (0)