Skip to content

Commit 6d5d92e

Browse files
authored
Housekeeping! (#191)
1 parent 19bfc77 commit 6d5d92e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+377
-386
lines changed

handlers/auth.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"net/http"
88
"strings"
99

10-
jwt "github.com/dgrijalva/jwt-go"
10+
"github.com/dgrijalva/jwt-go"
1111
"github.com/gaia-pipeline/gaia"
1212
"github.com/gaia-pipeline/gaia/helper/rolehelper"
1313
"github.com/labstack/echo"
@@ -77,7 +77,7 @@ func (ra *AuthConfig) checkRole(userRoles interface{}, method, path string) erro
7777
return nil
7878
}
7979
}
80-
return fmt.Errorf("Required permission role %s", perm)
80+
return fmt.Errorf("required permission role %s", perm)
8181
}
8282

8383
// Iterate over each category to find a permission (if existing) for this API endpoint.

handlers/auth_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"testing"
1111
"time"
1212

13-
jwt "github.com/dgrijalva/jwt-go"
13+
"github.com/dgrijalva/jwt-go"
1414
"github.com/gaia-pipeline/gaia"
1515
"github.com/gaia-pipeline/gaia/helper/rolehelper"
1616
"github.com/labstack/echo"

handlers/hook.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Payload struct {
4141

4242
func signBody(secret, body []byte) []byte {
4343
computed := hmac.New(sha1.New, secret)
44-
computed.Write(body)
44+
_, _ = computed.Write(body)
4545
return []byte(computed.Sum(nil))
4646
}
4747

@@ -54,7 +54,7 @@ func verifySignature(secret []byte, signature string, body []byte) bool {
5454
}
5555

5656
actual := make([]byte, 20)
57-
hex.Decode(actual, []byte(signature[5:]))
57+
_, _ = hex.Decode(actual, []byte(signature[5:]))
5858
expected := signBody(secret, body)
5959
return hmac.Equal(expected, actual)
6060
}

handlers/hook_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestHookReceive(t *testing.T) {
4545

4646
defer func() {
4747
gaia.Cfg = nil
48-
os.RemoveAll(dataDir)
48+
_ = os.RemoveAll(dataDir)
4949
}()
5050
gaia.Cfg = &gaia.Config{
5151
Logger: hclog.NewNullLogger(),
@@ -84,7 +84,7 @@ func TestHookReceive(t *testing.T) {
8484

8585
ap.Append(p)
8686

87-
InitHandlers(e)
87+
_ = InitHandlers(e)
8888

8989
t.Run("successfully extracting path information from payload", func(t *testing.T) {
9090
payload, _ := ioutil.ReadFile(filepath.Join("fixtures", "hook_basic_push_payload.json"))
@@ -98,7 +98,7 @@ func TestHookReceive(t *testing.T) {
9898
rec := httptest.NewRecorder()
9999
c := e.NewContext(req, rec)
100100

101-
GitWebHook(c)
101+
_ = GitWebHook(c)
102102

103103
// Expected failure because repository does not exist
104104
if rec.Code != http.StatusInternalServerError {
@@ -125,7 +125,7 @@ func TestHookReceive(t *testing.T) {
125125
rec := httptest.NewRecorder()
126126
c := e.NewContext(req, rec)
127127

128-
GitWebHook(c)
128+
_ = GitWebHook(c)
129129

130130
// Expected failure because repository does not exist
131131
if rec.Code != http.StatusBadRequest {

handlers/pipeline.go

+30-29
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package handlers
22

33
import (
4-
"github.com/gaia-pipeline/gaia/helper/stringhelper"
54
"net/http"
65
"strconv"
76
"time"
87

8+
"github.com/gaia-pipeline/gaia/helper/stringhelper"
9+
910
"github.com/gaia-pipeline/gaia/security"
1011

1112
"github.com/gaia-pipeline/gaia"
@@ -118,9 +119,9 @@ func PipelineGet(c echo.Context) error {
118119
}
119120

120121
// Look up pipeline for the given id
121-
for _, pipeline := range pipeline.GlobalActivePipelines.GetAll() {
122-
if pipeline.ID == pipelineID {
123-
return c.JSON(http.StatusOK, pipeline)
122+
for _, p := range pipeline.GlobalActivePipelines.GetAll() {
123+
if p.ID == pipelineID {
124+
return c.JSON(http.StatusOK, p)
124125
}
125126
}
126127

@@ -138,9 +139,9 @@ func PipelineUpdate(c echo.Context) error {
138139

139140
// Look up pipeline for the given id
140141
var foundPipeline gaia.Pipeline
141-
for _, pipeline := range pipeline.GlobalActivePipelines.GetAll() {
142-
if pipeline.ID == p.ID {
143-
foundPipeline = pipeline
142+
for _, pipe := range pipeline.GlobalActivePipelines.GetAll() {
143+
if pipe.ID == p.ID {
144+
foundPipeline = pipe
144145
break
145146
}
146147
}
@@ -184,8 +185,8 @@ func PipelineUpdate(c echo.Context) error {
184185
foundPipeline.CronInst = cron.New()
185186

186187
// Iterate over all cron schedules.
187-
for _, cron := range p.PeriodicSchedules {
188-
err := foundPipeline.CronInst.AddFunc(cron, func() {
188+
for _, schedule := range p.PeriodicSchedules {
189+
err := foundPipeline.CronInst.AddFunc(schedule, func() {
189190
_, err := schedulerService.SchedulePipeline(&foundPipeline, []*gaia.Argument{})
190191
if err != nil {
191192
gaia.Cfg.Logger.Error("cannot schedule pipeline from periodic schedule", "error", err, "pipeline", foundPipeline)
@@ -246,9 +247,9 @@ func PipelineDelete(c echo.Context) error {
246247
// Look up pipeline for the given id
247248
var foundPipeline gaia.Pipeline
248249
var deletedPipelineIndex int
249-
for index, pipeline := range pipeline.GlobalActivePipelines.GetAll() {
250-
if pipeline.ID == pipelineID {
251-
foundPipeline = pipeline
250+
for index, p := range pipeline.GlobalActivePipelines.GetAll() {
251+
if p.ID == pipelineID {
252+
foundPipeline = p
252253
deletedPipelineIndex = index
253254
break
254255
}
@@ -298,9 +299,9 @@ func PipelineTrigger(c echo.Context) error {
298299

299300
// Look up pipeline for the given id
300301
var foundPipeline gaia.Pipeline
301-
for _, pipeline := range pipeline.GlobalActivePipelines.GetAll() {
302-
if pipeline.ID == pipelineID {
303-
foundPipeline = pipeline
302+
for _, p := range pipeline.GlobalActivePipelines.GetAll() {
303+
if p.ID == pipelineID {
304+
foundPipeline = p
304305
break
305306
}
306307
}
@@ -314,8 +315,8 @@ func PipelineTrigger(c echo.Context) error {
314315
}
315316

316317
schedulerService, _ := services.SchedulerService()
317-
args := []*gaia.Argument{}
318-
c.Bind(&args)
318+
var args []*gaia.Argument
319+
_ = c.Bind(&args)
319320
pipelineRun, err := schedulerService.SchedulePipeline(&foundPipeline, args)
320321
if err != nil {
321322
return c.String(http.StatusBadRequest, err.Error())
@@ -340,9 +341,9 @@ func PipelineResetToken(c echo.Context) error {
340341

341342
// Look up pipeline for the given id
342343
var foundPipeline gaia.Pipeline
343-
for _, pipeline := range pipeline.GlobalActivePipelines.GetAll() {
344-
if pipeline.ID == pipelineID {
345-
foundPipeline = pipeline
344+
for _, p := range pipeline.GlobalActivePipelines.GetAll() {
345+
if p.ID == pipelineID {
346+
foundPipeline = p
346347
break
347348
}
348349
}
@@ -395,8 +396,8 @@ func PipelineStart(c echo.Context) error {
395396

396397
// Look for arguments.
397398
// We do not check for errors here cause arguments are optional.
398-
args := []*gaia.Argument{}
399-
c.Bind(&args)
399+
var args []*gaia.Argument
400+
_ = c.Bind(&args)
400401

401402
// Convert string to int because id is int
402403
pipelineID, err := strconv.Atoi(pipelineIDStr)
@@ -406,9 +407,9 @@ func PipelineStart(c echo.Context) error {
406407

407408
// Look up pipeline for the given id
408409
var foundPipeline gaia.Pipeline
409-
for _, pipeline := range pipeline.GlobalActivePipelines.GetAll() {
410-
if pipeline.ID == pipelineID {
411-
foundPipeline = pipeline
410+
for _, p := range pipeline.GlobalActivePipelines.GetAll() {
411+
if p.ID == pipelineID {
412+
foundPipeline = p
412413
break
413414
}
414415
}
@@ -440,16 +441,16 @@ func PipelineGetAllWithLatestRun(c echo.Context) error {
440441

441442
// Iterate all pipelines
442443
var pipelinesWithLatestRun []getAllWithLatestRun
443-
for _, pipeline := range pipelines {
444+
for _, p := range pipelines {
444445
// Get the latest run by the given pipeline id
445-
run, err := storeService.PipelineGetLatestRun(pipeline.ID)
446+
run, err := storeService.PipelineGetLatestRun(p.ID)
446447
if err != nil {
447448
return c.String(http.StatusInternalServerError, err.Error())
448449
}
449450

450451
// Append run if one exists
451452
g := getAllWithLatestRun{}
452-
g.Pipeline = pipeline
453+
g.Pipeline = p
453454
if run != nil {
454455
g.PipelineRun = *run
455456
}
@@ -463,7 +464,7 @@ func PipelineGetAllWithLatestRun(c echo.Context) error {
463464

464465
// PipelineCheckPeriodicSchedules validates the added periodic schedules.
465466
func PipelineCheckPeriodicSchedules(c echo.Context) error {
466-
pSchedules := []string{}
467+
var pSchedules []string
467468
if err := c.Bind(&pSchedules); err != nil {
468469
return c.String(http.StatusBadRequest, err.Error())
469470
}

handlers/pipeline_run.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ import (
1313
"github.com/labstack/echo"
1414
)
1515

16-
const (
17-
maxMaxBufferLen = 1024
18-
)
19-
2016
// jobLogs represents the json format which is returned
2117
// by GetJobLogs.
2218
type jobLogs struct {
@@ -73,9 +69,9 @@ func PipelineStop(c echo.Context) error {
7369

7470
// Look up pipeline for the given id
7571
var foundPipeline gaia.Pipeline
76-
for _, pipeline := range pipeline.GlobalActivePipelines.GetAll() {
77-
if pipeline.ID == p {
78-
foundPipeline = pipeline
72+
for _, pipe := range pipeline.GlobalActivePipelines.GetAll() {
73+
if pipe.ID == p {
74+
foundPipeline = pipe
7975
break
8076
}
8177
}

0 commit comments

Comments
 (0)