Add optional keepWebhook flag when removing an entity
The user can opt to not delete the webhook (if installed) when removing the entity from garm. Garm will only ever try to remove a webhook that exactly matches the URL that is composed of the base webhook URL configured in the config.toml file and the unique controller ID that is generated when the controller is first installed. It should be safe to remove the webhook when the entity is removed. Of course, this behavior can be disabled. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
bb6ee9c668
commit
c00048e128
7 changed files with 108 additions and 2 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
gErrors "github.com/cloudbase/garm-provider-common/errors"
|
||||
"github.com/cloudbase/garm/apiserver/params"
|
||||
|
|
@ -139,6 +140,12 @@ func (a *APIController) GetOrgByIDHandler(w http.ResponseWriter, r *http.Request
|
|||
// in: path
|
||||
// required: true
|
||||
//
|
||||
// + name: keepWebhook
|
||||
// description: If true and a webhook is installed for this organization, it will not be removed.
|
||||
// type: boolean
|
||||
// in: query
|
||||
// required: false
|
||||
//
|
||||
// Responses:
|
||||
// default: APIErrorResponse
|
||||
func (a *APIController) DeleteOrgHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -157,7 +164,9 @@ func (a *APIController) DeleteOrgHandler(w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
|
||||
if err := a.r.DeleteOrganization(ctx, orgID, false); err != nil {
|
||||
keepWebhook, _ := strconv.ParseBool(r.URL.Query().Get("keepWebhook"))
|
||||
|
||||
if err := a.r.DeleteOrganization(ctx, orgID, keepWebhook); err != nil {
|
||||
log.Printf("removing org: %+v", err)
|
||||
handleError(w, err)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
gErrors "github.com/cloudbase/garm-provider-common/errors"
|
||||
"github.com/cloudbase/garm/apiserver/params"
|
||||
|
|
@ -139,6 +140,12 @@ func (a *APIController) GetRepoByIDHandler(w http.ResponseWriter, r *http.Reques
|
|||
// in: path
|
||||
// required: true
|
||||
//
|
||||
// + name: keepWebhook
|
||||
// description: If true and a webhook is installed for this repo, it will not be removed.
|
||||
// type: boolean
|
||||
// in: query
|
||||
// required: false
|
||||
//
|
||||
// Responses:
|
||||
// default: APIErrorResponse
|
||||
func (a *APIController) DeleteRepoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -157,7 +164,8 @@ func (a *APIController) DeleteRepoHandler(w http.ResponseWriter, r *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
if err := a.r.DeleteRepository(ctx, repoID, false); err != nil {
|
||||
keepWebhook, _ := strconv.ParseBool(r.URL.Query().Get("keepWebhook"))
|
||||
if err := a.r.DeleteRepository(ctx, repoID, keepWebhook); err != nil {
|
||||
log.Printf("fetching repo: %s", err)
|
||||
handleError(w, err)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -702,6 +702,10 @@ paths:
|
|||
name: orgID
|
||||
required: true
|
||||
type: string
|
||||
- description: If true and a webhook is installed for this organization, it will not be removed.
|
||||
in: query
|
||||
name: keepWebhook
|
||||
type: boolean
|
||||
responses:
|
||||
default:
|
||||
description: APIErrorResponse
|
||||
|
|
@ -1147,6 +1151,10 @@ paths:
|
|||
name: repoID
|
||||
required: true
|
||||
type: string
|
||||
- description: If true and a webhook is installed for this repo, it will not be removed.
|
||||
in: query
|
||||
name: keepWebhook
|
||||
type: boolean
|
||||
responses:
|
||||
default:
|
||||
description: APIErrorResponse
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue