Skip to content

Commit aeb620a

Browse files
committed
Migrated away from iris to echo
1 parent e2715d5 commit aeb620a

File tree

14 files changed

+259
-298
lines changed

14 files changed

+259
-298
lines changed

cmd/gaia/main.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import (
1111
scheduler "github.com/gaia-pipeline/gaia/scheduler"
1212
"github.com/gaia-pipeline/gaia/store"
1313
hclog "github.com/hashicorp/go-hclog"
14-
"github.com/kataras/iris"
14+
"github.com/labstack/echo"
1515
)
1616

1717
var (
18-
irisInstance *iris.Application
18+
echoInstance *echo.Echo
1919
)
2020

2121
const (
@@ -80,8 +80,8 @@ func main() {
8080
os.Exit(1)
8181
}
8282

83-
// Initialize IRIS
84-
irisInstance = iris.New()
83+
// Initialize echo instance
84+
echoInstance = echo.New()
8585

8686
// Initialize store
8787
store := store.NewStore()
@@ -96,7 +96,7 @@ func main() {
9696
scheduler.Init()
9797

9898
// Initialize handlers
99-
err = handlers.InitHandlers(irisInstance, store, scheduler)
99+
err = handlers.InitHandlers(echoInstance, store, scheduler)
100100
if err != nil {
101101
gaia.Cfg.Logger.Error("cannot initialize handlers", "error", err.Error())
102102
os.Exit(1)
@@ -106,7 +106,7 @@ func main() {
106106
pipeline.InitTicker(store, scheduler)
107107

108108
// Start listen
109-
irisInstance.Run(iris.Addr(":" + gaia.Cfg.ListenPort))
109+
echoInstance.Logger.Fatal(echoInstance.Start(":" + gaia.Cfg.ListenPort))
110110
}
111111

112112
// findExecuteablePath returns the absolute path for the current

frontend/client/auth/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export default {
22

33
login (context, creds) {
4-
return context.$http.post('/api/v1/users/login', creds)
4+
return context.$http.post('/api/v1/login', creds)
55
.then((response) => {
66
var newSession = {
77
'token': response.data.tokenstring,

frontend/client/components/layout/Navbar.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default {
8989
},
9090
9191
createPipeline () {
92-
this.$router.push('/pipelines/create')
92+
this.$router.push('/pipeline/create')
9393
},
9494
9595
...mapActions([

frontend/client/router/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ export default new Router({
1616
},
1717
{
1818
name: 'Pipeline Detail',
19-
path: '/pipelines/detail',
20-
component: lazyLoading('pipelines/detail')
19+
path: '/pipeline/detail',
20+
component: lazyLoading('pipeline/detail')
2121
},
2222
{
2323
name: 'Pipeline Logs',
24-
path: '/jobs/log',
25-
component: lazyLoading('jobs/log')
24+
path: '/pipeline/log',
25+
component: lazyLoading('pipeline/log')
2626
}
2727
]
2828
})

frontend/client/store/modules/menu/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ const state = {
1717
},
1818
{
1919
name: 'Create Pipeline',
20-
path: '/pipelines/create',
20+
path: '/pipeline/create',
2121
meta: {
2222
icon: 'fa-plus'
2323
},
24-
component: lazyLoading('pipelines/create')
24+
component: lazyLoading('pipeline/create')
2525
}
2626
]
2727
}

frontend/client/views/overview/index.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<img :src="getImagePath(pipeline.type)" class="outer-box-image">
1010
</div>
1111
<div>
12-
<router-link :to="{ path: '/pipelines/detail', query: { pipelineid: pipeline.id }}" class="subtitle">{{ pipeline.name }}</router-link>
12+
<router-link :to="{ path: '/pipeline/detail', query: { pipelineid: pipeline.id }}" class="subtitle">{{ pipeline.name }}</router-link>
1313
</div>
1414
<div>
1515
<hr style="color: lightgrey;">
@@ -55,7 +55,7 @@ export default {
5555
methods: {
5656
fetchData () {
5757
this.$http
58-
.get('/api/v1/pipelines', { showProgressBar: false })
58+
.get('/api/v1/pipeline', { showProgressBar: false })
5959
.then(response => {
6060
if (response.data) {
6161
this.pipelines = response.data
@@ -70,10 +70,10 @@ export default {
7070
startPipeline (pipelineid) {
7171
// Send start request
7272
this.$http
73-
.get('/api/v1/pipelines/start/' + pipelineid)
73+
.post('/api/v1/pipeline/' + pipelineid + '/start')
7474
.then(response => {
7575
if (response.data) {
76-
this.$router.push({path: '/pipelines/detail', query: { pipelineid: pipelineid, runid: response.data.id }})
76+
this.$router.push({path: '/pipeline/detail', query: { pipelineid: pipelineid, runid: response.data.id }})
7777
}
7878
})
7979
.catch((error) => {

frontend/client/views/pipelines/create.vue frontend/client/views/pipeline/create.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export default {
275275
methods: {
276276
fetchData () {
277277
this.$http
278-
.get('/api/v1/pipelines/create', { showProgressBar: false })
278+
.get('/api/v1/pipeline/created', { showProgressBar: false })
279279
.then(response => {
280280
if (response.data) {
281281
this.historyRows = response.data
@@ -305,7 +305,7 @@ export default {
305305
this.gitSuccess = false
306306
307307
this.$http
308-
.post('/api/v1/pipelines/gitlsremote', this.createPipeline.pipeline.repo)
308+
.post('/api/v1/pipeline/gitlsremote', this.createPipeline.pipeline.repo)
309309
.then(response => {
310310
// Reset error message before
311311
this.gitErrorMsg = ''
@@ -343,7 +343,7 @@ export default {
343343
344344
// Request for availability
345345
this.$http
346-
.post('/api/v1/pipelines/name', this.createPipeline)
346+
.get('/api/v1/pipeline/name', { params: { name: this.pipelinename } })
347347
.then(response => {
348348
// pipeline name valid and available
349349
this.pipelineErrorMsg = ''
@@ -362,7 +362,7 @@ export default {
362362
363363
// Start the create pipeline process in the backend
364364
this.$http
365-
.post('/api/v1/pipelines/create', this.createPipeline)
365+
.post('/api/v1/pipeline', this.createPipeline)
366366
.then(response => {
367367
// Run fetchData to see the pipeline in our history table
368368
this.fetchData()

frontend/client/views/pipelines/detail.vue frontend/client/views/pipeline/detail.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
styleClass="table table-own-bordered">
3434
<template slot="table-row" slot-scope="props">
3535
<td>
36-
<router-link :to="{ path: '/pipelines/detail', query: { pipelineid: pipelineID, runid: props.row.id }}" class="is-blue">
36+
<router-link :to="{ path: '/pipeline/detail', query: { pipelineid: pipelineID, runid: props.row.id }}" class="is-blue">
3737
{{ props.row.id }}
3838
</router-link>
3939
</td>
@@ -199,15 +199,15 @@ export default {
199199
},
200200
201201
getPipeline (pipelineID) {
202-
return this.$http.get('/api/v1/pipelines/detail/' + pipelineID, { showProgressBar: false })
202+
return this.$http.get('/api/v1/pipeline/' + pipelineID, { showProgressBar: false })
203203
},
204204
205205
getPipelineRun (pipelineID, runID) {
206-
return this.$http.get('/api/v1/pipelines/detail/' + pipelineID + '/' + runID, { showProgressBar: false })
206+
return this.$http.get('/api/v1/pipelinerun/' + pipelineID + '/' + runID, { showProgressBar: false })
207207
},
208208
209209
getPipelineRuns (pipelineID) {
210-
return this.$http.get('/api/v1/pipelines/runs/' + pipelineID, { showProgressBar: false })
210+
return this.$http.get('/api/v1/pipelinerun/' + pipelineID, { showProgressBar: false })
211211
},
212212
213213
drawPipelineDetail (pipeline, pipelineRun) {
@@ -346,7 +346,7 @@ export default {
346346
},
347347
348348
jobLog () {
349-
this.$router.push({path: '/jobs/log', query: { pipelineid: this.pipelineID, runid: this.runID, jobid: this.job.internalID }})
349+
this.$router.push({path: '/pipeline/log', query: { pipelineid: this.pipelineID, runid: this.runID, jobid: this.job.internalID }})
350350
}
351351
}
352352

frontend/client/views/jobs/log.vue frontend/client/views/pipeline/log.vue

+2-4
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@ export default {
5757
// Maximum received bytes
5858
const bufferSize = 1024
5959
this.$http
60-
.get('/api/v1/jobs/log', {
60+
.get('/api/v1/pipelinerun/' + this.pipelineID + '/' + this.runID + '/log', {
6161
showProgressBar: false,
6262
params: {
63-
pipelineid: this.pipelineid,
64-
pipelinerunid: this.runID,
65-
jobid: this.jobid,
63+
jobid: this.jobID,
6664
start: this.startPos,
6765
maxbufferlen: bufferSize
6866
}

handlers/User.go

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package handlers
22

33
import (
4+
"net/http"
45
"time"
56

7+
"github.com/labstack/echo"
8+
69
jwt "github.com/dgrijalva/jwt-go"
710
"github.com/gaia-pipeline/gaia"
8-
"github.com/kataras/iris"
911
)
1012

1113
// jwtExpiry defines how long the produced jwt tokens
@@ -19,26 +21,21 @@ type jwtCustomClaims struct {
1921

2022
// UserLogin authenticates the user with
2123
// the given credentials.
22-
func UserLogin(ctx iris.Context) {
24+
func UserLogin(c echo.Context) error {
2325
u := &gaia.User{}
24-
if err := ctx.ReadJSON(u); err != nil {
25-
ctx.StatusCode(iris.StatusBadRequest)
26-
ctx.WriteString(err.Error())
26+
if err := c.Bind(u); err != nil {
2727
gaia.Cfg.Logger.Debug("error reading json during UserLogin", "error", err.Error())
28-
return
28+
return c.String(http.StatusBadRequest, err.Error())
2929
}
3030

3131
// Authenticate user
3232
user, err := storeService.UserAuth(u)
3333
if err != nil {
3434
gaia.Cfg.Logger.Error("error during UserAuth", "error", err.Error())
35-
ctx.StatusCode(iris.StatusInternalServerError)
36-
return
35+
return c.String(http.StatusInternalServerError, err.Error())
3736
}
3837
if user == nil {
39-
ctx.StatusCode(iris.StatusForbidden)
40-
ctx.WriteString("invalid username and/or password")
41-
return
38+
return c.String(http.StatusForbidden, "invalid username and/or password")
4239
}
4340

4441
// Setup custom claims
@@ -57,13 +54,12 @@ func UserLogin(ctx iris.Context) {
5754
// Sign and get encoded token
5855
tokenstring, err := token.SignedString(jwtKey)
5956
if err != nil {
60-
ctx.StatusCode(iris.StatusInternalServerError)
6157
gaia.Cfg.Logger.Error("error signing jwt token", "error", err.Error())
62-
return
58+
return c.String(http.StatusInternalServerError, err.Error())
6359
}
6460
user.JwtExpiry = claims.ExpiresAt
6561
user.Tokenstring = tokenstring
6662

6763
// Return JWT token and display name
68-
ctx.JSON(user)
64+
return c.JSON(http.StatusOK, user)
6965
}

0 commit comments

Comments
 (0)