Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6987967

Browse files
authored
[WIP] Remote triggering a pipeline (#158)
* WIP for trigger.* Started working on remote triggering a pipeline.* Need to find a better way to inject a handler.. but maybe this is okay.* Put the user generation into the right place.* Auto user authentication.* Updated auth.* Update server.go* Remote triggering works now.* Do not use a pointer.* This now works with parameters.* Okay this works now.* Added endpoints to reset the token... no front-end work yet.* Updated echo.* Displaying the tokens for users and pipelines.* Fixed failing tests.* Working user token re-generation.* Extra warding..* Only allow token reset for auto user.* Only allow token reset for auto user.* No need to autogenerate the password. No real login will be performed with auto* Disallow deleting the auto user.* First test.* First pipeline test.* Resetting mock.* Moar coverage.* Added test for pipeline token reset.* Moar coverage.* Addressed comments.* Moved trigger token generation to the right place.* Using a random namespace.* Extracted the secret uuid generation into a separate package.* Added test coverage.
1 parentddf8c49 commit6987967

File tree

17 files changed

+692
-21
lines changed

17 files changed

+692
-21
lines changed

‎frontend/client/views/overview/index.vue‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,35 @@
1818
<hrclass="pipeline-hr">
1919
<div>
2020
<iclass="fa fa-hourglass"></i>
21-
<spanstyle="color:#b1adad;">
22-
Duration:
21+
<spanstyle="color:#b1adad;">
22+
Duration:
2323
</span>
24-
<spanv-if="pipeline.r.status === 'success' || pipeline.r.status === 'failed'">
24+
<spanv-if="pipeline.r.status === 'success' || pipeline.r.status === 'failed'">
2525
{{ calculateDuration(pipeline.r.startdate, pipeline.r.finishdate) }}
2626
</span>
2727
<spanv-else>
2828
unknown
2929
</span><br />
3030
<iclass="fa fa-calendar"></i>
31-
<spanstyle="color:#b1adad;">
32-
Started:
31+
<spanstyle="color:#b1adad;">
32+
Started:
3333
</span>
34-
<spanv-if="pipeline.r.status === 'success' || pipeline.r.status === 'failed'">
34+
<spanv-if="pipeline.r.status === 'success' || pipeline.r.status === 'failed'">
3535
{{ humanizedDate(pipeline.r.finishdate) }}
3636
</span>
3737
<spanv-else>
3838
unknown
3939
</span><br />
40+
<iclass="fa fa-exchange"></i>
41+
<spanstyle="color:#b1adad;">
42+
Trigger Token:
43+
</span>
44+
<spanv-if="pipeline.p.trigger_token !== ''">
45+
{{ pipeline.p.trigger_token }}
46+
</span>
47+
<spanv-else>
48+
unknown
49+
</span><br />
4050
<divclass="pipelinegrid-footer">
4151
<aclass="button is-primary"@click="checkPipelineArgs(pipeline.p)"style="width:100%;">
4252
<spanclass="icon">

‎frontend/client/views/settings/index.vue‎

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@
3030
<td:title="props.row.lastlogin"v-tippy="{ arrow : true, animation : 'shift-away'}">
3131
<span>{{ convertTime(props.row.lastlogin) }}</span>
3232
</td>
33+
<td:title="props.row.trigger_token"v-tippy="{ arrow : true, animation : 'shift-away'}">
34+
<span>{{ props.row.trigger_token }}</span>
35+
</td>
3336
<td>
3437
<av-on:click="editUserModal(props.row)"><iclass="fa fa-edit"
3538
style="color:whitesmoke;"></i></a>
36-
<av-on:click="deleteUserModal(props.row)"v-if="props.row.username !== session.username"><i
39+
<av-on:click="resetTriggerTokenModal(props.row)"v-if="props.row.username === 'auto'">
40+
<iclass="fa fa-sliders"style="color:whitesmoke;"></i></a>
41+
<av-on:click="deleteUserModal(props.row)"v-if="props.row.username !== session.username && props.row.username !== 'auto'"><i
3742
class="fa fa-trash"style="color:whitesmoke;"></i></a>
3843
</td>
3944
</template>
@@ -83,6 +88,8 @@
8388
<td>
8489
<av-on:click="editPipelineModal(props.row)"><iclass="fa fa-edit"
8590
style="color:whitesmoke;"></i></a>
91+
<av-on:click="resetPipelineTriggerTokenModal(props.row)"><iclass="fa fa-sliders"
92+
style="color:whitesmoke;"></i></a>
8693
<av-on:click="deletePipelineModal(props.row)"><iclass="fa fa-trash"
8794
style="color:whitesmoke;"></i></a>
8895
</td>
@@ -144,6 +151,30 @@
144151
</div>
145152
</modal>
146153

154+
<!-- reset trigger token modal-->
155+
<modal:visible="showResetTriggerTokenModal"class="modal-z-index"@close="close">
156+
<divclass="box user-modal">
157+
<divclass="block user-modal-content">
158+
<collapseaccordionis-fullwidth>
159+
<collapse-itemtitle="Reset Trigger Token"selected>
160+
<divclass="user-modal-content">
161+
<labelclass="label"style="text-align:left;">Reset Trigger Token for user {{ selectUser.display_name
162+
}}?</label>
163+
</div>
164+
</collapse-item>
165+
</collapse>
166+
<divclass="modal-footer">
167+
<divstyle="float:left;">
168+
<buttonclass="button is-primary"v-on:click="resetUserTriggerToken">Reset Token</button>
169+
</div>
170+
<divstyle="float:right;">
171+
<buttonclass="button is-danger"v-on:click="close">Cancel</button>
172+
</div>
173+
</div>
174+
</div>
175+
</div>
176+
</modal>
177+
147178
<!-- delete user modal-->
148179
<modal:visible="showDeleteUserModal"class="modal-z-index"@close="close">
149180
<divclass="box user-modal">
@@ -260,6 +291,32 @@
260291
</div>
261292
</modal>
262293

294+
<!-- reset trigger token modal-->
295+
<modal:visible="showResetPipelineTriggerTokenModal"class="modal-z-index"@close="close">
296+
<divclass="box pipeline-modal">
297+
<divclass="block pipeline-modal-content">
298+
<collapseaccordionis-fullwidth>
299+
<collapse-itemtitle="Reset Pipeline Trigger Token"selected>
300+
<divclass="pipeline-modal-content">
301+
<pclass="control has-icons-left"style="padding-bottom:5px;">
302+
<labelclass="label"style="text-align:left;">Reset Token for pipeline {{ selectPipeline.name
303+
}}?</label>
304+
</p>
305+
</div>
306+
</collapse-item>
307+
</collapse>
308+
<divclass="modal-footer">
309+
<divstyle="float:left;">
310+
<buttonclass="button is-primary"v-on:click="resetPipelineTriggerToken">Reset Token</button>
311+
</div>
312+
<divstyle="float:right;">
313+
<buttonclass="button is-danger"v-on:click="close">Cancel</button>
314+
</div>
315+
</div>
316+
</div>
317+
</div>
318+
</modal>
319+
263320
<!-- delete pipeline modal-->
264321
<modal:visible="showDeletePipelineModal"class="modal-z-index"@close="close">
265322
<divclass="box pipeline-modal">
@@ -339,6 +396,10 @@
339396
label:'Last Login',
340397
field:'lastlogin'
341398
},
399+
{
400+
label:'Trigger Token',
401+
field:'trigger_token'
402+
},
342403
{
343404
label:''
344405
}
@@ -366,8 +427,10 @@
366427
selectPipeline: {},
367428
showEditUserModal:false,
368429
showDeleteUserModal:false,
430+
showResetTriggerTokenModal:false,
369431
showAddUserModal:false,
370432
showEditPipelineModal:false,
433+
showResetPipelineTriggerTokenModal:false,
371434
showDeletePipelineModal:false,
372435
pipelinePeriodicSchedules:''
373436
}
@@ -419,6 +482,11 @@
419482
this.showEditUserModal=true
420483
},
421484
485+
resetTriggerTokenModal (user) {
486+
this.selectUser= user
487+
this.showResetTriggerTokenModal=true
488+
},
489+
422490
deleteUserModal (user) {
423491
this.selectUser= user
424492
this.showDeleteUserModal=true
@@ -439,6 +507,11 @@
439507
this.showEditPipelineModal=true
440508
},
441509
510+
resetPipelineTriggerTokenModal (pipeline) {
511+
this.selectPipeline= pipeline
512+
this.showResetPipelineTriggerTokenModal=true
513+
},
514+
442515
deletePipelineModal (pipeline) {
443516
this.selectPipeline= pipeline
444517
this.showDeletePipelineModal=true
@@ -447,9 +520,11 @@
447520
close () {
448521
this.showEditUserModal=false
449522
this.showDeleteUserModal=false
523+
this.showResetTriggerTokenModal=false
450524
this.showAddUserModal=false
451525
this.selectUser= {}
452526
this.showEditPipelineModal=false
527+
this.showResetPipelineTriggerTokenModal=false
453528
this.showDeletePipelineModal=false
454529
this.selectPipeline= {}
455530
this.pipelinePeriodicSchedules=''
@@ -483,6 +558,22 @@
483558
this.close()
484559
},
485560
561+
resetUserTriggerToken () {
562+
this.$http
563+
.put('/api/v1/user/'+this.selectUser.username+'/reset-trigger-token')
564+
.then(response=> {
565+
openNotification({
566+
title:'Token changed!',
567+
message:'New trigger token has been generated!',
568+
type:'success'
569+
})
570+
})
571+
.catch((error)=> {
572+
this.$onError(error)
573+
})
574+
this.close()
575+
},
576+
486577
addUser () {
487578
// pre-validate
488579
if (!this.selectUser.password||!this.selectUser.passwordconf) {
@@ -582,6 +673,22 @@
582673
this.close()
583674
},
584675
676+
resetPipelineTriggerToken () {
677+
this.$http
678+
.put('/api/v1/pipeline/'+this.selectPipeline.id+'/reset-trigger-token')
679+
.then(response=> {
680+
openNotification({
681+
title:'Token changed!',
682+
message:'New trigger token has been generated!',
683+
type:'success'
684+
})
685+
})
686+
.catch((error)=> {
687+
this.$onError(error)
688+
})
689+
this.close()
690+
},
691+
585692
deletePipeline () {
586693
this.$http
587694
.delete('/api/v1/pipeline/'+this.selectPipeline.id)

‎gaia.go‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,13 @@ const (
107107

108108
// User is the user object
109109
typeUserstruct {
110-
Usernamestring`json:"username,omitempty"`
111-
Passwordstring`json:"password,omitempty"`
112-
DisplayNamestring`json:"display_name,omitempty"`
113-
Tokenstringstring`json:"tokenstring,omitempty"`
114-
JwtExpiryint64`json:"jwtexpiry,omitempty"`
115-
LastLogin time.Time`json:"lastlogin,omitempty"`
110+
Usernamestring`json:"username,omitempty"`
111+
Passwordstring`json:"password,omitempty"`
112+
DisplayNamestring`json:"display_name,omitempty"`
113+
Tokenstringstring`json:"tokenstring,omitempty"`
114+
JwtExpiryint64`json:"jwtexpiry,omitempty"`
115+
LastLogin time.Time`json:"lastlogin,omitempty"`
116+
TriggerTokenstring`json:"trigger_token,omitempty"`
116117
}
117118

118119
// UserPermission is stored in its own data structure away from the core user. It represents all permission data
@@ -156,6 +157,7 @@ type Pipeline struct {
156157
UUIDstring`json:"uuid,omitempty"`
157158
IsNotValidbool`json:"notvalid,omitempty"`
158159
PeriodicSchedules []string`json:"periodicschedules,omitempty"`
160+
TriggerTokenstring`json:"trigger_token,omitempty"`
159161
CronInst*cron.Cron`json:"-"`
160162
}
161163

‎go.mod‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ require (
1111
github.com/emirpasic/godsv1.9.0// indirect
1212
github.com/flynn/go-shlexv0.0.0-20150515145356-3f9db97f8568// indirect
1313
github.com/gaia-pipeline/flagv1.7.4-pre
14+
github.com/gaia-pipeline/gosdkv0.0.0-20180909192508-cc9f89055777
1415
github.com/gaia-pipeline/protobufv0.0.0-20180812091451-7be8a901b55a
1516
github.com/gliderlabs/sshv0.1.1// indirect
17+
github.com/golang/protobufv1.2.0
1618
github.com/google/go-cmpv0.2.0// indirect
1719
github.com/google/go-githubv15.0.0+incompatible
1820
github.com/google/go-querystringv0.0.0-20170111101155-53e6ce116135// indirect
@@ -21,7 +23,7 @@ require (
2123
github.com/hashicorp/yamuxv0.0.0-20180604194846-3520598351bb// indirect
2224
github.com/jbenet/go-contextv0.0.0-20150711004518-d14ea06fba99// indirect
2325
github.com/kevinburke/ssh_configv0.0.0-20180317175531-9fc7bb800b55// indirect
24-
github.com/labstack/echov3.3.5+incompatible
26+
github.com/labstack/echov3.3.10+incompatible
2527
github.com/labstack/gommonv0.0.0-20180613044413-d6898124de91// indirect
2628
github.com/mattn/go-colorablev0.0.9// indirect
2729
github.com/mattn/go-isattyv0.0.3// indirect
@@ -39,9 +41,11 @@ require (
3941
github.com/valyala/fasttemplatev0.0.0-20170224212429-dcecefd839c4// indirect
4042
github.com/xanzy/ssh-agentv0.2.0// indirect
4143
golang.org/x/cryptov0.0.0-20190103213133-ff983b9c42bc
44+
golang.org/x/netv0.0.0-20180826012351-8a410e7b638d
4245
golang.org/x/oauth2v0.0.0-20180821212333-d2e6202438be
4346
golang.org/x/syncv0.0.0-20181221193216-37e7f081c4d4// indirect
4447
golang.org/x/sysv0.0.0-20180905080454-ebe1bf3edb33// indirect
48+
golang.org/x/textv0.3.0
4549
google.golang.org/grpcv1.18.0
4650
gopkg.in/src-d/go-billy.v4v4.3.0// indirect
4751
gopkg.in/src-d/go-git-fixtures.v3v3.3.0// indirect

‎go.sum‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjr
2222
github.com/flynn/go-shlexv0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
2323
github.com/gaia-pipeline/flagv1.7.4-pre h1:/TAmHVYVQGE4Mw9xl0Qs0D5UruVDMF95thexyEFbTAY=
2424
github.com/gaia-pipeline/flagv1.7.4-pre/go.mod h1:rLpsWzqOEPa2K0Yl4aC34nmblLpIYjGqjP/srZbYvEk=
25+
github.com/gaia-pipeline/gosdkv0.0.0-20180909192508-cc9f89055777 h1:Gn3nmETr4IE44pIFLeTDNNBBRhNXXh53PqFV23CsVok=
26+
github.com/gaia-pipeline/gosdkv0.0.0-20180909192508-cc9f89055777/go.mod h1:e3TkvPdcdSdHZTgwiS89fs8lJrveYHsGLlz/Q0oXlN8=
2527
github.com/gaia-pipeline/protobufv0.0.0-20180812091451-7be8a901b55a h1:/5XAmdAyGl4yL9BugdPdBLaXquif1zw6Hih6go8E7Xs=
2628
github.com/gaia-pipeline/protobufv0.0.0-20180812091451-7be8a901b55a/go.mod h1:H0w7MofSuW53Nz7kesnBdVkvr437flf5B7D9Lcsb+lQ=
2729
github.com/gliderlabs/sshv0.1.1 h1:j3L6gSLQalDETeEg/Jg0mGY0/y/N6zI2xX1978P0Uqw=
@@ -53,8 +55,10 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
5355
github.com/kr/ptyv1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
5456
github.com/kr/textv0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
5557
github.com/kr/textv0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
56-
github.com/labstack/echov3.3.5+incompatible h1:9PfxPUmasKzeJor9uQTaXLT6WUG/r+vSTmvXxvv3JO4=
58+
github.com/labstack/echov3.3.5+incompatible h1:Y3vG4kINVWNQN8Y6Jdur8uLat7fSLV5n5yLE8n+JbF4=
5759
github.com/labstack/echov3.3.5+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
60+
github.com/labstack/echov3.3.10+incompatible h1:pGRcYk231ExFAyoAjAfD85kQzRJCRI8bbnE7CX5OEgg=
61+
github.com/labstack/echov3.3.10+incompatible/go.mod h1:0INS7j/VjnFxD4E2wkz67b8cVwCLbBmJyDaka6Cmk1s=
5862
github.com/labstack/gommonv0.0.0-20180613044413-d6898124de91 h1:6R2WAx0PYNGtK2ZED9xKlTGEha51GsCFZijom+NMGEk=
5963
github.com/labstack/gommonv0.0.0-20180613044413-d6898124de91/go.mod h1:/tj9csK2iPSBvn+3NLM9e52usepMtrd5ilFYA+wQNJ4=
6064
github.com/mattn/go-colorablev0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=

‎handlers/auth.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ func AuthMiddleware(roleAuth *AuthConfig) echo.MiddlewareFunc {
2929
c.Path()=="/"||
3030
strings.Contains(c.Path(),"/assets/")||
3131
c.Path()=="/favicon.ico"||
32-
strings.Contains(c.Path(),"pipeline/githook") {
32+
strings.Contains(c.Path(),"pipeline/githook")||
33+
strings.Contains(c.Path(),"/trigger") {
3334
returnnext(c)
3435
}
3536

‎handlers/handler.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func InitHandlers(e *echo.Echo) error {
4343
e.GET(p+"user/:username/permissions",UserGetPermissions)
4444
e.PUT(p+"user/:username/permissions",UserPutPermissions)
4545
e.POST(p+"user",UserAdd)
46+
e.PUT(p+"user/:username/reset-trigger-token",UserResetTriggerToken)
4647

4748
perms:=e.Group(p+"permission")
4849
perms.GET("",PermissionGetAll)
@@ -58,6 +59,8 @@ func InitHandlers(e *echo.Echo) error {
5859
e.PUT(p+"pipeline/:pipelineid",PipelineUpdate)
5960
e.DELETE(p+"pipeline/:pipelineid",PipelineDelete)
6061
e.POST(p+"pipeline/:pipelineid/start",PipelineStart)
62+
e.POST(p+"pipeline/:pipelineid/:pipelinetoken/trigger",PipelineTrigger)
63+
e.PUT(p+"pipeline/:pipelineid/reset-trigger-token",PipelineResetToken)
6164
e.GET(p+"pipeline/latest",PipelineGetAllWithLatestRun)
6265
e.POST(p+"pipeline/periodicschedules",PipelineCheckPeriodicSchedules)
6366

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp