Skip to content

Commit c7a866c

Browse files
authored
Fixes for workflow automations (#214)
* Addressing issues from golint
1 parent 4b3661b commit c7a866c

File tree

9 files changed

+94
-82
lines changed

9 files changed

+94
-82
lines changed

cmd/root.go

+24-23
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()
@@ -107,31 +108,31 @@ func Handler(ctx context.Context, event events.CodePipelineEvent) (string, error
107108
if cplErr != nil {
108109
log.Fatalf(errors.Wrap(err, "Failed to update CodePipeline jobID status").Error())
109110
}
110-
return "Failure", err
111-
} else {
112-
log.Info("Notifying CodePipeline and mark its job execution as Success")
113-
jobID := event.CodePipelineJob.ID
114-
if len(jobID) == 0 {
115-
panic("CodePipeline Job ID is not set")
116-
}
117-
// mark the job as Success.
118-
cplSuccess := &codepipeline.PutJobSuccessResultInput{
119-
JobId: aws.String(jobID),
120-
}
121-
_, cplErr := cpl.PutJobSuccessResult(cplSuccess)
122-
if cplErr != nil {
123-
log.Fatalf(errors.Wrap(err, "Failed to update CodePipeline jobID status").Error())
124-
}
125-
return "Success", nil
111+
return "Failure", err
126112
}
127-
} else {
128-
if err != nil {
129-
log.Fatalf(errors.Wrap(err, "Notifying Lambda and mark this execution as Failure").Error())
130-
return "Failure", err
131-
} else {
132-
return "Success", nil
113+
114+
log.Info("Notifying CodePipeline and mark its job execution as Success")
115+
jobID := event.CodePipelineJob.ID
116+
if len(jobID) == 0 {
117+
panic("CodePipeline Job ID is not set")
133118
}
119+
// mark the job as Success.
120+
cplSuccess := &codepipeline.PutJobSuccessResultInput{
121+
JobId: aws.String(jobID),
122+
}
123+
_, cplErr := cpl.PutJobSuccessResult(cplSuccess)
124+
if cplErr != nil {
125+
log.Fatalf(errors.Wrap(err, "Failed to update CodePipeline jobID status").Error())
126+
}
127+
128+
return "Success", nil
129+
}
130+
131+
if err != nil {
132+
log.Fatalf(errors.Wrap(err, "Notifying Lambda and mark this execution as Failure").Error())
133+
return "Failure", err
134134
}
135+
return "Success", nil
135136
}
136137

137138
func init() {
@@ -215,7 +216,7 @@ func configLambda() {
215216
}
216217
cfg.SCIMAccessToken = unwrap
217218

218-
unwrap, err = secrets.SCIMEndpointUrl(os.Getenv("SCIM_ENDPOINT"))
219+
unwrap, err = secrets.SCIMEndpointURL(os.Getenv("SCIM_ENDPOINT"))
219220
if err != nil {
220221
log.Fatalf(errors.Wrap(err, "cannot read config: SCIM_ENDPOINT").Error())
221222
}

internal/aws/client.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@ import (
2828
)
2929

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

36-
type ErrHttpNotOK struct {
39+
// ErrHTTPNotOK
40+
type ErrHTTPNotOK struct {
3741
StatusCode int
3842
}
3943

40-
func (e *ErrHttpNotOK) Error() string {
44+
func (e *ErrHTTPNotOK) Error() string {
4145
return fmt.Sprintf("status of http response was %d", e.StatusCode)
4246
}
4347

@@ -62,15 +66,15 @@ type Client interface {
6266
}
6367

6468
type client struct {
65-
httpClient HttpClient
69+
httpClient HTTPClient
6670
endpointURL *url.URL
6771
bearerToken string
6872
}
6973

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

119123
// If we get a non-2xx status code, raise that via an error
120124
if resp.StatusCode < http.StatusOK || resp.StatusCode > http.StatusNoContent {
121-
err = &ErrHttpNotOK{resp.StatusCode}
125+
err = &ErrHTTPNotOK{resp.StatusCode}
122126
}
123127

124128
return

internal/aws/client_test.go

+9-9
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

+2-2
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

+14-14
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

+4-4
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

+9-10
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,17 @@ func (c *client) GetGroups(query string) ([]*admin.Group, error) {
175175
return nil
176176
})
177177
return g, err
178-
} else {
178+
}
179179

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, ",")
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, ",")
182182

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-
}
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+
})
190189
}
191190

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

0 commit comments

Comments
 (0)