Implement optional signature
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a48bc1f1bc
commit
b4b531409f
@ -39,6 +39,11 @@ func initializeDroneOauth() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RepositoryAdminPull struct {
|
||||||
|
Tag *string `json:"tag"`
|
||||||
|
OptionalSignature bool `json:"sig_optional"`
|
||||||
|
}
|
||||||
|
|
||||||
func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
||||||
router.GET("/repositories", func(c *gin.Context) {
|
router.GET("/repositories", func(c *gin.Context) {
|
||||||
var u *User
|
var u *User
|
||||||
@ -203,12 +208,12 @@ func declareAPIAuthRepositoriesRoutes(router *gin.RouterGroup) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var tag *string
|
var rap RepositoryAdminPull
|
||||||
if loggeduser.IsAdmin {
|
if loggeduser.IsAdmin {
|
||||||
c.ShouldBindJSON(&tag)
|
c.ShouldBindJSON(&rap)
|
||||||
}
|
}
|
||||||
|
|
||||||
TriggerTagUpdate(c, work, repo, u, tag)
|
TriggerTagUpdate(c, work, repo, u, rap.Tag, rap.OptionalSignature)
|
||||||
})
|
})
|
||||||
|
|
||||||
repositoriesRoutes.GET("/state", func(c *gin.Context) {
|
repositoriesRoutes.GET("/state", func(c *gin.Context) {
|
||||||
@ -327,7 +332,7 @@ func declareCallbacksRoutes(router *gin.RouterGroup) {
|
|||||||
|
|
||||||
tmp := strings.SplitN(hook.Ref, "/", 3)
|
tmp := strings.SplitN(hook.Ref, "/", 3)
|
||||||
if len(tmp) != 3 {
|
if len(tmp) != 3 {
|
||||||
TriggerTagUpdate(c, work, repo, user, nil)
|
TriggerTagUpdate(c, work, repo, user, nil, false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +360,7 @@ func declareCallbacksRoutes(router *gin.RouterGroup) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TriggerTagUpdate(c, work, repo, user, &tmp[2])
|
TriggerTagUpdate(c, work, repo, user, &tmp[2], false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,7 +392,7 @@ func repositoryHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TriggerTagUpdate(c *gin.Context, work *Work, repo *Repository, u *User, tag *string) {
|
func TriggerTagUpdate(c *gin.Context, work *Work, repo *Repository, u *User, tag *string, sig_optional bool) {
|
||||||
loggeduser := c.MustGet("LoggedUser").(*User)
|
loggeduser := c.MustGet("LoggedUser").(*User)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
@ -411,14 +416,20 @@ func TriggerTagUpdate(c *gin.Context, work *Work, repo *Repository, u *User, tag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client := drone.NewClient(droneEndpoint, droneConfig)
|
env := map[string]string{
|
||||||
result, err := client.BuildCreate("srs", "atsebay.t-worker", "", "master", map[string]string{
|
|
||||||
"REPO_URL": repo.URI,
|
"REPO_URL": repo.URI,
|
||||||
"REPO_TAG": repo_tag,
|
"REPO_TAG": repo_tag,
|
||||||
"LOGIN": login,
|
"LOGIN": login,
|
||||||
"GROUPS": groups,
|
"GROUPS": groups,
|
||||||
"DEST": fmt.Sprintf("%d", work.Id),
|
"DEST": fmt.Sprintf("%d", work.Id),
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if sig_optional {
|
||||||
|
env["TAG_SIG_OPTIONAL"] = "1"
|
||||||
|
}
|
||||||
|
|
||||||
|
client := drone.NewClient(droneEndpoint, droneConfig)
|
||||||
|
result, err := client.BuildCreate("srs", "atsebay.t-worker", "", "master", env)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Unable to communicate with Drone:", err.Error())
|
log.Println("Unable to communicate with Drone:", err.Error())
|
||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to communication with the extraction service."})
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Unable to communication with the extraction service."})
|
||||||
|
@ -55,11 +55,11 @@ export class WorkRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async retrieveWork(tag) {
|
async retrieveWork(admin_struct) {
|
||||||
const res = await fetch(this.id_work?`api/works/${this.id_work}/repositories/${this.id}/trigger`:`api/repositories/${this.id}/trigger`, {
|
const res = await fetch(this.id_work?`api/works/${this.id_work}/repositories/${this.id}/trigger`:`api/repositories/${this.id}/trigger`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {'Accept': 'application/json'},
|
headers: {'Accept': 'application/json'},
|
||||||
body: !tag || tag.length == 0?null:JSON.stringify(tag)
|
body: !admin_struct?{}:JSON.stringify(admin_struct)
|
||||||
});
|
});
|
||||||
if (res.status == 200) {
|
if (res.status == 200) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
let nb_users = 0;
|
let nb_users = 0;
|
||||||
|
|
||||||
let show_logs = null;
|
let show_logs = null;
|
||||||
let run_pull_for = {repo: null, user: null, tag: null};
|
let run_pull_for = {repo: null, user: null, struct: {tag: null, sig_optional: false}};
|
||||||
let search_repo_for = {repo: null, user: null};
|
let search_repo_for = {repo: null, user: null};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -90,7 +90,7 @@
|
|||||||
<button
|
<button
|
||||||
class="btn btn-sm btn-primary mx-1"
|
class="btn btn-sm btn-primary mx-1"
|
||||||
title="Rafraîchir"
|
title="Rafraîchir"
|
||||||
on:click={() => { run_pull_for = { repo, user, tag: '', modal: new bootstrap.Modal(document.getElementById('pullModal'))}; run_pull_for.modal.show(); }}
|
on:click={() => { run_pull_for = { repo, user, struct: {tag:''}, modal: new bootstrap.Modal(document.getElementById('pullModal'))}; run_pull_for.modal.show(); }}
|
||||||
>
|
>
|
||||||
<i class="bi bi-arrow-clockwise"></i>
|
<i class="bi bi-arrow-clockwise"></i>
|
||||||
</button>
|
</button>
|
||||||
@ -128,7 +128,7 @@
|
|||||||
|
|
||||||
<div class="modal fade" tabindex="-1" id="pullModal">
|
<div class="modal fade" tabindex="-1" id="pullModal">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<form class="modal-content" on:submit|preventDefault={() => {run_pull_for.modal.hide(); try { run_pull_for.repo.retrieveWork(run_pull_for.tag) } catch(err) { ToastsStore.addToast({color: "danger", title: "Connexion impossible", msg: err}) };}}>
|
<form class="modal-content" on:submit|preventDefault={() => {run_pull_for.modal.hide(); try { run_pull_for.repo.retrieveWork(run_pull_for.struct) } catch(err) { ToastsStore.addToast({color: "danger", title: "Connexion impossible", msg: err}) };}}>
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title">Repository Pull {#if run_pull_for.user}{run_pull_for.user.login}{/if}</h5>
|
<h5 class="modal-title">Repository Pull {#if run_pull_for.user}{run_pull_for.user.login}{/if}</h5>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
@ -136,7 +136,13 @@
|
|||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="form-group row mb-2">
|
<div class="form-group row mb-2">
|
||||||
<label class="col-2 col-form-label" for="pull-tag">Tag</label>
|
<label class="col-2 col-form-label" for="pull-tag">Tag</label>
|
||||||
<input class="form-control col" id="pull-tag" autofocus placeholder={w.tag} bind:value={run_pull_for.tag}>
|
<input class="form-control col" id="pull-tag" autofocus placeholder={w.tag} bind:value={run_pull_for.struct.tag}>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="checkbox" value="1" id="optional-sig" bind:checked={run_pull_for.struct.sig_optional}>
|
||||||
|
<label class="form-check-label" for="optional-sig">
|
||||||
|
Signature du tag optionnelle
|
||||||
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
@ -150,7 +156,7 @@
|
|||||||
|
|
||||||
<div class="modal fade" tabindex="-1" id="repoModal">
|
<div class="modal fade" tabindex="-1" id="repoModal">
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<form class="modal-content" on:submit|preventDefault={() => {search_repo_for.modal.hide(); try { search_repo_for.repo.retrieveWork(run_pull_for.tag) } catch(err) { ToastsStore.addToast({color: "danger", title: "Connexion impossible", msg: err}) }; search_repo_for.user = null; }}>
|
<form class="modal-content" on:submit|preventDefault={() => {search_repo_for.modal.hide(); try { search_repo_for.repo.retrieveWork(run_pull_for.struct) } catch(err) { ToastsStore.addToast({color: "danger", title: "Connexion impossible", msg: err}) }; search_repo_for.user = null; }}>
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h5 class="modal-title">Repository selector {#if search_repo_for.user}{search_repo_for.user.login}{/if}</h5>
|
<h5 class="modal-title">Repository selector {#if search_repo_for.user}{search_repo_for.user.login}{/if}</h5>
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||||
|
Reference in New Issue
Block a user