Merge pull request #393 from gabriel-samfira/add-gitea

Add gitea
This commit is contained in:
Gabriel 2025-05-20 19:26:46 +03:00 committed by GitHub
commit dee6bf7c9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
208 changed files with 13539 additions and 1621 deletions

View file

@ -106,8 +106,15 @@ func (a *APIController) handleWorkflowJobEvent(ctx context.Context, w http.Respo
signature := r.Header.Get("X-Hub-Signature-256")
hookType := r.Header.Get("X-Github-Hook-Installation-Target-Type")
giteaTargetType := r.Header.Get("X-Gitea-Hook-Installation-Target-Type")
if err := a.r.DispatchWorkflowJob(hookType, signature, body); err != nil {
forgeType := runnerParams.GithubEndpointType
if giteaTargetType != "" {
forgeType = runnerParams.GiteaEndpointType
hookType = giteaTargetType
}
if err := a.r.DispatchWorkflowJob(hookType, signature, forgeType, body); err != nil {
switch {
case errors.Is(err, gErrors.ErrNotFound):
metrics.WebhooksReceived.WithLabelValues(

View file

@ -320,7 +320,7 @@ func (a *APIController) CreateEnterpriseScaleSetHandler(w http.ResponseWriter, r
return
}
scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.GithubEntityTypeEnterprise, enterpriseID, scaleSetData)
scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.ForgeEntityTypeEnterprise, enterpriseID, scaleSetData)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "error creating enterprise scale set")
handleError(ctx, w, err)
@ -404,7 +404,7 @@ func (a *APIController) ListEnterpriseScaleSetsHandler(w http.ResponseWriter, r
return
}
scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.GithubEntityTypeEnterprise, enterpriseID)
scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.ForgeEntityTypeEnterprise, enterpriseID)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing scale sets")
handleError(ctx, w, err)

View file

@ -0,0 +1,241 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package controllers
import (
"encoding/json"
"log/slog"
"math"
"net/http"
"strconv"
"github.com/gorilla/mux"
gErrors "github.com/cloudbase/garm-provider-common/errors"
"github.com/cloudbase/garm/params"
)
// swagger:route GET /gitea/credentials credentials ListGiteaCredentials
//
// List all credentials.
//
// Responses:
// 200: Credentials
// 400: APIErrorResponse
func (a *APIController) ListGiteaCredentials(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
creds, err := a.r.ListGiteaCredentials(ctx)
if err != nil {
handleError(ctx, w, err)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(creds); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response")
}
}
// swagger:route POST /gitea/credentials credentials CreateGiteaCredentials
//
// Create a Gitea credential.
//
// Parameters:
// + name: Body
// description: Parameters used when creating a Gitea credential.
// type: CreateGiteaCredentialsParams
// in: body
// required: true
//
// Responses:
// 200: ForgeCredentials
// 400: APIErrorResponse
func (a *APIController) CreateGiteaCredential(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var params params.CreateGiteaCredentialsParams
if err := json.NewDecoder(r.Body).Decode(&params); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to decode request")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
cred, err := a.r.CreateGiteaCredentials(ctx, params)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to create Gitea credential")
handleError(ctx, w, err)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(cred); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response")
}
}
// swagger:route GET /gitea/credentials/{id} credentials GetGiteaCredentials
//
// Get a Gitea credential.
//
// Parameters:
// + name: id
// description: ID of the Gitea credential.
// type: integer
// in: path
// required: true
//
// Responses:
// 200: ForgeCredentials
// 400: APIErrorResponse
func (a *APIController) GetGiteaCredential(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
idParam, ok := vars["id"]
if !ok {
slog.ErrorContext(ctx, "missing id in request")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
id, err := strconv.ParseUint(idParam, 10, 64)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to parse id")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
if id > math.MaxUint {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "id is too large")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
cred, err := a.r.GetGiteaCredentials(ctx, uint(id))
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to get Gitea credential")
handleError(ctx, w, err)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(cred); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response")
}
}
// swagger:route DELETE /gitea/credentials/{id} credentials DeleteGiteaCredentials
//
// Delete a Gitea credential.
//
// Parameters:
// + name: id
// description: ID of the Gitea credential.
// type: integer
// in: path
// required: true
//
// Responses:
// default: APIErrorResponse
func (a *APIController) DeleteGiteaCredential(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
idParam, ok := vars["id"]
if !ok {
slog.ErrorContext(ctx, "missing id in request")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
id, err := strconv.ParseUint(idParam, 10, 64)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to parse id")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
if id > math.MaxUint {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "id is too large")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
if err := a.r.DeleteGiteaCredentials(ctx, uint(id)); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to delete Gitea credential")
handleError(ctx, w, err)
return
}
w.WriteHeader(http.StatusNoContent)
}
// swagger:route PUT /gitea/credentials/{id} credentials UpdateGiteaCredentials
//
// Update a Gitea credential.
//
// Parameters:
// + name: id
// description: ID of the Gitea credential.
// type: integer
// in: path
// required: true
// + name: Body
// description: Parameters used when updating a Gitea credential.
// type: UpdateGiteaCredentialsParams
// in: body
// required: true
//
// Responses:
// 200: ForgeCredentials
// 400: APIErrorResponse
func (a *APIController) UpdateGiteaCredential(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
idParam, ok := vars["id"]
if !ok {
slog.ErrorContext(ctx, "missing id in request")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
id, err := strconv.ParseUint(idParam, 10, 64)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to parse id")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
if id > math.MaxUint {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "id is too large")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
var params params.UpdateGiteaCredentialsParams
if err := json.NewDecoder(r.Body).Decode(&params); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to decode request")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
cred, err := a.r.UpdateGiteaCredentials(ctx, uint(id), params)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to update Gitea credential")
handleError(ctx, w, err)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(cred); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response")
}
}

View file

@ -0,0 +1,199 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package controllers
import (
"encoding/json"
"log/slog"
"net/http"
"github.com/gorilla/mux"
gErrors "github.com/cloudbase/garm-provider-common/errors"
"github.com/cloudbase/garm/params"
)
// swagger:route POST /gitea/endpoints endpoints CreateGiteaEndpoint
//
// Create a Gitea Endpoint.
//
// Parameters:
// + name: Body
// description: Parameters used when creating a Gitea endpoint.
// type: CreateGiteaEndpointParams
// in: body
// required: true
//
// Responses:
// 200: ForgeEndpoint
// default: APIErrorResponse
func (a *APIController) CreateGiteaEndpoint(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var params params.CreateGiteaEndpointParams
if err := json.NewDecoder(r.Body).Decode(&params); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to decode request")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
endpoint, err := a.r.CreateGiteaEndpoint(ctx, params)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to create Gitea endpoint")
handleError(ctx, w, err)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(endpoint); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response")
}
}
// swagger:route GET /gitea/endpoints endpoints ListGiteaEndpoints
//
// List all Gitea Endpoints.
//
// Responses:
// 200: ForgeEndpoints
// default: APIErrorResponse
func (a *APIController) ListGiteaEndpoints(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
endpoints, err := a.r.ListGiteaEndpoints(ctx)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to list Gitea endpoints")
handleError(ctx, w, err)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(endpoints); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response")
}
}
// swagger:route GET /gitea/endpoints/{name} endpoints GetGiteaEndpoint
//
// Get a Gitea Endpoint.
//
// Parameters:
// + name: name
// description: The name of the Gitea endpoint.
// type: string
// in: path
// required: true
//
// Responses:
// 200: ForgeEndpoint
// default: APIErrorResponse
func (a *APIController) GetGiteaEndpoint(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
name, ok := vars["name"]
if !ok {
slog.ErrorContext(ctx, "missing name in request")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
endpoint, err := a.r.GetGiteaEndpoint(ctx, name)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to get Gitea endpoint")
handleError(ctx, w, err)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(endpoint); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response")
}
}
// swagger:route DELETE /gitea/endpoints/{name} endpoints DeleteGiteaEndpoint
//
// Delete a Gitea Endpoint.
//
// Parameters:
// + name: name
// description: The name of the Gitea endpoint.
// type: string
// in: path
// required: true
//
// Responses:
// default: APIErrorResponse
func (a *APIController) DeleteGiteaEndpoint(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
name, ok := vars["name"]
if !ok {
slog.ErrorContext(ctx, "missing name in request")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
if err := a.r.DeleteGiteaEndpoint(ctx, name); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to delete Gitea endpoint")
handleError(ctx, w, err)
return
}
w.WriteHeader(http.StatusNoContent)
}
// swagger:route PUT /gitea/endpoints/{name} endpoints UpdateGiteaEndpoint
//
// Update a Gitea Endpoint.
//
// Parameters:
// + name: name
// description: The name of the Gitea endpoint.
// type: string
// in: path
// required: true
// + name: Body
// description: Parameters used when updating a Gitea endpoint.
// type: UpdateGiteaEndpointParams
// in: body
// required: true
//
// Responses:
// 200: ForgeEndpoint
// default: APIErrorResponse
func (a *APIController) UpdateGiteaEndpoint(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
vars := mux.Vars(r)
name, ok := vars["name"]
if !ok {
slog.ErrorContext(ctx, "missing name in request")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
var params params.UpdateGiteaEndpointParams
if err := json.NewDecoder(r.Body).Decode(&params); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to decode request")
handleError(ctx, w, gErrors.ErrBadRequest)
return
}
endpoint, err := a.r.UpdateGiteaEndpoint(ctx, name, params)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to update GitHub endpoint")
handleError(ctx, w, err)
return
}
w.Header().Set("Content-Type", "application/json")
if err := json.NewEncoder(w).Encode(endpoint); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to encode response")
}
}

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package controllers
import (
@ -47,7 +60,7 @@ func (a *APIController) ListCredentials(w http.ResponseWriter, r *http.Request)
// required: true
//
// Responses:
// 200: GithubCredentials
// 200: ForgeCredentials
// 400: APIErrorResponse
func (a *APIController) CreateGithubCredential(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
@ -83,7 +96,7 @@ func (a *APIController) CreateGithubCredential(w http.ResponseWriter, r *http.Re
// required: true
//
// Responses:
// 200: GithubCredentials
// 200: ForgeCredentials
// 400: APIErrorResponse
func (a *APIController) GetGithubCredential(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
@ -183,7 +196,7 @@ func (a *APIController) DeleteGithubCredential(w http.ResponseWriter, r *http.Re
// required: true
//
// Responses:
// 200: GithubCredentials
// 200: ForgeCredentials
// 400: APIErrorResponse
func (a *APIController) UpdateGithubCredential(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package controllers
import (
@ -23,7 +36,7 @@ import (
// required: true
//
// Responses:
// 200: GithubEndpoint
// 200: ForgeEndpoint
// default: APIErrorResponse
func (a *APIController) CreateGithubEndpoint(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
@ -52,7 +65,7 @@ func (a *APIController) CreateGithubEndpoint(w http.ResponseWriter, r *http.Requ
// List all GitHub Endpoints.
//
// Responses:
// 200: GithubEndpoints
// 200: ForgeEndpoints
// default: APIErrorResponse
func (a *APIController) ListGithubEndpoints(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
@ -81,7 +94,7 @@ func (a *APIController) ListGithubEndpoints(w http.ResponseWriter, r *http.Reque
// required: true
//
// Responses:
// 200: GithubEndpoint
// 200: ForgeEndpoint
// default: APIErrorResponse
func (a *APIController) GetGithubEndpoint(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
@ -153,7 +166,7 @@ func (a *APIController) DeleteGithubEndpoint(w http.ResponseWriter, r *http.Requ
// required: true
//
// Responses:
// 200: GithubEndpoint
// 200: ForgeEndpoint
// default: APIErrorResponse
func (a *APIController) UpdateGithubEndpoint(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()

View file

@ -330,7 +330,7 @@ func (a *APIController) CreateOrgScaleSetHandler(w http.ResponseWriter, r *http.
return
}
scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.GithubEntityTypeOrganization, orgID, scalesetData)
scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.ForgeEntityTypeOrganization, orgID, scalesetData)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "error creating organization scale set")
handleError(ctx, w, err)
@ -414,7 +414,7 @@ func (a *APIController) ListOrgScaleSetsHandler(w http.ResponseWriter, r *http.R
return
}
scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.GithubEntityTypeOrganization, orgID)
scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.ForgeEntityTypeOrganization, orgID)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing scale sets")
handleError(ctx, w, err)

View file

@ -329,7 +329,7 @@ func (a *APIController) CreateRepoScaleSetHandler(w http.ResponseWriter, r *http
return
}
scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.GithubEntityTypeRepository, repoID, scaleSetData)
scaleSet, err := a.r.CreateEntityScaleSet(ctx, runnerParams.ForgeEntityTypeRepository, repoID, scaleSetData)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "error creating repository scale set")
handleError(ctx, w, err)
@ -413,7 +413,7 @@ func (a *APIController) ListRepoScaleSetsHandler(w http.ResponseWriter, r *http.
return
}
scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.GithubEntityTypeRepository, repoID)
scaleSets, err := a.r.ListEntityScaleSets(ctx, runnerParams.ForgeEntityTypeRepository, repoID)
if err != nil {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "listing scale sets")
handleError(ctx, w, err)

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package events
import (

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package events
import (
@ -14,7 +27,7 @@ func (f Filter) Validate() error {
case common.RepositoryEntityType, common.OrganizationEntityType, common.EnterpriseEntityType,
common.PoolEntityType, common.UserEntityType, common.InstanceEntityType,
common.JobEntityType, common.ControllerEntityType, common.GithubCredentialsEntityType,
common.GithubEndpointEntityType:
common.GiteaCredentialsEntityType, common.ScaleSetEntityType, common.GithubEndpointEntityType:
default:
return common.ErrInvalidEntityType
}

View file

@ -454,6 +454,44 @@ func NewAPIRouter(han *controllers.APIController, authMiddleware, initMiddleware
apiRouter.Handle("/github/credentials/{id}/", http.HandlerFunc(han.UpdateGithubCredential)).Methods("PUT", "OPTIONS")
apiRouter.Handle("/github/credentials/{id}", http.HandlerFunc(han.UpdateGithubCredential)).Methods("PUT", "OPTIONS")
//////////////////////
// Gitea Endpoints //
//////////////////////
// Create Gitea Endpoint
apiRouter.Handle("/gitea/endpoints/", http.HandlerFunc(han.CreateGiteaEndpoint)).Methods("POST", "OPTIONS")
apiRouter.Handle("/gitea/endpoints", http.HandlerFunc(han.CreateGiteaEndpoint)).Methods("POST", "OPTIONS")
// List Gitea Endpoints
apiRouter.Handle("/gitea/endpoints/", http.HandlerFunc(han.ListGiteaEndpoints)).Methods("GET", "OPTIONS")
apiRouter.Handle("/gitea/endpoints", http.HandlerFunc(han.ListGiteaEndpoints)).Methods("GET", "OPTIONS")
// Get Gitea Endpoint
apiRouter.Handle("/gitea/endpoints/{name}/", http.HandlerFunc(han.GetGiteaEndpoint)).Methods("GET", "OPTIONS")
apiRouter.Handle("/gitea/endpoints/{name}", http.HandlerFunc(han.GetGiteaEndpoint)).Methods("GET", "OPTIONS")
// Delete Gitea Endpoint
apiRouter.Handle("/gitea/endpoints/{name}/", http.HandlerFunc(han.DeleteGiteaEndpoint)).Methods("DELETE", "OPTIONS")
apiRouter.Handle("/gitea/endpoints/{name}", http.HandlerFunc(han.DeleteGiteaEndpoint)).Methods("DELETE", "OPTIONS")
// Update Gitea Endpoint
apiRouter.Handle("/gitea/endpoints/{name}/", http.HandlerFunc(han.UpdateGiteaEndpoint)).Methods("PUT", "OPTIONS")
apiRouter.Handle("/gitea/endpoints/{name}", http.HandlerFunc(han.UpdateGiteaEndpoint)).Methods("PUT", "OPTIONS")
////////////////////////
// Gitea credentials //
////////////////////////
// List Gitea Credentials
apiRouter.Handle("/gitea/credentials/", http.HandlerFunc(han.ListGiteaCredentials)).Methods("GET", "OPTIONS")
apiRouter.Handle("/gitea/credentials", http.HandlerFunc(han.ListGiteaCredentials)).Methods("GET", "OPTIONS")
// Create Gitea Credentials
apiRouter.Handle("/gitea/credentials/", http.HandlerFunc(han.CreateGiteaCredential)).Methods("POST", "OPTIONS")
apiRouter.Handle("/gitea/credentials", http.HandlerFunc(han.CreateGiteaCredential)).Methods("POST", "OPTIONS")
// Get Gitea Credential
apiRouter.Handle("/gitea/credentials/{id}/", http.HandlerFunc(han.GetGiteaCredential)).Methods("GET", "OPTIONS")
apiRouter.Handle("/gitea/credentials/{id}", http.HandlerFunc(han.GetGiteaCredential)).Methods("GET", "OPTIONS")
// Delete Gitea Credential
apiRouter.Handle("/gitea/credentials/{id}/", http.HandlerFunc(han.DeleteGiteaCredential)).Methods("DELETE", "OPTIONS")
apiRouter.Handle("/gitea/credentials/{id}", http.HandlerFunc(han.DeleteGiteaCredential)).Methods("DELETE", "OPTIONS")
// Update Gitea Credential
apiRouter.Handle("/gitea/credentials/{id}/", http.HandlerFunc(han.UpdateGiteaCredential)).Methods("PUT", "OPTIONS")
apiRouter.Handle("/gitea/credentials/{id}", http.HandlerFunc(han.UpdateGiteaCredential)).Methods("PUT", "OPTIONS")
/////////////////////////
// Websocket endpoints //
/////////////////////////

View file

@ -74,11 +74,11 @@ definitions:
package: github.com/cloudbase/garm/params
alias: garm_params
items:
$ref: '#/definitions/GithubCredentials'
GithubCredentials:
$ref: '#/definitions/ForgeCredentials'
ForgeCredentials:
type: object
x-go-type:
type: GithubCredentials
type: ForgeCredentials
import:
package: github.com/cloudbase/garm/params
alias: garm_params
@ -271,22 +271,29 @@ definitions:
import:
package: github.com/cloudbase/garm/params
alias: garm_params
GithubEndpoint:
UpdateGiteaEndpointParams:
type: object
x-go-type:
type: GithubEndpoint
type: UpdateGiteaEndpointParams
import:
package: github.com/cloudbase/garm/params
alias: garm_params
GithubEndpoints:
ForgeEndpoint:
type: object
x-go-type:
type: ForgeEndpoint
import:
package: github.com/cloudbase/garm/params
alias: garm_params
ForgeEndpoints:
type: array
x-go-type:
type: GithubEndpoints
type: ForgeEndpoints
import:
package: github.com/cloudbase/garm/params
alias: garm_params
items:
$ref: '#/definitions/GithubEndpoint'
$ref: '#/definitions/ForgeEndpoint'
CreateGithubEndpointParams:
type: object
x-go-type:
@ -294,6 +301,13 @@ definitions:
import:
package: github.com/cloudbase/garm/params
alias: garm_params
CreateGiteaEndpointParams:
type: object
x-go-type:
type: CreateGiteaEndpointParams
import:
package: github.com/cloudbase/garm/params
alias: garm_params
CreateGithubCredentialsParams:
type: object
x-go-type:
@ -301,6 +315,13 @@ definitions:
import:
package: github.com/cloudbase/garm/params
alias: garm_params
CreateGiteaCredentialsParams:
type: object
x-go-type:
type: CreateGiteaCredentialsParams
import:
package: github.com/cloudbase/garm/params
alias: garm_params
UpdateGithubCredentialsParams:
type: object
x-go-type:
@ -308,6 +329,13 @@ definitions:
import:
package: github.com/cloudbase/garm/params
alias: garm_params
UpdateGiteaCredentialsParams:
type: object
x-go-type:
type: UpdateGiteaCredentialsParams
import:
package: github.com/cloudbase/garm/params
alias: garm_params
UpdateControllerParams:
type: object
x-go-type:

View file

@ -23,6 +23,20 @@ definitions:
alias: garm_params
package: github.com/cloudbase/garm/params
type: CreateEnterpriseParams
CreateGiteaCredentialsParams:
type: object
x-go-type:
import:
alias: garm_params
package: github.com/cloudbase/garm/params
type: CreateGiteaCredentialsParams
CreateGiteaEndpointParams:
type: object
x-go-type:
import:
alias: garm_params
package: github.com/cloudbase/garm/params
type: CreateGiteaEndpointParams
CreateGithubCredentialsParams:
type: object
x-go-type:
@ -74,7 +88,7 @@ definitions:
type: CreateScaleSetParams
Credentials:
items:
$ref: '#/definitions/GithubCredentials'
$ref: '#/definitions/ForgeCredentials'
type: array
x-go-type:
import:
@ -97,29 +111,29 @@ definitions:
alias: garm_params
package: github.com/cloudbase/garm/params
type: Enterprises
GithubCredentials:
ForgeCredentials:
type: object
x-go-type:
import:
alias: garm_params
package: github.com/cloudbase/garm/params
type: GithubCredentials
GithubEndpoint:
type: ForgeCredentials
ForgeEndpoint:
type: object
x-go-type:
import:
alias: garm_params
package: github.com/cloudbase/garm/params
type: GithubEndpoint
GithubEndpoints:
type: ForgeEndpoint
ForgeEndpoints:
items:
$ref: '#/definitions/GithubEndpoint'
$ref: '#/definitions/ForgeEndpoint'
type: array
x-go-type:
import:
alias: garm_params
package: github.com/cloudbase/garm/params
type: GithubEndpoints
type: ForgeEndpoints
HookInfo:
type: object
x-go-type:
@ -281,6 +295,20 @@ definitions:
alias: garm_params
package: github.com/cloudbase/garm/params
type: UpdateEntityParams
UpdateGiteaCredentialsParams:
type: object
x-go-type:
import:
alias: garm_params
package: github.com/cloudbase/garm/params
type: UpdateGiteaCredentialsParams
UpdateGiteaEndpointParams:
type: object
x-go-type:
import:
alias: garm_params
package: github.com/cloudbase/garm/params
type: UpdateGiteaEndpointParams
UpdateGithubCredentialsParams:
type: object
x-go-type:
@ -721,6 +749,212 @@ paths:
summary: Initialize the first run of the controller.
tags:
- first-run
/gitea/credentials:
get:
operationId: ListGiteaCredentials
responses:
"200":
description: Credentials
schema:
$ref: '#/definitions/Credentials'
"400":
description: APIErrorResponse
schema:
$ref: '#/definitions/APIErrorResponse'
summary: List all credentials.
tags:
- credentials
post:
operationId: CreateGiteaCredentials
parameters:
- description: Parameters used when creating a Gitea credential.
in: body
name: Body
required: true
schema:
$ref: '#/definitions/CreateGiteaCredentialsParams'
description: Parameters used when creating a Gitea credential.
type: object
responses:
"200":
description: ForgeCredentials
schema:
$ref: '#/definitions/ForgeCredentials'
"400":
description: APIErrorResponse
schema:
$ref: '#/definitions/APIErrorResponse'
summary: Create a Gitea credential.
tags:
- credentials
/gitea/credentials/{id}:
delete:
operationId: DeleteGiteaCredentials
parameters:
- description: ID of the Gitea credential.
in: path
name: id
required: true
type: integer
responses:
default:
description: APIErrorResponse
schema:
$ref: '#/definitions/APIErrorResponse'
summary: Delete a Gitea credential.
tags:
- credentials
get:
operationId: GetGiteaCredentials
parameters:
- description: ID of the Gitea credential.
in: path
name: id
required: true
type: integer
responses:
"200":
description: ForgeCredentials
schema:
$ref: '#/definitions/ForgeCredentials'
"400":
description: APIErrorResponse
schema:
$ref: '#/definitions/APIErrorResponse'
summary: Get a Gitea credential.
tags:
- credentials
put:
operationId: UpdateGiteaCredentials
parameters:
- description: ID of the Gitea credential.
in: path
name: id
required: true
type: integer
- description: Parameters used when updating a Gitea credential.
in: body
name: Body
required: true
schema:
$ref: '#/definitions/UpdateGiteaCredentialsParams'
description: Parameters used when updating a Gitea credential.
type: object
responses:
"200":
description: ForgeCredentials
schema:
$ref: '#/definitions/ForgeCredentials'
"400":
description: APIErrorResponse
schema:
$ref: '#/definitions/APIErrorResponse'
summary: Update a Gitea credential.
tags:
- credentials
/gitea/endpoints:
get:
operationId: ListGiteaEndpoints
responses:
"200":
description: ForgeEndpoints
schema:
$ref: '#/definitions/ForgeEndpoints'
default:
description: APIErrorResponse
schema:
$ref: '#/definitions/APIErrorResponse'
summary: List all Gitea Endpoints.
tags:
- endpoints
post:
operationId: CreateGiteaEndpoint
parameters:
- description: Parameters used when creating a Gitea endpoint.
in: body
name: Body
required: true
schema:
$ref: '#/definitions/CreateGiteaEndpointParams'
description: Parameters used when creating a Gitea endpoint.
type: object
responses:
"200":
description: ForgeEndpoint
schema:
$ref: '#/definitions/ForgeEndpoint'
default:
description: APIErrorResponse
schema:
$ref: '#/definitions/APIErrorResponse'
summary: Create a Gitea Endpoint.
tags:
- endpoints
/gitea/endpoints/{name}:
delete:
operationId: DeleteGiteaEndpoint
parameters:
- description: The name of the Gitea endpoint.
in: path
name: name
required: true
type: string
responses:
default:
description: APIErrorResponse
schema:
$ref: '#/definitions/APIErrorResponse'
summary: Delete a Gitea Endpoint.
tags:
- endpoints
get:
operationId: GetGiteaEndpoint
parameters:
- description: The name of the Gitea endpoint.
in: path
name: name
required: true
type: string
responses:
"200":
description: ForgeEndpoint
schema:
$ref: '#/definitions/ForgeEndpoint'
default:
description: APIErrorResponse
schema:
$ref: '#/definitions/APIErrorResponse'
summary: Get a Gitea Endpoint.
tags:
- endpoints
put:
operationId: UpdateGiteaEndpoint
parameters:
- description: The name of the Gitea endpoint.
in: path
name: name
required: true
type: string
- description: Parameters used when updating a Gitea endpoint.
in: body
name: Body
required: true
schema:
$ref: '#/definitions/UpdateGiteaEndpointParams'
description: Parameters used when updating a Gitea endpoint.
type: object
responses:
"200":
description: ForgeEndpoint
schema:
$ref: '#/definitions/ForgeEndpoint'
default:
description: APIErrorResponse
schema:
$ref: '#/definitions/APIErrorResponse'
summary: Update a Gitea Endpoint.
tags:
- endpoints
/github/credentials:
get:
operationId: ListCredentials
@ -749,9 +983,9 @@ paths:
type: object
responses:
"200":
description: GithubCredentials
description: ForgeCredentials
schema:
$ref: '#/definitions/GithubCredentials'
$ref: '#/definitions/ForgeCredentials'
"400":
description: APIErrorResponse
schema:
@ -786,9 +1020,9 @@ paths:
type: integer
responses:
"200":
description: GithubCredentials
description: ForgeCredentials
schema:
$ref: '#/definitions/GithubCredentials'
$ref: '#/definitions/ForgeCredentials'
"400":
description: APIErrorResponse
schema:
@ -814,9 +1048,9 @@ paths:
type: object
responses:
"200":
description: GithubCredentials
description: ForgeCredentials
schema:
$ref: '#/definitions/GithubCredentials'
$ref: '#/definitions/ForgeCredentials'
"400":
description: APIErrorResponse
schema:
@ -829,9 +1063,9 @@ paths:
operationId: ListGithubEndpoints
responses:
"200":
description: GithubEndpoints
description: ForgeEndpoints
schema:
$ref: '#/definitions/GithubEndpoints'
$ref: '#/definitions/ForgeEndpoints'
default:
description: APIErrorResponse
schema:
@ -852,9 +1086,9 @@ paths:
type: object
responses:
"200":
description: GithubEndpoint
description: ForgeEndpoint
schema:
$ref: '#/definitions/GithubEndpoint'
$ref: '#/definitions/ForgeEndpoint'
default:
description: APIErrorResponse
schema:
@ -889,9 +1123,9 @@ paths:
type: string
responses:
"200":
description: GithubEndpoint
description: ForgeEndpoint
schema:
$ref: '#/definitions/GithubEndpoint'
$ref: '#/definitions/ForgeEndpoint'
default:
description: APIErrorResponse
schema:
@ -917,9 +1151,9 @@ paths:
type: object
responses:
"200":
description: GithubEndpoint
description: ForgeEndpoint
schema:
$ref: '#/definitions/GithubEndpoint'
$ref: '#/definitions/ForgeEndpoint'
default:
description: APIErrorResponse
schema:

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package auth
import "net/http"

View file

@ -44,8 +44,21 @@ const (
instanceTokenFetched contextFlags = "tokenFetched"
instanceHasJITConfig contextFlags = "hasJITConfig"
instanceParams contextFlags = "instanceParams"
instanceForgeTypeKey contextFlags = "forge_type"
)
func SetInstanceForgeType(ctx context.Context, val string) context.Context {
return context.WithValue(ctx, instanceForgeTypeKey, val)
}
func InstanceForgeType(ctx context.Context) params.EndpointType {
elem := ctx.Value(instanceForgeTypeKey)
if elem == nil {
return ""
}
return elem.(params.EndpointType)
}
func SetInstanceID(ctx context.Context, id string) context.Context {
return context.WithValue(ctx, instanceIDKey, id)
}
@ -159,7 +172,7 @@ func InstanceEntity(ctx context.Context) string {
return elem.(string)
}
func PopulateInstanceContext(ctx context.Context, instance params.Instance) context.Context {
func PopulateInstanceContext(ctx context.Context, instance params.Instance, claims *InstanceJWTClaims) context.Context {
ctx = SetInstanceID(ctx, instance.ID)
ctx = SetInstanceName(ctx, instance.Name)
ctx = SetInstancePoolID(ctx, instance.PoolID)
@ -167,6 +180,7 @@ func PopulateInstanceContext(ctx context.Context, instance params.Instance) cont
ctx = SetInstanceTokenFetched(ctx, instance.TokenFetched)
ctx = SetInstanceHasJITConfig(ctx, instance.JitConfiguration)
ctx = SetInstanceParams(ctx, instance)
ctx = SetInstanceForgeType(ctx, claims.ForgeType)
return ctx
}

View file

@ -40,10 +40,11 @@ type InstanceJWTClaims struct {
Name string `json:"name"`
PoolID string `json:"provider_id"`
// Scope is either repository or organization
Scope params.GithubEntityType `json:"scope"`
Scope params.ForgeEntityType `json:"scope"`
// Entity is the repo or org name
Entity string `json:"entity"`
CreateAttempt int `json:"create_attempt"`
ForgeType string `json:"forge_type"`
jwt.RegisteredClaims
}
@ -60,7 +61,7 @@ type instanceToken struct {
jwtSecret string
}
func (i *instanceToken) NewInstanceJWTToken(instance params.Instance, entity string, entityType params.GithubEntityType, ttlMinutes uint) (string, error) {
func (i *instanceToken) NewInstanceJWTToken(instance params.Instance, entity params.ForgeEntity, entityType params.ForgeEntityType, ttlMinutes uint) (string, error) {
// Token expiration is equal to the bootstrap timeout set on the pool plus the polling
// interval garm uses to check for timed out runners. Runners that have not sent their info
// by the end of this interval are most likely failed and will be reaped by garm anyway.
@ -83,7 +84,8 @@ func (i *instanceToken) NewInstanceJWTToken(instance params.Instance, entity str
Name: instance.Name,
PoolID: instance.PoolID,
Scope: entityType,
Entity: entity,
Entity: entity.String(),
ForgeType: string(entity.Credentials.ForgeType),
CreateAttempt: instance.CreateAttempt,
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
@ -124,7 +126,7 @@ func (amw *instanceMiddleware) claimsToContext(ctx context.Context, claims *Inst
return ctx, runnerErrors.ErrUnauthorized
}
ctx = PopulateInstanceContext(ctx, instanceInfo)
ctx = PopulateInstanceContext(ctx, instanceInfo, claims)
return ctx, nil
}

View file

@ -26,5 +26,5 @@ type Middleware interface {
}
type InstanceTokenGetter interface {
NewInstanceJWTToken(instance params.Instance, entity string, poolType params.GithubEntityType, ttlMinutes uint) (string, error)
NewInstanceJWTToken(instance params.Instance, entity params.ForgeEntity, poolType params.ForgeEntityType, ttlMinutes uint) (string, error)
}

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package auth
import (

523
cache/cache_test.go vendored
View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cache
import (
@ -6,6 +19,7 @@ import (
"github.com/stretchr/testify/suite"
runnerErrors "github.com/cloudbase/garm-provider-common/errors"
commonParams "github.com/cloudbase/garm-provider-common/params"
garmTesting "github.com/cloudbase/garm/internal/testing"
"github.com/cloudbase/garm/params"
@ -13,15 +27,20 @@ import (
type CacheTestSuite struct {
suite.Suite
entity params.GithubEntity
entity params.ForgeEntity
}
func (c *CacheTestSuite) SetupTest() {
c.entity = params.GithubEntity{
c.entity = params.ForgeEntity{
ID: "1234",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
Credentials: params.ForgeCredentials{
ID: 1,
Name: "test",
ForgeType: params.GithubEndpointType,
},
}
}
@ -30,7 +49,8 @@ func (c *CacheTestSuite) TearDownTest() {
githubToolsCache.mux.Lock()
defer githubToolsCache.mux.Unlock()
githubToolsCache.entities = make(map[string]GithubEntityTools)
credentialsCache.cache = make(map[uint]params.GithubCredentials)
giteaCredentialsCache.cache = make(map[uint]params.ForgeCredentials)
credentialsCache.cache = make(map[uint]params.ForgeCredentials)
instanceCache.cache = make(map[string]params.Instance)
entityCache = &EntityCache{
entities: make(map[string]EntityItem),
@ -44,23 +64,55 @@ func (c *CacheTestSuite) TestCacheIsInitialized() {
c.Require().NotNil(entityCache)
}
func (c *CacheTestSuite) TestSetCacheWorks() {
func (c *CacheTestSuite) TestSetToolsCacheWorks() {
tools := []commonParams.RunnerApplicationDownload{
{
DownloadURL: garmTesting.Ptr("https://example.com"),
},
}
c.Require().NotNil(githubToolsCache)
c.Require().Len(githubToolsCache.entities, 0)
SetGithubToolsCache(c.entity, tools)
c.Require().Len(githubToolsCache.entities, 1)
cachedTools, ok := GetGithubToolsCache(c.entity.ID)
c.Require().True(ok)
cachedTools, err := GetGithubToolsCache(c.entity.ID)
c.Require().NoError(err)
c.Require().Len(cachedTools, 1)
c.Require().Equal(tools[0].GetDownloadURL(), cachedTools[0].GetDownloadURL())
}
func (c *CacheTestSuite) TestSetToolsCacheWithError() {
tools := []commonParams.RunnerApplicationDownload{
{
DownloadURL: garmTesting.Ptr("https://example.com"),
},
}
c.Require().NotNil(githubToolsCache)
c.Require().Len(githubToolsCache.entities, 0)
SetGithubToolsCache(c.entity, tools)
entity := githubToolsCache.entities[c.entity.ID]
c.Require().Equal(int64(entity.expiresAt.Sub(entity.updatedAt).Minutes()), int64(60))
c.Require().Len(githubToolsCache.entities, 1)
SetGithubToolsCacheError(c.entity, runnerErrors.ErrNotFound)
cachedTools, err := GetGithubToolsCache(c.entity.ID)
c.Require().Error(err)
c.Require().Nil(cachedTools)
}
func (c *CacheTestSuite) TestSetErrorOnNonExistingCacheEntity() {
entity := params.ForgeEntity{
ID: "non-existing-entity",
}
c.Require().NotNil(githubToolsCache)
c.Require().Len(githubToolsCache.entities, 0)
SetGithubToolsCacheError(entity, runnerErrors.ErrNotFound)
storedEntity, err := GetGithubToolsCache(entity.ID)
c.Require().Error(err)
c.Require().Nil(storedEntity)
}
func (c *CacheTestSuite) TestTimedOutToolsCache() {
tools := []commonParams.RunnerApplicationDownload{
{
@ -71,26 +123,30 @@ func (c *CacheTestSuite) TestTimedOutToolsCache() {
c.Require().NotNil(githubToolsCache)
c.Require().Len(githubToolsCache.entities, 0)
SetGithubToolsCache(c.entity, tools)
c.Require().Len(githubToolsCache.entities, 1)
entity := githubToolsCache.entities[c.entity.ID]
entity.updatedAt = entity.updatedAt.Add(-2 * time.Hour)
c.Require().Equal(int64(entity.expiresAt.Sub(entity.updatedAt).Minutes()), int64(60))
c.Require().Len(githubToolsCache.entities, 1)
entity = githubToolsCache.entities[c.entity.ID]
entity.updatedAt = entity.updatedAt.Add(-3 * time.Hour)
entity.expiresAt = entity.updatedAt.Add(-2 * time.Hour)
githubToolsCache.entities[c.entity.ID] = entity
cachedTools, ok := GetGithubToolsCache(c.entity.ID)
c.Require().False(ok)
cachedTools, err := GetGithubToolsCache(c.entity.ID)
c.Require().Error(err)
c.Require().Nil(cachedTools)
}
func (c *CacheTestSuite) TestGetInexistentCache() {
c.Require().NotNil(githubToolsCache)
c.Require().Len(githubToolsCache.entities, 0)
cachedTools, ok := GetGithubToolsCache(c.entity.ID)
c.Require().False(ok)
cachedTools, err := GetGithubToolsCache(c.entity.ID)
c.Require().Error(err)
c.Require().Nil(cachedTools)
}
func (c *CacheTestSuite) TestSetGithubCredentials() {
credentials := params.GithubCredentials{
credentials := params.ForgeCredentials{
ID: 1,
}
SetGithubCredentials(credentials)
@ -100,7 +156,7 @@ func (c *CacheTestSuite) TestSetGithubCredentials() {
}
func (c *CacheTestSuite) TestGetGithubCredentials() {
credentials := params.GithubCredentials{
credentials := params.ForgeCredentials{
ID: 1,
}
SetGithubCredentials(credentials)
@ -110,11 +166,11 @@ func (c *CacheTestSuite) TestGetGithubCredentials() {
nonExisting, ok := GetGithubCredentials(2)
c.Require().False(ok)
c.Require().Equal(params.GithubCredentials{}, nonExisting)
c.Require().Equal(params.ForgeCredentials{}, nonExisting)
}
func (c *CacheTestSuite) TestDeleteGithubCredentials() {
credentials := params.GithubCredentials{
credentials := params.ForgeCredentials{
ID: 1,
}
SetGithubCredentials(credentials)
@ -125,14 +181,14 @@ func (c *CacheTestSuite) TestDeleteGithubCredentials() {
DeleteGithubCredentials(1)
cachedCreds, ok = GetGithubCredentials(1)
c.Require().False(ok)
c.Require().Equal(params.GithubCredentials{}, cachedCreds)
c.Require().Equal(params.ForgeCredentials{}, cachedCreds)
}
func (c *CacheTestSuite) TestGetAllGithubCredentials() {
credentials1 := params.GithubCredentials{
credentials1 := params.ForgeCredentials{
ID: 1,
}
credentials2 := params.GithubCredentials{
credentials2 := params.ForgeCredentials{
ID: 2,
}
SetGithubCredentials(credentials1)
@ -254,9 +310,9 @@ func (c *CacheTestSuite) TestGetInstancesForScaleSet() {
}
func (c *CacheTestSuite) TestSetGetEntityCache() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
@ -265,22 +321,34 @@ func (c *CacheTestSuite) TestSetGetEntityCache() {
c.Require().True(ok)
c.Require().Equal(entity.ID, cachedEntity.ID)
pool := params.Pool{
ID: "pool-1",
}
SetEntityPool(entity.ID, pool)
cachedEntityPools := GetEntityPools("test-entity")
c.Require().Equal(1, len(cachedEntityPools))
entity.Credentials.Description = "test description"
SetEntity(entity)
cachedEntity, ok = GetEntity("test-entity")
c.Require().True(ok)
c.Require().Equal(entity.ID, cachedEntity.ID)
c.Require().Equal(entity.Credentials.Description, cachedEntity.Credentials.Description)
// Make sure we don't clobber pools after updating the entity
cachedEntityPools = GetEntityPools("test-entity")
c.Require().Equal(1, len(cachedEntityPools))
}
func (c *CacheTestSuite) TestReplaceEntityPools() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
Credentials: params.GithubCredentials{
ID: 1,
Credentials: params.ForgeCredentials{
ID: 1,
ForgeType: params.GithubEndpointType,
},
}
pool1 := params.Pool{
@ -290,9 +358,10 @@ func (c *CacheTestSuite) TestReplaceEntityPools() {
ID: "pool-2",
}
credentials := params.GithubCredentials{
ID: 1,
Name: "test",
credentials := params.ForgeCredentials{
ID: 1,
Name: "test",
ForgeType: params.GithubEndpointType,
}
SetGithubCredentials(credentials)
@ -310,9 +379,9 @@ func (c *CacheTestSuite) TestReplaceEntityPools() {
}
func (c *CacheTestSuite) TestReplaceEntityScaleSets() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
@ -336,9 +405,9 @@ func (c *CacheTestSuite) TestReplaceEntityScaleSets() {
}
func (c *CacheTestSuite) TestDeleteEntity() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
@ -350,13 +419,13 @@ func (c *CacheTestSuite) TestDeleteEntity() {
DeleteEntity(entity.ID)
cachedEntity, ok = GetEntity(entity.ID)
c.Require().False(ok)
c.Require().Equal(params.GithubEntity{}, cachedEntity)
c.Require().Equal(params.ForgeEntity{}, cachedEntity)
}
func (c *CacheTestSuite) TestSetEntityPool() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
@ -387,9 +456,9 @@ func (c *CacheTestSuite) TestSetEntityPool() {
}
func (c *CacheTestSuite) TestSetEntityScaleSet() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
@ -417,9 +486,9 @@ func (c *CacheTestSuite) TestSetEntityScaleSet() {
}
func (c *CacheTestSuite) TestDeleteEntityPool() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
@ -440,9 +509,9 @@ func (c *CacheTestSuite) TestDeleteEntityPool() {
}
func (c *CacheTestSuite) TestDeleteEntityScaleSet() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
@ -463,9 +532,9 @@ func (c *CacheTestSuite) TestDeleteEntityScaleSet() {
}
func (c *CacheTestSuite) TestFindPoolsMatchingAllTags() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
@ -520,9 +589,9 @@ func (c *CacheTestSuite) TestFindPoolsMatchingAllTags() {
}
func (c *CacheTestSuite) TestGetEntityPools() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
@ -562,9 +631,9 @@ func (c *CacheTestSuite) TestGetEntityPools() {
}
func (c *CacheTestSuite) TestGetEntityScaleSet() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
@ -584,9 +653,9 @@ func (c *CacheTestSuite) TestGetEntityScaleSet() {
}
func (c *CacheTestSuite) TestGetEntityPool() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
@ -613,6 +682,358 @@ func (c *CacheTestSuite) TestGetEntityPool() {
c.Require().Equal(pool.ID, poolFromCache.ID)
}
func (c *CacheTestSuite) TestSetGiteaCredentials() {
credentials := params.ForgeCredentials{
ID: 1,
Description: "test description",
}
SetGiteaCredentials(credentials)
cachedCreds, ok := GetGiteaCredentials(1)
c.Require().True(ok)
c.Require().Equal(credentials.ID, cachedCreds.ID)
cachedCreds.Description = "new description"
SetGiteaCredentials(cachedCreds)
cachedCreds, ok = GetGiteaCredentials(1)
c.Require().True(ok)
c.Require().Equal(credentials.ID, cachedCreds.ID)
c.Require().Equal("new description", cachedCreds.Description)
}
func (c *CacheTestSuite) TestGetAllGiteaCredentials() {
credentials1 := params.ForgeCredentials{
ID: 1,
}
credentials2 := params.ForgeCredentials{
ID: 2,
}
SetGiteaCredentials(credentials1)
SetGiteaCredentials(credentials2)
cachedCreds := GetAllGiteaCredentials()
c.Require().Len(cachedCreds, 2)
c.Require().Contains(cachedCreds, credentials1)
c.Require().Contains(cachedCreds, credentials2)
}
func (c *CacheTestSuite) TestDeleteGiteaCredentials() {
credentials := params.ForgeCredentials{
ID: 1,
}
SetGiteaCredentials(credentials)
cachedCreds, ok := GetGiteaCredentials(1)
c.Require().True(ok)
c.Require().Equal(credentials.ID, cachedCreds.ID)
DeleteGiteaCredentials(1)
cachedCreds, ok = GetGiteaCredentials(1)
c.Require().False(ok)
c.Require().Equal(params.ForgeCredentials{}, cachedCreds)
}
func (c *CacheTestSuite) TestDeleteGiteaCredentialsNotFound() {
credentials := params.ForgeCredentials{
ID: 1,
}
SetGiteaCredentials(credentials)
cachedCreds, ok := GetGiteaCredentials(1)
c.Require().True(ok)
c.Require().Equal(credentials.ID, cachedCreds.ID)
DeleteGiteaCredentials(2)
cachedCreds, ok = GetGiteaCredentials(1)
c.Require().True(ok)
c.Require().Equal(credentials.ID, cachedCreds.ID)
}
func (c *CacheTestSuite) TestUpdateCredentialsInAffectedEntities() {
credentials := params.ForgeCredentials{
ID: 1,
Description: "test description",
}
entity1 := params.ForgeEntity{
ID: "test-entity-1",
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
Credentials: credentials,
}
entity2 := params.ForgeEntity{
ID: "test-entity-2",
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
Credentials: credentials,
}
SetEntity(entity1)
SetEntity(entity2)
cachedEntity1, ok := GetEntity(entity1.ID)
c.Require().True(ok)
c.Require().Equal(entity1.ID, cachedEntity1.ID)
cachedEntity2, ok := GetEntity(entity2.ID)
c.Require().True(ok)
c.Require().Equal(entity2.ID, cachedEntity2.ID)
c.Require().Equal(credentials.ID, cachedEntity1.Credentials.ID)
c.Require().Equal(credentials.ID, cachedEntity2.Credentials.ID)
c.Require().Equal(credentials.Description, cachedEntity1.Credentials.Description)
c.Require().Equal(credentials.Description, cachedEntity2.Credentials.Description)
credentials.Description = "new description"
SetGiteaCredentials(credentials)
cachedEntity1, ok = GetEntity(entity1.ID)
c.Require().True(ok)
c.Require().Equal(entity1.ID, cachedEntity1.ID)
cachedEntity2, ok = GetEntity(entity2.ID)
c.Require().True(ok)
c.Require().Equal(entity2.ID, cachedEntity2.ID)
c.Require().Equal(credentials.ID, cachedEntity1.Credentials.ID)
c.Require().Equal(credentials.ID, cachedEntity2.Credentials.ID)
c.Require().Equal(credentials.Description, cachedEntity1.Credentials.Description)
c.Require().Equal(credentials.Description, cachedEntity2.Credentials.Description)
}
func (c *CacheTestSuite) TestSetGiteaEntity() {
credentials := params.ForgeCredentials{
ID: 1,
Description: "test description",
ForgeType: params.GiteaEndpointType,
}
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
Credentials: credentials,
}
SetGiteaCredentials(credentials)
SetEntity(entity)
cachedEntity, ok := GetEntity(entity.ID)
c.Require().True(ok)
c.Require().Equal(entity.ID, cachedEntity.ID)
c.Require().Equal(credentials.ID, cachedEntity.Credentials.ID)
c.Require().Equal(credentials.Description, cachedEntity.Credentials.Description)
c.Require().Equal(credentials.ForgeType, cachedEntity.Credentials.ForgeType)
}
func (c *CacheTestSuite) TestGetEntitiesUsingCredentials() {
credentials := params.ForgeCredentials{
ID: 1,
Description: "test description",
Name: "test",
ForgeType: params.GithubEndpointType,
}
credentials2 := params.ForgeCredentials{
ID: 2,
Description: "test description2",
Name: "test",
ForgeType: params.GiteaEndpointType,
}
entity1 := params.ForgeEntity{
ID: "test-entity-1",
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
Credentials: credentials,
}
entity2 := params.ForgeEntity{
ID: "test-entity-2",
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
Credentials: credentials,
}
entity3 := params.ForgeEntity{
ID: "test-entity-3",
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
Credentials: credentials2,
}
SetEntity(entity1)
SetEntity(entity2)
SetEntity(entity3)
cachedEntities := GetEntitiesUsingCredentials(credentials)
c.Require().Len(cachedEntities, 2)
c.Require().Contains(cachedEntities, entity1)
c.Require().Contains(cachedEntities, entity2)
cachedEntities = GetEntitiesUsingCredentials(credentials2)
c.Require().Len(cachedEntities, 1)
c.Require().Contains(cachedEntities, entity3)
}
func (c *CacheTestSuite) TestGetallEntities() {
credentials := params.ForgeCredentials{
ID: 1,
Description: "test description",
Name: "test",
ForgeType: params.GithubEndpointType,
}
credentials2 := params.ForgeCredentials{
ID: 2,
Description: "test description2",
Name: "test",
ForgeType: params.GiteaEndpointType,
}
entity1 := params.ForgeEntity{
ID: "test-entity-1",
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
Credentials: credentials,
CreatedAt: time.Now(),
}
entity2 := params.ForgeEntity{
ID: "test-entity-2",
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
Credentials: credentials,
CreatedAt: time.Now().Add(1 * time.Second),
}
entity3 := params.ForgeEntity{
ID: "test-entity-3",
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
Credentials: credentials2,
CreatedAt: time.Now().Add(2 * time.Second),
}
SetEntity(entity1)
SetEntity(entity2)
SetEntity(entity3)
// Sorted by creation date
cachedEntities := GetAllEntities()
c.Require().Len(cachedEntities, 3)
c.Require().Equal(cachedEntities[0], entity1)
c.Require().Equal(cachedEntities[1], entity2)
c.Require().Equal(cachedEntities[2], entity3)
}
func (c *CacheTestSuite) TestGetAllPools() {
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
pool1 := params.Pool{
ID: "pool-1",
CreatedAt: time.Now(),
Tags: []params.Tag{
{
Name: "tag1",
},
{
Name: "tag2",
},
},
}
pool2 := params.Pool{
ID: "pool-2",
CreatedAt: time.Now().Add(1 * time.Second),
Tags: []params.Tag{
{
Name: "tag1",
},
{
Name: "tag3",
},
},
}
SetEntity(entity)
SetEntityPool(entity.ID, pool1)
SetEntityPool(entity.ID, pool2)
cachedEntity, ok := GetEntity(entity.ID)
c.Require().True(ok)
c.Require().Equal(entity.ID, cachedEntity.ID)
pools := GetAllPools()
c.Require().Len(pools, 2)
c.Require().Equal(pools[0].ID, pool1.ID)
c.Require().Equal(pools[1].ID, pool2.ID)
}
func (c *CacheTestSuite) TestGetAllScaleSets() {
entity := params.ForgeEntity{
ID: "test-entity",
EntityType: params.ForgeEntityTypeOrganization,
Name: "test",
Owner: "test",
}
scaleSet1 := params.ScaleSet{
ID: 1,
}
scaleSet2 := params.ScaleSet{
ID: 2,
}
SetEntity(entity)
SetEntityScaleSet(entity.ID, scaleSet1)
SetEntityScaleSet(entity.ID, scaleSet2)
cachedEntity, ok := GetEntity(entity.ID)
c.Require().True(ok)
c.Require().Equal(entity.ID, cachedEntity.ID)
scaleSets := GetAllScaleSets()
c.Require().Len(scaleSets, 2)
c.Require().Equal(scaleSets[0].ID, scaleSet1.ID)
c.Require().Equal(scaleSets[1].ID, scaleSet2.ID)
}
func (c *CacheTestSuite) TestGetAllGetAllGithubCredentialsAsMap() {
credentials1 := params.ForgeCredentials{
ID: 1,
}
credentials2 := params.ForgeCredentials{
ID: 2,
}
SetGithubCredentials(credentials1)
SetGithubCredentials(credentials2)
cachedCreds := GetAllGithubCredentialsAsMap()
c.Require().Len(cachedCreds, 2)
c.Require().Contains(cachedCreds, credentials1.ID)
c.Require().Contains(cachedCreds, credentials2.ID)
}
func (c *CacheTestSuite) TestGetAllGiteaCredentialsAsMap() {
credentials1 := params.ForgeCredentials{
ID: 1,
CreatedAt: time.Now(),
}
credentials2 := params.ForgeCredentials{
ID: 2,
CreatedAt: time.Now().Add(1 * time.Second),
}
SetGiteaCredentials(credentials1)
SetGiteaCredentials(credentials2)
cachedCreds := GetAllGiteaCredentialsAsMap()
c.Require().Len(cachedCreds, 2)
c.Require().Contains(cachedCreds, credentials1.ID)
c.Require().Contains(cachedCreds, credentials2.ID)
}
func TestCacheTestSuite(t *testing.T) {
t.Parallel()
suite.Run(t, new(CacheTestSuite))

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cache
import (
@ -6,32 +19,40 @@ import (
"github.com/cloudbase/garm/params"
)
var credentialsCache *GithubCredentials
var (
credentialsCache *CredentialCache
giteaCredentialsCache *CredentialCache
)
func init() {
ghCredentialsCache := &GithubCredentials{
cache: make(map[uint]params.GithubCredentials),
ghCredentialsCache := &CredentialCache{
cache: make(map[uint]params.ForgeCredentials),
}
gtCredentialsCache := &CredentialCache{
cache: make(map[uint]params.ForgeCredentials),
}
credentialsCache = ghCredentialsCache
giteaCredentialsCache = gtCredentialsCache
}
type GithubCredentials struct {
type CredentialCache struct {
mux sync.Mutex
cache map[uint]params.GithubCredentials
cache map[uint]params.ForgeCredentials
}
func (g *GithubCredentials) SetCredentialsRateLimit(credsID uint, rateLimit params.GithubRateLimit) {
func (g *CredentialCache) SetCredentialsRateLimit(credsID uint, rateLimit params.GithubRateLimit) {
g.mux.Lock()
defer g.mux.Unlock()
if creds, ok := g.cache[credsID]; ok {
creds.RateLimit = rateLimit
creds.RateLimit = &rateLimit
g.cache[credsID] = creds
}
}
func (g *GithubCredentials) SetCredentials(credentials params.GithubCredentials) {
func (g *CredentialCache) SetCredentials(credentials params.ForgeCredentials) {
g.mux.Lock()
defer g.mux.Unlock()
@ -39,28 +60,28 @@ func (g *GithubCredentials) SetCredentials(credentials params.GithubCredentials)
UpdateCredentialsInAffectedEntities(credentials)
}
func (g *GithubCredentials) GetCredentials(id uint) (params.GithubCredentials, bool) {
func (g *CredentialCache) GetCredentials(id uint) (params.ForgeCredentials, bool) {
g.mux.Lock()
defer g.mux.Unlock()
if creds, ok := g.cache[id]; ok {
return creds, true
}
return params.GithubCredentials{}, false
return params.ForgeCredentials{}, false
}
func (g *GithubCredentials) DeleteCredentials(id uint) {
func (g *CredentialCache) DeleteCredentials(id uint) {
g.mux.Lock()
defer g.mux.Unlock()
delete(g.cache, id)
}
func (g *GithubCredentials) GetAllCredentials() []params.GithubCredentials {
func (g *CredentialCache) GetAllCredentials() []params.ForgeCredentials {
g.mux.Lock()
defer g.mux.Unlock()
creds := make([]params.GithubCredentials, 0, len(g.cache))
creds := make([]params.ForgeCredentials, 0, len(g.cache))
for _, cred := range g.cache {
creds = append(creds, cred)
}
@ -70,11 +91,11 @@ func (g *GithubCredentials) GetAllCredentials() []params.GithubCredentials {
return creds
}
func (g *GithubCredentials) GetAllCredentialsAsMap() map[uint]params.GithubCredentials {
func (g *CredentialCache) GetAllCredentialsAsMap() map[uint]params.ForgeCredentials {
g.mux.Lock()
defer g.mux.Unlock()
creds := make(map[uint]params.GithubCredentials, len(g.cache))
creds := make(map[uint]params.ForgeCredentials, len(g.cache))
for id, cred := range g.cache {
creds[id] = cred
}
@ -82,11 +103,11 @@ func (g *GithubCredentials) GetAllCredentialsAsMap() map[uint]params.GithubCrede
return creds
}
func SetGithubCredentials(credentials params.GithubCredentials) {
func SetGithubCredentials(credentials params.ForgeCredentials) {
credentialsCache.SetCredentials(credentials)
}
func GetGithubCredentials(id uint) (params.GithubCredentials, bool) {
func GetGithubCredentials(id uint) (params.ForgeCredentials, bool) {
return credentialsCache.GetCredentials(id)
}
@ -94,7 +115,7 @@ func DeleteGithubCredentials(id uint) {
credentialsCache.DeleteCredentials(id)
}
func GetAllGithubCredentials() []params.GithubCredentials {
func GetAllGithubCredentials() []params.ForgeCredentials {
return credentialsCache.GetAllCredentials()
}
@ -102,6 +123,26 @@ func SetCredentialsRateLimit(credsID uint, rateLimit params.GithubRateLimit) {
credentialsCache.SetCredentialsRateLimit(credsID, rateLimit)
}
func GetAllGithubCredentialsAsMap() map[uint]params.GithubCredentials {
func GetAllGithubCredentialsAsMap() map[uint]params.ForgeCredentials {
return credentialsCache.GetAllCredentialsAsMap()
}
func SetGiteaCredentials(credentials params.ForgeCredentials) {
giteaCredentialsCache.SetCredentials(credentials)
}
func GetGiteaCredentials(id uint) (params.ForgeCredentials, bool) {
return giteaCredentialsCache.GetCredentials(id)
}
func DeleteGiteaCredentials(id uint) {
giteaCredentialsCache.DeleteCredentials(id)
}
func GetAllGiteaCredentials() []params.ForgeCredentials {
return giteaCredentialsCache.GetAllCredentials()
}
func GetAllGiteaCredentialsAsMap() map[uint]params.ForgeCredentials {
return giteaCredentialsCache.GetAllCredentialsAsMap()
}

70
cache/entity_cache.go vendored
View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cache
import (
@ -16,7 +29,7 @@ func init() {
}
type EntityItem struct {
Entity params.GithubEntity
Entity params.ForgeEntity
Pools map[string]params.Pool
ScaleSets map[uint]params.ScaleSet
}
@ -27,34 +40,40 @@ type EntityCache struct {
entities map[string]EntityItem
}
func (e *EntityCache) UpdateCredentialsInAffectedEntities(creds params.GithubCredentials) {
func (e *EntityCache) UpdateCredentialsInAffectedEntities(creds params.ForgeCredentials) {
e.mux.Lock()
defer e.mux.Unlock()
for entityID, cache := range e.entities {
if cache.Entity.Credentials.ID == creds.ID {
if cache.Entity.Credentials.GetID() == creds.GetID() {
cache.Entity.Credentials = creds
e.entities[entityID] = cache
}
}
}
func (e *EntityCache) GetEntity(entityID string) (params.GithubEntity, bool) {
func (e *EntityCache) GetEntity(entityID string) (params.ForgeEntity, bool) {
e.mux.Lock()
defer e.mux.Unlock()
if cache, ok := e.entities[entityID]; ok {
// Get the credentials from the credentials cache.
creds, ok := GetGithubCredentials(cache.Entity.Credentials.ID)
var creds params.ForgeCredentials
var ok bool
switch cache.Entity.Credentials.ForgeType {
case params.GithubEndpointType:
creds, ok = GetGithubCredentials(cache.Entity.Credentials.ID)
case params.GiteaEndpointType:
creds, ok = GetGiteaCredentials(cache.Entity.Credentials.ID)
}
if ok {
cache.Entity.Credentials = creds
}
return cache.Entity, true
}
return params.GithubEntity{}, false
return params.ForgeEntity{}, false
}
func (e *EntityCache) SetEntity(entity params.GithubEntity) {
func (e *EntityCache) SetEntity(entity params.ForgeEntity) {
e.mux.Lock()
defer e.mux.Unlock()
@ -225,13 +244,17 @@ func (e *EntityCache) GetEntityScaleSets(entityID string) []params.ScaleSet {
return nil
}
func (e *EntityCache) GetEntitiesUsingGredentials(credsID uint) []params.GithubEntity {
func (e *EntityCache) GetEntitiesUsingCredentials(creds params.ForgeCredentials) []params.ForgeEntity {
e.mux.Lock()
defer e.mux.Unlock()
var entities []params.GithubEntity
var entities []params.ForgeEntity
for _, cache := range e.entities {
if cache.Entity.Credentials.ID == credsID {
if cache.Entity.Credentials.ForgeType != creds.ForgeType {
continue
}
if cache.Entity.Credentials.GetID() == creds.GetID() {
entities = append(entities, cache.Entity)
}
}
@ -239,14 +262,21 @@ func (e *EntityCache) GetEntitiesUsingGredentials(credsID uint) []params.GithubE
return entities
}
func (e *EntityCache) GetAllEntities() []params.GithubEntity {
func (e *EntityCache) GetAllEntities() []params.ForgeEntity {
e.mux.Lock()
defer e.mux.Unlock()
var entities []params.GithubEntity
var entities []params.ForgeEntity
for _, cache := range e.entities {
// Get the credentials from the credentials cache.
creds, ok := GetGithubCredentials(cache.Entity.Credentials.ID)
var creds params.ForgeCredentials
var ok bool
switch cache.Entity.Credentials.ForgeType {
case params.GithubEndpointType:
creds, ok = GetGithubCredentials(cache.Entity.Credentials.ID)
case params.GiteaEndpointType:
creds, ok = GetGiteaCredentials(cache.Entity.Credentials.ID)
}
if ok {
cache.Entity.Credentials = creds
}
@ -284,11 +314,11 @@ func (e *EntityCache) GetAllScaleSets() []params.ScaleSet {
return scaleSets
}
func GetEntity(entityID string) (params.GithubEntity, bool) {
func GetEntity(entityID string) (params.ForgeEntity, bool) {
return entityCache.GetEntity(entityID)
}
func SetEntity(entity params.GithubEntity) {
func SetEntity(entity params.ForgeEntity) {
entityCache.SetEntity(entity)
}
@ -340,15 +370,15 @@ func GetEntityScaleSets(entityID string) []params.ScaleSet {
return entityCache.GetEntityScaleSets(entityID)
}
func UpdateCredentialsInAffectedEntities(creds params.GithubCredentials) {
func UpdateCredentialsInAffectedEntities(creds params.ForgeCredentials) {
entityCache.UpdateCredentialsInAffectedEntities(creds)
}
func GetEntitiesUsingGredentials(credsID uint) []params.GithubEntity {
return entityCache.GetEntitiesUsingGredentials(credsID)
func GetEntitiesUsingCredentials(creds params.ForgeCredentials) []params.ForgeEntity {
return entityCache.GetEntitiesUsingCredentials(creds)
}
func GetAllEntities() []params.GithubEntity {
func GetAllEntities() []params.ForgeEntity {
return entityCache.GetAllEntities()
}

60
cache/github_client.go vendored Normal file
View file

@ -0,0 +1,60 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cache
import (
"sync"
"github.com/cloudbase/garm/runner/common"
)
var ghClientCache *GithubClientCache
type GithubClientCache struct {
mux sync.Mutex
cache map[string]common.GithubClient
}
func init() {
clientCache := &GithubClientCache{
cache: make(map[string]common.GithubClient),
}
ghClientCache = clientCache
}
func (g *GithubClientCache) SetClient(entityID string, client common.GithubClient) {
g.mux.Lock()
defer g.mux.Unlock()
g.cache[entityID] = client
}
func (g *GithubClientCache) GetClient(entityID string) (common.GithubClient, bool) {
g.mux.Lock()
defer g.mux.Unlock()
if client, ok := g.cache[entityID]; ok {
return client, true
}
return nil, false
}
func SetGithubClient(entityID string, client common.GithubClient) {
ghClientCache.SetClient(entityID, client)
}
func GetGithubClient(entityID string) (common.GithubClient, bool) {
return ghClientCache.GetClient(entityID)
}

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cache
import (

76
cache/tools_cache.go vendored
View file

@ -1,6 +1,20 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cache
import (
"fmt"
"sync"
"time"
@ -19,7 +33,9 @@ func init() {
type GithubEntityTools struct {
updatedAt time.Time
entity params.GithubEntity
expiresAt time.Time
err error
entity params.ForgeEntity
tools []commonParams.RunnerApplicationDownload
}
@ -29,36 +45,72 @@ type GithubToolsCache struct {
entities map[string]GithubEntityTools
}
func (g *GithubToolsCache) Get(entityID string) ([]commonParams.RunnerApplicationDownload, bool) {
func (g *GithubToolsCache) Get(entityID string) ([]commonParams.RunnerApplicationDownload, error) {
g.mux.Lock()
defer g.mux.Unlock()
if cache, ok := g.entities[entityID]; ok {
if time.Since(cache.updatedAt) > 1*time.Hour {
// Stale cache, remove it.
delete(g.entities, entityID)
return nil, false
if cache.entity.Credentials.ForgeType == params.GithubEndpointType {
if time.Now().UTC().After(cache.expiresAt.Add(-5 * time.Minute)) {
// Stale cache, remove it.
delete(g.entities, entityID)
return nil, fmt.Errorf("cache expired for entity %s", entityID)
}
}
return cache.tools, true
if cache.err != nil {
return nil, cache.err
}
return cache.tools, nil
}
return nil, false
return nil, fmt.Errorf("no cache found for entity %s", entityID)
}
func (g *GithubToolsCache) Set(entity params.GithubEntity, tools []commonParams.RunnerApplicationDownload) {
func (g *GithubToolsCache) Set(entity params.ForgeEntity, tools []commonParams.RunnerApplicationDownload) {
g.mux.Lock()
defer g.mux.Unlock()
g.entities[entity.ID] = GithubEntityTools{
forgeTools := GithubEntityTools{
updatedAt: time.Now(),
entity: entity,
tools: tools,
err: nil,
}
if entity.Credentials.ForgeType == params.GithubEndpointType {
forgeTools.expiresAt = time.Now().Add(1 * time.Hour)
}
g.entities[entity.ID] = forgeTools
}
func SetGithubToolsCache(entity params.GithubEntity, tools []commonParams.RunnerApplicationDownload) {
func (g *GithubToolsCache) SetToolsError(entity params.ForgeEntity, err error) {
g.mux.Lock()
defer g.mux.Unlock()
// If the entity is not in the cache, add it with the error.
cache, ok := g.entities[entity.ID]
if !ok {
g.entities[entity.ID] = GithubEntityTools{
updatedAt: time.Now(),
entity: entity,
err: err,
}
return
}
// Update the error for the existing entity.
cache.err = err
g.entities[entity.ID] = cache
}
func SetGithubToolsCache(entity params.ForgeEntity, tools []commonParams.RunnerApplicationDownload) {
githubToolsCache.Set(entity, tools)
}
func GetGithubToolsCache(entityID string) ([]commonParams.RunnerApplicationDownload, bool) {
func GetGithubToolsCache(entityID string) ([]commonParams.RunnerApplicationDownload, error) {
return githubToolsCache.Get(entityID)
}
func SetGithubToolsCacheError(entity params.ForgeEntity, err error) {
githubToolsCache.SetToolsError(entity, err)
}

13
cache/util.go vendored
View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cache
import (

View file

@ -50,10 +50,10 @@ func NewCreateCredentialsOK() *CreateCredentialsOK {
/*
CreateCredentialsOK describes a response with status code 200, with default header values.
GithubCredentials
ForgeCredentials
*/
type CreateCredentialsOK struct {
Payload garm_params.GithubCredentials
Payload garm_params.ForgeCredentials
}
// IsSuccess returns true when this create credentials o k response has a 2xx status code
@ -96,7 +96,7 @@ func (o *CreateCredentialsOK) String() string {
return fmt.Sprintf("[POST /github/credentials][%d] createCredentialsOK %s", 200, payload)
}
func (o *CreateCredentialsOK) GetPayload() garm_params.GithubCredentials {
func (o *CreateCredentialsOK) GetPayload() garm_params.ForgeCredentials {
return o.Payload
}

View file

@ -0,0 +1,151 @@
// Code generated by go-swagger; DO NOT EDIT.
package credentials
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
garm_params "github.com/cloudbase/garm/params"
)
// NewCreateGiteaCredentialsParams creates a new CreateGiteaCredentialsParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewCreateGiteaCredentialsParams() *CreateGiteaCredentialsParams {
return &CreateGiteaCredentialsParams{
timeout: cr.DefaultTimeout,
}
}
// NewCreateGiteaCredentialsParamsWithTimeout creates a new CreateGiteaCredentialsParams object
// with the ability to set a timeout on a request.
func NewCreateGiteaCredentialsParamsWithTimeout(timeout time.Duration) *CreateGiteaCredentialsParams {
return &CreateGiteaCredentialsParams{
timeout: timeout,
}
}
// NewCreateGiteaCredentialsParamsWithContext creates a new CreateGiteaCredentialsParams object
// with the ability to set a context for a request.
func NewCreateGiteaCredentialsParamsWithContext(ctx context.Context) *CreateGiteaCredentialsParams {
return &CreateGiteaCredentialsParams{
Context: ctx,
}
}
// NewCreateGiteaCredentialsParamsWithHTTPClient creates a new CreateGiteaCredentialsParams object
// with the ability to set a custom HTTPClient for a request.
func NewCreateGiteaCredentialsParamsWithHTTPClient(client *http.Client) *CreateGiteaCredentialsParams {
return &CreateGiteaCredentialsParams{
HTTPClient: client,
}
}
/*
CreateGiteaCredentialsParams contains all the parameters to send to the API endpoint
for the create gitea credentials operation.
Typically these are written to a http.Request.
*/
type CreateGiteaCredentialsParams struct {
/* Body.
Parameters used when creating a Gitea credential.
*/
Body garm_params.CreateGiteaCredentialsParams
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the create gitea credentials params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *CreateGiteaCredentialsParams) WithDefaults() *CreateGiteaCredentialsParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the create gitea credentials params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *CreateGiteaCredentialsParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the create gitea credentials params
func (o *CreateGiteaCredentialsParams) WithTimeout(timeout time.Duration) *CreateGiteaCredentialsParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the create gitea credentials params
func (o *CreateGiteaCredentialsParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the create gitea credentials params
func (o *CreateGiteaCredentialsParams) WithContext(ctx context.Context) *CreateGiteaCredentialsParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the create gitea credentials params
func (o *CreateGiteaCredentialsParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the create gitea credentials params
func (o *CreateGiteaCredentialsParams) WithHTTPClient(client *http.Client) *CreateGiteaCredentialsParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the create gitea credentials params
func (o *CreateGiteaCredentialsParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the create gitea credentials params
func (o *CreateGiteaCredentialsParams) WithBody(body garm_params.CreateGiteaCredentialsParams) *CreateGiteaCredentialsParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the create gitea credentials params
func (o *CreateGiteaCredentialsParams) SetBody(body garm_params.CreateGiteaCredentialsParams) {
o.Body = body
}
// WriteToRequest writes these params to a swagger request
func (o *CreateGiteaCredentialsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,179 @@
// Code generated by go-swagger; DO NOT EDIT.
package credentials
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
garm_params "github.com/cloudbase/garm/params"
)
// CreateGiteaCredentialsReader is a Reader for the CreateGiteaCredentials structure.
type CreateGiteaCredentialsReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *CreateGiteaCredentialsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewCreateGiteaCredentialsOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 400:
result := NewCreateGiteaCredentialsBadRequest()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("[POST /gitea/credentials] CreateGiteaCredentials", response, response.Code())
}
}
// NewCreateGiteaCredentialsOK creates a CreateGiteaCredentialsOK with default headers values
func NewCreateGiteaCredentialsOK() *CreateGiteaCredentialsOK {
return &CreateGiteaCredentialsOK{}
}
/*
CreateGiteaCredentialsOK describes a response with status code 200, with default header values.
ForgeCredentials
*/
type CreateGiteaCredentialsOK struct {
Payload garm_params.ForgeCredentials
}
// IsSuccess returns true when this create gitea credentials o k response has a 2xx status code
func (o *CreateGiteaCredentialsOK) IsSuccess() bool {
return true
}
// IsRedirect returns true when this create gitea credentials o k response has a 3xx status code
func (o *CreateGiteaCredentialsOK) IsRedirect() bool {
return false
}
// IsClientError returns true when this create gitea credentials o k response has a 4xx status code
func (o *CreateGiteaCredentialsOK) IsClientError() bool {
return false
}
// IsServerError returns true when this create gitea credentials o k response has a 5xx status code
func (o *CreateGiteaCredentialsOK) IsServerError() bool {
return false
}
// IsCode returns true when this create gitea credentials o k response a status code equal to that given
func (o *CreateGiteaCredentialsOK) IsCode(code int) bool {
return code == 200
}
// Code gets the status code for the create gitea credentials o k response
func (o *CreateGiteaCredentialsOK) Code() int {
return 200
}
func (o *CreateGiteaCredentialsOK) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[POST /gitea/credentials][%d] createGiteaCredentialsOK %s", 200, payload)
}
func (o *CreateGiteaCredentialsOK) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[POST /gitea/credentials][%d] createGiteaCredentialsOK %s", 200, payload)
}
func (o *CreateGiteaCredentialsOK) GetPayload() garm_params.ForgeCredentials {
return o.Payload
}
func (o *CreateGiteaCredentialsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewCreateGiteaCredentialsBadRequest creates a CreateGiteaCredentialsBadRequest with default headers values
func NewCreateGiteaCredentialsBadRequest() *CreateGiteaCredentialsBadRequest {
return &CreateGiteaCredentialsBadRequest{}
}
/*
CreateGiteaCredentialsBadRequest describes a response with status code 400, with default header values.
APIErrorResponse
*/
type CreateGiteaCredentialsBadRequest struct {
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this create gitea credentials bad request response has a 2xx status code
func (o *CreateGiteaCredentialsBadRequest) IsSuccess() bool {
return false
}
// IsRedirect returns true when this create gitea credentials bad request response has a 3xx status code
func (o *CreateGiteaCredentialsBadRequest) IsRedirect() bool {
return false
}
// IsClientError returns true when this create gitea credentials bad request response has a 4xx status code
func (o *CreateGiteaCredentialsBadRequest) IsClientError() bool {
return true
}
// IsServerError returns true when this create gitea credentials bad request response has a 5xx status code
func (o *CreateGiteaCredentialsBadRequest) IsServerError() bool {
return false
}
// IsCode returns true when this create gitea credentials bad request response a status code equal to that given
func (o *CreateGiteaCredentialsBadRequest) IsCode(code int) bool {
return code == 400
}
// Code gets the status code for the create gitea credentials bad request response
func (o *CreateGiteaCredentialsBadRequest) Code() int {
return 400
}
func (o *CreateGiteaCredentialsBadRequest) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[POST /gitea/credentials][%d] createGiteaCredentialsBadRequest %s", 400, payload)
}
func (o *CreateGiteaCredentialsBadRequest) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[POST /gitea/credentials][%d] createGiteaCredentialsBadRequest %s", 400, payload)
}
func (o *CreateGiteaCredentialsBadRequest) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *CreateGiteaCredentialsBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -58,14 +58,24 @@ type ClientOption func(*runtime.ClientOperation)
type ClientService interface {
CreateCredentials(params *CreateCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateCredentialsOK, error)
CreateGiteaCredentials(params *CreateGiteaCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateGiteaCredentialsOK, error)
DeleteCredentials(params *DeleteCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) error
DeleteGiteaCredentials(params *DeleteGiteaCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) error
GetCredentials(params *GetCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetCredentialsOK, error)
GetGiteaCredentials(params *GetGiteaCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetGiteaCredentialsOK, error)
ListCredentials(params *ListCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListCredentialsOK, error)
ListGiteaCredentials(params *ListGiteaCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListGiteaCredentialsOK, error)
UpdateCredentials(params *UpdateCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateCredentialsOK, error)
UpdateGiteaCredentials(params *UpdateGiteaCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateGiteaCredentialsOK, error)
SetTransport(transport runtime.ClientTransport)
}
@ -108,6 +118,45 @@ func (a *Client) CreateCredentials(params *CreateCredentialsParams, authInfo run
panic(msg)
}
/*
CreateGiteaCredentials creates a gitea credential
*/
func (a *Client) CreateGiteaCredentials(params *CreateGiteaCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateGiteaCredentialsOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewCreateGiteaCredentialsParams()
}
op := &runtime.ClientOperation{
ID: "CreateGiteaCredentials",
Method: "POST",
PathPattern: "/gitea/credentials",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &CreateGiteaCredentialsReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
result, err := a.transport.Submit(op)
if err != nil {
return nil, err
}
success, ok := result.(*CreateGiteaCredentialsOK)
if ok {
return success, nil
}
// unexpected success response
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
msg := fmt.Sprintf("unexpected success response for CreateGiteaCredentials: API contract not enforced by server. Client expected to get an error, but got: %T", result)
panic(msg)
}
/*
DeleteCredentials deletes a git hub credential
*/
@ -140,6 +189,38 @@ func (a *Client) DeleteCredentials(params *DeleteCredentialsParams, authInfo run
return nil
}
/*
DeleteGiteaCredentials deletes a gitea credential
*/
func (a *Client) DeleteGiteaCredentials(params *DeleteGiteaCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) error {
// TODO: Validate the params before sending
if params == nil {
params = NewDeleteGiteaCredentialsParams()
}
op := &runtime.ClientOperation{
ID: "DeleteGiteaCredentials",
Method: "DELETE",
PathPattern: "/gitea/credentials/{id}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &DeleteGiteaCredentialsReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
_, err := a.transport.Submit(op)
if err != nil {
return err
}
return nil
}
/*
GetCredentials gets a git hub credential
*/
@ -179,6 +260,45 @@ func (a *Client) GetCredentials(params *GetCredentialsParams, authInfo runtime.C
panic(msg)
}
/*
GetGiteaCredentials gets a gitea credential
*/
func (a *Client) GetGiteaCredentials(params *GetGiteaCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetGiteaCredentialsOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewGetGiteaCredentialsParams()
}
op := &runtime.ClientOperation{
ID: "GetGiteaCredentials",
Method: "GET",
PathPattern: "/gitea/credentials/{id}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &GetGiteaCredentialsReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
result, err := a.transport.Submit(op)
if err != nil {
return nil, err
}
success, ok := result.(*GetGiteaCredentialsOK)
if ok {
return success, nil
}
// unexpected success response
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
msg := fmt.Sprintf("unexpected success response for GetGiteaCredentials: API contract not enforced by server. Client expected to get an error, but got: %T", result)
panic(msg)
}
/*
ListCredentials lists all credentials
*/
@ -218,6 +338,45 @@ func (a *Client) ListCredentials(params *ListCredentialsParams, authInfo runtime
panic(msg)
}
/*
ListGiteaCredentials lists all credentials
*/
func (a *Client) ListGiteaCredentials(params *ListGiteaCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListGiteaCredentialsOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewListGiteaCredentialsParams()
}
op := &runtime.ClientOperation{
ID: "ListGiteaCredentials",
Method: "GET",
PathPattern: "/gitea/credentials",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ListGiteaCredentialsReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
result, err := a.transport.Submit(op)
if err != nil {
return nil, err
}
success, ok := result.(*ListGiteaCredentialsOK)
if ok {
return success, nil
}
// unexpected success response
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
msg := fmt.Sprintf("unexpected success response for ListGiteaCredentials: API contract not enforced by server. Client expected to get an error, but got: %T", result)
panic(msg)
}
/*
UpdateCredentials updates a git hub credential
*/
@ -257,6 +416,45 @@ func (a *Client) UpdateCredentials(params *UpdateCredentialsParams, authInfo run
panic(msg)
}
/*
UpdateGiteaCredentials updates a gitea credential
*/
func (a *Client) UpdateGiteaCredentials(params *UpdateGiteaCredentialsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateGiteaCredentialsOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewUpdateGiteaCredentialsParams()
}
op := &runtime.ClientOperation{
ID: "UpdateGiteaCredentials",
Method: "PUT",
PathPattern: "/gitea/credentials/{id}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &UpdateGiteaCredentialsReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
result, err := a.transport.Submit(op)
if err != nil {
return nil, err
}
success, ok := result.(*UpdateGiteaCredentialsOK)
if ok {
return success, nil
}
// unexpected success response
// safeguard: normally, absent a default response, unknown success responses return an error above: so this is a codegen issue
msg := fmt.Sprintf("unexpected success response for UpdateGiteaCredentials: API contract not enforced by server. Client expected to get an error, but got: %T", result)
panic(msg)
}
// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport

View file

@ -0,0 +1,152 @@
// Code generated by go-swagger; DO NOT EDIT.
package credentials
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// NewDeleteGiteaCredentialsParams creates a new DeleteGiteaCredentialsParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewDeleteGiteaCredentialsParams() *DeleteGiteaCredentialsParams {
return &DeleteGiteaCredentialsParams{
timeout: cr.DefaultTimeout,
}
}
// NewDeleteGiteaCredentialsParamsWithTimeout creates a new DeleteGiteaCredentialsParams object
// with the ability to set a timeout on a request.
func NewDeleteGiteaCredentialsParamsWithTimeout(timeout time.Duration) *DeleteGiteaCredentialsParams {
return &DeleteGiteaCredentialsParams{
timeout: timeout,
}
}
// NewDeleteGiteaCredentialsParamsWithContext creates a new DeleteGiteaCredentialsParams object
// with the ability to set a context for a request.
func NewDeleteGiteaCredentialsParamsWithContext(ctx context.Context) *DeleteGiteaCredentialsParams {
return &DeleteGiteaCredentialsParams{
Context: ctx,
}
}
// NewDeleteGiteaCredentialsParamsWithHTTPClient creates a new DeleteGiteaCredentialsParams object
// with the ability to set a custom HTTPClient for a request.
func NewDeleteGiteaCredentialsParamsWithHTTPClient(client *http.Client) *DeleteGiteaCredentialsParams {
return &DeleteGiteaCredentialsParams{
HTTPClient: client,
}
}
/*
DeleteGiteaCredentialsParams contains all the parameters to send to the API endpoint
for the delete gitea credentials operation.
Typically these are written to a http.Request.
*/
type DeleteGiteaCredentialsParams struct {
/* ID.
ID of the Gitea credential.
*/
ID int64
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the delete gitea credentials params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *DeleteGiteaCredentialsParams) WithDefaults() *DeleteGiteaCredentialsParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the delete gitea credentials params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *DeleteGiteaCredentialsParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the delete gitea credentials params
func (o *DeleteGiteaCredentialsParams) WithTimeout(timeout time.Duration) *DeleteGiteaCredentialsParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the delete gitea credentials params
func (o *DeleteGiteaCredentialsParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the delete gitea credentials params
func (o *DeleteGiteaCredentialsParams) WithContext(ctx context.Context) *DeleteGiteaCredentialsParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the delete gitea credentials params
func (o *DeleteGiteaCredentialsParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the delete gitea credentials params
func (o *DeleteGiteaCredentialsParams) WithHTTPClient(client *http.Client) *DeleteGiteaCredentialsParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the delete gitea credentials params
func (o *DeleteGiteaCredentialsParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithID adds the id to the delete gitea credentials params
func (o *DeleteGiteaCredentialsParams) WithID(id int64) *DeleteGiteaCredentialsParams {
o.SetID(id)
return o
}
// SetID adds the id to the delete gitea credentials params
func (o *DeleteGiteaCredentialsParams) SetID(id int64) {
o.ID = id
}
// WriteToRequest writes these params to a swagger request
func (o *DeleteGiteaCredentialsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param id
if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,106 @@
// Code generated by go-swagger; DO NOT EDIT.
package credentials
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
)
// DeleteGiteaCredentialsReader is a Reader for the DeleteGiteaCredentials structure.
type DeleteGiteaCredentialsReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *DeleteGiteaCredentialsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
result := NewDeleteGiteaCredentialsDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
// NewDeleteGiteaCredentialsDefault creates a DeleteGiteaCredentialsDefault with default headers values
func NewDeleteGiteaCredentialsDefault(code int) *DeleteGiteaCredentialsDefault {
return &DeleteGiteaCredentialsDefault{
_statusCode: code,
}
}
/*
DeleteGiteaCredentialsDefault describes a response with status code -1, with default header values.
APIErrorResponse
*/
type DeleteGiteaCredentialsDefault struct {
_statusCode int
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this delete gitea credentials default response has a 2xx status code
func (o *DeleteGiteaCredentialsDefault) IsSuccess() bool {
return o._statusCode/100 == 2
}
// IsRedirect returns true when this delete gitea credentials default response has a 3xx status code
func (o *DeleteGiteaCredentialsDefault) IsRedirect() bool {
return o._statusCode/100 == 3
}
// IsClientError returns true when this delete gitea credentials default response has a 4xx status code
func (o *DeleteGiteaCredentialsDefault) IsClientError() bool {
return o._statusCode/100 == 4
}
// IsServerError returns true when this delete gitea credentials default response has a 5xx status code
func (o *DeleteGiteaCredentialsDefault) IsServerError() bool {
return o._statusCode/100 == 5
}
// IsCode returns true when this delete gitea credentials default response a status code equal to that given
func (o *DeleteGiteaCredentialsDefault) IsCode(code int) bool {
return o._statusCode == code
}
// Code gets the status code for the delete gitea credentials default response
func (o *DeleteGiteaCredentialsDefault) Code() int {
return o._statusCode
}
func (o *DeleteGiteaCredentialsDefault) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[DELETE /gitea/credentials/{id}][%d] DeleteGiteaCredentials default %s", o._statusCode, payload)
}
func (o *DeleteGiteaCredentialsDefault) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[DELETE /gitea/credentials/{id}][%d] DeleteGiteaCredentials default %s", o._statusCode, payload)
}
func (o *DeleteGiteaCredentialsDefault) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *DeleteGiteaCredentialsDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -50,10 +50,10 @@ func NewGetCredentialsOK() *GetCredentialsOK {
/*
GetCredentialsOK describes a response with status code 200, with default header values.
GithubCredentials
ForgeCredentials
*/
type GetCredentialsOK struct {
Payload garm_params.GithubCredentials
Payload garm_params.ForgeCredentials
}
// IsSuccess returns true when this get credentials o k response has a 2xx status code
@ -96,7 +96,7 @@ func (o *GetCredentialsOK) String() string {
return fmt.Sprintf("[GET /github/credentials/{id}][%d] getCredentialsOK %s", 200, payload)
}
func (o *GetCredentialsOK) GetPayload() garm_params.GithubCredentials {
func (o *GetCredentialsOK) GetPayload() garm_params.ForgeCredentials {
return o.Payload
}

View file

@ -0,0 +1,152 @@
// Code generated by go-swagger; DO NOT EDIT.
package credentials
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// NewGetGiteaCredentialsParams creates a new GetGiteaCredentialsParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewGetGiteaCredentialsParams() *GetGiteaCredentialsParams {
return &GetGiteaCredentialsParams{
timeout: cr.DefaultTimeout,
}
}
// NewGetGiteaCredentialsParamsWithTimeout creates a new GetGiteaCredentialsParams object
// with the ability to set a timeout on a request.
func NewGetGiteaCredentialsParamsWithTimeout(timeout time.Duration) *GetGiteaCredentialsParams {
return &GetGiteaCredentialsParams{
timeout: timeout,
}
}
// NewGetGiteaCredentialsParamsWithContext creates a new GetGiteaCredentialsParams object
// with the ability to set a context for a request.
func NewGetGiteaCredentialsParamsWithContext(ctx context.Context) *GetGiteaCredentialsParams {
return &GetGiteaCredentialsParams{
Context: ctx,
}
}
// NewGetGiteaCredentialsParamsWithHTTPClient creates a new GetGiteaCredentialsParams object
// with the ability to set a custom HTTPClient for a request.
func NewGetGiteaCredentialsParamsWithHTTPClient(client *http.Client) *GetGiteaCredentialsParams {
return &GetGiteaCredentialsParams{
HTTPClient: client,
}
}
/*
GetGiteaCredentialsParams contains all the parameters to send to the API endpoint
for the get gitea credentials operation.
Typically these are written to a http.Request.
*/
type GetGiteaCredentialsParams struct {
/* ID.
ID of the Gitea credential.
*/
ID int64
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the get gitea credentials params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *GetGiteaCredentialsParams) WithDefaults() *GetGiteaCredentialsParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the get gitea credentials params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *GetGiteaCredentialsParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the get gitea credentials params
func (o *GetGiteaCredentialsParams) WithTimeout(timeout time.Duration) *GetGiteaCredentialsParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the get gitea credentials params
func (o *GetGiteaCredentialsParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the get gitea credentials params
func (o *GetGiteaCredentialsParams) WithContext(ctx context.Context) *GetGiteaCredentialsParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the get gitea credentials params
func (o *GetGiteaCredentialsParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the get gitea credentials params
func (o *GetGiteaCredentialsParams) WithHTTPClient(client *http.Client) *GetGiteaCredentialsParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the get gitea credentials params
func (o *GetGiteaCredentialsParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithID adds the id to the get gitea credentials params
func (o *GetGiteaCredentialsParams) WithID(id int64) *GetGiteaCredentialsParams {
o.SetID(id)
return o
}
// SetID adds the id to the get gitea credentials params
func (o *GetGiteaCredentialsParams) SetID(id int64) {
o.ID = id
}
// WriteToRequest writes these params to a swagger request
func (o *GetGiteaCredentialsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param id
if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,179 @@
// Code generated by go-swagger; DO NOT EDIT.
package credentials
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
garm_params "github.com/cloudbase/garm/params"
)
// GetGiteaCredentialsReader is a Reader for the GetGiteaCredentials structure.
type GetGiteaCredentialsReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *GetGiteaCredentialsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewGetGiteaCredentialsOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 400:
result := NewGetGiteaCredentialsBadRequest()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("[GET /gitea/credentials/{id}] GetGiteaCredentials", response, response.Code())
}
}
// NewGetGiteaCredentialsOK creates a GetGiteaCredentialsOK with default headers values
func NewGetGiteaCredentialsOK() *GetGiteaCredentialsOK {
return &GetGiteaCredentialsOK{}
}
/*
GetGiteaCredentialsOK describes a response with status code 200, with default header values.
ForgeCredentials
*/
type GetGiteaCredentialsOK struct {
Payload garm_params.ForgeCredentials
}
// IsSuccess returns true when this get gitea credentials o k response has a 2xx status code
func (o *GetGiteaCredentialsOK) IsSuccess() bool {
return true
}
// IsRedirect returns true when this get gitea credentials o k response has a 3xx status code
func (o *GetGiteaCredentialsOK) IsRedirect() bool {
return false
}
// IsClientError returns true when this get gitea credentials o k response has a 4xx status code
func (o *GetGiteaCredentialsOK) IsClientError() bool {
return false
}
// IsServerError returns true when this get gitea credentials o k response has a 5xx status code
func (o *GetGiteaCredentialsOK) IsServerError() bool {
return false
}
// IsCode returns true when this get gitea credentials o k response a status code equal to that given
func (o *GetGiteaCredentialsOK) IsCode(code int) bool {
return code == 200
}
// Code gets the status code for the get gitea credentials o k response
func (o *GetGiteaCredentialsOK) Code() int {
return 200
}
func (o *GetGiteaCredentialsOK) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/credentials/{id}][%d] getGiteaCredentialsOK %s", 200, payload)
}
func (o *GetGiteaCredentialsOK) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/credentials/{id}][%d] getGiteaCredentialsOK %s", 200, payload)
}
func (o *GetGiteaCredentialsOK) GetPayload() garm_params.ForgeCredentials {
return o.Payload
}
func (o *GetGiteaCredentialsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewGetGiteaCredentialsBadRequest creates a GetGiteaCredentialsBadRequest with default headers values
func NewGetGiteaCredentialsBadRequest() *GetGiteaCredentialsBadRequest {
return &GetGiteaCredentialsBadRequest{}
}
/*
GetGiteaCredentialsBadRequest describes a response with status code 400, with default header values.
APIErrorResponse
*/
type GetGiteaCredentialsBadRequest struct {
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this get gitea credentials bad request response has a 2xx status code
func (o *GetGiteaCredentialsBadRequest) IsSuccess() bool {
return false
}
// IsRedirect returns true when this get gitea credentials bad request response has a 3xx status code
func (o *GetGiteaCredentialsBadRequest) IsRedirect() bool {
return false
}
// IsClientError returns true when this get gitea credentials bad request response has a 4xx status code
func (o *GetGiteaCredentialsBadRequest) IsClientError() bool {
return true
}
// IsServerError returns true when this get gitea credentials bad request response has a 5xx status code
func (o *GetGiteaCredentialsBadRequest) IsServerError() bool {
return false
}
// IsCode returns true when this get gitea credentials bad request response a status code equal to that given
func (o *GetGiteaCredentialsBadRequest) IsCode(code int) bool {
return code == 400
}
// Code gets the status code for the get gitea credentials bad request response
func (o *GetGiteaCredentialsBadRequest) Code() int {
return 400
}
func (o *GetGiteaCredentialsBadRequest) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/credentials/{id}][%d] getGiteaCredentialsBadRequest %s", 400, payload)
}
func (o *GetGiteaCredentialsBadRequest) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/credentials/{id}][%d] getGiteaCredentialsBadRequest %s", 400, payload)
}
func (o *GetGiteaCredentialsBadRequest) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *GetGiteaCredentialsBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -0,0 +1,128 @@
// Code generated by go-swagger; DO NOT EDIT.
package credentials
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
)
// NewListGiteaCredentialsParams creates a new ListGiteaCredentialsParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewListGiteaCredentialsParams() *ListGiteaCredentialsParams {
return &ListGiteaCredentialsParams{
timeout: cr.DefaultTimeout,
}
}
// NewListGiteaCredentialsParamsWithTimeout creates a new ListGiteaCredentialsParams object
// with the ability to set a timeout on a request.
func NewListGiteaCredentialsParamsWithTimeout(timeout time.Duration) *ListGiteaCredentialsParams {
return &ListGiteaCredentialsParams{
timeout: timeout,
}
}
// NewListGiteaCredentialsParamsWithContext creates a new ListGiteaCredentialsParams object
// with the ability to set a context for a request.
func NewListGiteaCredentialsParamsWithContext(ctx context.Context) *ListGiteaCredentialsParams {
return &ListGiteaCredentialsParams{
Context: ctx,
}
}
// NewListGiteaCredentialsParamsWithHTTPClient creates a new ListGiteaCredentialsParams object
// with the ability to set a custom HTTPClient for a request.
func NewListGiteaCredentialsParamsWithHTTPClient(client *http.Client) *ListGiteaCredentialsParams {
return &ListGiteaCredentialsParams{
HTTPClient: client,
}
}
/*
ListGiteaCredentialsParams contains all the parameters to send to the API endpoint
for the list gitea credentials operation.
Typically these are written to a http.Request.
*/
type ListGiteaCredentialsParams struct {
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the list gitea credentials params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *ListGiteaCredentialsParams) WithDefaults() *ListGiteaCredentialsParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the list gitea credentials params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *ListGiteaCredentialsParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the list gitea credentials params
func (o *ListGiteaCredentialsParams) WithTimeout(timeout time.Duration) *ListGiteaCredentialsParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the list gitea credentials params
func (o *ListGiteaCredentialsParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the list gitea credentials params
func (o *ListGiteaCredentialsParams) WithContext(ctx context.Context) *ListGiteaCredentialsParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the list gitea credentials params
func (o *ListGiteaCredentialsParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the list gitea credentials params
func (o *ListGiteaCredentialsParams) WithHTTPClient(client *http.Client) *ListGiteaCredentialsParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the list gitea credentials params
func (o *ListGiteaCredentialsParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WriteToRequest writes these params to a swagger request
func (o *ListGiteaCredentialsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,179 @@
// Code generated by go-swagger; DO NOT EDIT.
package credentials
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
garm_params "github.com/cloudbase/garm/params"
)
// ListGiteaCredentialsReader is a Reader for the ListGiteaCredentials structure.
type ListGiteaCredentialsReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ListGiteaCredentialsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewListGiteaCredentialsOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 400:
result := NewListGiteaCredentialsBadRequest()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("[GET /gitea/credentials] ListGiteaCredentials", response, response.Code())
}
}
// NewListGiteaCredentialsOK creates a ListGiteaCredentialsOK with default headers values
func NewListGiteaCredentialsOK() *ListGiteaCredentialsOK {
return &ListGiteaCredentialsOK{}
}
/*
ListGiteaCredentialsOK describes a response with status code 200, with default header values.
Credentials
*/
type ListGiteaCredentialsOK struct {
Payload garm_params.Credentials
}
// IsSuccess returns true when this list gitea credentials o k response has a 2xx status code
func (o *ListGiteaCredentialsOK) IsSuccess() bool {
return true
}
// IsRedirect returns true when this list gitea credentials o k response has a 3xx status code
func (o *ListGiteaCredentialsOK) IsRedirect() bool {
return false
}
// IsClientError returns true when this list gitea credentials o k response has a 4xx status code
func (o *ListGiteaCredentialsOK) IsClientError() bool {
return false
}
// IsServerError returns true when this list gitea credentials o k response has a 5xx status code
func (o *ListGiteaCredentialsOK) IsServerError() bool {
return false
}
// IsCode returns true when this list gitea credentials o k response a status code equal to that given
func (o *ListGiteaCredentialsOK) IsCode(code int) bool {
return code == 200
}
// Code gets the status code for the list gitea credentials o k response
func (o *ListGiteaCredentialsOK) Code() int {
return 200
}
func (o *ListGiteaCredentialsOK) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/credentials][%d] listGiteaCredentialsOK %s", 200, payload)
}
func (o *ListGiteaCredentialsOK) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/credentials][%d] listGiteaCredentialsOK %s", 200, payload)
}
func (o *ListGiteaCredentialsOK) GetPayload() garm_params.Credentials {
return o.Payload
}
func (o *ListGiteaCredentialsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewListGiteaCredentialsBadRequest creates a ListGiteaCredentialsBadRequest with default headers values
func NewListGiteaCredentialsBadRequest() *ListGiteaCredentialsBadRequest {
return &ListGiteaCredentialsBadRequest{}
}
/*
ListGiteaCredentialsBadRequest describes a response with status code 400, with default header values.
APIErrorResponse
*/
type ListGiteaCredentialsBadRequest struct {
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this list gitea credentials bad request response has a 2xx status code
func (o *ListGiteaCredentialsBadRequest) IsSuccess() bool {
return false
}
// IsRedirect returns true when this list gitea credentials bad request response has a 3xx status code
func (o *ListGiteaCredentialsBadRequest) IsRedirect() bool {
return false
}
// IsClientError returns true when this list gitea credentials bad request response has a 4xx status code
func (o *ListGiteaCredentialsBadRequest) IsClientError() bool {
return true
}
// IsServerError returns true when this list gitea credentials bad request response has a 5xx status code
func (o *ListGiteaCredentialsBadRequest) IsServerError() bool {
return false
}
// IsCode returns true when this list gitea credentials bad request response a status code equal to that given
func (o *ListGiteaCredentialsBadRequest) IsCode(code int) bool {
return code == 400
}
// Code gets the status code for the list gitea credentials bad request response
func (o *ListGiteaCredentialsBadRequest) Code() int {
return 400
}
func (o *ListGiteaCredentialsBadRequest) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/credentials][%d] listGiteaCredentialsBadRequest %s", 400, payload)
}
func (o *ListGiteaCredentialsBadRequest) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/credentials][%d] listGiteaCredentialsBadRequest %s", 400, payload)
}
func (o *ListGiteaCredentialsBadRequest) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *ListGiteaCredentialsBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -50,10 +50,10 @@ func NewUpdateCredentialsOK() *UpdateCredentialsOK {
/*
UpdateCredentialsOK describes a response with status code 200, with default header values.
GithubCredentials
ForgeCredentials
*/
type UpdateCredentialsOK struct {
Payload garm_params.GithubCredentials
Payload garm_params.ForgeCredentials
}
// IsSuccess returns true when this update credentials o k response has a 2xx status code
@ -96,7 +96,7 @@ func (o *UpdateCredentialsOK) String() string {
return fmt.Sprintf("[PUT /github/credentials/{id}][%d] updateCredentialsOK %s", 200, payload)
}
func (o *UpdateCredentialsOK) GetPayload() garm_params.GithubCredentials {
func (o *UpdateCredentialsOK) GetPayload() garm_params.ForgeCredentials {
return o.Payload
}

View file

@ -0,0 +1,174 @@
// Code generated by go-swagger; DO NOT EDIT.
package credentials
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
garm_params "github.com/cloudbase/garm/params"
)
// NewUpdateGiteaCredentialsParams creates a new UpdateGiteaCredentialsParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewUpdateGiteaCredentialsParams() *UpdateGiteaCredentialsParams {
return &UpdateGiteaCredentialsParams{
timeout: cr.DefaultTimeout,
}
}
// NewUpdateGiteaCredentialsParamsWithTimeout creates a new UpdateGiteaCredentialsParams object
// with the ability to set a timeout on a request.
func NewUpdateGiteaCredentialsParamsWithTimeout(timeout time.Duration) *UpdateGiteaCredentialsParams {
return &UpdateGiteaCredentialsParams{
timeout: timeout,
}
}
// NewUpdateGiteaCredentialsParamsWithContext creates a new UpdateGiteaCredentialsParams object
// with the ability to set a context for a request.
func NewUpdateGiteaCredentialsParamsWithContext(ctx context.Context) *UpdateGiteaCredentialsParams {
return &UpdateGiteaCredentialsParams{
Context: ctx,
}
}
// NewUpdateGiteaCredentialsParamsWithHTTPClient creates a new UpdateGiteaCredentialsParams object
// with the ability to set a custom HTTPClient for a request.
func NewUpdateGiteaCredentialsParamsWithHTTPClient(client *http.Client) *UpdateGiteaCredentialsParams {
return &UpdateGiteaCredentialsParams{
HTTPClient: client,
}
}
/*
UpdateGiteaCredentialsParams contains all the parameters to send to the API endpoint
for the update gitea credentials operation.
Typically these are written to a http.Request.
*/
type UpdateGiteaCredentialsParams struct {
/* Body.
Parameters used when updating a Gitea credential.
*/
Body garm_params.UpdateGiteaCredentialsParams
/* ID.
ID of the Gitea credential.
*/
ID int64
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the update gitea credentials params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *UpdateGiteaCredentialsParams) WithDefaults() *UpdateGiteaCredentialsParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the update gitea credentials params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *UpdateGiteaCredentialsParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the update gitea credentials params
func (o *UpdateGiteaCredentialsParams) WithTimeout(timeout time.Duration) *UpdateGiteaCredentialsParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the update gitea credentials params
func (o *UpdateGiteaCredentialsParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the update gitea credentials params
func (o *UpdateGiteaCredentialsParams) WithContext(ctx context.Context) *UpdateGiteaCredentialsParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the update gitea credentials params
func (o *UpdateGiteaCredentialsParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the update gitea credentials params
func (o *UpdateGiteaCredentialsParams) WithHTTPClient(client *http.Client) *UpdateGiteaCredentialsParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the update gitea credentials params
func (o *UpdateGiteaCredentialsParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the update gitea credentials params
func (o *UpdateGiteaCredentialsParams) WithBody(body garm_params.UpdateGiteaCredentialsParams) *UpdateGiteaCredentialsParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the update gitea credentials params
func (o *UpdateGiteaCredentialsParams) SetBody(body garm_params.UpdateGiteaCredentialsParams) {
o.Body = body
}
// WithID adds the id to the update gitea credentials params
func (o *UpdateGiteaCredentialsParams) WithID(id int64) *UpdateGiteaCredentialsParams {
o.SetID(id)
return o
}
// SetID adds the id to the update gitea credentials params
func (o *UpdateGiteaCredentialsParams) SetID(id int64) {
o.ID = id
}
// WriteToRequest writes these params to a swagger request
func (o *UpdateGiteaCredentialsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
// path param id
if err := r.SetPathParam("id", swag.FormatInt64(o.ID)); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,179 @@
// Code generated by go-swagger; DO NOT EDIT.
package credentials
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
garm_params "github.com/cloudbase/garm/params"
)
// UpdateGiteaCredentialsReader is a Reader for the UpdateGiteaCredentials structure.
type UpdateGiteaCredentialsReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *UpdateGiteaCredentialsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewUpdateGiteaCredentialsOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
case 400:
result := NewUpdateGiteaCredentialsBadRequest()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return nil, result
default:
return nil, runtime.NewAPIError("[PUT /gitea/credentials/{id}] UpdateGiteaCredentials", response, response.Code())
}
}
// NewUpdateGiteaCredentialsOK creates a UpdateGiteaCredentialsOK with default headers values
func NewUpdateGiteaCredentialsOK() *UpdateGiteaCredentialsOK {
return &UpdateGiteaCredentialsOK{}
}
/*
UpdateGiteaCredentialsOK describes a response with status code 200, with default header values.
ForgeCredentials
*/
type UpdateGiteaCredentialsOK struct {
Payload garm_params.ForgeCredentials
}
// IsSuccess returns true when this update gitea credentials o k response has a 2xx status code
func (o *UpdateGiteaCredentialsOK) IsSuccess() bool {
return true
}
// IsRedirect returns true when this update gitea credentials o k response has a 3xx status code
func (o *UpdateGiteaCredentialsOK) IsRedirect() bool {
return false
}
// IsClientError returns true when this update gitea credentials o k response has a 4xx status code
func (o *UpdateGiteaCredentialsOK) IsClientError() bool {
return false
}
// IsServerError returns true when this update gitea credentials o k response has a 5xx status code
func (o *UpdateGiteaCredentialsOK) IsServerError() bool {
return false
}
// IsCode returns true when this update gitea credentials o k response a status code equal to that given
func (o *UpdateGiteaCredentialsOK) IsCode(code int) bool {
return code == 200
}
// Code gets the status code for the update gitea credentials o k response
func (o *UpdateGiteaCredentialsOK) Code() int {
return 200
}
func (o *UpdateGiteaCredentialsOK) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /gitea/credentials/{id}][%d] updateGiteaCredentialsOK %s", 200, payload)
}
func (o *UpdateGiteaCredentialsOK) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /gitea/credentials/{id}][%d] updateGiteaCredentialsOK %s", 200, payload)
}
func (o *UpdateGiteaCredentialsOK) GetPayload() garm_params.ForgeCredentials {
return o.Payload
}
func (o *UpdateGiteaCredentialsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewUpdateGiteaCredentialsBadRequest creates a UpdateGiteaCredentialsBadRequest with default headers values
func NewUpdateGiteaCredentialsBadRequest() *UpdateGiteaCredentialsBadRequest {
return &UpdateGiteaCredentialsBadRequest{}
}
/*
UpdateGiteaCredentialsBadRequest describes a response with status code 400, with default header values.
APIErrorResponse
*/
type UpdateGiteaCredentialsBadRequest struct {
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this update gitea credentials bad request response has a 2xx status code
func (o *UpdateGiteaCredentialsBadRequest) IsSuccess() bool {
return false
}
// IsRedirect returns true when this update gitea credentials bad request response has a 3xx status code
func (o *UpdateGiteaCredentialsBadRequest) IsRedirect() bool {
return false
}
// IsClientError returns true when this update gitea credentials bad request response has a 4xx status code
func (o *UpdateGiteaCredentialsBadRequest) IsClientError() bool {
return true
}
// IsServerError returns true when this update gitea credentials bad request response has a 5xx status code
func (o *UpdateGiteaCredentialsBadRequest) IsServerError() bool {
return false
}
// IsCode returns true when this update gitea credentials bad request response a status code equal to that given
func (o *UpdateGiteaCredentialsBadRequest) IsCode(code int) bool {
return code == 400
}
// Code gets the status code for the update gitea credentials bad request response
func (o *UpdateGiteaCredentialsBadRequest) Code() int {
return 400
}
func (o *UpdateGiteaCredentialsBadRequest) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /gitea/credentials/{id}][%d] updateGiteaCredentialsBadRequest %s", 400, payload)
}
func (o *UpdateGiteaCredentialsBadRequest) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /gitea/credentials/{id}][%d] updateGiteaCredentialsBadRequest %s", 400, payload)
}
func (o *UpdateGiteaCredentialsBadRequest) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *UpdateGiteaCredentialsBadRequest) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -0,0 +1,151 @@
// Code generated by go-swagger; DO NOT EDIT.
package endpoints
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
garm_params "github.com/cloudbase/garm/params"
)
// NewCreateGiteaEndpointParams creates a new CreateGiteaEndpointParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewCreateGiteaEndpointParams() *CreateGiteaEndpointParams {
return &CreateGiteaEndpointParams{
timeout: cr.DefaultTimeout,
}
}
// NewCreateGiteaEndpointParamsWithTimeout creates a new CreateGiteaEndpointParams object
// with the ability to set a timeout on a request.
func NewCreateGiteaEndpointParamsWithTimeout(timeout time.Duration) *CreateGiteaEndpointParams {
return &CreateGiteaEndpointParams{
timeout: timeout,
}
}
// NewCreateGiteaEndpointParamsWithContext creates a new CreateGiteaEndpointParams object
// with the ability to set a context for a request.
func NewCreateGiteaEndpointParamsWithContext(ctx context.Context) *CreateGiteaEndpointParams {
return &CreateGiteaEndpointParams{
Context: ctx,
}
}
// NewCreateGiteaEndpointParamsWithHTTPClient creates a new CreateGiteaEndpointParams object
// with the ability to set a custom HTTPClient for a request.
func NewCreateGiteaEndpointParamsWithHTTPClient(client *http.Client) *CreateGiteaEndpointParams {
return &CreateGiteaEndpointParams{
HTTPClient: client,
}
}
/*
CreateGiteaEndpointParams contains all the parameters to send to the API endpoint
for the create gitea endpoint operation.
Typically these are written to a http.Request.
*/
type CreateGiteaEndpointParams struct {
/* Body.
Parameters used when creating a Gitea endpoint.
*/
Body garm_params.CreateGiteaEndpointParams
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the create gitea endpoint params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *CreateGiteaEndpointParams) WithDefaults() *CreateGiteaEndpointParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the create gitea endpoint params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *CreateGiteaEndpointParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the create gitea endpoint params
func (o *CreateGiteaEndpointParams) WithTimeout(timeout time.Duration) *CreateGiteaEndpointParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the create gitea endpoint params
func (o *CreateGiteaEndpointParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the create gitea endpoint params
func (o *CreateGiteaEndpointParams) WithContext(ctx context.Context) *CreateGiteaEndpointParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the create gitea endpoint params
func (o *CreateGiteaEndpointParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the create gitea endpoint params
func (o *CreateGiteaEndpointParams) WithHTTPClient(client *http.Client) *CreateGiteaEndpointParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the create gitea endpoint params
func (o *CreateGiteaEndpointParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the create gitea endpoint params
func (o *CreateGiteaEndpointParams) WithBody(body garm_params.CreateGiteaEndpointParams) *CreateGiteaEndpointParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the create gitea endpoint params
func (o *CreateGiteaEndpointParams) SetBody(body garm_params.CreateGiteaEndpointParams) {
o.Body = body
}
// WriteToRequest writes these params to a swagger request
func (o *CreateGiteaEndpointParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,184 @@
// Code generated by go-swagger; DO NOT EDIT.
package endpoints
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
garm_params "github.com/cloudbase/garm/params"
)
// CreateGiteaEndpointReader is a Reader for the CreateGiteaEndpoint structure.
type CreateGiteaEndpointReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *CreateGiteaEndpointReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewCreateGiteaEndpointOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewCreateGiteaEndpointDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewCreateGiteaEndpointOK creates a CreateGiteaEndpointOK with default headers values
func NewCreateGiteaEndpointOK() *CreateGiteaEndpointOK {
return &CreateGiteaEndpointOK{}
}
/*
CreateGiteaEndpointOK describes a response with status code 200, with default header values.
ForgeEndpoint
*/
type CreateGiteaEndpointOK struct {
Payload garm_params.ForgeEndpoint
}
// IsSuccess returns true when this create gitea endpoint o k response has a 2xx status code
func (o *CreateGiteaEndpointOK) IsSuccess() bool {
return true
}
// IsRedirect returns true when this create gitea endpoint o k response has a 3xx status code
func (o *CreateGiteaEndpointOK) IsRedirect() bool {
return false
}
// IsClientError returns true when this create gitea endpoint o k response has a 4xx status code
func (o *CreateGiteaEndpointOK) IsClientError() bool {
return false
}
// IsServerError returns true when this create gitea endpoint o k response has a 5xx status code
func (o *CreateGiteaEndpointOK) IsServerError() bool {
return false
}
// IsCode returns true when this create gitea endpoint o k response a status code equal to that given
func (o *CreateGiteaEndpointOK) IsCode(code int) bool {
return code == 200
}
// Code gets the status code for the create gitea endpoint o k response
func (o *CreateGiteaEndpointOK) Code() int {
return 200
}
func (o *CreateGiteaEndpointOK) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[POST /gitea/endpoints][%d] createGiteaEndpointOK %s", 200, payload)
}
func (o *CreateGiteaEndpointOK) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[POST /gitea/endpoints][%d] createGiteaEndpointOK %s", 200, payload)
}
func (o *CreateGiteaEndpointOK) GetPayload() garm_params.ForgeEndpoint {
return o.Payload
}
func (o *CreateGiteaEndpointOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewCreateGiteaEndpointDefault creates a CreateGiteaEndpointDefault with default headers values
func NewCreateGiteaEndpointDefault(code int) *CreateGiteaEndpointDefault {
return &CreateGiteaEndpointDefault{
_statusCode: code,
}
}
/*
CreateGiteaEndpointDefault describes a response with status code -1, with default header values.
APIErrorResponse
*/
type CreateGiteaEndpointDefault struct {
_statusCode int
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this create gitea endpoint default response has a 2xx status code
func (o *CreateGiteaEndpointDefault) IsSuccess() bool {
return o._statusCode/100 == 2
}
// IsRedirect returns true when this create gitea endpoint default response has a 3xx status code
func (o *CreateGiteaEndpointDefault) IsRedirect() bool {
return o._statusCode/100 == 3
}
// IsClientError returns true when this create gitea endpoint default response has a 4xx status code
func (o *CreateGiteaEndpointDefault) IsClientError() bool {
return o._statusCode/100 == 4
}
// IsServerError returns true when this create gitea endpoint default response has a 5xx status code
func (o *CreateGiteaEndpointDefault) IsServerError() bool {
return o._statusCode/100 == 5
}
// IsCode returns true when this create gitea endpoint default response a status code equal to that given
func (o *CreateGiteaEndpointDefault) IsCode(code int) bool {
return o._statusCode == code
}
// Code gets the status code for the create gitea endpoint default response
func (o *CreateGiteaEndpointDefault) Code() int {
return o._statusCode
}
func (o *CreateGiteaEndpointDefault) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[POST /gitea/endpoints][%d] CreateGiteaEndpoint default %s", o._statusCode, payload)
}
func (o *CreateGiteaEndpointDefault) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[POST /gitea/endpoints][%d] CreateGiteaEndpoint default %s", o._statusCode, payload)
}
func (o *CreateGiteaEndpointDefault) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *CreateGiteaEndpointDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -51,10 +51,10 @@ func NewCreateGithubEndpointOK() *CreateGithubEndpointOK {
/*
CreateGithubEndpointOK describes a response with status code 200, with default header values.
GithubEndpoint
ForgeEndpoint
*/
type CreateGithubEndpointOK struct {
Payload garm_params.GithubEndpoint
Payload garm_params.ForgeEndpoint
}
// IsSuccess returns true when this create github endpoint o k response has a 2xx status code
@ -97,7 +97,7 @@ func (o *CreateGithubEndpointOK) String() string {
return fmt.Sprintf("[POST /github/endpoints][%d] createGithubEndpointOK %s", 200, payload)
}
func (o *CreateGithubEndpointOK) GetPayload() garm_params.GithubEndpoint {
func (o *CreateGithubEndpointOK) GetPayload() garm_params.ForgeEndpoint {
return o.Payload
}

View file

@ -0,0 +1,151 @@
// Code generated by go-swagger; DO NOT EDIT.
package endpoints
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
)
// NewDeleteGiteaEndpointParams creates a new DeleteGiteaEndpointParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewDeleteGiteaEndpointParams() *DeleteGiteaEndpointParams {
return &DeleteGiteaEndpointParams{
timeout: cr.DefaultTimeout,
}
}
// NewDeleteGiteaEndpointParamsWithTimeout creates a new DeleteGiteaEndpointParams object
// with the ability to set a timeout on a request.
func NewDeleteGiteaEndpointParamsWithTimeout(timeout time.Duration) *DeleteGiteaEndpointParams {
return &DeleteGiteaEndpointParams{
timeout: timeout,
}
}
// NewDeleteGiteaEndpointParamsWithContext creates a new DeleteGiteaEndpointParams object
// with the ability to set a context for a request.
func NewDeleteGiteaEndpointParamsWithContext(ctx context.Context) *DeleteGiteaEndpointParams {
return &DeleteGiteaEndpointParams{
Context: ctx,
}
}
// NewDeleteGiteaEndpointParamsWithHTTPClient creates a new DeleteGiteaEndpointParams object
// with the ability to set a custom HTTPClient for a request.
func NewDeleteGiteaEndpointParamsWithHTTPClient(client *http.Client) *DeleteGiteaEndpointParams {
return &DeleteGiteaEndpointParams{
HTTPClient: client,
}
}
/*
DeleteGiteaEndpointParams contains all the parameters to send to the API endpoint
for the delete gitea endpoint operation.
Typically these are written to a http.Request.
*/
type DeleteGiteaEndpointParams struct {
/* Name.
The name of the Gitea endpoint.
*/
Name string
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the delete gitea endpoint params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *DeleteGiteaEndpointParams) WithDefaults() *DeleteGiteaEndpointParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the delete gitea endpoint params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *DeleteGiteaEndpointParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the delete gitea endpoint params
func (o *DeleteGiteaEndpointParams) WithTimeout(timeout time.Duration) *DeleteGiteaEndpointParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the delete gitea endpoint params
func (o *DeleteGiteaEndpointParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the delete gitea endpoint params
func (o *DeleteGiteaEndpointParams) WithContext(ctx context.Context) *DeleteGiteaEndpointParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the delete gitea endpoint params
func (o *DeleteGiteaEndpointParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the delete gitea endpoint params
func (o *DeleteGiteaEndpointParams) WithHTTPClient(client *http.Client) *DeleteGiteaEndpointParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the delete gitea endpoint params
func (o *DeleteGiteaEndpointParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithName adds the name to the delete gitea endpoint params
func (o *DeleteGiteaEndpointParams) WithName(name string) *DeleteGiteaEndpointParams {
o.SetName(name)
return o
}
// SetName adds the name to the delete gitea endpoint params
func (o *DeleteGiteaEndpointParams) SetName(name string) {
o.Name = name
}
// WriteToRequest writes these params to a swagger request
func (o *DeleteGiteaEndpointParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param name
if err := r.SetPathParam("name", o.Name); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,106 @@
// Code generated by go-swagger; DO NOT EDIT.
package endpoints
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
)
// DeleteGiteaEndpointReader is a Reader for the DeleteGiteaEndpoint structure.
type DeleteGiteaEndpointReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *DeleteGiteaEndpointReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
result := NewDeleteGiteaEndpointDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
// NewDeleteGiteaEndpointDefault creates a DeleteGiteaEndpointDefault with default headers values
func NewDeleteGiteaEndpointDefault(code int) *DeleteGiteaEndpointDefault {
return &DeleteGiteaEndpointDefault{
_statusCode: code,
}
}
/*
DeleteGiteaEndpointDefault describes a response with status code -1, with default header values.
APIErrorResponse
*/
type DeleteGiteaEndpointDefault struct {
_statusCode int
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this delete gitea endpoint default response has a 2xx status code
func (o *DeleteGiteaEndpointDefault) IsSuccess() bool {
return o._statusCode/100 == 2
}
// IsRedirect returns true when this delete gitea endpoint default response has a 3xx status code
func (o *DeleteGiteaEndpointDefault) IsRedirect() bool {
return o._statusCode/100 == 3
}
// IsClientError returns true when this delete gitea endpoint default response has a 4xx status code
func (o *DeleteGiteaEndpointDefault) IsClientError() bool {
return o._statusCode/100 == 4
}
// IsServerError returns true when this delete gitea endpoint default response has a 5xx status code
func (o *DeleteGiteaEndpointDefault) IsServerError() bool {
return o._statusCode/100 == 5
}
// IsCode returns true when this delete gitea endpoint default response a status code equal to that given
func (o *DeleteGiteaEndpointDefault) IsCode(code int) bool {
return o._statusCode == code
}
// Code gets the status code for the delete gitea endpoint default response
func (o *DeleteGiteaEndpointDefault) Code() int {
return o._statusCode
}
func (o *DeleteGiteaEndpointDefault) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[DELETE /gitea/endpoints/{name}][%d] DeleteGiteaEndpoint default %s", o._statusCode, payload)
}
func (o *DeleteGiteaEndpointDefault) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[DELETE /gitea/endpoints/{name}][%d] DeleteGiteaEndpoint default %s", o._statusCode, payload)
}
func (o *DeleteGiteaEndpointDefault) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *DeleteGiteaEndpointDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -54,19 +54,67 @@ type ClientOption func(*runtime.ClientOperation)
// ClientService is the interface for Client methods
type ClientService interface {
CreateGiteaEndpoint(params *CreateGiteaEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateGiteaEndpointOK, error)
CreateGithubEndpoint(params *CreateGithubEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateGithubEndpointOK, error)
DeleteGiteaEndpoint(params *DeleteGiteaEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) error
DeleteGithubEndpoint(params *DeleteGithubEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) error
GetGiteaEndpoint(params *GetGiteaEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetGiteaEndpointOK, error)
GetGithubEndpoint(params *GetGithubEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetGithubEndpointOK, error)
ListGiteaEndpoints(params *ListGiteaEndpointsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListGiteaEndpointsOK, error)
ListGithubEndpoints(params *ListGithubEndpointsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListGithubEndpointsOK, error)
UpdateGiteaEndpoint(params *UpdateGiteaEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateGiteaEndpointOK, error)
UpdateGithubEndpoint(params *UpdateGithubEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateGithubEndpointOK, error)
SetTransport(transport runtime.ClientTransport)
}
/*
CreateGiteaEndpoint creates a gitea endpoint
*/
func (a *Client) CreateGiteaEndpoint(params *CreateGiteaEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*CreateGiteaEndpointOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewCreateGiteaEndpointParams()
}
op := &runtime.ClientOperation{
ID: "CreateGiteaEndpoint",
Method: "POST",
PathPattern: "/gitea/endpoints",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &CreateGiteaEndpointReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
result, err := a.transport.Submit(op)
if err != nil {
return nil, err
}
success, ok := result.(*CreateGiteaEndpointOK)
if ok {
return success, nil
}
// unexpected success response
unexpectedSuccess := result.(*CreateGiteaEndpointDefault)
return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}
/*
CreateGithubEndpoint creates a git hub endpoint
*/
@ -105,6 +153,38 @@ func (a *Client) CreateGithubEndpoint(params *CreateGithubEndpointParams, authIn
return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}
/*
DeleteGiteaEndpoint deletes a gitea endpoint
*/
func (a *Client) DeleteGiteaEndpoint(params *DeleteGiteaEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) error {
// TODO: Validate the params before sending
if params == nil {
params = NewDeleteGiteaEndpointParams()
}
op := &runtime.ClientOperation{
ID: "DeleteGiteaEndpoint",
Method: "DELETE",
PathPattern: "/gitea/endpoints/{name}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &DeleteGiteaEndpointReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
_, err := a.transport.Submit(op)
if err != nil {
return err
}
return nil
}
/*
DeleteGithubEndpoint deletes a git hub endpoint
*/
@ -137,6 +217,44 @@ func (a *Client) DeleteGithubEndpoint(params *DeleteGithubEndpointParams, authIn
return nil
}
/*
GetGiteaEndpoint gets a gitea endpoint
*/
func (a *Client) GetGiteaEndpoint(params *GetGiteaEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*GetGiteaEndpointOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewGetGiteaEndpointParams()
}
op := &runtime.ClientOperation{
ID: "GetGiteaEndpoint",
Method: "GET",
PathPattern: "/gitea/endpoints/{name}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &GetGiteaEndpointReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
result, err := a.transport.Submit(op)
if err != nil {
return nil, err
}
success, ok := result.(*GetGiteaEndpointOK)
if ok {
return success, nil
}
// unexpected success response
unexpectedSuccess := result.(*GetGiteaEndpointDefault)
return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}
/*
GetGithubEndpoint gets a git hub endpoint
*/
@ -175,6 +293,44 @@ func (a *Client) GetGithubEndpoint(params *GetGithubEndpointParams, authInfo run
return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}
/*
ListGiteaEndpoints lists all gitea endpoints
*/
func (a *Client) ListGiteaEndpoints(params *ListGiteaEndpointsParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*ListGiteaEndpointsOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewListGiteaEndpointsParams()
}
op := &runtime.ClientOperation{
ID: "ListGiteaEndpoints",
Method: "GET",
PathPattern: "/gitea/endpoints",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ListGiteaEndpointsReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
result, err := a.transport.Submit(op)
if err != nil {
return nil, err
}
success, ok := result.(*ListGiteaEndpointsOK)
if ok {
return success, nil
}
// unexpected success response
unexpectedSuccess := result.(*ListGiteaEndpointsDefault)
return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}
/*
ListGithubEndpoints lists all git hub endpoints
*/
@ -213,6 +369,44 @@ func (a *Client) ListGithubEndpoints(params *ListGithubEndpointsParams, authInfo
return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}
/*
UpdateGiteaEndpoint updates a gitea endpoint
*/
func (a *Client) UpdateGiteaEndpoint(params *UpdateGiteaEndpointParams, authInfo runtime.ClientAuthInfoWriter, opts ...ClientOption) (*UpdateGiteaEndpointOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewUpdateGiteaEndpointParams()
}
op := &runtime.ClientOperation{
ID: "UpdateGiteaEndpoint",
Method: "PUT",
PathPattern: "/gitea/endpoints/{name}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &UpdateGiteaEndpointReader{formats: a.formats},
AuthInfo: authInfo,
Context: params.Context,
Client: params.HTTPClient,
}
for _, opt := range opts {
opt(op)
}
result, err := a.transport.Submit(op)
if err != nil {
return nil, err
}
success, ok := result.(*UpdateGiteaEndpointOK)
if ok {
return success, nil
}
// unexpected success response
unexpectedSuccess := result.(*UpdateGiteaEndpointDefault)
return nil, runtime.NewAPIError("unexpected success response: content available as default response in error", unexpectedSuccess, unexpectedSuccess.Code())
}
/*
UpdateGithubEndpoint updates a git hub endpoint
*/

View file

@ -0,0 +1,151 @@
// Code generated by go-swagger; DO NOT EDIT.
package endpoints
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
)
// NewGetGiteaEndpointParams creates a new GetGiteaEndpointParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewGetGiteaEndpointParams() *GetGiteaEndpointParams {
return &GetGiteaEndpointParams{
timeout: cr.DefaultTimeout,
}
}
// NewGetGiteaEndpointParamsWithTimeout creates a new GetGiteaEndpointParams object
// with the ability to set a timeout on a request.
func NewGetGiteaEndpointParamsWithTimeout(timeout time.Duration) *GetGiteaEndpointParams {
return &GetGiteaEndpointParams{
timeout: timeout,
}
}
// NewGetGiteaEndpointParamsWithContext creates a new GetGiteaEndpointParams object
// with the ability to set a context for a request.
func NewGetGiteaEndpointParamsWithContext(ctx context.Context) *GetGiteaEndpointParams {
return &GetGiteaEndpointParams{
Context: ctx,
}
}
// NewGetGiteaEndpointParamsWithHTTPClient creates a new GetGiteaEndpointParams object
// with the ability to set a custom HTTPClient for a request.
func NewGetGiteaEndpointParamsWithHTTPClient(client *http.Client) *GetGiteaEndpointParams {
return &GetGiteaEndpointParams{
HTTPClient: client,
}
}
/*
GetGiteaEndpointParams contains all the parameters to send to the API endpoint
for the get gitea endpoint operation.
Typically these are written to a http.Request.
*/
type GetGiteaEndpointParams struct {
/* Name.
The name of the Gitea endpoint.
*/
Name string
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the get gitea endpoint params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *GetGiteaEndpointParams) WithDefaults() *GetGiteaEndpointParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the get gitea endpoint params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *GetGiteaEndpointParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the get gitea endpoint params
func (o *GetGiteaEndpointParams) WithTimeout(timeout time.Duration) *GetGiteaEndpointParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the get gitea endpoint params
func (o *GetGiteaEndpointParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the get gitea endpoint params
func (o *GetGiteaEndpointParams) WithContext(ctx context.Context) *GetGiteaEndpointParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the get gitea endpoint params
func (o *GetGiteaEndpointParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the get gitea endpoint params
func (o *GetGiteaEndpointParams) WithHTTPClient(client *http.Client) *GetGiteaEndpointParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the get gitea endpoint params
func (o *GetGiteaEndpointParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithName adds the name to the get gitea endpoint params
func (o *GetGiteaEndpointParams) WithName(name string) *GetGiteaEndpointParams {
o.SetName(name)
return o
}
// SetName adds the name to the get gitea endpoint params
func (o *GetGiteaEndpointParams) SetName(name string) {
o.Name = name
}
// WriteToRequest writes these params to a swagger request
func (o *GetGiteaEndpointParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param name
if err := r.SetPathParam("name", o.Name); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,184 @@
// Code generated by go-swagger; DO NOT EDIT.
package endpoints
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
garm_params "github.com/cloudbase/garm/params"
)
// GetGiteaEndpointReader is a Reader for the GetGiteaEndpoint structure.
type GetGiteaEndpointReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *GetGiteaEndpointReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewGetGiteaEndpointOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewGetGiteaEndpointDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewGetGiteaEndpointOK creates a GetGiteaEndpointOK with default headers values
func NewGetGiteaEndpointOK() *GetGiteaEndpointOK {
return &GetGiteaEndpointOK{}
}
/*
GetGiteaEndpointOK describes a response with status code 200, with default header values.
ForgeEndpoint
*/
type GetGiteaEndpointOK struct {
Payload garm_params.ForgeEndpoint
}
// IsSuccess returns true when this get gitea endpoint o k response has a 2xx status code
func (o *GetGiteaEndpointOK) IsSuccess() bool {
return true
}
// IsRedirect returns true when this get gitea endpoint o k response has a 3xx status code
func (o *GetGiteaEndpointOK) IsRedirect() bool {
return false
}
// IsClientError returns true when this get gitea endpoint o k response has a 4xx status code
func (o *GetGiteaEndpointOK) IsClientError() bool {
return false
}
// IsServerError returns true when this get gitea endpoint o k response has a 5xx status code
func (o *GetGiteaEndpointOK) IsServerError() bool {
return false
}
// IsCode returns true when this get gitea endpoint o k response a status code equal to that given
func (o *GetGiteaEndpointOK) IsCode(code int) bool {
return code == 200
}
// Code gets the status code for the get gitea endpoint o k response
func (o *GetGiteaEndpointOK) Code() int {
return 200
}
func (o *GetGiteaEndpointOK) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/endpoints/{name}][%d] getGiteaEndpointOK %s", 200, payload)
}
func (o *GetGiteaEndpointOK) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/endpoints/{name}][%d] getGiteaEndpointOK %s", 200, payload)
}
func (o *GetGiteaEndpointOK) GetPayload() garm_params.ForgeEndpoint {
return o.Payload
}
func (o *GetGiteaEndpointOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewGetGiteaEndpointDefault creates a GetGiteaEndpointDefault with default headers values
func NewGetGiteaEndpointDefault(code int) *GetGiteaEndpointDefault {
return &GetGiteaEndpointDefault{
_statusCode: code,
}
}
/*
GetGiteaEndpointDefault describes a response with status code -1, with default header values.
APIErrorResponse
*/
type GetGiteaEndpointDefault struct {
_statusCode int
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this get gitea endpoint default response has a 2xx status code
func (o *GetGiteaEndpointDefault) IsSuccess() bool {
return o._statusCode/100 == 2
}
// IsRedirect returns true when this get gitea endpoint default response has a 3xx status code
func (o *GetGiteaEndpointDefault) IsRedirect() bool {
return o._statusCode/100 == 3
}
// IsClientError returns true when this get gitea endpoint default response has a 4xx status code
func (o *GetGiteaEndpointDefault) IsClientError() bool {
return o._statusCode/100 == 4
}
// IsServerError returns true when this get gitea endpoint default response has a 5xx status code
func (o *GetGiteaEndpointDefault) IsServerError() bool {
return o._statusCode/100 == 5
}
// IsCode returns true when this get gitea endpoint default response a status code equal to that given
func (o *GetGiteaEndpointDefault) IsCode(code int) bool {
return o._statusCode == code
}
// Code gets the status code for the get gitea endpoint default response
func (o *GetGiteaEndpointDefault) Code() int {
return o._statusCode
}
func (o *GetGiteaEndpointDefault) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/endpoints/{name}][%d] GetGiteaEndpoint default %s", o._statusCode, payload)
}
func (o *GetGiteaEndpointDefault) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/endpoints/{name}][%d] GetGiteaEndpoint default %s", o._statusCode, payload)
}
func (o *GetGiteaEndpointDefault) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *GetGiteaEndpointDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -51,10 +51,10 @@ func NewGetGithubEndpointOK() *GetGithubEndpointOK {
/*
GetGithubEndpointOK describes a response with status code 200, with default header values.
GithubEndpoint
ForgeEndpoint
*/
type GetGithubEndpointOK struct {
Payload garm_params.GithubEndpoint
Payload garm_params.ForgeEndpoint
}
// IsSuccess returns true when this get github endpoint o k response has a 2xx status code
@ -97,7 +97,7 @@ func (o *GetGithubEndpointOK) String() string {
return fmt.Sprintf("[GET /github/endpoints/{name}][%d] getGithubEndpointOK %s", 200, payload)
}
func (o *GetGithubEndpointOK) GetPayload() garm_params.GithubEndpoint {
func (o *GetGithubEndpointOK) GetPayload() garm_params.ForgeEndpoint {
return o.Payload
}

View file

@ -0,0 +1,128 @@
// Code generated by go-swagger; DO NOT EDIT.
package endpoints
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
)
// NewListGiteaEndpointsParams creates a new ListGiteaEndpointsParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewListGiteaEndpointsParams() *ListGiteaEndpointsParams {
return &ListGiteaEndpointsParams{
timeout: cr.DefaultTimeout,
}
}
// NewListGiteaEndpointsParamsWithTimeout creates a new ListGiteaEndpointsParams object
// with the ability to set a timeout on a request.
func NewListGiteaEndpointsParamsWithTimeout(timeout time.Duration) *ListGiteaEndpointsParams {
return &ListGiteaEndpointsParams{
timeout: timeout,
}
}
// NewListGiteaEndpointsParamsWithContext creates a new ListGiteaEndpointsParams object
// with the ability to set a context for a request.
func NewListGiteaEndpointsParamsWithContext(ctx context.Context) *ListGiteaEndpointsParams {
return &ListGiteaEndpointsParams{
Context: ctx,
}
}
// NewListGiteaEndpointsParamsWithHTTPClient creates a new ListGiteaEndpointsParams object
// with the ability to set a custom HTTPClient for a request.
func NewListGiteaEndpointsParamsWithHTTPClient(client *http.Client) *ListGiteaEndpointsParams {
return &ListGiteaEndpointsParams{
HTTPClient: client,
}
}
/*
ListGiteaEndpointsParams contains all the parameters to send to the API endpoint
for the list gitea endpoints operation.
Typically these are written to a http.Request.
*/
type ListGiteaEndpointsParams struct {
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the list gitea endpoints params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *ListGiteaEndpointsParams) WithDefaults() *ListGiteaEndpointsParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the list gitea endpoints params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *ListGiteaEndpointsParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the list gitea endpoints params
func (o *ListGiteaEndpointsParams) WithTimeout(timeout time.Duration) *ListGiteaEndpointsParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the list gitea endpoints params
func (o *ListGiteaEndpointsParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the list gitea endpoints params
func (o *ListGiteaEndpointsParams) WithContext(ctx context.Context) *ListGiteaEndpointsParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the list gitea endpoints params
func (o *ListGiteaEndpointsParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the list gitea endpoints params
func (o *ListGiteaEndpointsParams) WithHTTPClient(client *http.Client) *ListGiteaEndpointsParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the list gitea endpoints params
func (o *ListGiteaEndpointsParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WriteToRequest writes these params to a swagger request
func (o *ListGiteaEndpointsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,184 @@
// Code generated by go-swagger; DO NOT EDIT.
package endpoints
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
garm_params "github.com/cloudbase/garm/params"
)
// ListGiteaEndpointsReader is a Reader for the ListGiteaEndpoints structure.
type ListGiteaEndpointsReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ListGiteaEndpointsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewListGiteaEndpointsOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewListGiteaEndpointsDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewListGiteaEndpointsOK creates a ListGiteaEndpointsOK with default headers values
func NewListGiteaEndpointsOK() *ListGiteaEndpointsOK {
return &ListGiteaEndpointsOK{}
}
/*
ListGiteaEndpointsOK describes a response with status code 200, with default header values.
ForgeEndpoints
*/
type ListGiteaEndpointsOK struct {
Payload garm_params.ForgeEndpoints
}
// IsSuccess returns true when this list gitea endpoints o k response has a 2xx status code
func (o *ListGiteaEndpointsOK) IsSuccess() bool {
return true
}
// IsRedirect returns true when this list gitea endpoints o k response has a 3xx status code
func (o *ListGiteaEndpointsOK) IsRedirect() bool {
return false
}
// IsClientError returns true when this list gitea endpoints o k response has a 4xx status code
func (o *ListGiteaEndpointsOK) IsClientError() bool {
return false
}
// IsServerError returns true when this list gitea endpoints o k response has a 5xx status code
func (o *ListGiteaEndpointsOK) IsServerError() bool {
return false
}
// IsCode returns true when this list gitea endpoints o k response a status code equal to that given
func (o *ListGiteaEndpointsOK) IsCode(code int) bool {
return code == 200
}
// Code gets the status code for the list gitea endpoints o k response
func (o *ListGiteaEndpointsOK) Code() int {
return 200
}
func (o *ListGiteaEndpointsOK) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/endpoints][%d] listGiteaEndpointsOK %s", 200, payload)
}
func (o *ListGiteaEndpointsOK) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/endpoints][%d] listGiteaEndpointsOK %s", 200, payload)
}
func (o *ListGiteaEndpointsOK) GetPayload() garm_params.ForgeEndpoints {
return o.Payload
}
func (o *ListGiteaEndpointsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewListGiteaEndpointsDefault creates a ListGiteaEndpointsDefault with default headers values
func NewListGiteaEndpointsDefault(code int) *ListGiteaEndpointsDefault {
return &ListGiteaEndpointsDefault{
_statusCode: code,
}
}
/*
ListGiteaEndpointsDefault describes a response with status code -1, with default header values.
APIErrorResponse
*/
type ListGiteaEndpointsDefault struct {
_statusCode int
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this list gitea endpoints default response has a 2xx status code
func (o *ListGiteaEndpointsDefault) IsSuccess() bool {
return o._statusCode/100 == 2
}
// IsRedirect returns true when this list gitea endpoints default response has a 3xx status code
func (o *ListGiteaEndpointsDefault) IsRedirect() bool {
return o._statusCode/100 == 3
}
// IsClientError returns true when this list gitea endpoints default response has a 4xx status code
func (o *ListGiteaEndpointsDefault) IsClientError() bool {
return o._statusCode/100 == 4
}
// IsServerError returns true when this list gitea endpoints default response has a 5xx status code
func (o *ListGiteaEndpointsDefault) IsServerError() bool {
return o._statusCode/100 == 5
}
// IsCode returns true when this list gitea endpoints default response a status code equal to that given
func (o *ListGiteaEndpointsDefault) IsCode(code int) bool {
return o._statusCode == code
}
// Code gets the status code for the list gitea endpoints default response
func (o *ListGiteaEndpointsDefault) Code() int {
return o._statusCode
}
func (o *ListGiteaEndpointsDefault) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/endpoints][%d] ListGiteaEndpoints default %s", o._statusCode, payload)
}
func (o *ListGiteaEndpointsDefault) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[GET /gitea/endpoints][%d] ListGiteaEndpoints default %s", o._statusCode, payload)
}
func (o *ListGiteaEndpointsDefault) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *ListGiteaEndpointsDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -51,10 +51,10 @@ func NewListGithubEndpointsOK() *ListGithubEndpointsOK {
/*
ListGithubEndpointsOK describes a response with status code 200, with default header values.
GithubEndpoints
ForgeEndpoints
*/
type ListGithubEndpointsOK struct {
Payload garm_params.GithubEndpoints
Payload garm_params.ForgeEndpoints
}
// IsSuccess returns true when this list github endpoints o k response has a 2xx status code
@ -97,7 +97,7 @@ func (o *ListGithubEndpointsOK) String() string {
return fmt.Sprintf("[GET /github/endpoints][%d] listGithubEndpointsOK %s", 200, payload)
}
func (o *ListGithubEndpointsOK) GetPayload() garm_params.GithubEndpoints {
func (o *ListGithubEndpointsOK) GetPayload() garm_params.ForgeEndpoints {
return o.Payload
}

View file

@ -0,0 +1,173 @@
// Code generated by go-swagger; DO NOT EDIT.
package endpoints
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
garm_params "github.com/cloudbase/garm/params"
)
// NewUpdateGiteaEndpointParams creates a new UpdateGiteaEndpointParams object,
// with the default timeout for this client.
//
// Default values are not hydrated, since defaults are normally applied by the API server side.
//
// To enforce default values in parameter, use SetDefaults or WithDefaults.
func NewUpdateGiteaEndpointParams() *UpdateGiteaEndpointParams {
return &UpdateGiteaEndpointParams{
timeout: cr.DefaultTimeout,
}
}
// NewUpdateGiteaEndpointParamsWithTimeout creates a new UpdateGiteaEndpointParams object
// with the ability to set a timeout on a request.
func NewUpdateGiteaEndpointParamsWithTimeout(timeout time.Duration) *UpdateGiteaEndpointParams {
return &UpdateGiteaEndpointParams{
timeout: timeout,
}
}
// NewUpdateGiteaEndpointParamsWithContext creates a new UpdateGiteaEndpointParams object
// with the ability to set a context for a request.
func NewUpdateGiteaEndpointParamsWithContext(ctx context.Context) *UpdateGiteaEndpointParams {
return &UpdateGiteaEndpointParams{
Context: ctx,
}
}
// NewUpdateGiteaEndpointParamsWithHTTPClient creates a new UpdateGiteaEndpointParams object
// with the ability to set a custom HTTPClient for a request.
func NewUpdateGiteaEndpointParamsWithHTTPClient(client *http.Client) *UpdateGiteaEndpointParams {
return &UpdateGiteaEndpointParams{
HTTPClient: client,
}
}
/*
UpdateGiteaEndpointParams contains all the parameters to send to the API endpoint
for the update gitea endpoint operation.
Typically these are written to a http.Request.
*/
type UpdateGiteaEndpointParams struct {
/* Body.
Parameters used when updating a Gitea endpoint.
*/
Body garm_params.UpdateGiteaEndpointParams
/* Name.
The name of the Gitea endpoint.
*/
Name string
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithDefaults hydrates default values in the update gitea endpoint params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *UpdateGiteaEndpointParams) WithDefaults() *UpdateGiteaEndpointParams {
o.SetDefaults()
return o
}
// SetDefaults hydrates default values in the update gitea endpoint params (not the query body).
//
// All values with no default are reset to their zero value.
func (o *UpdateGiteaEndpointParams) SetDefaults() {
// no default values defined for this parameter
}
// WithTimeout adds the timeout to the update gitea endpoint params
func (o *UpdateGiteaEndpointParams) WithTimeout(timeout time.Duration) *UpdateGiteaEndpointParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the update gitea endpoint params
func (o *UpdateGiteaEndpointParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the update gitea endpoint params
func (o *UpdateGiteaEndpointParams) WithContext(ctx context.Context) *UpdateGiteaEndpointParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the update gitea endpoint params
func (o *UpdateGiteaEndpointParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the update gitea endpoint params
func (o *UpdateGiteaEndpointParams) WithHTTPClient(client *http.Client) *UpdateGiteaEndpointParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the update gitea endpoint params
func (o *UpdateGiteaEndpointParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the update gitea endpoint params
func (o *UpdateGiteaEndpointParams) WithBody(body garm_params.UpdateGiteaEndpointParams) *UpdateGiteaEndpointParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the update gitea endpoint params
func (o *UpdateGiteaEndpointParams) SetBody(body garm_params.UpdateGiteaEndpointParams) {
o.Body = body
}
// WithName adds the name to the update gitea endpoint params
func (o *UpdateGiteaEndpointParams) WithName(name string) *UpdateGiteaEndpointParams {
o.SetName(name)
return o
}
// SetName adds the name to the update gitea endpoint params
func (o *UpdateGiteaEndpointParams) SetName(name string) {
o.Name = name
}
// WriteToRequest writes these params to a swagger request
func (o *UpdateGiteaEndpointParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
// path param name
if err := r.SetPathParam("name", o.Name); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View file

@ -0,0 +1,184 @@
// Code generated by go-swagger; DO NOT EDIT.
package endpoints
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
"fmt"
"io"
"github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt"
apiserver_params "github.com/cloudbase/garm/apiserver/params"
garm_params "github.com/cloudbase/garm/params"
)
// UpdateGiteaEndpointReader is a Reader for the UpdateGiteaEndpoint structure.
type UpdateGiteaEndpointReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *UpdateGiteaEndpointReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewUpdateGiteaEndpointOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewUpdateGiteaEndpointDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewUpdateGiteaEndpointOK creates a UpdateGiteaEndpointOK with default headers values
func NewUpdateGiteaEndpointOK() *UpdateGiteaEndpointOK {
return &UpdateGiteaEndpointOK{}
}
/*
UpdateGiteaEndpointOK describes a response with status code 200, with default header values.
ForgeEndpoint
*/
type UpdateGiteaEndpointOK struct {
Payload garm_params.ForgeEndpoint
}
// IsSuccess returns true when this update gitea endpoint o k response has a 2xx status code
func (o *UpdateGiteaEndpointOK) IsSuccess() bool {
return true
}
// IsRedirect returns true when this update gitea endpoint o k response has a 3xx status code
func (o *UpdateGiteaEndpointOK) IsRedirect() bool {
return false
}
// IsClientError returns true when this update gitea endpoint o k response has a 4xx status code
func (o *UpdateGiteaEndpointOK) IsClientError() bool {
return false
}
// IsServerError returns true when this update gitea endpoint o k response has a 5xx status code
func (o *UpdateGiteaEndpointOK) IsServerError() bool {
return false
}
// IsCode returns true when this update gitea endpoint o k response a status code equal to that given
func (o *UpdateGiteaEndpointOK) IsCode(code int) bool {
return code == 200
}
// Code gets the status code for the update gitea endpoint o k response
func (o *UpdateGiteaEndpointOK) Code() int {
return 200
}
func (o *UpdateGiteaEndpointOK) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /gitea/endpoints/{name}][%d] updateGiteaEndpointOK %s", 200, payload)
}
func (o *UpdateGiteaEndpointOK) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /gitea/endpoints/{name}][%d] updateGiteaEndpointOK %s", 200, payload)
}
func (o *UpdateGiteaEndpointOK) GetPayload() garm_params.ForgeEndpoint {
return o.Payload
}
func (o *UpdateGiteaEndpointOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewUpdateGiteaEndpointDefault creates a UpdateGiteaEndpointDefault with default headers values
func NewUpdateGiteaEndpointDefault(code int) *UpdateGiteaEndpointDefault {
return &UpdateGiteaEndpointDefault{
_statusCode: code,
}
}
/*
UpdateGiteaEndpointDefault describes a response with status code -1, with default header values.
APIErrorResponse
*/
type UpdateGiteaEndpointDefault struct {
_statusCode int
Payload apiserver_params.APIErrorResponse
}
// IsSuccess returns true when this update gitea endpoint default response has a 2xx status code
func (o *UpdateGiteaEndpointDefault) IsSuccess() bool {
return o._statusCode/100 == 2
}
// IsRedirect returns true when this update gitea endpoint default response has a 3xx status code
func (o *UpdateGiteaEndpointDefault) IsRedirect() bool {
return o._statusCode/100 == 3
}
// IsClientError returns true when this update gitea endpoint default response has a 4xx status code
func (o *UpdateGiteaEndpointDefault) IsClientError() bool {
return o._statusCode/100 == 4
}
// IsServerError returns true when this update gitea endpoint default response has a 5xx status code
func (o *UpdateGiteaEndpointDefault) IsServerError() bool {
return o._statusCode/100 == 5
}
// IsCode returns true when this update gitea endpoint default response a status code equal to that given
func (o *UpdateGiteaEndpointDefault) IsCode(code int) bool {
return o._statusCode == code
}
// Code gets the status code for the update gitea endpoint default response
func (o *UpdateGiteaEndpointDefault) Code() int {
return o._statusCode
}
func (o *UpdateGiteaEndpointDefault) Error() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /gitea/endpoints/{name}][%d] UpdateGiteaEndpoint default %s", o._statusCode, payload)
}
func (o *UpdateGiteaEndpointDefault) String() string {
payload, _ := json.Marshal(o.Payload)
return fmt.Sprintf("[PUT /gitea/endpoints/{name}][%d] UpdateGiteaEndpoint default %s", o._statusCode, payload)
}
func (o *UpdateGiteaEndpointDefault) GetPayload() apiserver_params.APIErrorResponse {
return o.Payload
}
func (o *UpdateGiteaEndpointDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View file

@ -51,10 +51,10 @@ func NewUpdateGithubEndpointOK() *UpdateGithubEndpointOK {
/*
UpdateGithubEndpointOK describes a response with status code 200, with default header values.
GithubEndpoint
ForgeEndpoint
*/
type UpdateGithubEndpointOK struct {
Payload garm_params.GithubEndpoint
Payload garm_params.ForgeEndpoint
}
// IsSuccess returns true when this update github endpoint o k response has a 2xx status code
@ -97,7 +97,7 @@ func (o *UpdateGithubEndpointOK) String() string {
return fmt.Sprintf("[PUT /github/endpoints/{name}][%d] updateGithubEndpointOK %s", 200, payload)
}
func (o *UpdateGithubEndpointOK) GetPayload() garm_params.GithubEndpoint {
func (o *UpdateGithubEndpointOK) GetPayload() garm_params.ForgeEndpoint {
return o.Payload
}

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cmd
import (

34
cmd/garm-cli/cmd/gitea.go Normal file
View file

@ -0,0 +1,34 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cmd
import "github.com/spf13/cobra"
// giteaCmd represents the the gitea command. This command has a set
// of subcommands that allow configuring and managing Gitea endpoints
// and credentials.
var giteaCmd = &cobra.Command{
Use: "gitea",
Aliases: []string{"gt"},
SilenceUsage: true,
Short: "Manage Gitea resources",
Long: `Manage Gitea related resources.
This command allows you to configure and manage Gitea endpoints and credentials`,
Run: nil,
}
func init() {
rootCmd.AddCommand(giteaCmd)
}

View file

@ -0,0 +1,317 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cmd
import (
"fmt"
"strconv"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
apiClientCreds "github.com/cloudbase/garm/client/credentials"
"github.com/cloudbase/garm/cmd/garm-cli/common"
"github.com/cloudbase/garm/params"
)
// giteaCredentialsCmd represents the gitea credentials command
var giteaCredentialsCmd = &cobra.Command{
Use: "credentials",
Aliases: []string{"creds"},
Short: "Manage gitea credentials",
Long: `Manage Gitea credentials stored in GARM.
This command allows you to add, update, list and delete Gitea credentials.`,
Run: nil,
}
var giteaCredentialsListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List configured gitea credentials",
Long: `List the names of the gitea personal access tokens available to the garm.`,
SilenceUsage: true,
RunE: func(_ *cobra.Command, _ []string) error {
if needsInit {
return errNeedsInitError
}
listCredsReq := apiClientCreds.NewListGiteaCredentialsParams()
response, err := apiCli.Credentials.ListGiteaCredentials(listCredsReq, authToken)
if err != nil {
return err
}
formatGiteaCredentials(response.Payload)
return nil
},
}
var giteaCredentialsShowCmd = &cobra.Command{
Use: "show",
Aliases: []string{"get"},
Short: "Show details of a configured gitea credential",
Long: `Show the details of a configured gitea credential.`,
SilenceUsage: true,
RunE: func(_ *cobra.Command, args []string) error {
if needsInit {
return errNeedsInitError
}
if len(args) < 1 {
return fmt.Errorf("missing required argument: credential ID")
}
credID, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return fmt.Errorf("invalid credential ID: %s", args[0])
}
showCredsReq := apiClientCreds.NewGetGiteaCredentialsParams().WithID(credID)
response, err := apiCli.Credentials.GetGiteaCredentials(showCredsReq, authToken)
if err != nil {
return err
}
formatOneGiteaCredential(response.Payload)
return nil
},
}
var giteaCredentialsUpdateCmd = &cobra.Command{
Use: "update",
Short: "Update a gitea credential",
Long: "Update a gitea credential",
SilenceUsage: true,
RunE: func(_ *cobra.Command, args []string) error {
if needsInit {
return errNeedsInitError
}
if len(args) < 1 {
return fmt.Errorf("missing required argument: credential ID")
}
if len(args) > 1 {
return fmt.Errorf("too many arguments")
}
credID, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return fmt.Errorf("invalid credential ID: %s", args[0])
}
updateParams, err := parseGiteaCredentialsUpdateParams()
if err != nil {
return err
}
updateCredsReq := apiClientCreds.NewUpdateGiteaCredentialsParams().WithID(credID)
updateCredsReq.Body = updateParams
response, err := apiCli.Credentials.UpdateGiteaCredentials(updateCredsReq, authToken)
if err != nil {
return err
}
formatOneGiteaCredential(response.Payload)
return nil
},
}
var giteaCredentialsDeleteCmd = &cobra.Command{
Use: "delete",
Aliases: []string{"remove", "rm"},
Short: "Delete a gitea credential",
Long: "Delete a gitea credential",
SilenceUsage: true,
RunE: func(_ *cobra.Command, args []string) error {
if needsInit {
return errNeedsInitError
}
if len(args) < 1 {
return fmt.Errorf("missing required argument: credential ID")
}
if len(args) > 1 {
return fmt.Errorf("too many arguments")
}
credID, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return fmt.Errorf("invalid credential ID: %s", args[0])
}
deleteCredsReq := apiClientCreds.NewDeleteGiteaCredentialsParams().WithID(credID)
if err := apiCli.Credentials.DeleteGiteaCredentials(deleteCredsReq, authToken); err != nil {
return err
}
return nil
},
}
var giteaCredentialsAddCmd = &cobra.Command{
Use: "add",
Short: "Add a gitea credential",
Long: "Add a gitea credential",
SilenceUsage: true,
RunE: func(_ *cobra.Command, args []string) error {
if needsInit {
return errNeedsInitError
}
if len(args) > 0 {
return fmt.Errorf("too many arguments")
}
addParams, err := parseGiteaCredentialsAddParams()
if err != nil {
return err
}
addCredsReq := apiClientCreds.NewCreateGiteaCredentialsParams()
addCredsReq.Body = addParams
response, err := apiCli.Credentials.CreateGiteaCredentials(addCredsReq, authToken)
if err != nil {
return err
}
formatOneGiteaCredential(response.Payload)
return nil
},
}
func init() {
giteaCredentialsUpdateCmd.Flags().StringVar(&credentialsName, "name", "", "Name of the credential")
giteaCredentialsUpdateCmd.Flags().StringVar(&credentialsDescription, "description", "", "Description of the credential")
giteaCredentialsUpdateCmd.Flags().StringVar(&credentialsOAuthToken, "pat-oauth-token", "", "If the credential is a personal access token, the OAuth token")
giteaCredentialsListCmd.Flags().BoolVarP(&long, "long", "l", false, "Include additional info.")
giteaCredentialsAddCmd.Flags().StringVar(&credentialsName, "name", "", "Name of the credential")
giteaCredentialsAddCmd.Flags().StringVar(&credentialsDescription, "description", "", "Description of the credential")
giteaCredentialsAddCmd.Flags().StringVar(&credentialsOAuthToken, "pat-oauth-token", "", "If the credential is a personal access token, the OAuth token")
giteaCredentialsAddCmd.Flags().StringVar(&credentialsType, "auth-type", "", "The type of the credential")
giteaCredentialsAddCmd.Flags().StringVar(&credentialsEndpoint, "endpoint", "", "The endpoint to associate the credential with")
giteaCredentialsAddCmd.MarkFlagRequired("name")
giteaCredentialsAddCmd.MarkFlagRequired("auth-type")
giteaCredentialsAddCmd.MarkFlagRequired("description")
giteaCredentialsAddCmd.MarkFlagRequired("endpoint")
giteaCredentialsCmd.AddCommand(
giteaCredentialsListCmd,
giteaCredentialsShowCmd,
giteaCredentialsUpdateCmd,
giteaCredentialsDeleteCmd,
giteaCredentialsAddCmd,
)
giteaCmd.AddCommand(giteaCredentialsCmd)
}
func parseGiteaCredentialsAddParams() (ret params.CreateGiteaCredentialsParams, err error) {
ret.Name = credentialsName
ret.Description = credentialsDescription
ret.AuthType = params.ForgeAuthType(credentialsType)
ret.Endpoint = credentialsEndpoint
switch ret.AuthType {
case params.ForgeAuthTypePAT:
ret.PAT.OAuth2Token = credentialsOAuthToken
default:
return params.CreateGiteaCredentialsParams{}, fmt.Errorf("invalid auth type: %s (supported are: pat)", credentialsType)
}
return ret, nil
}
func parseGiteaCredentialsUpdateParams() (params.UpdateGiteaCredentialsParams, error) {
var updateParams params.UpdateGiteaCredentialsParams
if credentialsName != "" {
updateParams.Name = &credentialsName
}
if credentialsDescription != "" {
updateParams.Description = &credentialsDescription
}
if credentialsOAuthToken != "" {
if updateParams.PAT == nil {
updateParams.PAT = &params.GithubPAT{}
}
updateParams.PAT.OAuth2Token = credentialsOAuthToken
}
return updateParams, nil
}
func formatGiteaCredentials(creds []params.ForgeCredentials) {
if outputFormat == common.OutputFormatJSON {
printAsJSON(creds)
return
}
t := table.NewWriter()
header := table.Row{"ID", "Name", "Description", "Base URL", "API URL", "Type"}
if long {
header = append(header, "Created At", "Updated At")
}
t.AppendHeader(header)
for _, val := range creds {
row := table.Row{val.ID, val.Name, val.Description, val.BaseURL, val.APIBaseURL, val.AuthType}
if long {
row = append(row, val.CreatedAt, val.UpdatedAt)
}
t.AppendRow(row)
t.AppendSeparator()
}
fmt.Println(t.Render())
}
func formatOneGiteaCredential(cred params.ForgeCredentials) {
if outputFormat == common.OutputFormatJSON {
printAsJSON(cred)
return
}
t := table.NewWriter()
header := table.Row{"Field", "Value"}
t.AppendHeader(header)
t.AppendRow(table.Row{"ID", cred.ID})
t.AppendRow(table.Row{"Created At", cred.CreatedAt})
t.AppendRow(table.Row{"Updated At", cred.UpdatedAt})
t.AppendRow(table.Row{"Name", cred.Name})
t.AppendRow(table.Row{"Description", cred.Description})
t.AppendRow(table.Row{"Base URL", cred.BaseURL})
t.AppendRow(table.Row{"API URL", cred.APIBaseURL})
t.AppendRow(table.Row{"Type", cred.AuthType})
t.AppendRow(table.Row{"Endpoint", cred.Endpoint.Name})
if len(cred.Repositories) > 0 {
t.AppendRow(table.Row{"", ""})
for _, repo := range cred.Repositories {
t.AppendRow(table.Row{"Repositories", repo.String()})
}
}
if len(cred.Organizations) > 0 {
t.AppendRow(table.Row{"", ""})
for _, org := range cred.Organizations {
t.AppendRow(table.Row{"Organizations", org.Name})
}
}
t.SetColumnConfigs([]table.ColumnConfig{
{Number: 1, AutoMerge: true},
{Number: 2, AutoMerge: false, WidthMax: 100},
})
fmt.Println(t.Render())
}

View file

@ -0,0 +1,231 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cmd
import (
"fmt"
"github.com/spf13/cobra"
apiClientEndpoints "github.com/cloudbase/garm/client/endpoints"
"github.com/cloudbase/garm/params"
)
var giteaEndpointCmd = &cobra.Command{
Use: "endpoint",
SilenceUsage: true,
Short: "Manage Gitea endpoints",
Long: `Manage Gitea endpoints.
This command allows you to configure and manage Gitea endpoints`,
Run: nil,
}
var giteaEndpointListCmd = &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
SilenceUsage: true,
Short: "List Gitea endpoints",
Long: `List all configured Gitea endpoints.`,
RunE: func(_ *cobra.Command, _ []string) error {
if needsInit {
return errNeedsInitError
}
newListReq := apiClientEndpoints.NewListGiteaEndpointsParams()
response, err := apiCli.Endpoints.ListGiteaEndpoints(newListReq, authToken)
if err != nil {
return err
}
formatEndpoints(response.Payload)
return nil
},
}
var giteaEndpointShowCmd = &cobra.Command{
Use: "show",
Aliases: []string{"get"},
SilenceUsage: true,
Short: "Show Gitea endpoint",
Long: `Show details of a Gitea endpoint.`,
RunE: func(_ *cobra.Command, args []string) error {
if needsInit {
return errNeedsInitError
}
if len(args) == 0 {
return fmt.Errorf("requires an endpoint name")
}
if len(args) > 1 {
return fmt.Errorf("too many arguments")
}
newShowReq := apiClientEndpoints.NewGetGiteaEndpointParams()
newShowReq.Name = args[0]
response, err := apiCli.Endpoints.GetGiteaEndpoint(newShowReq, authToken)
if err != nil {
return err
}
formatOneEndpoint(response.Payload)
return nil
},
}
var giteaEndpointCreateCmd = &cobra.Command{
Use: "create",
SilenceUsage: true,
Short: "Create Gitea endpoint",
Long: `Create a new Gitea endpoint.`,
RunE: func(_ *cobra.Command, _ []string) error {
if needsInit {
return errNeedsInitError
}
createParams, err := parseGiteaCreateParams()
if err != nil {
return err
}
newCreateReq := apiClientEndpoints.NewCreateGiteaEndpointParams()
newCreateReq.Body = createParams
response, err := apiCli.Endpoints.CreateGiteaEndpoint(newCreateReq, authToken)
if err != nil {
return err
}
formatOneEndpoint(response.Payload)
return nil
},
}
var giteaEndpointDeleteCmd = &cobra.Command{
Use: "delete",
Aliases: []string{"remove", "rm"},
SilenceUsage: true,
Short: "Delete Gitea endpoint",
Long: "Delete a Gitea endpoint",
RunE: func(_ *cobra.Command, args []string) error {
if needsInit {
return errNeedsInitError
}
if len(args) == 0 {
return fmt.Errorf("requires an endpoint name")
}
if len(args) > 1 {
return fmt.Errorf("too many arguments")
}
newDeleteReq := apiClientEndpoints.NewDeleteGiteaEndpointParams()
newDeleteReq.Name = args[0]
if err := apiCli.Endpoints.DeleteGiteaEndpoint(newDeleteReq, authToken); err != nil {
return err
}
return nil
},
}
var giteaEndpointUpdateCmd = &cobra.Command{
Use: "update",
Short: "Update Gitea endpoint",
Long: "Update a Gitea endpoint",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if needsInit {
return errNeedsInitError
}
if len(args) == 0 {
return fmt.Errorf("requires an endpoint name")
}
if len(args) > 1 {
return fmt.Errorf("too many arguments")
}
updateParams := params.UpdateGiteaEndpointParams{}
if cmd.Flags().Changed("ca-cert-path") {
cert, err := parseAndReadCABundle()
if err != nil {
return err
}
updateParams.CACertBundle = cert
}
if cmd.Flags().Changed("description") {
updateParams.Description = &endpointDescription
}
if cmd.Flags().Changed("base-url") {
updateParams.BaseURL = &endpointBaseURL
}
if cmd.Flags().Changed("api-base-url") {
updateParams.APIBaseURL = &endpointAPIBaseURL
}
newEndpointUpdateReq := apiClientEndpoints.NewUpdateGiteaEndpointParams()
newEndpointUpdateReq.Name = args[0]
newEndpointUpdateReq.Body = updateParams
response, err := apiCli.Endpoints.UpdateGiteaEndpoint(newEndpointUpdateReq, authToken)
if err != nil {
return err
}
formatOneEndpoint(response.Payload)
return nil
},
}
func init() {
giteaEndpointCreateCmd.Flags().StringVar(&endpointName, "name", "", "Name of the Gitea endpoint")
giteaEndpointCreateCmd.Flags().StringVar(&endpointDescription, "description", "", "Description for the github endpoint")
giteaEndpointCreateCmd.Flags().StringVar(&endpointBaseURL, "base-url", "", "Base URL of the Gitea endpoint")
giteaEndpointCreateCmd.Flags().StringVar(&endpointAPIBaseURL, "api-base-url", "", "API Base URL of the Gitea endpoint")
giteaEndpointCreateCmd.Flags().StringVar(&endpointCACertPath, "ca-cert-path", "", "CA Cert Path of the Gitea endpoint")
giteaEndpointListCmd.Flags().BoolVarP(&long, "long", "l", false, "Include additional info.")
giteaEndpointCreateCmd.MarkFlagRequired("name")
giteaEndpointCreateCmd.MarkFlagRequired("base-url")
giteaEndpointCreateCmd.MarkFlagRequired("api-base-url")
giteaEndpointUpdateCmd.Flags().StringVar(&endpointDescription, "description", "", "Description for the gitea endpoint")
giteaEndpointUpdateCmd.Flags().StringVar(&endpointBaseURL, "base-url", "", "Base URL of the Gitea endpoint")
giteaEndpointUpdateCmd.Flags().StringVar(&endpointAPIBaseURL, "api-base-url", "", "API Base URL of the Gitea endpoint")
giteaEndpointUpdateCmd.Flags().StringVar(&endpointCACertPath, "ca-cert-path", "", "CA Cert Path of the Gitea endpoint")
giteaEndpointCmd.AddCommand(
giteaEndpointListCmd,
giteaEndpointShowCmd,
giteaEndpointCreateCmd,
giteaEndpointDeleteCmd,
giteaEndpointUpdateCmd,
)
giteaCmd.AddCommand(giteaEndpointCmd)
}
func parseGiteaCreateParams() (params.CreateGiteaEndpointParams, error) {
certBundleBytes, err := parseAndReadCABundle()
if err != nil {
return params.CreateGiteaEndpointParams{}, err
}
ret := params.CreateGiteaEndpointParams{
Name: endpointName,
BaseURL: endpointBaseURL,
APIBaseURL: endpointAPIBaseURL,
Description: endpointDescription,
CACertBundle: certBundleBytes,
}
return ret, nil
}

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cmd
import "github.com/spf13/cobra"

View file

@ -283,12 +283,12 @@ func parsePrivateKeyFromPath(path string) ([]byte, error) {
func parseCredentialsAddParams() (ret params.CreateGithubCredentialsParams, err error) {
ret.Name = credentialsName
ret.Description = credentialsDescription
ret.AuthType = params.GithubAuthType(credentialsType)
ret.AuthType = params.ForgeAuthType(credentialsType)
ret.Endpoint = credentialsEndpoint
switch ret.AuthType {
case params.GithubAuthTypePAT:
case params.ForgeAuthTypePAT:
ret.PAT.OAuth2Token = credentialsOAuthToken
case params.GithubAuthTypeApp:
case params.ForgeAuthTypeApp:
ret.App.InstallationID = credentialsAppInstallationID
ret.App.AppID = credentialsAppID
keyContents, err := parsePrivateKeyFromPath(credentialsPrivateKeyPath)
@ -344,7 +344,7 @@ func parseCredentialsUpdateParams() (params.UpdateGithubCredentialsParams, error
return updateParams, nil
}
func formatGithubCredentials(creds []params.GithubCredentials) {
func formatGithubCredentials(creds []params.ForgeCredentials) {
if outputFormat == common.OutputFormatJSON {
printAsJSON(creds)
return
@ -366,7 +366,7 @@ func formatGithubCredentials(creds []params.GithubCredentials) {
fmt.Println(t.Render())
}
func formatOneGithubCredential(cred params.GithubCredentials) {
func formatOneGithubCredential(cred params.ForgeCredentials) {
if outputFormat == common.OutputFormatJSON {
printAsJSON(cred)
return

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cmd
import (
@ -145,7 +158,7 @@ var githubEndpointUpdateCmd = &cobra.Command{
updateParams := params.UpdateGithubEndpointParams{}
if cmd.Flags().Changed("ca-cert-path") {
cert, err := parseReadAndParsCABundle()
cert, err := parseAndReadCABundle()
if err != nil {
return err
}
@ -213,7 +226,7 @@ func init() {
githubCmd.AddCommand(githubEndpointCmd)
}
func parseReadAndParsCABundle() ([]byte, error) {
func parseAndReadCABundle() ([]byte, error) {
if endpointCACertPath == "" {
return nil, nil
}
@ -236,7 +249,7 @@ func parseReadAndParsCABundle() ([]byte, error) {
}
func parseCreateParams() (params.CreateGithubEndpointParams, error) {
certBundleBytes, err := parseReadAndParsCABundle()
certBundleBytes, err := parseAndReadCABundle()
if err != nil {
return params.CreateGithubEndpointParams{}, err
}
@ -252,7 +265,7 @@ func parseCreateParams() (params.CreateGithubEndpointParams, error) {
return ret, nil
}
func formatEndpoints(endpoints params.GithubEndpoints) {
func formatEndpoints(endpoints params.ForgeEndpoints) {
if outputFormat == common.OutputFormatJSON {
printAsJSON(endpoints)
return
@ -274,7 +287,7 @@ func formatEndpoints(endpoints params.GithubEndpoints) {
fmt.Println(t.Render())
}
func formatOneEndpoint(endpoint params.GithubEndpoint) {
func formatOneEndpoint(endpoint params.ForgeEndpoint) {
if outputFormat == common.OutputFormatJSON {
printAsJSON(endpoint)
return
@ -287,7 +300,9 @@ func formatOneEndpoint(endpoint params.GithubEndpoint) {
t.AppendRow([]interface{}{"Created At", endpoint.CreatedAt})
t.AppendRow([]interface{}{"Updated At", endpoint.UpdatedAt})
t.AppendRow([]interface{}{"Base URL", endpoint.BaseURL})
t.AppendRow([]interface{}{"Upload URL", endpoint.UploadBaseURL})
if endpoint.UploadBaseURL != "" {
t.AppendRow([]interface{}{"Upload URL", endpoint.UploadBaseURL})
}
t.AppendRow([]interface{}{"API Base URL", endpoint.APIBaseURL})
if len(endpoint.CACertBundle) > 0 {
t.AppendRow([]interface{}{"CA Cert Bundle", string(endpoint.CACertBundle)})

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package cmd
import (

View file

@ -167,6 +167,7 @@ var orgAddCmd = &cobra.Command{
Name: orgName,
WebhookSecret: orgWebhookSecret,
CredentialsName: orgCreds,
ForgeType: params.EndpointType(forgeType),
PoolBalancerType: params.PoolBalancerType(poolBalancerType),
}
response, err := apiCli.Organizations.CreateOrg(newOrgReq, authToken)
@ -306,6 +307,7 @@ func init() {
orgAddCmd.Flags().StringVar(&orgName, "name", "", "The name of the organization")
orgAddCmd.Flags().StringVar(&poolBalancerType, "pool-balancer-type", string(params.PoolBalancerTypeRoundRobin), "The balancing strategy to use when creating runners in pools matching requested labels.")
orgAddCmd.Flags().StringVar(&orgWebhookSecret, "webhook-secret", "", "The webhook secret for this organization")
orgAddCmd.Flags().StringVar(&forgeType, "forge-type", string(params.GithubEndpointType), "The forge type of the organization. Supported values: github, gitea.")
orgAddCmd.Flags().StringVar(&orgCreds, "credentials", "", "Credentials name. See credentials list.")
orgAddCmd.Flags().BoolVar(&orgRandomWebhookSecret, "random-webhook-secret", false, "Generate a random webhook secret for this organization.")
orgAddCmd.Flags().BoolVar(&installOrgWebhook, "install-webhook", false, "Install the webhook as part of the add operation.")
@ -347,13 +349,17 @@ func formatOrganizations(orgs []params.Organization) {
return
}
t := table.NewWriter()
header := table.Row{"ID", "Name", "Endpoint", "Credentials name", "Pool Balancer Type", "Pool mgr running"}
header := table.Row{"ID", "Name", "Endpoint", "Credentials name", "Pool Balancer Type", "Forge type", "Pool mgr running"}
if long {
header = append(header, "Created At", "Updated At")
}
t.AppendHeader(header)
for _, val := range orgs {
row := table.Row{val.ID, val.Name, val.Endpoint.Name, val.CredentialsName, val.GetBalancerType(), val.PoolManagerStatus.IsRunning}
forgeType := val.Endpoint.EndpointType
if forgeType == "" {
forgeType = params.GithubEndpointType
}
row := table.Row{val.ID, val.Name, val.Endpoint.Name, val.CredentialsName, val.GetBalancerType(), forgeType, val.PoolManagerStatus.IsRunning}
if long {
row = append(row, val.CreatedAt, val.UpdatedAt)
}

View file

@ -31,6 +31,7 @@ var (
repoName string
repoWebhookSecret string
repoCreds string
forgeType string
randomWebhookSecret bool
insecureRepoWebhook bool
keepRepoWebhook bool
@ -169,6 +170,7 @@ var repoAddCmd = &cobra.Command{
Name: repoName,
WebhookSecret: repoWebhookSecret,
CredentialsName: repoCreds,
ForgeType: params.EndpointType(forgeType),
PoolBalancerType: params.PoolBalancerType(poolBalancerType),
}
response, err := apiCli.Repositories.CreateRepo(newRepoReq, authToken)
@ -309,6 +311,7 @@ func init() {
repoAddCmd.Flags().StringVar(&repoOwner, "owner", "", "The owner of this repository")
repoAddCmd.Flags().StringVar(&poolBalancerType, "pool-balancer-type", string(params.PoolBalancerTypeRoundRobin), "The balancing strategy to use when creating runners in pools matching requested labels.")
repoAddCmd.Flags().StringVar(&repoName, "name", "", "The name of the repository")
repoAddCmd.Flags().StringVar(&forgeType, "forge-type", string(params.GithubEndpointType), "The forge type of the repository. Supported values: github, gitea.")
repoAddCmd.Flags().StringVar(&repoWebhookSecret, "webhook-secret", "", "The webhook secret for this repository")
repoAddCmd.Flags().StringVar(&repoCreds, "credentials", "", "Credentials name. See credentials list.")
repoAddCmd.Flags().BoolVar(&randomWebhookSecret, "random-webhook-secret", false, "Generate a random webhook secret for this repository.")
@ -354,13 +357,17 @@ func formatRepositories(repos []params.Repository) {
return
}
t := table.NewWriter()
header := table.Row{"ID", "Owner", "Name", "Endpoint", "Credentials name", "Pool Balancer Type", "Pool mgr running"}
header := table.Row{"ID", "Owner", "Name", "Endpoint", "Credentials name", "Pool Balancer Type", "Forge type", "Pool mgr running"}
if long {
header = append(header, "Created At", "Updated At")
}
t.AppendHeader(header)
for _, val := range repos {
row := table.Row{val.ID, val.Owner, val.Name, val.Endpoint.Name, val.CredentialsName, val.GetBalancerType(), val.PoolManagerStatus.IsRunning}
forgeType := val.Endpoint.EndpointType
if forgeType == "" {
forgeType = params.GithubEndpointType
}
row := table.Row{val.ID, val.Owner, val.Name, val.Endpoint.Name, val.GetCredentialsName(), val.GetBalancerType(), forgeType, val.PoolManagerStatus.IsRunning}
if long {
row = append(row, val.CreatedAt, val.UpdatedAt)
}
@ -386,7 +393,7 @@ func formatOneRepository(repo params.Repository) {
t.AppendRow(table.Row{"Name", repo.Name})
t.AppendRow(table.Row{"Endpoint", repo.Endpoint.Name})
t.AppendRow(table.Row{"Pool balancer type", repo.GetBalancerType()})
t.AppendRow(table.Row{"Credentials", repo.CredentialsName})
t.AppendRow(table.Row{"Credentials", repo.GetCredentialsName()})
t.AppendRow(table.Row{"Pool manager running", repo.PoolManagerStatus.IsRunning})
if !repo.PoolManagerStatus.IsRunning {
t.AppendRow(table.Row{"Failure reason", repo.PoolManagerStatus.FailureReason})

View file

@ -1,3 +1,16 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package common
import "fmt"

View file

@ -1,6 +1,19 @@
//go:build !windows
// +build !windows
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package config
import (

View file

@ -1,6 +1,19 @@
//go:build windows && !linux
// +build windows,!linux
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package config
import (

View file

@ -240,10 +240,10 @@ func main() {
cacheWorker := cache.NewWorker(ctx, db)
if err != nil {
log.Fatalf("failed to create credentials worker: %+v", err)
log.Fatalf("failed to create cache worker: %+v", err)
}
if err := cacheWorker.Start(); err != nil {
log.Fatalf("failed to start credentials worker: %+v", err)
log.Fatalf("failed to start cache worker: %+v", err)
}
providers, err := providers.LoadProvidersFromConfig(ctx, *cfg, controllerInfo.ControllerID.String())
@ -384,6 +384,7 @@ func main() {
slog.With(slog.Any("error", err)).ErrorContext(ctx, "failed to stop provider worker")
}
slog.InfoContext(ctx, "shutting down http server")
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 60*time.Second)
defer shutdownCancel()
if err := srv.Shutdown(shutdownCtx); err != nil {

View file

@ -1,3 +1,17 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package common
import "fmt"

View file

@ -15,7 +15,7 @@ type Store struct {
}
// AddEntityEvent provides a mock function with given fields: ctx, entity, event, eventLevel, statusMessage, maxEvents
func (_m *Store) AddEntityEvent(ctx context.Context, entity params.GithubEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error {
func (_m *Store) AddEntityEvent(ctx context.Context, entity params.ForgeEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error {
ret := _m.Called(ctx, entity, event, eventLevel, statusMessage, maxEvents)
if len(ret) == 0 {
@ -23,7 +23,7 @@ func (_m *Store) AddEntityEvent(ctx context.Context, entity params.GithubEntity,
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, params.EventType, params.EventLevel, string, int) error); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, params.EventType, params.EventLevel, string, int) error); ok {
r0 = rf(ctx, entity, event, eventLevel, statusMessage, maxEvents)
} else {
r0 = ret.Error(0)
@ -125,7 +125,7 @@ func (_m *Store) CreateEnterprise(ctx context.Context, name string, credentialsN
}
// CreateEntityPool provides a mock function with given fields: ctx, entity, param
func (_m *Store) CreateEntityPool(ctx context.Context, entity params.GithubEntity, param params.CreatePoolParams) (params.Pool, error) {
func (_m *Store) CreateEntityPool(ctx context.Context, entity params.ForgeEntity, param params.CreatePoolParams) (params.Pool, error) {
ret := _m.Called(ctx, entity, param)
if len(ret) == 0 {
@ -134,16 +134,16 @@ func (_m *Store) CreateEntityPool(ctx context.Context, entity params.GithubEntit
var r0 params.Pool
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, params.CreatePoolParams) (params.Pool, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, params.CreatePoolParams) (params.Pool, error)); ok {
return rf(ctx, entity, param)
}
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, params.CreatePoolParams) params.Pool); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, params.CreatePoolParams) params.Pool); ok {
r0 = rf(ctx, entity, param)
} else {
r0 = ret.Get(0).(params.Pool)
}
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity, params.CreatePoolParams) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity, params.CreatePoolParams) error); ok {
r1 = rf(ctx, entity, param)
} else {
r1 = ret.Error(1)
@ -153,7 +153,7 @@ func (_m *Store) CreateEntityPool(ctx context.Context, entity params.GithubEntit
}
// CreateEntityScaleSet provides a mock function with given fields: _a0, entity, param
func (_m *Store) CreateEntityScaleSet(_a0 context.Context, entity params.GithubEntity, param params.CreateScaleSetParams) (params.ScaleSet, error) {
func (_m *Store) CreateEntityScaleSet(_a0 context.Context, entity params.ForgeEntity, param params.CreateScaleSetParams) (params.ScaleSet, error) {
ret := _m.Called(_a0, entity, param)
if len(ret) == 0 {
@ -162,16 +162,16 @@ func (_m *Store) CreateEntityScaleSet(_a0 context.Context, entity params.GithubE
var r0 params.ScaleSet
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, params.CreateScaleSetParams) (params.ScaleSet, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, params.CreateScaleSetParams) (params.ScaleSet, error)); ok {
return rf(_a0, entity, param)
}
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, params.CreateScaleSetParams) params.ScaleSet); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, params.CreateScaleSetParams) params.ScaleSet); ok {
r0 = rf(_a0, entity, param)
} else {
r0 = ret.Get(0).(params.ScaleSet)
}
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity, params.CreateScaleSetParams) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity, params.CreateScaleSetParams) error); ok {
r1 = rf(_a0, entity, param)
} else {
r1 = ret.Error(1)
@ -180,23 +180,79 @@ func (_m *Store) CreateEntityScaleSet(_a0 context.Context, entity params.GithubE
return r0, r1
}
// CreateGiteaCredentials provides a mock function with given fields: ctx, param
func (_m *Store) CreateGiteaCredentials(ctx context.Context, param params.CreateGiteaCredentialsParams) (params.ForgeCredentials, error) {
ret := _m.Called(ctx, param)
if len(ret) == 0 {
panic("no return value specified for CreateGiteaCredentials")
}
var r0 params.ForgeCredentials
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGiteaCredentialsParams) (params.ForgeCredentials, error)); ok {
return rf(ctx, param)
}
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGiteaCredentialsParams) params.ForgeCredentials); ok {
r0 = rf(ctx, param)
} else {
r0 = ret.Get(0).(params.ForgeCredentials)
}
if rf, ok := ret.Get(1).(func(context.Context, params.CreateGiteaCredentialsParams) error); ok {
r1 = rf(ctx, param)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// CreateGiteaEndpoint provides a mock function with given fields: _a0, param
func (_m *Store) CreateGiteaEndpoint(_a0 context.Context, param params.CreateGiteaEndpointParams) (params.ForgeEndpoint, error) {
ret := _m.Called(_a0, param)
if len(ret) == 0 {
panic("no return value specified for CreateGiteaEndpoint")
}
var r0 params.ForgeEndpoint
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGiteaEndpointParams) (params.ForgeEndpoint, error)); ok {
return rf(_a0, param)
}
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGiteaEndpointParams) params.ForgeEndpoint); ok {
r0 = rf(_a0, param)
} else {
r0 = ret.Get(0).(params.ForgeEndpoint)
}
if rf, ok := ret.Get(1).(func(context.Context, params.CreateGiteaEndpointParams) error); ok {
r1 = rf(_a0, param)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// CreateGithubCredentials provides a mock function with given fields: ctx, param
func (_m *Store) CreateGithubCredentials(ctx context.Context, param params.CreateGithubCredentialsParams) (params.GithubCredentials, error) {
func (_m *Store) CreateGithubCredentials(ctx context.Context, param params.CreateGithubCredentialsParams) (params.ForgeCredentials, error) {
ret := _m.Called(ctx, param)
if len(ret) == 0 {
panic("no return value specified for CreateGithubCredentials")
}
var r0 params.GithubCredentials
var r0 params.ForgeCredentials
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubCredentialsParams) (params.GithubCredentials, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubCredentialsParams) (params.ForgeCredentials, error)); ok {
return rf(ctx, param)
}
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubCredentialsParams) params.GithubCredentials); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubCredentialsParams) params.ForgeCredentials); ok {
r0 = rf(ctx, param)
} else {
r0 = ret.Get(0).(params.GithubCredentials)
r0 = ret.Get(0).(params.ForgeCredentials)
}
if rf, ok := ret.Get(1).(func(context.Context, params.CreateGithubCredentialsParams) error); ok {
@ -209,22 +265,22 @@ func (_m *Store) CreateGithubCredentials(ctx context.Context, param params.Creat
}
// CreateGithubEndpoint provides a mock function with given fields: ctx, param
func (_m *Store) CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.GithubEndpoint, error) {
func (_m *Store) CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.ForgeEndpoint, error) {
ret := _m.Called(ctx, param)
if len(ret) == 0 {
panic("no return value specified for CreateGithubEndpoint")
}
var r0 params.GithubEndpoint
var r0 params.ForgeEndpoint
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubEndpointParams) (params.GithubEndpoint, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubEndpointParams) (params.ForgeEndpoint, error)); ok {
return rf(ctx, param)
}
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubEndpointParams) params.GithubEndpoint); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.CreateGithubEndpointParams) params.ForgeEndpoint); ok {
r0 = rf(ctx, param)
} else {
r0 = ret.Get(0).(params.GithubEndpoint)
r0 = ret.Get(0).(params.ForgeEndpoint)
}
if rf, ok := ret.Get(1).(func(context.Context, params.CreateGithubEndpointParams) error); ok {
@ -292,9 +348,9 @@ func (_m *Store) CreateOrUpdateJob(ctx context.Context, job params.Job) (params.
return r0, r1
}
// CreateOrganization provides a mock function with given fields: ctx, name, credentialsName, webhookSecret, poolBalancerType
func (_m *Store) CreateOrganization(ctx context.Context, name string, credentialsName string, webhookSecret string, poolBalancerType params.PoolBalancerType) (params.Organization, error) {
ret := _m.Called(ctx, name, credentialsName, webhookSecret, poolBalancerType)
// CreateOrganization provides a mock function with given fields: ctx, name, credentials, webhookSecret, poolBalancerType
func (_m *Store) CreateOrganization(ctx context.Context, name string, credentials params.ForgeCredentials, webhookSecret string, poolBalancerType params.PoolBalancerType) (params.Organization, error) {
ret := _m.Called(ctx, name, credentials, webhookSecret, poolBalancerType)
if len(ret) == 0 {
panic("no return value specified for CreateOrganization")
@ -302,17 +358,17 @@ func (_m *Store) CreateOrganization(ctx context.Context, name string, credential
var r0 params.Organization
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, string, string, params.PoolBalancerType) (params.Organization, error)); ok {
return rf(ctx, name, credentialsName, webhookSecret, poolBalancerType)
if rf, ok := ret.Get(0).(func(context.Context, string, params.ForgeCredentials, string, params.PoolBalancerType) (params.Organization, error)); ok {
return rf(ctx, name, credentials, webhookSecret, poolBalancerType)
}
if rf, ok := ret.Get(0).(func(context.Context, string, string, string, params.PoolBalancerType) params.Organization); ok {
r0 = rf(ctx, name, credentialsName, webhookSecret, poolBalancerType)
if rf, ok := ret.Get(0).(func(context.Context, string, params.ForgeCredentials, string, params.PoolBalancerType) params.Organization); ok {
r0 = rf(ctx, name, credentials, webhookSecret, poolBalancerType)
} else {
r0 = ret.Get(0).(params.Organization)
}
if rf, ok := ret.Get(1).(func(context.Context, string, string, string, params.PoolBalancerType) error); ok {
r1 = rf(ctx, name, credentialsName, webhookSecret, poolBalancerType)
if rf, ok := ret.Get(1).(func(context.Context, string, params.ForgeCredentials, string, params.PoolBalancerType) error); ok {
r1 = rf(ctx, name, credentials, webhookSecret, poolBalancerType)
} else {
r1 = ret.Error(1)
}
@ -320,9 +376,9 @@ func (_m *Store) CreateOrganization(ctx context.Context, name string, credential
return r0, r1
}
// CreateRepository provides a mock function with given fields: ctx, owner, name, credentialsName, webhookSecret, poolBalancerType
func (_m *Store) CreateRepository(ctx context.Context, owner string, name string, credentialsName string, webhookSecret string, poolBalancerType params.PoolBalancerType) (params.Repository, error) {
ret := _m.Called(ctx, owner, name, credentialsName, webhookSecret, poolBalancerType)
// CreateRepository provides a mock function with given fields: ctx, owner, name, credentials, webhookSecret, poolBalancerType
func (_m *Store) CreateRepository(ctx context.Context, owner string, name string, credentials params.ForgeCredentials, webhookSecret string, poolBalancerType params.PoolBalancerType) (params.Repository, error) {
ret := _m.Called(ctx, owner, name, credentials, webhookSecret, poolBalancerType)
if len(ret) == 0 {
panic("no return value specified for CreateRepository")
@ -330,17 +386,17 @@ func (_m *Store) CreateRepository(ctx context.Context, owner string, name string
var r0 params.Repository
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, params.PoolBalancerType) (params.Repository, error)); ok {
return rf(ctx, owner, name, credentialsName, webhookSecret, poolBalancerType)
if rf, ok := ret.Get(0).(func(context.Context, string, string, params.ForgeCredentials, string, params.PoolBalancerType) (params.Repository, error)); ok {
return rf(ctx, owner, name, credentials, webhookSecret, poolBalancerType)
}
if rf, ok := ret.Get(0).(func(context.Context, string, string, string, string, params.PoolBalancerType) params.Repository); ok {
r0 = rf(ctx, owner, name, credentialsName, webhookSecret, poolBalancerType)
if rf, ok := ret.Get(0).(func(context.Context, string, string, params.ForgeCredentials, string, params.PoolBalancerType) params.Repository); ok {
r0 = rf(ctx, owner, name, credentials, webhookSecret, poolBalancerType)
} else {
r0 = ret.Get(0).(params.Repository)
}
if rf, ok := ret.Get(1).(func(context.Context, string, string, string, string, params.PoolBalancerType) error); ok {
r1 = rf(ctx, owner, name, credentialsName, webhookSecret, poolBalancerType)
if rf, ok := ret.Get(1).(func(context.Context, string, string, params.ForgeCredentials, string, params.PoolBalancerType) error); ok {
r1 = rf(ctx, owner, name, credentials, webhookSecret, poolBalancerType)
} else {
r1 = ret.Error(1)
}
@ -441,7 +497,7 @@ func (_m *Store) DeleteEnterprise(ctx context.Context, enterpriseID string) erro
}
// DeleteEntityPool provides a mock function with given fields: ctx, entity, poolID
func (_m *Store) DeleteEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) error {
func (_m *Store) DeleteEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string) error {
ret := _m.Called(ctx, entity, poolID)
if len(ret) == 0 {
@ -449,7 +505,7 @@ func (_m *Store) DeleteEntityPool(ctx context.Context, entity params.GithubEntit
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, string) error); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, string) error); ok {
r0 = rf(ctx, entity, poolID)
} else {
r0 = ret.Error(0)
@ -458,6 +514,42 @@ func (_m *Store) DeleteEntityPool(ctx context.Context, entity params.GithubEntit
return r0
}
// DeleteGiteaCredentials provides a mock function with given fields: ctx, id
func (_m *Store) DeleteGiteaCredentials(ctx context.Context, id uint) error {
ret := _m.Called(ctx, id)
if len(ret) == 0 {
panic("no return value specified for DeleteGiteaCredentials")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, uint) error); ok {
r0 = rf(ctx, id)
} else {
r0 = ret.Error(0)
}
return r0
}
// DeleteGiteaEndpoint provides a mock function with given fields: _a0, name
func (_m *Store) DeleteGiteaEndpoint(_a0 context.Context, name string) error {
ret := _m.Called(_a0, name)
if len(ret) == 0 {
panic("no return value specified for DeleteGiteaEndpoint")
}
var r0 error
if rf, ok := ret.Get(0).(func(context.Context, string) error); ok {
r0 = rf(_a0, name)
} else {
r0 = ret.Error(0)
}
return r0
}
// DeleteGithubCredentials provides a mock function with given fields: ctx, id
func (_m *Store) DeleteGithubCredentials(ctx context.Context, id uint) error {
ret := _m.Called(ctx, id)
@ -621,7 +713,7 @@ func (_m *Store) DeleteScaleSetByID(ctx context.Context, scaleSetID uint) error
}
// FindPoolsMatchingAllTags provides a mock function with given fields: ctx, entityType, entityID, tags
func (_m *Store) FindPoolsMatchingAllTags(ctx context.Context, entityType params.GithubEntityType, entityID string, tags []string) ([]params.Pool, error) {
func (_m *Store) FindPoolsMatchingAllTags(ctx context.Context, entityType params.ForgeEntityType, entityID string, tags []string) ([]params.Pool, error) {
ret := _m.Called(ctx, entityType, entityID, tags)
if len(ret) == 0 {
@ -630,10 +722,10 @@ func (_m *Store) FindPoolsMatchingAllTags(ctx context.Context, entityType params
var r0 []params.Pool
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string, []string) ([]params.Pool, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string, []string) ([]params.Pool, error)); ok {
return rf(ctx, entityType, entityID, tags)
}
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string, []string) []params.Pool); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string, []string) []params.Pool); ok {
r0 = rf(ctx, entityType, entityID, tags)
} else {
if ret.Get(0) != nil {
@ -641,7 +733,7 @@ func (_m *Store) FindPoolsMatchingAllTags(ctx context.Context, entityType params
}
}
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntityType, string, []string) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntityType, string, []string) error); ok {
r1 = rf(ctx, entityType, entityID, tags)
} else {
r1 = ret.Error(1)
@ -735,7 +827,7 @@ func (_m *Store) GetEnterpriseByID(ctx context.Context, enterpriseID string) (pa
}
// GetEntityPool provides a mock function with given fields: ctx, entity, poolID
func (_m *Store) GetEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) (params.Pool, error) {
func (_m *Store) GetEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string) (params.Pool, error) {
ret := _m.Called(ctx, entity, poolID)
if len(ret) == 0 {
@ -744,16 +836,16 @@ func (_m *Store) GetEntityPool(ctx context.Context, entity params.GithubEntity,
var r0 params.Pool
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, string) (params.Pool, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, string) (params.Pool, error)); ok {
return rf(ctx, entity, poolID)
}
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, string) params.Pool); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, string) params.Pool); ok {
r0 = rf(ctx, entity, poolID)
} else {
r0 = ret.Get(0).(params.Pool)
}
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity, string) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity, string) error); ok {
r1 = rf(ctx, entity, poolID)
} else {
r1 = ret.Error(1)
@ -762,23 +854,135 @@ func (_m *Store) GetEntityPool(ctx context.Context, entity params.GithubEntity,
return r0, r1
}
// GetForgeEntity provides a mock function with given fields: _a0, entityType, entityID
func (_m *Store) GetForgeEntity(_a0 context.Context, entityType params.ForgeEntityType, entityID string) (params.ForgeEntity, error) {
ret := _m.Called(_a0, entityType, entityID)
if len(ret) == 0 {
panic("no return value specified for GetForgeEntity")
}
var r0 params.ForgeEntity
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string) (params.ForgeEntity, error)); ok {
return rf(_a0, entityType, entityID)
}
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string) params.ForgeEntity); ok {
r0 = rf(_a0, entityType, entityID)
} else {
r0 = ret.Get(0).(params.ForgeEntity)
}
if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntityType, string) error); ok {
r1 = rf(_a0, entityType, entityID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetGiteaCredentials provides a mock function with given fields: ctx, id, detailed
func (_m *Store) GetGiteaCredentials(ctx context.Context, id uint, detailed bool) (params.ForgeCredentials, error) {
ret := _m.Called(ctx, id, detailed)
if len(ret) == 0 {
panic("no return value specified for GetGiteaCredentials")
}
var r0 params.ForgeCredentials
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, uint, bool) (params.ForgeCredentials, error)); ok {
return rf(ctx, id, detailed)
}
if rf, ok := ret.Get(0).(func(context.Context, uint, bool) params.ForgeCredentials); ok {
r0 = rf(ctx, id, detailed)
} else {
r0 = ret.Get(0).(params.ForgeCredentials)
}
if rf, ok := ret.Get(1).(func(context.Context, uint, bool) error); ok {
r1 = rf(ctx, id, detailed)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetGiteaCredentialsByName provides a mock function with given fields: ctx, name, detailed
func (_m *Store) GetGiteaCredentialsByName(ctx context.Context, name string, detailed bool) (params.ForgeCredentials, error) {
ret := _m.Called(ctx, name, detailed)
if len(ret) == 0 {
panic("no return value specified for GetGiteaCredentialsByName")
}
var r0 params.ForgeCredentials
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, bool) (params.ForgeCredentials, error)); ok {
return rf(ctx, name, detailed)
}
if rf, ok := ret.Get(0).(func(context.Context, string, bool) params.ForgeCredentials); ok {
r0 = rf(ctx, name, detailed)
} else {
r0 = ret.Get(0).(params.ForgeCredentials)
}
if rf, ok := ret.Get(1).(func(context.Context, string, bool) error); ok {
r1 = rf(ctx, name, detailed)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetGiteaEndpoint provides a mock function with given fields: _a0, name
func (_m *Store) GetGiteaEndpoint(_a0 context.Context, name string) (params.ForgeEndpoint, error) {
ret := _m.Called(_a0, name)
if len(ret) == 0 {
panic("no return value specified for GetGiteaEndpoint")
}
var r0 params.ForgeEndpoint
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string) (params.ForgeEndpoint, error)); ok {
return rf(_a0, name)
}
if rf, ok := ret.Get(0).(func(context.Context, string) params.ForgeEndpoint); ok {
r0 = rf(_a0, name)
} else {
r0 = ret.Get(0).(params.ForgeEndpoint)
}
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
r1 = rf(_a0, name)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetGithubCredentials provides a mock function with given fields: ctx, id, detailed
func (_m *Store) GetGithubCredentials(ctx context.Context, id uint, detailed bool) (params.GithubCredentials, error) {
func (_m *Store) GetGithubCredentials(ctx context.Context, id uint, detailed bool) (params.ForgeCredentials, error) {
ret := _m.Called(ctx, id, detailed)
if len(ret) == 0 {
panic("no return value specified for GetGithubCredentials")
}
var r0 params.GithubCredentials
var r0 params.ForgeCredentials
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, uint, bool) (params.GithubCredentials, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, uint, bool) (params.ForgeCredentials, error)); ok {
return rf(ctx, id, detailed)
}
if rf, ok := ret.Get(0).(func(context.Context, uint, bool) params.GithubCredentials); ok {
if rf, ok := ret.Get(0).(func(context.Context, uint, bool) params.ForgeCredentials); ok {
r0 = rf(ctx, id, detailed)
} else {
r0 = ret.Get(0).(params.GithubCredentials)
r0 = ret.Get(0).(params.ForgeCredentials)
}
if rf, ok := ret.Get(1).(func(context.Context, uint, bool) error); ok {
@ -791,22 +995,22 @@ func (_m *Store) GetGithubCredentials(ctx context.Context, id uint, detailed boo
}
// GetGithubCredentialsByName provides a mock function with given fields: ctx, name, detailed
func (_m *Store) GetGithubCredentialsByName(ctx context.Context, name string, detailed bool) (params.GithubCredentials, error) {
func (_m *Store) GetGithubCredentialsByName(ctx context.Context, name string, detailed bool) (params.ForgeCredentials, error) {
ret := _m.Called(ctx, name, detailed)
if len(ret) == 0 {
panic("no return value specified for GetGithubCredentialsByName")
}
var r0 params.GithubCredentials
var r0 params.ForgeCredentials
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, bool) (params.GithubCredentials, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, string, bool) (params.ForgeCredentials, error)); ok {
return rf(ctx, name, detailed)
}
if rf, ok := ret.Get(0).(func(context.Context, string, bool) params.GithubCredentials); ok {
if rf, ok := ret.Get(0).(func(context.Context, string, bool) params.ForgeCredentials); ok {
r0 = rf(ctx, name, detailed)
} else {
r0 = ret.Get(0).(params.GithubCredentials)
r0 = ret.Get(0).(params.ForgeCredentials)
}
if rf, ok := ret.Get(1).(func(context.Context, string, bool) error); ok {
@ -819,22 +1023,22 @@ func (_m *Store) GetGithubCredentialsByName(ctx context.Context, name string, de
}
// GetGithubEndpoint provides a mock function with given fields: ctx, name
func (_m *Store) GetGithubEndpoint(ctx context.Context, name string) (params.GithubEndpoint, error) {
func (_m *Store) GetGithubEndpoint(ctx context.Context, name string) (params.ForgeEndpoint, error) {
ret := _m.Called(ctx, name)
if len(ret) == 0 {
panic("no return value specified for GetGithubEndpoint")
}
var r0 params.GithubEndpoint
var r0 params.ForgeEndpoint
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string) (params.GithubEndpoint, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, string) (params.ForgeEndpoint, error)); ok {
return rf(ctx, name)
}
if rf, ok := ret.Get(0).(func(context.Context, string) params.GithubEndpoint); ok {
if rf, ok := ret.Get(0).(func(context.Context, string) params.ForgeEndpoint); ok {
r0 = rf(ctx, name)
} else {
r0 = ret.Get(0).(params.GithubEndpoint)
r0 = ret.Get(0).(params.ForgeEndpoint)
}
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
@ -846,34 +1050,6 @@ func (_m *Store) GetGithubEndpoint(ctx context.Context, name string) (params.Git
return r0, r1
}
// GetGithubEntity provides a mock function with given fields: _a0, entityType, entityID
func (_m *Store) GetGithubEntity(_a0 context.Context, entityType params.GithubEntityType, entityID string) (params.GithubEntity, error) {
ret := _m.Called(_a0, entityType, entityID)
if len(ret) == 0 {
panic("no return value specified for GetGithubEntity")
}
var r0 params.GithubEntity
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string) (params.GithubEntity, error)); ok {
return rf(_a0, entityType, entityID)
}
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string) params.GithubEntity); ok {
r0 = rf(_a0, entityType, entityID)
} else {
r0 = ret.Get(0).(params.GithubEntity)
}
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntityType, string) error); ok {
r1 = rf(_a0, entityType, entityID)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// GetInstanceByName provides a mock function with given fields: ctx, instanceName
func (_m *Store) GetInstanceByName(ctx context.Context, instanceName string) (params.Instance, error) {
ret := _m.Called(ctx, instanceName)
@ -1379,7 +1555,7 @@ func (_m *Store) ListEnterprises(ctx context.Context) ([]params.Enterprise, erro
}
// ListEntityInstances provides a mock function with given fields: ctx, entity
func (_m *Store) ListEntityInstances(ctx context.Context, entity params.GithubEntity) ([]params.Instance, error) {
func (_m *Store) ListEntityInstances(ctx context.Context, entity params.ForgeEntity) ([]params.Instance, error) {
ret := _m.Called(ctx, entity)
if len(ret) == 0 {
@ -1388,10 +1564,10 @@ func (_m *Store) ListEntityInstances(ctx context.Context, entity params.GithubEn
var r0 []params.Instance
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) ([]params.Instance, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) ([]params.Instance, error)); ok {
return rf(ctx, entity)
}
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) []params.Instance); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) []params.Instance); ok {
r0 = rf(ctx, entity)
} else {
if ret.Get(0) != nil {
@ -1399,7 +1575,7 @@ func (_m *Store) ListEntityInstances(ctx context.Context, entity params.GithubEn
}
}
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity) error); ok {
r1 = rf(ctx, entity)
} else {
r1 = ret.Error(1)
@ -1409,7 +1585,7 @@ func (_m *Store) ListEntityInstances(ctx context.Context, entity params.GithubEn
}
// ListEntityJobsByStatus provides a mock function with given fields: ctx, entityType, entityID, status
func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.GithubEntityType, entityID string, status params.JobStatus) ([]params.Job, error) {
func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.ForgeEntityType, entityID string, status params.JobStatus) ([]params.Job, error) {
ret := _m.Called(ctx, entityType, entityID, status)
if len(ret) == 0 {
@ -1418,10 +1594,10 @@ func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.G
var r0 []params.Job
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string, params.JobStatus) ([]params.Job, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string, params.JobStatus) ([]params.Job, error)); ok {
return rf(ctx, entityType, entityID, status)
}
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntityType, string, params.JobStatus) []params.Job); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntityType, string, params.JobStatus) []params.Job); ok {
r0 = rf(ctx, entityType, entityID, status)
} else {
if ret.Get(0) != nil {
@ -1429,7 +1605,7 @@ func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.G
}
}
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntityType, string, params.JobStatus) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntityType, string, params.JobStatus) error); ok {
r1 = rf(ctx, entityType, entityID, status)
} else {
r1 = ret.Error(1)
@ -1439,7 +1615,7 @@ func (_m *Store) ListEntityJobsByStatus(ctx context.Context, entityType params.G
}
// ListEntityPools provides a mock function with given fields: ctx, entity
func (_m *Store) ListEntityPools(ctx context.Context, entity params.GithubEntity) ([]params.Pool, error) {
func (_m *Store) ListEntityPools(ctx context.Context, entity params.ForgeEntity) ([]params.Pool, error) {
ret := _m.Called(ctx, entity)
if len(ret) == 0 {
@ -1448,10 +1624,10 @@ func (_m *Store) ListEntityPools(ctx context.Context, entity params.GithubEntity
var r0 []params.Pool
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) ([]params.Pool, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) ([]params.Pool, error)); ok {
return rf(ctx, entity)
}
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) []params.Pool); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) []params.Pool); ok {
r0 = rf(ctx, entity)
} else {
if ret.Get(0) != nil {
@ -1459,7 +1635,7 @@ func (_m *Store) ListEntityPools(ctx context.Context, entity params.GithubEntity
}
}
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity) error); ok {
r1 = rf(ctx, entity)
} else {
r1 = ret.Error(1)
@ -1469,7 +1645,7 @@ func (_m *Store) ListEntityPools(ctx context.Context, entity params.GithubEntity
}
// ListEntityScaleSets provides a mock function with given fields: _a0, entity
func (_m *Store) ListEntityScaleSets(_a0 context.Context, entity params.GithubEntity) ([]params.ScaleSet, error) {
func (_m *Store) ListEntityScaleSets(_a0 context.Context, entity params.ForgeEntity) ([]params.ScaleSet, error) {
ret := _m.Called(_a0, entity)
if len(ret) == 0 {
@ -1478,10 +1654,10 @@ func (_m *Store) ListEntityScaleSets(_a0 context.Context, entity params.GithubEn
var r0 []params.ScaleSet
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) ([]params.ScaleSet, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) ([]params.ScaleSet, error)); ok {
return rf(_a0, entity)
}
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity) []params.ScaleSet); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity) []params.ScaleSet); ok {
r0 = rf(_a0, entity)
} else {
if ret.Get(0) != nil {
@ -1489,7 +1665,7 @@ func (_m *Store) ListEntityScaleSets(_a0 context.Context, entity params.GithubEn
}
}
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity) error); ok {
r1 = rf(_a0, entity)
} else {
r1 = ret.Error(1)
@ -1498,24 +1674,84 @@ func (_m *Store) ListEntityScaleSets(_a0 context.Context, entity params.GithubEn
return r0, r1
}
// ListGiteaCredentials provides a mock function with given fields: ctx
func (_m *Store) ListGiteaCredentials(ctx context.Context) ([]params.ForgeCredentials, error) {
ret := _m.Called(ctx)
if len(ret) == 0 {
panic("no return value specified for ListGiteaCredentials")
}
var r0 []params.ForgeCredentials
var r1 error
if rf, ok := ret.Get(0).(func(context.Context) ([]params.ForgeCredentials, error)); ok {
return rf(ctx)
}
if rf, ok := ret.Get(0).(func(context.Context) []params.ForgeCredentials); ok {
r0 = rf(ctx)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]params.ForgeCredentials)
}
}
if rf, ok := ret.Get(1).(func(context.Context) error); ok {
r1 = rf(ctx)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// ListGiteaEndpoints provides a mock function with given fields: _a0
func (_m *Store) ListGiteaEndpoints(_a0 context.Context) ([]params.ForgeEndpoint, error) {
ret := _m.Called(_a0)
if len(ret) == 0 {
panic("no return value specified for ListGiteaEndpoints")
}
var r0 []params.ForgeEndpoint
var r1 error
if rf, ok := ret.Get(0).(func(context.Context) ([]params.ForgeEndpoint, error)); ok {
return rf(_a0)
}
if rf, ok := ret.Get(0).(func(context.Context) []params.ForgeEndpoint); ok {
r0 = rf(_a0)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]params.ForgeEndpoint)
}
}
if rf, ok := ret.Get(1).(func(context.Context) error); ok {
r1 = rf(_a0)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// ListGithubCredentials provides a mock function with given fields: ctx
func (_m *Store) ListGithubCredentials(ctx context.Context) ([]params.GithubCredentials, error) {
func (_m *Store) ListGithubCredentials(ctx context.Context) ([]params.ForgeCredentials, error) {
ret := _m.Called(ctx)
if len(ret) == 0 {
panic("no return value specified for ListGithubCredentials")
}
var r0 []params.GithubCredentials
var r0 []params.ForgeCredentials
var r1 error
if rf, ok := ret.Get(0).(func(context.Context) ([]params.GithubCredentials, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context) ([]params.ForgeCredentials, error)); ok {
return rf(ctx)
}
if rf, ok := ret.Get(0).(func(context.Context) []params.GithubCredentials); ok {
if rf, ok := ret.Get(0).(func(context.Context) []params.ForgeCredentials); ok {
r0 = rf(ctx)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]params.GithubCredentials)
r0 = ret.Get(0).([]params.ForgeCredentials)
}
}
@ -1529,23 +1765,23 @@ func (_m *Store) ListGithubCredentials(ctx context.Context) ([]params.GithubCred
}
// ListGithubEndpoints provides a mock function with given fields: ctx
func (_m *Store) ListGithubEndpoints(ctx context.Context) ([]params.GithubEndpoint, error) {
func (_m *Store) ListGithubEndpoints(ctx context.Context) ([]params.ForgeEndpoint, error) {
ret := _m.Called(ctx)
if len(ret) == 0 {
panic("no return value specified for ListGithubEndpoints")
}
var r0 []params.GithubEndpoint
var r0 []params.ForgeEndpoint
var r1 error
if rf, ok := ret.Get(0).(func(context.Context) ([]params.GithubEndpoint, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context) ([]params.ForgeEndpoint, error)); ok {
return rf(ctx)
}
if rf, ok := ret.Get(0).(func(context.Context) []params.GithubEndpoint); ok {
if rf, ok := ret.Get(0).(func(context.Context) []params.ForgeEndpoint); ok {
r0 = rf(ctx)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).([]params.GithubEndpoint)
r0 = ret.Get(0).([]params.ForgeEndpoint)
}
}
@ -1865,7 +2101,7 @@ func (_m *Store) UpdateEnterprise(ctx context.Context, enterpriseID string, para
}
// UpdateEntityPool provides a mock function with given fields: ctx, entity, poolID, param
func (_m *Store) UpdateEntityPool(ctx context.Context, entity params.GithubEntity, poolID string, param params.UpdatePoolParams) (params.Pool, error) {
func (_m *Store) UpdateEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string, param params.UpdatePoolParams) (params.Pool, error) {
ret := _m.Called(ctx, entity, poolID, param)
if len(ret) == 0 {
@ -1874,16 +2110,16 @@ func (_m *Store) UpdateEntityPool(ctx context.Context, entity params.GithubEntit
var r0 params.Pool
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, string, params.UpdatePoolParams) (params.Pool, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, string, params.UpdatePoolParams) (params.Pool, error)); ok {
return rf(ctx, entity, poolID, param)
}
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, string, params.UpdatePoolParams) params.Pool); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, string, params.UpdatePoolParams) params.Pool); ok {
r0 = rf(ctx, entity, poolID, param)
} else {
r0 = ret.Get(0).(params.Pool)
}
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity, string, params.UpdatePoolParams) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity, string, params.UpdatePoolParams) error); ok {
r1 = rf(ctx, entity, poolID, param)
} else {
r1 = ret.Error(1)
@ -1893,7 +2129,7 @@ func (_m *Store) UpdateEntityPool(ctx context.Context, entity params.GithubEntit
}
// UpdateEntityScaleSet provides a mock function with given fields: _a0, entity, scaleSetID, param, callback
func (_m *Store) UpdateEntityScaleSet(_a0 context.Context, entity params.GithubEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(params.ScaleSet, params.ScaleSet) error) (params.ScaleSet, error) {
func (_m *Store) UpdateEntityScaleSet(_a0 context.Context, entity params.ForgeEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(params.ScaleSet, params.ScaleSet) error) (params.ScaleSet, error) {
ret := _m.Called(_a0, entity, scaleSetID, param, callback)
if len(ret) == 0 {
@ -1902,16 +2138,16 @@ func (_m *Store) UpdateEntityScaleSet(_a0 context.Context, entity params.GithubE
var r0 params.ScaleSet
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) (params.ScaleSet, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) (params.ScaleSet, error)); ok {
return rf(_a0, entity, scaleSetID, param, callback)
}
if rf, ok := ret.Get(0).(func(context.Context, params.GithubEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) params.ScaleSet); ok {
if rf, ok := ret.Get(0).(func(context.Context, params.ForgeEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) params.ScaleSet); ok {
r0 = rf(_a0, entity, scaleSetID, param, callback)
} else {
r0 = ret.Get(0).(params.ScaleSet)
}
if rf, ok := ret.Get(1).(func(context.Context, params.GithubEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) error); ok {
if rf, ok := ret.Get(1).(func(context.Context, params.ForgeEntity, uint, params.UpdateScaleSetParams, func(params.ScaleSet, params.ScaleSet) error) error); ok {
r1 = rf(_a0, entity, scaleSetID, param, callback)
} else {
r1 = ret.Error(1)
@ -1920,23 +2156,79 @@ func (_m *Store) UpdateEntityScaleSet(_a0 context.Context, entity params.GithubE
return r0, r1
}
// UpdateGiteaCredentials provides a mock function with given fields: ctx, id, param
func (_m *Store) UpdateGiteaCredentials(ctx context.Context, id uint, param params.UpdateGiteaCredentialsParams) (params.ForgeCredentials, error) {
ret := _m.Called(ctx, id, param)
if len(ret) == 0 {
panic("no return value specified for UpdateGiteaCredentials")
}
var r0 params.ForgeCredentials
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, uint, params.UpdateGiteaCredentialsParams) (params.ForgeCredentials, error)); ok {
return rf(ctx, id, param)
}
if rf, ok := ret.Get(0).(func(context.Context, uint, params.UpdateGiteaCredentialsParams) params.ForgeCredentials); ok {
r0 = rf(ctx, id, param)
} else {
r0 = ret.Get(0).(params.ForgeCredentials)
}
if rf, ok := ret.Get(1).(func(context.Context, uint, params.UpdateGiteaCredentialsParams) error); ok {
r1 = rf(ctx, id, param)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// UpdateGiteaEndpoint provides a mock function with given fields: _a0, name, param
func (_m *Store) UpdateGiteaEndpoint(_a0 context.Context, name string, param params.UpdateGiteaEndpointParams) (params.ForgeEndpoint, error) {
ret := _m.Called(_a0, name, param)
if len(ret) == 0 {
panic("no return value specified for UpdateGiteaEndpoint")
}
var r0 params.ForgeEndpoint
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, params.UpdateGiteaEndpointParams) (params.ForgeEndpoint, error)); ok {
return rf(_a0, name, param)
}
if rf, ok := ret.Get(0).(func(context.Context, string, params.UpdateGiteaEndpointParams) params.ForgeEndpoint); ok {
r0 = rf(_a0, name, param)
} else {
r0 = ret.Get(0).(params.ForgeEndpoint)
}
if rf, ok := ret.Get(1).(func(context.Context, string, params.UpdateGiteaEndpointParams) error); ok {
r1 = rf(_a0, name, param)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// UpdateGithubCredentials provides a mock function with given fields: ctx, id, param
func (_m *Store) UpdateGithubCredentials(ctx context.Context, id uint, param params.UpdateGithubCredentialsParams) (params.GithubCredentials, error) {
func (_m *Store) UpdateGithubCredentials(ctx context.Context, id uint, param params.UpdateGithubCredentialsParams) (params.ForgeCredentials, error) {
ret := _m.Called(ctx, id, param)
if len(ret) == 0 {
panic("no return value specified for UpdateGithubCredentials")
}
var r0 params.GithubCredentials
var r0 params.ForgeCredentials
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, uint, params.UpdateGithubCredentialsParams) (params.GithubCredentials, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, uint, params.UpdateGithubCredentialsParams) (params.ForgeCredentials, error)); ok {
return rf(ctx, id, param)
}
if rf, ok := ret.Get(0).(func(context.Context, uint, params.UpdateGithubCredentialsParams) params.GithubCredentials); ok {
if rf, ok := ret.Get(0).(func(context.Context, uint, params.UpdateGithubCredentialsParams) params.ForgeCredentials); ok {
r0 = rf(ctx, id, param)
} else {
r0 = ret.Get(0).(params.GithubCredentials)
r0 = ret.Get(0).(params.ForgeCredentials)
}
if rf, ok := ret.Get(1).(func(context.Context, uint, params.UpdateGithubCredentialsParams) error); ok {
@ -1949,22 +2241,22 @@ func (_m *Store) UpdateGithubCredentials(ctx context.Context, id uint, param par
}
// UpdateGithubEndpoint provides a mock function with given fields: ctx, name, param
func (_m *Store) UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.GithubEndpoint, error) {
func (_m *Store) UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.ForgeEndpoint, error) {
ret := _m.Called(ctx, name, param)
if len(ret) == 0 {
panic("no return value specified for UpdateGithubEndpoint")
}
var r0 params.GithubEndpoint
var r0 params.ForgeEndpoint
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string, params.UpdateGithubEndpointParams) (params.GithubEndpoint, error)); ok {
if rf, ok := ret.Get(0).(func(context.Context, string, params.UpdateGithubEndpointParams) (params.ForgeEndpoint, error)); ok {
return rf(ctx, name, param)
}
if rf, ok := ret.Get(0).(func(context.Context, string, params.UpdateGithubEndpointParams) params.GithubEndpoint); ok {
if rf, ok := ret.Get(0).(func(context.Context, string, params.UpdateGithubEndpointParams) params.ForgeEndpoint); ok {
r0 = rf(ctx, name, param)
} else {
r0 = ret.Get(0).(params.GithubEndpoint)
r0 = ret.Get(0).(params.ForgeEndpoint)
}
if rf, ok := ret.Get(1).(func(context.Context, string, params.UpdateGithubEndpointParams) error); ok {

View file

@ -21,24 +21,24 @@ import (
)
type GithubEndpointStore interface {
CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.GithubEndpoint, error)
GetGithubEndpoint(ctx context.Context, name string) (params.GithubEndpoint, error)
ListGithubEndpoints(ctx context.Context) ([]params.GithubEndpoint, error)
UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.GithubEndpoint, error)
CreateGithubEndpoint(ctx context.Context, param params.CreateGithubEndpointParams) (params.ForgeEndpoint, error)
GetGithubEndpoint(ctx context.Context, name string) (params.ForgeEndpoint, error)
ListGithubEndpoints(ctx context.Context) ([]params.ForgeEndpoint, error)
UpdateGithubEndpoint(ctx context.Context, name string, param params.UpdateGithubEndpointParams) (params.ForgeEndpoint, error)
DeleteGithubEndpoint(ctx context.Context, name string) error
}
type GithubCredentialsStore interface {
CreateGithubCredentials(ctx context.Context, param params.CreateGithubCredentialsParams) (params.GithubCredentials, error)
GetGithubCredentials(ctx context.Context, id uint, detailed bool) (params.GithubCredentials, error)
GetGithubCredentialsByName(ctx context.Context, name string, detailed bool) (params.GithubCredentials, error)
ListGithubCredentials(ctx context.Context) ([]params.GithubCredentials, error)
UpdateGithubCredentials(ctx context.Context, id uint, param params.UpdateGithubCredentialsParams) (params.GithubCredentials, error)
CreateGithubCredentials(ctx context.Context, param params.CreateGithubCredentialsParams) (params.ForgeCredentials, error)
GetGithubCredentials(ctx context.Context, id uint, detailed bool) (params.ForgeCredentials, error)
GetGithubCredentialsByName(ctx context.Context, name string, detailed bool) (params.ForgeCredentials, error)
ListGithubCredentials(ctx context.Context) ([]params.ForgeCredentials, error)
UpdateGithubCredentials(ctx context.Context, id uint, param params.UpdateGithubCredentialsParams) (params.ForgeCredentials, error)
DeleteGithubCredentials(ctx context.Context, id uint) error
}
type RepoStore interface {
CreateRepository(ctx context.Context, owner, name, credentialsName, webhookSecret string, poolBalancerType params.PoolBalancerType) (params.Repository, error)
CreateRepository(ctx context.Context, owner, name string, credentials params.ForgeCredentials, webhookSecret string, poolBalancerType params.PoolBalancerType) (param params.Repository, err error)
GetRepository(ctx context.Context, owner, name, endpointName string) (params.Repository, error)
GetRepositoryByID(ctx context.Context, repoID string) (params.Repository, error)
ListRepositories(ctx context.Context) ([]params.Repository, error)
@ -47,7 +47,7 @@ type RepoStore interface {
}
type OrgStore interface {
CreateOrganization(ctx context.Context, name, credentialsName, webhookSecret string, poolBalancerType params.PoolBalancerType) (params.Organization, error)
CreateOrganization(ctx context.Context, name string, credentials params.ForgeCredentials, webhookSecret string, poolBalancerType params.PoolBalancerType) (org params.Organization, err error)
GetOrganization(ctx context.Context, name, endpointName string) (params.Organization, error)
GetOrganizationByID(ctx context.Context, orgID string) (params.Organization, error)
ListOrganizations(ctx context.Context) ([]params.Organization, error)
@ -56,7 +56,7 @@ type OrgStore interface {
}
type EnterpriseStore interface {
CreateEnterprise(ctx context.Context, name, credentialsName, webhookSecret string, poolBalancerType params.PoolBalancerType) (params.Enterprise, error)
CreateEnterprise(ctx context.Context, name string, credentialsName params.ForgeCredentials, webhookSecret string, poolBalancerType params.PoolBalancerType) (params.Enterprise, error)
GetEnterprise(ctx context.Context, name, endpointName string) (params.Enterprise, error)
GetEnterpriseByID(ctx context.Context, enterpriseID string) (params.Enterprise, error)
ListEnterprises(ctx context.Context) ([]params.Enterprise, error)
@ -76,7 +76,7 @@ type PoolStore interface {
PoolInstanceCount(ctx context.Context, poolID string) (int64, error)
GetPoolInstanceByName(ctx context.Context, poolID string, instanceName string) (params.Instance, error)
FindPoolsMatchingAllTags(ctx context.Context, entityType params.GithubEntityType, entityID string, tags []string) ([]params.Pool, error)
FindPoolsMatchingAllTags(ctx context.Context, entityType params.ForgeEntityType, entityID string, tags []string) ([]params.Pool, error)
}
type UserStore interface {
@ -107,7 +107,7 @@ type InstanceStore interface {
type JobsStore interface {
CreateOrUpdateJob(ctx context.Context, job params.Job) (params.Job, error)
ListEntityJobsByStatus(ctx context.Context, entityType params.GithubEntityType, entityID string, status params.JobStatus) ([]params.Job, error)
ListEntityJobsByStatus(ctx context.Context, entityType params.ForgeEntityType, entityID string, status params.JobStatus) ([]params.Job, error)
ListJobsByStatus(ctx context.Context, status params.JobStatus) ([]params.Job, error)
ListAllJobs(ctx context.Context) ([]params.Job, error)
@ -121,13 +121,13 @@ type JobsStore interface {
}
type EntityPoolStore interface {
CreateEntityPool(ctx context.Context, entity params.GithubEntity, param params.CreatePoolParams) (params.Pool, error)
GetEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) (params.Pool, error)
DeleteEntityPool(ctx context.Context, entity params.GithubEntity, poolID string) error
UpdateEntityPool(ctx context.Context, entity params.GithubEntity, poolID string, param params.UpdatePoolParams) (params.Pool, error)
CreateEntityPool(ctx context.Context, entity params.ForgeEntity, param params.CreatePoolParams) (params.Pool, error)
GetEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string) (params.Pool, error)
DeleteEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string) error
UpdateEntityPool(ctx context.Context, entity params.ForgeEntity, poolID string, param params.UpdatePoolParams) (params.Pool, error)
ListEntityPools(ctx context.Context, entity params.GithubEntity) ([]params.Pool, error)
ListEntityInstances(ctx context.Context, entity params.GithubEntity) ([]params.Instance, error)
ListEntityPools(ctx context.Context, entity params.ForgeEntity) ([]params.Pool, error)
ListEntityInstances(ctx context.Context, entity params.ForgeEntity) ([]params.Instance, error)
}
type ControllerStore interface {
@ -138,9 +138,9 @@ type ControllerStore interface {
type ScaleSetsStore interface {
ListAllScaleSets(ctx context.Context) ([]params.ScaleSet, error)
CreateEntityScaleSet(_ context.Context, entity params.GithubEntity, param params.CreateScaleSetParams) (scaleSet params.ScaleSet, err error)
ListEntityScaleSets(_ context.Context, entity params.GithubEntity) ([]params.ScaleSet, error)
UpdateEntityScaleSet(_ context.Context, entity params.GithubEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(old, newSet params.ScaleSet) error) (updatedScaleSet params.ScaleSet, err error)
CreateEntityScaleSet(_ context.Context, entity params.ForgeEntity, param params.CreateScaleSetParams) (scaleSet params.ScaleSet, err error)
ListEntityScaleSets(_ context.Context, entity params.ForgeEntity) ([]params.ScaleSet, error)
UpdateEntityScaleSet(_ context.Context, entity params.ForgeEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(old, newSet params.ScaleSet) error) (updatedScaleSet params.ScaleSet, err error)
GetScaleSetByID(ctx context.Context, scaleSet uint) (params.ScaleSet, error)
DeleteScaleSetByID(ctx context.Context, scaleSetID uint) (err error)
SetScaleSetLastMessageID(ctx context.Context, scaleSetID uint, lastMessageID int64) error
@ -152,6 +152,23 @@ type ScaleSetInstanceStore interface {
CreateScaleSetInstance(_ context.Context, scaleSetID uint, param params.CreateInstanceParams) (instance params.Instance, err error)
}
type GiteaEndpointStore interface {
CreateGiteaEndpoint(_ context.Context, param params.CreateGiteaEndpointParams) (ghEndpoint params.ForgeEndpoint, err error)
ListGiteaEndpoints(_ context.Context) ([]params.ForgeEndpoint, error)
DeleteGiteaEndpoint(_ context.Context, name string) (err error)
GetGiteaEndpoint(_ context.Context, name string) (params.ForgeEndpoint, error)
UpdateGiteaEndpoint(_ context.Context, name string, param params.UpdateGiteaEndpointParams) (ghEndpoint params.ForgeEndpoint, err error)
}
type GiteaCredentialsStore interface {
CreateGiteaCredentials(ctx context.Context, param params.CreateGiteaCredentialsParams) (gtCreds params.ForgeCredentials, err error)
GetGiteaCredentialsByName(ctx context.Context, name string, detailed bool) (params.ForgeCredentials, error)
GetGiteaCredentials(ctx context.Context, id uint, detailed bool) (params.ForgeCredentials, error)
ListGiteaCredentials(ctx context.Context) ([]params.ForgeCredentials, error)
UpdateGiteaCredentials(ctx context.Context, id uint, param params.UpdateGiteaCredentialsParams) (gtCreds params.ForgeCredentials, err error)
DeleteGiteaCredentials(ctx context.Context, id uint) (err error)
}
//go:generate mockery --name=Store
type Store interface {
RepoStore
@ -167,9 +184,11 @@ type Store interface {
EntityPoolStore
ScaleSetsStore
ScaleSetInstanceStore
GiteaEndpointStore
GiteaCredentialsStore
ControllerInfo() (params.ControllerInfo, error)
InitController() (params.ControllerInfo, error)
GetGithubEntity(_ context.Context, entityType params.GithubEntityType, entityID string) (params.GithubEntity, error)
AddEntityEvent(ctx context.Context, entity params.GithubEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error
GetForgeEntity(_ context.Context, entityType params.ForgeEntityType, entityID string) (params.ForgeEntity, error)
AddEntityEvent(ctx context.Context, entity params.ForgeEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error
}

View file

@ -1,3 +1,17 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package common
import "context"
@ -18,6 +32,7 @@ const (
JobEntityType DatabaseEntityType = "job"
ControllerEntityType DatabaseEntityType = "controller"
GithubCredentialsEntityType DatabaseEntityType = "github_credentials" // #nosec G101
GiteaCredentialsEntityType DatabaseEntityType = "gitea_credentials" // #nosec G101
GithubEndpointEntityType DatabaseEntityType = "github_endpoint"
ScaleSetEntityType DatabaseEntityType = "scaleset"
)

View file

@ -1,3 +1,17 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package sql
const (

View file

@ -28,10 +28,14 @@ import (
"github.com/cloudbase/garm/params"
)
func (s *sqlDatabase) CreateEnterprise(ctx context.Context, name, credentialsName, webhookSecret string, poolBalancerType params.PoolBalancerType) (paramEnt params.Enterprise, err error) {
func (s *sqlDatabase) CreateEnterprise(ctx context.Context, name string, credentials params.ForgeCredentials, webhookSecret string, poolBalancerType params.PoolBalancerType) (paramEnt params.Enterprise, err error) {
if webhookSecret == "" {
return params.Enterprise{}, errors.New("creating enterprise: missing secret")
}
if credentials.ForgeType != params.GithubEndpointType {
return params.Enterprise{}, errors.Wrap(runnerErrors.ErrBadRequest, "enterprises are not supported on this forge type")
}
secret, err := util.Seal([]byte(webhookSecret), []byte(s.cfg.Passphrase))
if err != nil {
return params.Enterprise{}, errors.Wrap(err, "encoding secret")
@ -45,29 +49,21 @@ func (s *sqlDatabase) CreateEnterprise(ctx context.Context, name, credentialsNam
newEnterprise := Enterprise{
Name: name,
WebhookSecret: secret,
CredentialsName: credentialsName,
PoolBalancerType: poolBalancerType,
}
err = s.conn.Transaction(func(tx *gorm.DB) error {
creds, err := s.getGithubCredentialsByName(ctx, tx, credentialsName, false)
if err != nil {
return errors.Wrap(err, "creating enterprise")
}
if creds.EndpointName == nil {
return errors.Wrap(runnerErrors.ErrUnprocessable, "credentials have no endpoint")
}
newEnterprise.CredentialsID = &creds.ID
newEnterprise.CredentialsName = creds.Name
newEnterprise.EndpointName = creds.EndpointName
newEnterprise.CredentialsID = &credentials.ID
newEnterprise.EndpointName = &credentials.Endpoint.Name
q := tx.Create(&newEnterprise)
if q.Error != nil {
return errors.Wrap(q.Error, "creating enterprise")
}
newEnterprise.Credentials = creds
newEnterprise.Endpoint = creds.Endpoint
newEnterprise, err = s.getEnterpriseByID(ctx, tx, newEnterprise.ID.String(), "Pools", "Credentials", "Endpoint", "Credentials.Endpoint")
if err != nil {
return errors.Wrap(err, "creating enterprise")
}
return nil
})
if err != nil {

View file

@ -53,9 +53,9 @@ type EnterpriseTestSuite struct {
adminCtx context.Context
adminUserID string
testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint
testCreds params.ForgeCredentials
secondaryTestCreds params.ForgeCredentials
githubEndpoint params.ForgeEndpoint
}
func (s *EnterpriseTestSuite) equalInstancesByName(expected, actual []params.Instance) {
@ -99,7 +99,7 @@ func (s *EnterpriseTestSuite) SetupTest() {
enterprise, err := db.CreateEnterprise(
s.adminCtx,
fmt.Sprintf("test-enterprise-%d", i),
s.testCreds.Name,
s.testCreds,
fmt.Sprintf("test-webhook-secret-%d", i),
params.PoolBalancerTypeRoundRobin,
)
@ -178,7 +178,7 @@ func (s *EnterpriseTestSuite) TestCreateEnterprise() {
enterprise, err := s.Store.CreateEnterprise(
s.adminCtx,
s.Fixtures.CreateEnterpriseParams.Name,
s.Fixtures.CreateEnterpriseParams.CredentialsName,
s.testCreds,
s.Fixtures.CreateEnterpriseParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin)
@ -209,7 +209,7 @@ func (s *EnterpriseTestSuite) TestCreateEnterpriseInvalidDBPassphrase() {
_, err = sqlDB.CreateEnterprise(
s.adminCtx,
s.Fixtures.CreateEnterpriseParams.Name,
s.Fixtures.CreateEnterpriseParams.CredentialsName,
s.testCreds,
s.Fixtures.CreateEnterpriseParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin)
@ -219,14 +219,6 @@ func (s *EnterpriseTestSuite) TestCreateEnterpriseInvalidDBPassphrase() {
func (s *EnterpriseTestSuite) TestCreateEnterpriseDBCreateErr() {
s.Fixtures.SQLMock.ExpectBegin()
s.Fixtures.SQLMock.
ExpectQuery(regexp.QuoteMeta("SELECT * FROM `github_credentials` WHERE user_id = ? AND name = ? AND `github_credentials`.`deleted_at` IS NULL ORDER BY `github_credentials`.`id` LIMIT ?")).
WithArgs(s.adminUserID, s.Fixtures.Enterprises[0].CredentialsName, 1).
WillReturnRows(sqlmock.NewRows([]string{"id", "endpoint_name"}).AddRow(s.testCreds.ID, s.testCreds.Endpoint.Name))
s.Fixtures.SQLMock.ExpectQuery(regexp.QuoteMeta("SELECT * FROM `github_endpoints` WHERE `github_endpoints`.`name` = ? AND `github_endpoints`.`deleted_at` IS NULL")).
WithArgs(s.testCreds.Endpoint.Name).
WillReturnRows(sqlmock.NewRows([]string{"name"}).
AddRow(s.testCreds.Endpoint.Name))
s.Fixtures.SQLMock.
ExpectExec(regexp.QuoteMeta("INSERT INTO `enterprises`")).
WillReturnError(fmt.Errorf("creating enterprise mock error"))
@ -235,7 +227,7 @@ func (s *EnterpriseTestSuite) TestCreateEnterpriseDBCreateErr() {
_, err := s.StoreSQLMocked.CreateEnterprise(
s.adminCtx,
s.Fixtures.CreateEnterpriseParams.Name,
s.Fixtures.CreateEnterpriseParams.CredentialsName,
s.testCreds,
s.Fixtures.CreateEnterpriseParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin)
@ -490,9 +482,9 @@ func (s *EnterpriseTestSuite) TestCreateEnterprisePoolMissingTags() {
}
func (s *EnterpriseTestSuite) TestCreateEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
_, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams)
@ -637,9 +629,9 @@ func (s *EnterpriseTestSuite) TestListEnterprisePools() {
}
func (s *EnterpriseTestSuite) TestListEnterprisePoolsInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
_, err := s.Store.ListEntityPools(s.adminCtx, entity)
@ -662,9 +654,9 @@ func (s *EnterpriseTestSuite) TestGetEnterprisePool() {
}
func (s *EnterpriseTestSuite) TestGetEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
_, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -688,9 +680,9 @@ func (s *EnterpriseTestSuite) TestDeleteEnterprisePool() {
}
func (s *EnterpriseTestSuite) TestDeleteEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -743,9 +735,9 @@ func (s *EnterpriseTestSuite) TestListEnterpriseInstances() {
}
func (s *EnterpriseTestSuite) TestListEnterpriseInstancesInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
_, err := s.Store.ListEntityInstances(s.adminCtx, entity)
@ -771,9 +763,9 @@ func (s *EnterpriseTestSuite) TestUpdateEnterprisePool() {
}
func (s *EnterpriseTestSuite) TestUpdateEnterprisePoolInvalidEnterpriseID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-enterprise-id",
EntityType: params.GithubEntityTypeEnterprise,
EntityType: params.ForgeEntityTypeEnterprise,
}
_, err := s.Store.UpdateEntityPool(s.adminCtx, entity, "dummy-pool-id", s.Fixtures.UpdatePoolParams)

478
database/sql/gitea.go Normal file
View file

@ -0,0 +1,478 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package sql
import (
"context"
"log/slog"
"github.com/pkg/errors"
"gorm.io/gorm"
runnerErrors "github.com/cloudbase/garm-provider-common/errors"
"github.com/cloudbase/garm/auth"
"github.com/cloudbase/garm/database/common"
"github.com/cloudbase/garm/params"
)
func (s *sqlDatabase) CreateGiteaEndpoint(_ context.Context, param params.CreateGiteaEndpointParams) (ghEndpoint params.ForgeEndpoint, err error) {
defer func() {
if err == nil {
s.sendNotify(common.GithubEndpointEntityType, common.CreateOperation, ghEndpoint)
}
}()
var endpoint GithubEndpoint
err = s.conn.Transaction(func(tx *gorm.DB) error {
if err := tx.Where("name = ?", param.Name).First(&endpoint).Error; err == nil {
return errors.Wrap(runnerErrors.ErrDuplicateEntity, "gitea endpoint already exists")
}
endpoint = GithubEndpoint{
Name: param.Name,
Description: param.Description,
APIBaseURL: param.APIBaseURL,
BaseURL: param.BaseURL,
CACertBundle: param.CACertBundle,
EndpointType: params.GiteaEndpointType,
}
if err := tx.Create(&endpoint).Error; err != nil {
return errors.Wrap(err, "creating gitea endpoint")
}
return nil
})
if err != nil {
return params.ForgeEndpoint{}, errors.Wrap(err, "creating gitea endpoint")
}
ghEndpoint, err = s.sqlToCommonGithubEndpoint(endpoint)
if err != nil {
return params.ForgeEndpoint{}, errors.Wrap(err, "converting gitea endpoint")
}
return ghEndpoint, nil
}
func (s *sqlDatabase) ListGiteaEndpoints(_ context.Context) ([]params.ForgeEndpoint, error) {
var endpoints []GithubEndpoint
err := s.conn.Where("endpoint_type = ?", params.GiteaEndpointType).Find(&endpoints).Error
if err != nil {
return nil, errors.Wrap(err, "fetching gitea endpoints")
}
var ret []params.ForgeEndpoint
for _, ep := range endpoints {
commonEp, err := s.sqlToCommonGithubEndpoint(ep)
if err != nil {
return nil, errors.Wrap(err, "converting gitea endpoint")
}
ret = append(ret, commonEp)
}
return ret, nil
}
func (s *sqlDatabase) UpdateGiteaEndpoint(_ context.Context, name string, param params.UpdateGiteaEndpointParams) (ghEndpoint params.ForgeEndpoint, err error) {
defer func() {
if err == nil {
s.sendNotify(common.GithubEndpointEntityType, common.UpdateOperation, ghEndpoint)
}
}()
var endpoint GithubEndpoint
err = s.conn.Transaction(func(tx *gorm.DB) error {
if err := tx.Where("name = ? and endpoint_type = ?", name, params.GiteaEndpointType).First(&endpoint).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return errors.Wrap(runnerErrors.ErrNotFound, "gitea endpoint not found")
}
return errors.Wrap(err, "fetching gitea endpoint")
}
if param.APIBaseURL != nil {
endpoint.APIBaseURL = *param.APIBaseURL
}
if param.BaseURL != nil {
endpoint.BaseURL = *param.BaseURL
}
if param.CACertBundle != nil {
endpoint.CACertBundle = param.CACertBundle
}
if param.Description != nil {
endpoint.Description = *param.Description
}
if err := tx.Save(&endpoint).Error; err != nil {
return errors.Wrap(err, "updating gitea endpoint")
}
return nil
})
if err != nil {
return params.ForgeEndpoint{}, errors.Wrap(err, "updating gitea endpoint")
}
ghEndpoint, err = s.sqlToCommonGithubEndpoint(endpoint)
if err != nil {
return params.ForgeEndpoint{}, errors.Wrap(err, "converting gitea endpoint")
}
return ghEndpoint, nil
}
func (s *sqlDatabase) GetGiteaEndpoint(_ context.Context, name string) (params.ForgeEndpoint, error) {
var endpoint GithubEndpoint
err := s.conn.Where("name = ? and endpoint_type = ?", name, params.GiteaEndpointType).First(&endpoint).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return params.ForgeEndpoint{}, errors.Wrap(runnerErrors.ErrNotFound, "gitea endpoint not found")
}
return params.ForgeEndpoint{}, errors.Wrap(err, "fetching gitea endpoint")
}
return s.sqlToCommonGithubEndpoint(endpoint)
}
func (s *sqlDatabase) DeleteGiteaEndpoint(_ context.Context, name string) (err error) {
if name == defaultGithubEndpoint {
return runnerErrors.NewBadRequestError("cannot delete default endpoint %s", defaultGithubEndpoint)
}
defer func() {
if err == nil {
s.sendNotify(common.GithubEndpointEntityType, common.DeleteOperation, params.ForgeEndpoint{Name: name})
}
}()
err = s.conn.Transaction(func(tx *gorm.DB) error {
var endpoint GithubEndpoint
if err := tx.Where("name = ? and endpoint_type = ?", name, params.GiteaEndpointType).First(&endpoint).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil
}
return errors.Wrap(err, "fetching gitea endpoint")
}
var credsCount int64
if err := tx.Model(&GiteaCredentials{}).Where("endpoint_name = ?", endpoint.Name).Count(&credsCount).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return errors.Wrap(err, "fetching gitea credentials")
}
}
var repoCnt int64
if err := tx.Model(&Repository{}).Where("endpoint_name = ?", endpoint.Name).Count(&repoCnt).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return errors.Wrap(err, "fetching gitea repositories")
}
}
var orgCnt int64
if err := tx.Model(&Organization{}).Where("endpoint_name = ?", endpoint.Name).Count(&orgCnt).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
return errors.Wrap(err, "fetching gitea organizations")
}
}
if credsCount > 0 || repoCnt > 0 || orgCnt > 0 {
return runnerErrors.NewBadRequestError("cannot delete endpoint with associated entities")
}
if err := tx.Unscoped().Delete(&endpoint).Error; err != nil {
return errors.Wrap(err, "deleting gitea endpoint")
}
return nil
})
if err != nil {
return errors.Wrap(err, "deleting gitea endpoint")
}
return nil
}
func (s *sqlDatabase) CreateGiteaCredentials(ctx context.Context, param params.CreateGiteaCredentialsParams) (gtCreds params.ForgeCredentials, err error) {
userID, err := getUIDFromContext(ctx)
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "creating gitea credentials")
}
if param.Endpoint == "" {
return params.ForgeCredentials{}, errors.Wrap(runnerErrors.ErrBadRequest, "endpoint name is required")
}
defer func() {
if err == nil {
s.sendNotify(common.GiteaCredentialsEntityType, common.CreateOperation, gtCreds)
}
}()
var creds GiteaCredentials
err = s.conn.Transaction(func(tx *gorm.DB) error {
var endpoint GithubEndpoint
if err := tx.Where("name = ? and endpoint_type = ?", param.Endpoint, params.GiteaEndpointType).First(&endpoint).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return errors.Wrap(runnerErrors.ErrNotFound, "gitea endpoint not found")
}
return errors.Wrap(err, "fetching gitea endpoint")
}
if err := tx.Where("name = ? and user_id = ?", param.Name, userID).First(&creds).Error; err == nil {
return errors.Wrap(runnerErrors.ErrDuplicateEntity, "gitea credentials already exists")
}
var data []byte
var err error
switch param.AuthType {
case params.ForgeAuthTypePAT:
data, err = s.marshalAndSeal(param.PAT)
default:
return errors.Wrap(runnerErrors.ErrBadRequest, "invalid auth type")
}
if err != nil {
return errors.Wrap(err, "marshaling and sealing credentials")
}
creds = GiteaCredentials{
Name: param.Name,
Description: param.Description,
EndpointName: &endpoint.Name,
AuthType: param.AuthType,
Payload: data,
UserID: &userID,
}
if err := tx.Create(&creds).Error; err != nil {
return errors.Wrap(err, "creating gitea credentials")
}
// Skip making an extra query.
creds.Endpoint = endpoint
return nil
})
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "creating gitea credentials")
}
gtCreds, err = s.sqlGiteaToCommonForgeCredentials(creds)
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "converting gitea credentials")
}
return gtCreds, nil
}
func (s *sqlDatabase) getGiteaCredentialsByName(ctx context.Context, tx *gorm.DB, name string, detailed bool) (GiteaCredentials, error) {
var creds GiteaCredentials
q := tx.Preload("Endpoint")
if detailed {
q = q.
Preload("Repositories").
Preload("Organizations").
Preload("Repositories.GiteaCredentials").
Preload("Organizations.GiteaCredentials").
Preload("Repositories.Credentials").
Preload("Organizations.Credentials")
}
userID, err := getUIDFromContext(ctx)
if err != nil {
return GiteaCredentials{}, errors.Wrap(err, "fetching gitea credentials")
}
q = q.Where("user_id = ?", userID)
err = q.Where("name = ?", name).First(&creds).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return GiteaCredentials{}, errors.Wrap(runnerErrors.ErrNotFound, "gitea credentials not found")
}
return GiteaCredentials{}, errors.Wrap(err, "fetching gitea credentials")
}
return creds, nil
}
func (s *sqlDatabase) GetGiteaCredentialsByName(ctx context.Context, name string, detailed bool) (params.ForgeCredentials, error) {
creds, err := s.getGiteaCredentialsByName(ctx, s.conn, name, detailed)
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "fetching gitea credentials")
}
return s.sqlGiteaToCommonForgeCredentials(creds)
}
func (s *sqlDatabase) GetGiteaCredentials(ctx context.Context, id uint, detailed bool) (params.ForgeCredentials, error) {
var creds GiteaCredentials
q := s.conn.Preload("Endpoint")
if detailed {
q = q.
Preload("Repositories").
Preload("Organizations").
Preload("Repositories.GiteaCredentials").
Preload("Organizations.GiteaCredentials").
Preload("Repositories.Credentials").
Preload("Organizations.Credentials")
}
if !auth.IsAdmin(ctx) {
userID, err := getUIDFromContext(ctx)
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "fetching gitea credentials")
}
q = q.Where("user_id = ?", userID)
}
err := q.Where("id = ?", id).First(&creds).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return params.ForgeCredentials{}, errors.Wrap(runnerErrors.ErrNotFound, "gitea credentials not found")
}
return params.ForgeCredentials{}, errors.Wrap(err, "fetching gitea credentials")
}
return s.sqlGiteaToCommonForgeCredentials(creds)
}
func (s *sqlDatabase) ListGiteaCredentials(ctx context.Context) ([]params.ForgeCredentials, error) {
q := s.conn.Preload("Endpoint")
if !auth.IsAdmin(ctx) {
userID, err := getUIDFromContext(ctx)
if err != nil {
return nil, errors.Wrap(err, "fetching gitea credentials")
}
q = q.Where("user_id = ?", userID)
}
var creds []GiteaCredentials
err := q.Preload("Endpoint").Find(&creds).Error
if err != nil {
return nil, errors.Wrap(err, "fetching gitea credentials")
}
var ret []params.ForgeCredentials
for _, c := range creds {
commonCreds, err := s.sqlGiteaToCommonForgeCredentials(c)
if err != nil {
return nil, errors.Wrap(err, "converting gitea credentials")
}
ret = append(ret, commonCreds)
}
return ret, nil
}
func (s *sqlDatabase) UpdateGiteaCredentials(ctx context.Context, id uint, param params.UpdateGiteaCredentialsParams) (gtCreds params.ForgeCredentials, err error) {
defer func() {
if err == nil {
s.sendNotify(common.GiteaCredentialsEntityType, common.UpdateOperation, gtCreds)
}
}()
var creds GiteaCredentials
err = s.conn.Transaction(func(tx *gorm.DB) error {
q := tx.Preload("Endpoint")
if !auth.IsAdmin(ctx) {
userID, err := getUIDFromContext(ctx)
if err != nil {
return errors.Wrap(err, "updating gitea credentials")
}
q = q.Where("user_id = ?", userID)
}
if err := q.Where("id = ?", id).First(&creds).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return errors.Wrap(runnerErrors.ErrNotFound, "gitea credentials not found")
}
return errors.Wrap(err, "fetching gitea credentials")
}
if param.Name != nil {
creds.Name = *param.Name
}
if param.Description != nil {
creds.Description = *param.Description
}
var data []byte
var err error
switch creds.AuthType {
case params.ForgeAuthTypePAT:
if param.PAT != nil {
data, err = s.marshalAndSeal(param.PAT)
}
default:
return errors.Wrap(runnerErrors.ErrBadRequest, "invalid auth type")
}
if err != nil {
return errors.Wrap(err, "marshaling and sealing credentials")
}
if len(data) > 0 {
creds.Payload = data
}
if err := tx.Save(&creds).Error; err != nil {
return errors.Wrap(err, "updating gitea credentials")
}
return nil
})
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "updating gitea credentials")
}
gtCreds, err = s.sqlGiteaToCommonForgeCredentials(creds)
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "converting gitea credentials")
}
return gtCreds, nil
}
func (s *sqlDatabase) DeleteGiteaCredentials(ctx context.Context, id uint) (err error) {
var creds GiteaCredentials
defer func() {
if err == nil {
forgeCreds, innerErr := s.sqlGiteaToCommonForgeCredentials(creds)
if innerErr != nil {
slog.ErrorContext(ctx, "converting gitea credentials", "error", innerErr)
}
if creds.ID == 0 || creds.Name == "" {
return
}
s.sendNotify(common.GiteaCredentialsEntityType, common.DeleteOperation, forgeCreds)
}
}()
err = s.conn.Transaction(func(tx *gorm.DB) error {
q := tx.Where("id = ?", id).
Preload("Repositories").
Preload("Organizations")
if !auth.IsAdmin(ctx) {
userID, err := getUIDFromContext(ctx)
if err != nil {
return errors.Wrap(err, "deleting gitea credentials")
}
q = q.Where("user_id = ?", userID)
}
err := q.First(&creds).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil
}
return errors.Wrap(err, "fetching gitea credentials")
}
if len(creds.Repositories) > 0 {
return errors.Wrap(runnerErrors.ErrBadRequest, "cannot delete credentials with repositories")
}
if len(creds.Organizations) > 0 {
return errors.Wrap(runnerErrors.ErrBadRequest, "cannot delete credentials with organizations")
}
if err := tx.Unscoped().Delete(&creds).Error; err != nil {
return errors.Wrap(err, "deleting gitea credentials")
}
return nil
})
if err != nil {
return errors.Wrap(err, "deleting gitea credentials")
}
return nil
}

793
database/sql/gitea_test.go Normal file
View file

@ -0,0 +1,793 @@
// Copyright 2024 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package sql
import (
"context"
"fmt"
"os"
"testing"
"github.com/stretchr/testify/suite"
runnerErrors "github.com/cloudbase/garm-provider-common/errors"
"github.com/cloudbase/garm/auth"
"github.com/cloudbase/garm/database/common"
garmTesting "github.com/cloudbase/garm/internal/testing"
"github.com/cloudbase/garm/params"
)
type GiteaTestSuite struct {
suite.Suite
giteaEndpoint params.ForgeEndpoint
db common.Store
}
func (s *GiteaTestSuite) SetupTest() {
db, err := NewSQLDatabase(context.Background(), garmTesting.GetTestSqliteDBConfig(s.T()))
if err != nil {
s.FailNow(fmt.Sprintf("failed to create db connection: %s", err))
}
s.db = db
createEpParams := params.CreateGiteaEndpointParams{
Name: testEndpointName,
Description: testEndpointDescription,
APIBaseURL: testAPIBaseURL,
BaseURL: testBaseURL,
}
endpoint, err := s.db.CreateGiteaEndpoint(context.Background(), createEpParams)
s.Require().NoError(err)
s.Require().NotNil(endpoint)
s.Require().Equal(testEndpointName, endpoint.Name)
s.giteaEndpoint = endpoint
}
func (s *GiteaTestSuite) TestCreatingEndpoint() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
createEpParams := params.CreateGiteaEndpointParams{
Name: alternetTestEndpointName,
Description: testEndpointDescription,
APIBaseURL: testAPIBaseURL,
BaseURL: testBaseURL,
}
endpoint, err := s.db.CreateGiteaEndpoint(ctx, createEpParams)
s.Require().NoError(err)
s.Require().NotNil(endpoint)
s.Require().Equal(alternetTestEndpointName, endpoint.Name)
}
func (s *GiteaTestSuite) TestCreatingDuplicateEndpointFails() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
createEpParams := params.CreateGiteaEndpointParams{
Name: alternetTestEndpointName,
Description: testEndpointDescription,
APIBaseURL: testAPIBaseURL,
BaseURL: testBaseURL,
}
_, err := s.db.CreateGiteaEndpoint(ctx, createEpParams)
s.Require().NoError(err)
_, err = s.db.CreateGiteaEndpoint(ctx, createEpParams)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrDuplicateEntity)
}
func (s *GiteaTestSuite) TestGetEndpoint() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
createEpParams := params.CreateGiteaEndpointParams{
Name: alternetTestEndpointName,
Description: testEndpointDescription,
APIBaseURL: testAPIBaseURL,
BaseURL: testBaseURL,
}
newEndpoint, err := s.db.CreateGiteaEndpoint(ctx, createEpParams)
s.Require().NoError(err)
endpoint, err := s.db.GetGiteaEndpoint(ctx, createEpParams.Name)
s.Require().NoError(err)
s.Require().NotNil(endpoint)
s.Require().Equal(newEndpoint.Name, endpoint.Name)
}
func (s *GiteaTestSuite) TestGetNonExistingEndpointFailsWithNotFoundError() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
_, err := s.db.GetGiteaEndpoint(ctx, "non-existing")
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestDeletingNonExistingEndpointIsANoop() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
err := s.db.DeleteGiteaEndpoint(ctx, "non-existing")
s.Require().NoError(err)
}
func (s *GiteaTestSuite) TestDeletingEndpoint() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
createEpParams := params.CreateGiteaEndpointParams{
Name: alternetTestEndpointName,
Description: testEndpointDescription,
APIBaseURL: testAPIBaseURL,
BaseURL: testBaseURL,
}
endpoint, err := s.db.CreateGiteaEndpoint(ctx, createEpParams)
s.Require().NoError(err)
s.Require().NotNil(endpoint)
err = s.db.DeleteGiteaEndpoint(ctx, alternetTestEndpointName)
s.Require().NoError(err)
_, err = s.db.GetGiteaEndpoint(ctx, alternetTestEndpointName)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestUpdateEndpoint() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
createEpParams := params.CreateGiteaEndpointParams{
Name: "deleteme",
Description: testEndpointDescription,
APIBaseURL: testAPIBaseURL,
BaseURL: testBaseURL,
}
endpoint, err := s.db.CreateGiteaEndpoint(ctx, createEpParams)
s.Require().NoError(err)
s.Require().NotNil(endpoint)
newDescription := "another description"
newAPIBaseURL := "https://new-api.example.com"
newBaseURL := "https://new.example.com"
caCertBundle, err := os.ReadFile("../../testdata/certs/srv-pub.pem")
s.Require().NoError(err)
updateEpParams := params.UpdateGiteaEndpointParams{
Description: &newDescription,
APIBaseURL: &newAPIBaseURL,
BaseURL: &newBaseURL,
CACertBundle: caCertBundle,
}
updatedEndpoint, err := s.db.UpdateGiteaEndpoint(ctx, testEndpointName, updateEpParams)
s.Require().NoError(err)
s.Require().NotNil(updatedEndpoint)
s.Require().Equal(newDescription, updatedEndpoint.Description)
s.Require().Equal(newAPIBaseURL, updatedEndpoint.APIBaseURL)
s.Require().Equal(newBaseURL, updatedEndpoint.BaseURL)
s.Require().Equal(caCertBundle, updatedEndpoint.CACertBundle)
}
func (s *GiteaTestSuite) TestUpdatingNonExistingEndpointReturnsNotFoundError() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
newDescription := "test desc"
updateEpParams := params.UpdateGiteaEndpointParams{
Description: &newDescription,
}
_, err := s.db.UpdateGiteaEndpoint(ctx, "non-existing", updateEpParams)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestListEndpoints() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
createEpParams := params.CreateGiteaEndpointParams{
Name: alternetTestEndpointName,
Description: testEndpointDescription,
APIBaseURL: testAPIBaseURL,
BaseURL: testBaseURL,
}
_, err := s.db.CreateGiteaEndpoint(ctx, createEpParams)
s.Require().NoError(err)
endpoints, err := s.db.ListGiteaEndpoints(ctx)
s.Require().NoError(err)
s.Require().Len(endpoints, 2)
}
func (s *GiteaTestSuite) TestCreateCredentialsFailsWithUnauthorizedForAnonUser() {
ctx := context.Background()
_, err := s.db.CreateGiteaCredentials(ctx, params.CreateGiteaCredentialsParams{})
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrUnauthorized)
}
func (s *GiteaTestSuite) TestCreateCredentialsFailsWhenEndpointNameIsEmpty() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
_, err := s.db.CreateGiteaCredentials(ctx, params.CreateGiteaCredentialsParams{})
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrBadRequest)
s.Require().Regexp("endpoint name is required", err.Error())
}
func (s *GiteaTestSuite) TestCreateCredentialsFailsWhenEndpointDoesNotExist() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
_, err := s.db.CreateGiteaCredentials(ctx, params.CreateGiteaCredentialsParams{Endpoint: "non-existing"})
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
s.Require().Regexp("endpoint not found", err.Error())
}
func (s *GiteaTestSuite) TestCreateCredentialsFailsWhenAuthTypeIsInvalid() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
_, err := s.db.CreateGiteaCredentials(ctx, params.CreateGiteaCredentialsParams{Endpoint: s.giteaEndpoint.Name, AuthType: "invalid"})
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrBadRequest)
s.Require().Regexp("invalid auth type", err.Error())
}
func (s *GiteaTestSuite) TestCreateCredentials() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
}
creds, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
s.Require().Equal(credParams.Name, creds.Name)
s.Require().Equal(credParams.Description, creds.Description)
s.Require().Equal(credParams.Endpoint, creds.Endpoint.Name)
s.Require().Equal(credParams.AuthType, creds.AuthType)
}
func (s *GiteaTestSuite) TestCreateCredentialsFailsOnDuplicateCredentials() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
testUser := garmTesting.CreateGARMTestUser(ctx, "testuser", s.db, s.T())
testUserCtx := auth.PopulateContext(context.Background(), testUser, nil)
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
}
_, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
// Creating creds with the same parameters should fail for the same user.
_, err = s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrDuplicateEntity)
// Creating creds with the same parameters should work for different users.
_, err = s.db.CreateGiteaCredentials(testUserCtx, credParams)
s.Require().NoError(err)
}
func (s *GiteaTestSuite) TestNormalUsersCanOnlySeeTheirOwnCredentialsAdminCanSeeAll() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
testUser := garmTesting.CreateGARMTestUser(ctx, "testuser1", s.db, s.T())
testUser2 := garmTesting.CreateGARMTestUser(ctx, "testuser2", s.db, s.T())
testUserCtx := auth.PopulateContext(context.Background(), testUser, nil)
testUser2Ctx := auth.PopulateContext(context.Background(), testUser2, nil)
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
}
creds, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
credParams.Name = "test-creds2"
creds2, err := s.db.CreateGiteaCredentials(testUserCtx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds2)
credParams.Name = "test-creds3"
creds3, err := s.db.CreateGiteaCredentials(testUser2Ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds3)
credsList, err := s.db.ListGiteaCredentials(ctx)
s.Require().NoError(err)
s.Require().Len(credsList, 3)
credsList, err = s.db.ListGiteaCredentials(testUserCtx)
s.Require().NoError(err)
s.Require().Len(credsList, 1)
s.Require().Equal("test-creds2", credsList[0].Name)
credsList, err = s.db.ListGiteaCredentials(testUser2Ctx)
s.Require().NoError(err)
s.Require().Len(credsList, 1)
s.Require().Equal("test-creds3", credsList[0].Name)
}
func (s *GiteaTestSuite) TestGetGiteaCredentialsFailsWhenCredentialsDontExist() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
_, err := s.db.GetGiteaCredentials(ctx, 1, true)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
_, err = s.db.GetGiteaCredentialsByName(ctx, "non-existing", true)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestGetGithubCredentialsByNameReturnsOnlyCurrentUserCredentials() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
testUser := garmTesting.CreateGARMTestUser(ctx, "test-user1", s.db, s.T())
testUserCtx := auth.PopulateContext(context.Background(), testUser, nil)
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
}
creds, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
creds2, err := s.db.CreateGiteaCredentials(testUserCtx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds2)
creds2Get, err := s.db.GetGiteaCredentialsByName(testUserCtx, testCredsName, true)
s.Require().NoError(err)
s.Require().NotNil(creds2)
s.Require().Equal(testCredsName, creds2Get.Name)
s.Require().Equal(creds2.ID, creds2Get.ID)
credsGet, err := s.db.GetGiteaCredentialsByName(ctx, testCredsName, true)
s.Require().NoError(err)
s.Require().NotNil(creds)
s.Require().Equal(testCredsName, credsGet.Name)
s.Require().Equal(creds.ID, credsGet.ID)
// Admin can get any creds by ID
credsGet, err = s.db.GetGiteaCredentials(ctx, creds2.ID, true)
s.Require().NoError(err)
s.Require().NotNil(creds2)
s.Require().Equal(creds2.ID, credsGet.ID)
// Normal user cannot get other user creds by ID
_, err = s.db.GetGiteaCredentials(testUserCtx, creds.ID, true)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestGetGithubCredentials() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
}
creds, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
creds2, err := s.db.GetGiteaCredentialsByName(ctx, testCredsName, true)
s.Require().NoError(err)
s.Require().NotNil(creds2)
s.Require().Equal(creds.Name, creds2.Name)
s.Require().Equal(creds.ID, creds2.ID)
creds2, err = s.db.GetGiteaCredentials(ctx, creds.ID, true)
s.Require().NoError(err)
s.Require().NotNil(creds2)
s.Require().Equal(creds.Name, creds2.Name)
s.Require().Equal(creds.ID, creds2.ID)
}
func (s *GiteaTestSuite) TestDeleteGiteaCredentials() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
}
creds, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
err = s.db.DeleteGiteaCredentials(ctx, creds.ID)
s.Require().NoError(err)
_, err = s.db.GetGiteaCredentials(ctx, creds.ID, true)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestDeleteGiteaCredentialsByNonAdminUser() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
testUser := garmTesting.CreateGARMTestUser(ctx, "test-user4", s.db, s.T())
testUserCtx := auth.PopulateContext(context.Background(), testUser, nil)
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test-creds4",
},
}
// Create creds as admin
creds, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
// Deleting non existent creds will return a nil error. For the test user
// the creds created by the admin should not be visible, which leads to not found
// which in turn returns no error.
err = s.db.DeleteGiteaCredentials(testUserCtx, creds.ID)
s.Require().NoError(err)
// Check that the creds created by the admin are still there.
credsGet, err := s.db.GetGiteaCredentials(ctx, creds.ID, true)
s.Require().NoError(err)
s.Require().NotNil(credsGet)
s.Require().Equal(creds.ID, credsGet.ID)
// Create the same creds with the test user.
creds2, err := s.db.CreateGiteaCredentials(testUserCtx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds2)
// Remove creds created by test user.
err = s.db.DeleteGiteaCredentials(testUserCtx, creds2.ID)
s.Require().NoError(err)
// The creds created by the test user should be gone.
_, err = s.db.GetGiteaCredentials(testUserCtx, creds2.ID, true)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestDeleteCredentialsFailsIfReposOrgsOrEntitiesUseIt() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
}
creds, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
repo, err := s.db.CreateRepository(ctx, "test-owner", "test-repo", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotNil(repo)
err = s.db.DeleteGiteaCredentials(ctx, creds.ID)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrBadRequest)
err = s.db.DeleteRepository(ctx, repo.ID)
s.Require().NoError(err)
org, err := s.db.CreateOrganization(ctx, "test-org", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotNil(org)
err = s.db.DeleteGiteaCredentials(ctx, creds.ID)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrBadRequest)
err = s.db.DeleteOrganization(ctx, org.ID)
s.Require().NoError(err)
enterprise, err := s.db.CreateEnterprise(ctx, "test-enterprise", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().ErrorIs(err, runnerErrors.ErrBadRequest)
s.Require().Equal(params.Enterprise{}, enterprise)
err = s.db.DeleteGiteaCredentials(ctx, creds.ID)
s.Require().NoError(err)
_, err = s.db.GetGiteaCredentials(ctx, creds.ID, true)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestUpdateCredentials() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
}
creds, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
newDescription := "just a description"
newName := "new-name"
newToken := "new-token"
updateCredParams := params.UpdateGiteaCredentialsParams{
Description: &newDescription,
Name: &newName,
PAT: &params.GithubPAT{
OAuth2Token: newToken,
},
}
updatedCreds, err := s.db.UpdateGiteaCredentials(ctx, creds.ID, updateCredParams)
s.Require().NoError(err)
s.Require().NotNil(updatedCreds)
s.Require().Equal(newDescription, updatedCreds.Description)
s.Require().Equal(newName, updatedCreds.Name)
}
func (s *GiteaTestSuite) TestUpdateCredentialsFailsForNonExistingCredentials() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
updateCredParams := params.UpdateGiteaCredentialsParams{
Description: nil,
}
_, err := s.db.UpdateGiteaCredentials(ctx, 1, updateCredParams)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestUpdateCredentialsFailsIfCredentialsAreOwnedByNonAdminUser() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
testUser := garmTesting.CreateGARMTestUser(ctx, "test-user5", s.db, s.T())
testUserCtx := auth.PopulateContext(context.Background(), testUser, nil)
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test-creds5",
},
}
creds, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
newDescription := "new params desc"
updateCredParams := params.UpdateGiteaCredentialsParams{
Description: &newDescription,
}
_, err = s.db.UpdateGiteaCredentials(testUserCtx, creds.ID, updateCredParams)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestAdminUserCanUpdateAnyGiteaCredentials() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
testUser := garmTesting.CreateGARMTestUser(ctx, "test-user5", s.db, s.T())
testUserCtx := auth.PopulateContext(context.Background(), testUser, nil)
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test-creds5",
},
}
creds, err := s.db.CreateGiteaCredentials(testUserCtx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
newDescription := "another new description"
updateCredParams := params.UpdateGiteaCredentialsParams{
Description: &newDescription,
}
newCreds, err := s.db.UpdateGiteaCredentials(ctx, creds.ID, updateCredParams)
s.Require().NoError(err)
s.Require().Equal(newDescription, newCreds.Description)
}
func (s *GiteaTestSuite) TestDeleteCredentialsWithOrgsOrReposFails() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: s.giteaEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test-creds5",
},
}
creds, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
repo, err := s.db.CreateRepository(ctx, "test-owner", "test-repo", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotNil(repo)
err = s.db.DeleteGiteaCredentials(ctx, creds.ID)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrBadRequest)
err = s.db.DeleteRepository(ctx, repo.ID)
s.Require().NoError(err)
org, err := s.db.CreateOrganization(ctx, "test-org", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotNil(org)
err = s.db.DeleteGiteaCredentials(ctx, creds.ID)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrBadRequest)
err = s.db.DeleteOrganization(ctx, org.ID)
s.Require().NoError(err)
err = s.db.DeleteGiteaCredentials(ctx, creds.ID)
s.Require().NoError(err)
_, err = s.db.GetGiteaCredentials(ctx, creds.ID, true)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestDeleteGiteaEndpointFailsWithOrgsReposOrCredentials() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
endpointParams := params.CreateGiteaEndpointParams{
Name: "deleteme",
Description: testEndpointDescription,
APIBaseURL: testAPIBaseURL,
BaseURL: testBaseURL,
}
ep, err := s.db.CreateGiteaEndpoint(ctx, endpointParams)
s.Require().NoError(err)
s.Require().NotNil(ep)
credParams := params.CreateGiteaCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: ep.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test-creds5",
},
}
creds, err := s.db.CreateGiteaCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
repo, err := s.db.CreateRepository(ctx, "test-owner", "test-repo", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotNil(repo)
badRequest := &runnerErrors.BadRequestError{}
err = s.db.DeleteGiteaEndpoint(ctx, ep.Name)
s.Require().Error(err)
s.Require().ErrorAs(err, &badRequest)
err = s.db.DeleteRepository(ctx, repo.ID)
s.Require().NoError(err)
org, err := s.db.CreateOrganization(ctx, "test-org", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotNil(org)
err = s.db.DeleteGiteaEndpoint(ctx, ep.Name)
s.Require().Error(err)
s.Require().ErrorAs(err, &badRequest)
err = s.db.DeleteOrganization(ctx, org.ID)
s.Require().NoError(err)
err = s.db.DeleteGiteaCredentials(ctx, creds.ID)
s.Require().NoError(err)
err = s.db.DeleteGiteaEndpoint(ctx, ep.Name)
s.Require().NoError(err)
_, err = s.db.GetGiteaEndpoint(ctx, ep.Name)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func (s *GiteaTestSuite) TestListGiteaEndpoints() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
createEpParams := params.CreateGiteaEndpointParams{
Name: "deleteme",
Description: testEndpointDescription,
APIBaseURL: testAPIBaseURL,
BaseURL: testBaseURL,
}
_, err := s.db.CreateGiteaEndpoint(ctx, createEpParams)
s.Require().NoError(err)
endpoints, err := s.db.ListGiteaEndpoints(ctx)
s.Require().NoError(err)
s.Require().Len(endpoints, 2)
}
func TestGiteaTestSuite(t *testing.T) {
suite.Run(t, new(GiteaTestSuite))
}

View file

@ -17,12 +17,10 @@ package sql
import (
"context"
"github.com/google/uuid"
"github.com/pkg/errors"
"gorm.io/gorm"
runnerErrors "github.com/cloudbase/garm-provider-common/errors"
"github.com/cloudbase/garm-provider-common/util"
"github.com/cloudbase/garm/auth"
"github.com/cloudbase/garm/database/common"
"github.com/cloudbase/garm/params"
@ -32,89 +30,7 @@ const (
defaultGithubEndpoint string = "github.com"
)
func (s *sqlDatabase) sqlToCommonGithubCredentials(creds GithubCredentials) (params.GithubCredentials, error) {
if len(creds.Payload) == 0 {
return params.GithubCredentials{}, errors.New("empty credentials payload")
}
data, err := util.Unseal(creds.Payload, []byte(s.cfg.Passphrase))
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "unsealing credentials")
}
ep, err := s.sqlToCommonGithubEndpoint(creds.Endpoint)
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "converting github endpoint")
}
commonCreds := params.GithubCredentials{
ID: creds.ID,
Name: creds.Name,
Description: creds.Description,
APIBaseURL: creds.Endpoint.APIBaseURL,
BaseURL: creds.Endpoint.BaseURL,
UploadBaseURL: creds.Endpoint.UploadBaseURL,
CABundle: creds.Endpoint.CACertBundle,
AuthType: creds.AuthType,
CreatedAt: creds.CreatedAt,
UpdatedAt: creds.UpdatedAt,
Endpoint: ep,
CredentialsPayload: data,
}
for _, repo := range creds.Repositories {
commonRepo, err := s.sqlToCommonRepository(repo, false)
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "converting github repository")
}
commonCreds.Repositories = append(commonCreds.Repositories, commonRepo)
}
for _, org := range creds.Organizations {
commonOrg, err := s.sqlToCommonOrganization(org, false)
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "converting github organization")
}
commonCreds.Organizations = append(commonCreds.Organizations, commonOrg)
}
for _, ent := range creds.Enterprises {
commonEnt, err := s.sqlToCommonEnterprise(ent, false)
if err != nil {
return params.GithubCredentials{}, errors.Wrapf(err, "converting github enterprise: %s", ent.Name)
}
commonCreds.Enterprises = append(commonCreds.Enterprises, commonEnt)
}
return commonCreds, nil
}
func (s *sqlDatabase) sqlToCommonGithubEndpoint(ep GithubEndpoint) (params.GithubEndpoint, error) {
return params.GithubEndpoint{
Name: ep.Name,
Description: ep.Description,
APIBaseURL: ep.APIBaseURL,
BaseURL: ep.BaseURL,
UploadBaseURL: ep.UploadBaseURL,
CACertBundle: ep.CACertBundle,
CreatedAt: ep.CreatedAt,
UpdatedAt: ep.UpdatedAt,
}, nil
}
func getUIDFromContext(ctx context.Context) (uuid.UUID, error) {
userID := auth.UserID(ctx)
if userID == "" {
return uuid.Nil, errors.Wrap(runnerErrors.ErrUnauthorized, "getting UID from context")
}
asUUID, err := uuid.Parse(userID)
if err != nil {
return uuid.Nil, errors.Wrap(runnerErrors.ErrUnauthorized, "parsing UID from context")
}
return asUUID, nil
}
func (s *sqlDatabase) CreateGithubEndpoint(_ context.Context, param params.CreateGithubEndpointParams) (ghEndpoint params.GithubEndpoint, err error) {
func (s *sqlDatabase) CreateGithubEndpoint(_ context.Context, param params.CreateGithubEndpointParams) (ghEndpoint params.ForgeEndpoint, err error) {
defer func() {
if err == nil {
s.sendNotify(common.GithubEndpointEntityType, common.CreateOperation, ghEndpoint)
@ -132,6 +48,7 @@ func (s *sqlDatabase) CreateGithubEndpoint(_ context.Context, param params.Creat
BaseURL: param.BaseURL,
UploadBaseURL: param.UploadBaseURL,
CACertBundle: param.CACertBundle,
EndpointType: params.GithubEndpointType,
}
if err := tx.Create(&endpoint).Error; err != nil {
@ -140,23 +57,23 @@ func (s *sqlDatabase) CreateGithubEndpoint(_ context.Context, param params.Creat
return nil
})
if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "creating github endpoint")
return params.ForgeEndpoint{}, errors.Wrap(err, "creating github endpoint")
}
ghEndpoint, err = s.sqlToCommonGithubEndpoint(endpoint)
if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "converting github endpoint")
return params.ForgeEndpoint{}, errors.Wrap(err, "converting github endpoint")
}
return ghEndpoint, nil
}
func (s *sqlDatabase) ListGithubEndpoints(_ context.Context) ([]params.GithubEndpoint, error) {
func (s *sqlDatabase) ListGithubEndpoints(_ context.Context) ([]params.ForgeEndpoint, error) {
var endpoints []GithubEndpoint
err := s.conn.Find(&endpoints).Error
err := s.conn.Where("endpoint_type = ?", params.GithubEndpointType).Find(&endpoints).Error
if err != nil {
return nil, errors.Wrap(err, "fetching github endpoints")
}
var ret []params.GithubEndpoint
var ret []params.ForgeEndpoint
for _, ep := range endpoints {
commonEp, err := s.sqlToCommonGithubEndpoint(ep)
if err != nil {
@ -167,9 +84,9 @@ func (s *sqlDatabase) ListGithubEndpoints(_ context.Context) ([]params.GithubEnd
return ret, nil
}
func (s *sqlDatabase) UpdateGithubEndpoint(_ context.Context, name string, param params.UpdateGithubEndpointParams) (ghEndpoint params.GithubEndpoint, err error) {
func (s *sqlDatabase) UpdateGithubEndpoint(_ context.Context, name string, param params.UpdateGithubEndpointParams) (ghEndpoint params.ForgeEndpoint, err error) {
if name == defaultGithubEndpoint {
return params.GithubEndpoint{}, errors.Wrap(runnerErrors.ErrBadRequest, "cannot update default github endpoint")
return params.ForgeEndpoint{}, errors.Wrap(runnerErrors.ErrBadRequest, "cannot update default github endpoint")
}
defer func() {
@ -179,7 +96,7 @@ func (s *sqlDatabase) UpdateGithubEndpoint(_ context.Context, name string, param
}()
var endpoint GithubEndpoint
err = s.conn.Transaction(func(tx *gorm.DB) error {
if err := tx.Where("name = ?", name).First(&endpoint).Error; err != nil {
if err := tx.Where("name = ? and endpoint_type = ?", name, params.GithubEndpointType).First(&endpoint).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return errors.Wrap(runnerErrors.ErrNotFound, "github endpoint not found")
}
@ -212,24 +129,24 @@ func (s *sqlDatabase) UpdateGithubEndpoint(_ context.Context, name string, param
return nil
})
if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "updating github endpoint")
return params.ForgeEndpoint{}, errors.Wrap(err, "updating github endpoint")
}
ghEndpoint, err = s.sqlToCommonGithubEndpoint(endpoint)
if err != nil {
return params.GithubEndpoint{}, errors.Wrap(err, "converting github endpoint")
return params.ForgeEndpoint{}, errors.Wrap(err, "converting github endpoint")
}
return ghEndpoint, nil
}
func (s *sqlDatabase) GetGithubEndpoint(_ context.Context, name string) (params.GithubEndpoint, error) {
func (s *sqlDatabase) GetGithubEndpoint(_ context.Context, name string) (params.ForgeEndpoint, error) {
var endpoint GithubEndpoint
err := s.conn.Where("name = ?", name).First(&endpoint).Error
err := s.conn.Where("name = ? and endpoint_type = ?", name, params.GithubEndpointType).First(&endpoint).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return params.GithubEndpoint{}, errors.Wrap(runnerErrors.ErrNotFound, "github endpoint not found")
return params.ForgeEndpoint{}, errors.Wrap(runnerErrors.ErrNotFound, "github endpoint not found")
}
return params.GithubEndpoint{}, errors.Wrap(err, "fetching github endpoint")
return params.ForgeEndpoint{}, errors.Wrap(err, "fetching github endpoint")
}
return s.sqlToCommonGithubEndpoint(endpoint)
@ -242,12 +159,12 @@ func (s *sqlDatabase) DeleteGithubEndpoint(_ context.Context, name string) (err
defer func() {
if err == nil {
s.sendNotify(common.GithubEndpointEntityType, common.DeleteOperation, params.GithubEndpoint{Name: name})
s.sendNotify(common.GithubEndpointEntityType, common.DeleteOperation, params.ForgeEndpoint{Name: name})
}
}()
err = s.conn.Transaction(func(tx *gorm.DB) error {
var endpoint GithubEndpoint
if err := tx.Where("name = ?", name).First(&endpoint).Error; err != nil {
if err := tx.Where("name = ? and endpoint_type = ?", name, params.GithubEndpointType).First(&endpoint).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil
}
@ -283,7 +200,7 @@ func (s *sqlDatabase) DeleteGithubEndpoint(_ context.Context, name string) (err
}
if credsCount > 0 || repoCnt > 0 || orgCnt > 0 || entCnt > 0 {
return errors.New("cannot delete endpoint with associated entities")
return runnerErrors.NewBadRequestError("cannot delete endpoint with associated entities")
}
if err := tx.Unscoped().Delete(&endpoint).Error; err != nil {
@ -297,13 +214,13 @@ func (s *sqlDatabase) DeleteGithubEndpoint(_ context.Context, name string) (err
return nil
}
func (s *sqlDatabase) CreateGithubCredentials(ctx context.Context, param params.CreateGithubCredentialsParams) (ghCreds params.GithubCredentials, err error) {
func (s *sqlDatabase) CreateGithubCredentials(ctx context.Context, param params.CreateGithubCredentialsParams) (ghCreds params.ForgeCredentials, err error) {
userID, err := getUIDFromContext(ctx)
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "creating github credentials")
return params.ForgeCredentials{}, errors.Wrap(err, "creating github credentials")
}
if param.Endpoint == "" {
return params.GithubCredentials{}, errors.Wrap(runnerErrors.ErrBadRequest, "endpoint name is required")
return params.ForgeCredentials{}, errors.Wrap(runnerErrors.ErrBadRequest, "endpoint name is required")
}
defer func() {
@ -314,7 +231,7 @@ func (s *sqlDatabase) CreateGithubCredentials(ctx context.Context, param params.
var creds GithubCredentials
err = s.conn.Transaction(func(tx *gorm.DB) error {
var endpoint GithubEndpoint
if err := tx.Where("name = ?", param.Endpoint).First(&endpoint).Error; err != nil {
if err := tx.Where("name = ? and endpoint_type = ?", param.Endpoint, params.GithubEndpointType).First(&endpoint).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return errors.Wrap(runnerErrors.ErrNotFound, "github endpoint not found")
}
@ -328,9 +245,9 @@ func (s *sqlDatabase) CreateGithubCredentials(ctx context.Context, param params.
var data []byte
var err error
switch param.AuthType {
case params.GithubAuthTypePAT:
case params.ForgeAuthTypePAT:
data, err = s.marshalAndSeal(param.PAT)
case params.GithubAuthTypeApp:
case params.ForgeAuthTypeApp:
data, err = s.marshalAndSeal(param.App)
default:
return errors.Wrap(runnerErrors.ErrBadRequest, "invalid auth type")
@ -357,11 +274,11 @@ func (s *sqlDatabase) CreateGithubCredentials(ctx context.Context, param params.
return nil
})
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "creating github credentials")
return params.ForgeCredentials{}, errors.Wrap(err, "creating github credentials")
}
ghCreds, err = s.sqlToCommonGithubCredentials(creds)
ghCreds, err = s.sqlToCommonForgeCredentials(creds)
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "converting github credentials")
return params.ForgeCredentials{}, errors.Wrap(err, "converting github credentials")
}
return ghCreds, nil
}
@ -373,8 +290,11 @@ func (s *sqlDatabase) getGithubCredentialsByName(ctx context.Context, tx *gorm.D
if detailed {
q = q.
Preload("Repositories").
Preload("Repositories.Credentials").
Preload("Organizations").
Preload("Enterprises")
Preload("Organizations.Credentials").
Preload("Enterprises").
Preload("Enterprises.Credentials")
}
userID, err := getUIDFromContext(ctx)
@ -394,30 +314,32 @@ func (s *sqlDatabase) getGithubCredentialsByName(ctx context.Context, tx *gorm.D
return creds, nil
}
func (s *sqlDatabase) GetGithubCredentialsByName(ctx context.Context, name string, detailed bool) (params.GithubCredentials, error) {
func (s *sqlDatabase) GetGithubCredentialsByName(ctx context.Context, name string, detailed bool) (params.ForgeCredentials, error) {
creds, err := s.getGithubCredentialsByName(ctx, s.conn, name, detailed)
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "fetching github credentials")
return params.ForgeCredentials{}, errors.Wrap(err, "fetching github credentials")
}
return s.sqlToCommonGithubCredentials(creds)
return s.sqlToCommonForgeCredentials(creds)
}
func (s *sqlDatabase) GetGithubCredentials(ctx context.Context, id uint, detailed bool) (params.GithubCredentials, error) {
func (s *sqlDatabase) GetGithubCredentials(ctx context.Context, id uint, detailed bool) (params.ForgeCredentials, error) {
var creds GithubCredentials
q := s.conn.Preload("Endpoint")
if detailed {
q = q.
Preload("Repositories").
Preload("Repositories.Credentials").
Preload("Organizations").
Preload("Enterprises")
Preload("Organizations.Credentials").
Preload("Enterprises").
Preload("Enterprises.Credentials")
}
if !auth.IsAdmin(ctx) {
userID, err := getUIDFromContext(ctx)
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "fetching github credentials")
return params.ForgeCredentials{}, errors.Wrap(err, "fetching github credentials")
}
q = q.Where("user_id = ?", userID)
}
@ -425,15 +347,15 @@ func (s *sqlDatabase) GetGithubCredentials(ctx context.Context, id uint, detaile
err := q.Where("id = ?", id).First(&creds).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return params.GithubCredentials{}, errors.Wrap(runnerErrors.ErrNotFound, "github credentials not found")
return params.ForgeCredentials{}, errors.Wrap(runnerErrors.ErrNotFound, "github credentials not found")
}
return params.GithubCredentials{}, errors.Wrap(err, "fetching github credentials")
return params.ForgeCredentials{}, errors.Wrap(err, "fetching github credentials")
}
return s.sqlToCommonGithubCredentials(creds)
return s.sqlToCommonForgeCredentials(creds)
}
func (s *sqlDatabase) ListGithubCredentials(ctx context.Context) ([]params.GithubCredentials, error) {
func (s *sqlDatabase) ListGithubCredentials(ctx context.Context) ([]params.ForgeCredentials, error) {
q := s.conn.Preload("Endpoint")
if !auth.IsAdmin(ctx) {
userID, err := getUIDFromContext(ctx)
@ -449,9 +371,9 @@ func (s *sqlDatabase) ListGithubCredentials(ctx context.Context) ([]params.Githu
return nil, errors.Wrap(err, "fetching github credentials")
}
var ret []params.GithubCredentials
var ret []params.ForgeCredentials
for _, c := range creds {
commonCreds, err := s.sqlToCommonGithubCredentials(c)
commonCreds, err := s.sqlToCommonForgeCredentials(c)
if err != nil {
return nil, errors.Wrap(err, "converting github credentials")
}
@ -460,7 +382,7 @@ func (s *sqlDatabase) ListGithubCredentials(ctx context.Context) ([]params.Githu
return ret, nil
}
func (s *sqlDatabase) UpdateGithubCredentials(ctx context.Context, id uint, param params.UpdateGithubCredentialsParams) (ghCreds params.GithubCredentials, err error) {
func (s *sqlDatabase) UpdateGithubCredentials(ctx context.Context, id uint, param params.UpdateGithubCredentialsParams) (ghCreds params.ForgeCredentials, err error) {
defer func() {
if err == nil {
s.sendNotify(common.GithubCredentialsEntityType, common.UpdateOperation, ghCreds)
@ -494,7 +416,7 @@ func (s *sqlDatabase) UpdateGithubCredentials(ctx context.Context, id uint, para
var data []byte
var err error
switch creds.AuthType {
case params.GithubAuthTypePAT:
case params.ForgeAuthTypePAT:
if param.PAT != nil {
data, err = s.marshalAndSeal(param.PAT)
}
@ -502,7 +424,7 @@ func (s *sqlDatabase) UpdateGithubCredentials(ctx context.Context, id uint, para
if param.App != nil {
return errors.Wrap(runnerErrors.ErrBadRequest, "cannot update app credentials for PAT")
}
case params.GithubAuthTypeApp:
case params.ForgeAuthTypeApp:
if param.App != nil {
data, err = s.marshalAndSeal(param.App)
}
@ -529,12 +451,12 @@ func (s *sqlDatabase) UpdateGithubCredentials(ctx context.Context, id uint, para
return nil
})
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "updating github credentials")
return params.ForgeCredentials{}, errors.Wrap(err, "updating github credentials")
}
ghCreds, err = s.sqlToCommonGithubCredentials(creds)
ghCreds, err = s.sqlToCommonForgeCredentials(creds)
if err != nil {
return params.GithubCredentials{}, errors.Wrap(err, "converting github credentials")
return params.ForgeCredentials{}, errors.Wrap(err, "converting github credentials")
}
return ghCreds, nil
}
@ -543,7 +465,7 @@ func (s *sqlDatabase) DeleteGithubCredentials(ctx context.Context, id uint) (err
var name string
defer func() {
if err == nil {
s.sendNotify(common.GithubCredentialsEntityType, common.DeleteOperation, params.GithubCredentials{ID: id, Name: name})
s.sendNotify(common.GithubCredentialsEntityType, common.DeleteOperation, params.ForgeCredentials{ID: id, Name: name})
}
}()
err = s.conn.Transaction(func(tx *gorm.DB) error {

View file

@ -33,13 +33,14 @@ import (
)
const (
testUploadBaseURL string = "https://uploads.example.com"
testBaseURL string = "https://example.com"
testAPIBaseURL string = "https://api.example.com"
testEndpointName string = "test-endpoint"
testEndpointDescription string = "test description"
testCredsName string = "test-creds"
testCredsDescription string = "test creds"
testUploadBaseURL string = "https://uploads.example.com"
testBaseURL string = "https://example.com"
testAPIBaseURL string = "https://api.example.com"
testEndpointName string = "test-endpoint"
alternetTestEndpointName string = "test-endpoint-alternate"
testEndpointDescription string = "test description"
testCredsName string = "test-creds"
testCredsDescription string = "test creds"
)
type GithubTestSuite struct {
@ -266,7 +267,7 @@ func (s *GithubTestSuite) TestCreateCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -290,7 +291,7 @@ func (s *GithubTestSuite) TestCreateCredentialsFailsOnDuplicateCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -320,7 +321,7 @@ func (s *GithubTestSuite) TestNormalUsersCanOnlySeeTheirOwnCredentialsAdminCanSe
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -376,7 +377,7 @@ func (s *GithubTestSuite) TestGetGithubCredentialsByNameReturnsOnlyCurrentUserCr
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -421,7 +422,7 @@ func (s *GithubTestSuite) TestGetGithubCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -451,7 +452,7 @@ func (s *GithubTestSuite) TestDeleteGithubCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -478,7 +479,7 @@ func (s *GithubTestSuite) TestDeleteGithubCredentialsByNonAdminUser() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test-creds4",
},
@ -523,7 +524,7 @@ func (s *GithubTestSuite) TestDeleteCredentialsFailsIfReposOrgsOrEntitiesUseIt()
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -533,7 +534,7 @@ func (s *GithubTestSuite) TestDeleteCredentialsFailsIfReposOrgsOrEntitiesUseIt()
s.Require().NoError(err)
s.Require().NotNil(creds)
repo, err := s.db.CreateRepository(ctx, "test-owner", "test-repo", creds.Name, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
repo, err := s.db.CreateRepository(ctx, "test-owner", "test-repo", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotNil(repo)
@ -544,7 +545,7 @@ func (s *GithubTestSuite) TestDeleteCredentialsFailsIfReposOrgsOrEntitiesUseIt()
err = s.db.DeleteRepository(ctx, repo.ID)
s.Require().NoError(err)
org, err := s.db.CreateOrganization(ctx, "test-org", creds.Name, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
org, err := s.db.CreateOrganization(ctx, "test-org", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotNil(org)
@ -555,7 +556,7 @@ func (s *GithubTestSuite) TestDeleteCredentialsFailsIfReposOrgsOrEntitiesUseIt()
err = s.db.DeleteOrganization(ctx, org.ID)
s.Require().NoError(err)
enterprise, err := s.db.CreateEnterprise(ctx, "test-enterprise", creds.Name, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
enterprise, err := s.db.CreateEnterprise(ctx, "test-enterprise", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotNil(enterprise)
@ -581,7 +582,7 @@ func (s *GithubTestSuite) TestUpdateCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -616,7 +617,7 @@ func (s *GithubTestSuite) TestUpdateGithubCredentialsFailIfWrongCredentialTypeIs
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test",
},
@ -643,7 +644,7 @@ func (s *GithubTestSuite) TestUpdateGithubCredentialsFailIfWrongCredentialTypeIs
Name: "test-credsApp",
Description: "test credsApp",
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypeApp,
AuthType: params.ForgeAuthTypeApp,
App: params.GithubApp{
AppID: 1,
InstallationID: 2,
@ -688,7 +689,7 @@ func (s *GithubTestSuite) TestUpdateCredentialsFailsIfCredentialsAreOwnedByNonAd
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test-creds5",
},
@ -717,7 +718,7 @@ func (s *GithubTestSuite) TestAdminUserCanUpdateAnyGithubCredentials() {
Name: testCredsName,
Description: testCredsDescription,
Endpoint: defaultGithubEndpoint,
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test-creds5",
},
@ -737,6 +738,68 @@ func (s *GithubTestSuite) TestAdminUserCanUpdateAnyGithubCredentials() {
s.Require().Equal(newDescription, newCreds.Description)
}
func (s *GithubTestSuite) TestDeleteGithubEndpointFailsWithOrgsReposOrCredentials() {
ctx := garmTesting.ImpersonateAdminContext(context.Background(), s.db, s.T())
endpointParams := params.CreateGithubEndpointParams{
Name: "deleteme",
Description: testEndpointDescription,
APIBaseURL: testAPIBaseURL,
BaseURL: testBaseURL,
}
ep, err := s.db.CreateGithubEndpoint(ctx, endpointParams)
s.Require().NoError(err)
s.Require().NotNil(ep)
credParams := params.CreateGithubCredentialsParams{
Name: testCredsName,
Description: testCredsDescription,
Endpoint: ep.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "test-creds5",
},
}
creds, err := s.db.CreateGithubCredentials(ctx, credParams)
s.Require().NoError(err)
s.Require().NotNil(creds)
repo, err := s.db.CreateRepository(ctx, "test-owner", "test-repo", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotNil(repo)
badRequest := &runnerErrors.BadRequestError{}
err = s.db.DeleteGithubEndpoint(ctx, ep.Name)
s.Require().Error(err)
s.Require().ErrorAs(err, &badRequest)
err = s.db.DeleteRepository(ctx, repo.ID)
s.Require().NoError(err)
org, err := s.db.CreateOrganization(ctx, "test-org", creds, "superSecret@123BlaBla", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotNil(org)
err = s.db.DeleteGithubEndpoint(ctx, ep.Name)
s.Require().Error(err)
s.Require().ErrorAs(err, &badRequest)
err = s.db.DeleteOrganization(ctx, org.ID)
s.Require().NoError(err)
err = s.db.DeleteGithubCredentials(ctx, creds.ID)
s.Require().NoError(err)
err = s.db.DeleteGithubEndpoint(ctx, ep.Name)
s.Require().NoError(err)
_, err = s.db.GetGithubEndpoint(ctx, ep.Name)
s.Require().Error(err)
s.Require().ErrorIs(err, runnerErrors.ErrNotFound)
}
func TestGithubTestSuite(t *testing.T) {
suite.Run(t, new(GithubTestSuite))
}
@ -836,10 +899,10 @@ func TestCredentialsAndEndpointMigration(t *testing.T) {
t.Fatalf("expected ghes-test to be associated with example.com endpoint, got %s", creds[1].Endpoint.Name)
}
if creds[0].AuthType != params.GithubAuthTypePAT {
if creds[0].AuthType != params.ForgeAuthTypePAT {
t.Fatalf("expected test-creds to have PAT auth type, got %s", creds[0].AuthType)
}
if creds[1].AuthType != params.GithubAuthTypeApp {
if creds[1].AuthType != params.ForgeAuthTypeApp {
t.Fatalf("expected ghes-test to have App auth type, got %s", creds[1].AuthType)
}
if len(creds[0].CredentialsPayload) == 0 {

View file

@ -84,7 +84,7 @@ func (s *InstancesTestSuite) SetupTest() {
creds := garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), githubEndpoint)
// create an organization for testing purposes
org, err := s.Store.CreateOrganization(s.adminCtx, "test-org", creds.Name, "test-webhookSecret", params.PoolBalancerTypeRoundRobin)
org, err := s.Store.CreateOrganization(s.adminCtx, "test-org", creds, "test-webhookSecret", params.PoolBalancerTypeRoundRobin)
if err != nil {
s.FailNow(fmt.Sprintf("failed to create org: %s", err))
}

View file

@ -1,3 +1,17 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package sql
import (
@ -306,7 +320,7 @@ func (s *sqlDatabase) ListJobsByStatus(_ context.Context, status params.JobStatu
}
// ListEntityJobsByStatus lists all jobs for a given entity type and id.
func (s *sqlDatabase) ListEntityJobsByStatus(_ context.Context, entityType params.GithubEntityType, entityID string, status params.JobStatus) ([]params.Job, error) {
func (s *sqlDatabase) ListEntityJobsByStatus(_ context.Context, entityType params.ForgeEntityType, entityID string, status params.JobStatus) ([]params.Job, error) {
u, err := uuid.Parse(entityID)
if err != nil {
return nil, err
@ -316,11 +330,11 @@ func (s *sqlDatabase) ListEntityJobsByStatus(_ context.Context, entityType param
query := s.conn.Model(&WorkflowJob{}).Preload("Instance").Where("status = ?", status)
switch entityType {
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
query = query.Where("org_id = ?", u)
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
query = query.Where("repo_id = ?", u)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
query = query.Where("enterprise_id = ?", u)
}

View file

@ -1,4 +1,4 @@
// Copyright 2022 Cloudbase Solutions SRL
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
@ -46,6 +46,22 @@ func (b *Base) BeforeCreate(_ *gorm.DB) error {
return nil
}
type ControllerInfo struct {
Base
ControllerID uuid.UUID
CallbackURL string
MetadataURL string
WebhookBaseURL string
// MinimumJobAgeBackoff is the minimum time that a job must be in the queue
// before GARM will attempt to allocate a runner to service it. This backoff
// is useful if you have idle runners in various pools that could potentially
// pick up the job. GARM would allow this amount of time for runners to react
// before spinning up a new one and potentially having to scale down later.
MinimumJobAgeBackoff uint
}
type Tag struct {
Base
@ -152,11 +168,12 @@ type RepositoryEvent struct {
type Repository struct {
Base
CredentialsName string
CredentialsID *uint `gorm:"index"`
Credentials GithubCredentials `gorm:"foreignKey:CredentialsID;constraint:OnDelete:SET NULL"`
GiteaCredentialsID *uint `gorm:"index"`
GiteaCredentials GiteaCredentials `gorm:"foreignKey:GiteaCredentialsID;constraint:OnDelete:SET NULL"`
Owner string `gorm:"index:idx_owner_nocase,unique,collate:nocase"`
Name string `gorm:"index:idx_owner_nocase,unique,collate:nocase"`
WebhookSecret []byte
@ -168,7 +185,7 @@ type Repository struct {
EndpointName *string `gorm:"index:idx_owner_nocase,unique,collate:nocase"`
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName;constraint:OnDelete:SET NULL"`
Events []RepositoryEvent `gorm:"foreignKey:RepoID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
Events []*RepositoryEvent `gorm:"foreignKey:RepoID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
}
type OrganizationEvent struct {
@ -184,11 +201,12 @@ type OrganizationEvent struct {
type Organization struct {
Base
CredentialsName string
CredentialsID *uint `gorm:"index"`
Credentials GithubCredentials `gorm:"foreignKey:CredentialsID;constraint:OnDelete:SET NULL"`
GiteaCredentialsID *uint `gorm:"index"`
GiteaCredentials GiteaCredentials `gorm:"foreignKey:GiteaCredentialsID;constraint:OnDelete:SET NULL"`
Name string `gorm:"index:idx_org_name_nocase,collate:nocase"`
WebhookSecret []byte
Pools []Pool `gorm:"foreignKey:OrgID"`
@ -199,7 +217,7 @@ type Organization struct {
EndpointName *string `gorm:"index:idx_org_name_nocase,collate:nocase"`
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName;constraint:OnDelete:SET NULL"`
Events []OrganizationEvent `gorm:"foreignKey:OrgID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
Events []*OrganizationEvent `gorm:"foreignKey:OrgID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
}
type EnterpriseEvent struct {
@ -216,8 +234,6 @@ type EnterpriseEvent struct {
type Enterprise struct {
Base
CredentialsName string
CredentialsID *uint `gorm:"index"`
Credentials GithubCredentials `gorm:"foreignKey:CredentialsID;constraint:OnDelete:SET NULL"`
@ -231,7 +247,7 @@ type Enterprise struct {
EndpointName *string `gorm:"index:idx_ent_name_nocase,collate:nocase"`
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName;constraint:OnDelete:SET NULL"`
Events []EnterpriseEvent `gorm:"foreignKey:EnterpriseID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
Events []*EnterpriseEvent `gorm:"foreignKey:EnterpriseID;constraint:OnDelete:CASCADE,OnUpdate:CASCADE;"`
}
type Address struct {
@ -300,22 +316,6 @@ type User struct {
Enabled bool
}
type ControllerInfo struct {
Base
ControllerID uuid.UUID
CallbackURL string
MetadataURL string
WebhookBaseURL string
// MinimumJobAgeBackoff is the minimum time that a job must be in the queue
// before GARM will attempt to allocate a runner to service it. This backoff
// is useful if you have idle runners in various pools that could potentially
// pick up the job. GARM would allow this amount of time for runners to react
// before spinning up a new one and potentially having to scale down later.
MinimumJobAgeBackoff uint
}
type WorkflowJob struct {
// ID is the ID of the job.
ID int64 `gorm:"index"`
@ -381,6 +381,8 @@ type GithubEndpoint struct {
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
EndpointType params.EndpointType `gorm:"index:idx_endpoint_type"`
Description string `gorm:"type:text"`
APIBaseURL string `gorm:"type:text collate nocase"`
UploadBaseURL string `gorm:"type:text collate nocase"`
@ -395,9 +397,9 @@ type GithubCredentials struct {
UserID *uuid.UUID `gorm:"index:idx_github_credentials,unique"`
User User `gorm:"foreignKey:UserID"`
Description string `gorm:"type:text"`
AuthType params.GithubAuthType `gorm:"index"`
Payload []byte `gorm:"type:longblob"`
Description string `gorm:"type:text"`
AuthType params.ForgeAuthType `gorm:"index"`
Payload []byte `gorm:"type:longblob"`
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName"`
EndpointName *string `gorm:"index"`
@ -406,3 +408,21 @@ type GithubCredentials struct {
Organizations []Organization `gorm:"foreignKey:CredentialsID"`
Enterprises []Enterprise `gorm:"foreignKey:CredentialsID"`
}
type GiteaCredentials struct {
gorm.Model
Name string `gorm:"index:idx_gitea_credentials,unique;type:varchar(64) collate nocase"`
UserID *uuid.UUID `gorm:"index:idx_gitea_credentials,unique"`
User User `gorm:"foreignKey:UserID"`
Description string `gorm:"type:text"`
AuthType params.ForgeAuthType `gorm:"index"`
Payload []byte `gorm:"type:longblob"`
Endpoint GithubEndpoint `gorm:"foreignKey:EndpointName"`
EndpointName *string `gorm:"index"`
Repositories []Repository `gorm:"foreignKey:GiteaCredentialsID"`
Organizations []Organization `gorm:"foreignKey:GiteaCredentialsID"`
}

View file

@ -29,7 +29,7 @@ import (
"github.com/cloudbase/garm/params"
)
func (s *sqlDatabase) CreateOrganization(ctx context.Context, name, credentialsName, webhookSecret string, poolBalancerType params.PoolBalancerType) (org params.Organization, err error) {
func (s *sqlDatabase) CreateOrganization(ctx context.Context, name string, credentials params.ForgeCredentials, webhookSecret string, poolBalancerType params.PoolBalancerType) (param params.Organization, err error) {
if webhookSecret == "" {
return params.Organization{}, errors.New("creating org: missing secret")
}
@ -40,49 +40,47 @@ func (s *sqlDatabase) CreateOrganization(ctx context.Context, name, credentialsN
defer func() {
if err == nil {
s.sendNotify(common.OrganizationEntityType, common.CreateOperation, org)
s.sendNotify(common.OrganizationEntityType, common.CreateOperation, param)
}
}()
newOrg := Organization{
Name: name,
WebhookSecret: secret,
CredentialsName: credentialsName,
PoolBalancerType: poolBalancerType,
}
err = s.conn.Transaction(func(tx *gorm.DB) error {
creds, err := s.getGithubCredentialsByName(ctx, tx, credentialsName, false)
if err != nil {
return errors.Wrap(err, "creating org")
switch credentials.ForgeType {
case params.GithubEndpointType:
newOrg.CredentialsID = &credentials.ID
case params.GiteaEndpointType:
newOrg.GiteaCredentialsID = &credentials.ID
default:
return errors.Wrap(runnerErrors.ErrBadRequest, "unsupported credentials type")
}
if creds.EndpointName == nil {
return errors.Wrap(runnerErrors.ErrUnprocessable, "credentials have no endpoint")
}
newOrg.CredentialsID = &creds.ID
newOrg.CredentialsName = creds.Name
newOrg.EndpointName = creds.EndpointName
newOrg.EndpointName = &credentials.Endpoint.Name
q := tx.Create(&newOrg)
if q.Error != nil {
return errors.Wrap(q.Error, "creating org")
}
newOrg.Credentials = creds
newOrg.Endpoint = creds.Endpoint
return nil
})
if err != nil {
return params.Organization{}, errors.Wrap(err, "creating org")
}
org, err = s.sqlToCommonOrganization(newOrg, true)
org, err := s.getOrgByID(ctx, s.conn, newOrg.ID.String(), "Pools", "Endpoint", "Credentials", "GiteaCredentials", "Credentials.Endpoint", "GiteaCredentials.Endpoint")
if err != nil {
return params.Organization{}, errors.Wrap(err, "creating org")
}
org.WebhookSecret = webhookSecret
return org, nil
param, err = s.sqlToCommonOrganization(org, true)
if err != nil {
return params.Organization{}, errors.Wrap(err, "creating org")
}
return param, nil
}
func (s *sqlDatabase) GetOrganization(ctx context.Context, name, endpointName string) (params.Organization, error) {
@ -103,7 +101,9 @@ func (s *sqlDatabase) ListOrganizations(_ context.Context) ([]params.Organizatio
var orgs []Organization
q := s.conn.
Preload("Credentials").
Preload("GiteaCredentials").
Preload("Credentials.Endpoint").
Preload("GiteaCredentials.Endpoint").
Preload("Endpoint").
Find(&orgs)
if q.Error != nil {
@ -123,7 +123,7 @@ func (s *sqlDatabase) ListOrganizations(_ context.Context) ([]params.Organizatio
}
func (s *sqlDatabase) DeleteOrganization(ctx context.Context, orgID string) (err error) {
org, err := s.getOrgByID(ctx, s.conn, orgID, "Endpoint", "Credentials", "Credentials.Endpoint")
org, err := s.getOrgByID(ctx, s.conn, orgID, "Endpoint", "Credentials", "Credentials.Endpoint", "GiteaCredentials", "GiteaCredentials.Endpoint")
if err != nil {
return errors.Wrap(err, "fetching org")
}
@ -166,7 +166,6 @@ func (s *sqlDatabase) UpdateOrganization(ctx context.Context, orgID string, para
}
if param.CredentialsName != "" {
org.CredentialsName = param.CredentialsName
creds, err = s.getGithubCredentialsByName(ctx, tx, param.CredentialsName, false)
if err != nil {
return errors.Wrap(err, "fetching credentials")
@ -204,7 +203,7 @@ func (s *sqlDatabase) UpdateOrganization(ctx context.Context, orgID string, para
return params.Organization{}, errors.Wrap(err, "saving org")
}
org, err = s.getOrgByID(ctx, s.conn, orgID, "Endpoint", "Credentials", "Credentials.Endpoint")
org, err = s.getOrgByID(ctx, s.conn, orgID, "Endpoint", "Credentials", "Credentials.Endpoint", "GiteaCredentials", "GiteaCredentials.Endpoint")
if err != nil {
return params.Organization{}, errors.Wrap(err, "updating enterprise")
}
@ -216,7 +215,7 @@ func (s *sqlDatabase) UpdateOrganization(ctx context.Context, orgID string, para
}
func (s *sqlDatabase) GetOrganizationByID(ctx context.Context, orgID string) (params.Organization, error) {
org, err := s.getOrgByID(ctx, s.conn, orgID, "Pools", "Credentials", "Endpoint", "Credentials.Endpoint")
org, err := s.getOrgByID(ctx, s.conn, orgID, "Pools", "Credentials", "Endpoint", "Credentials.Endpoint", "GiteaCredentials", "GiteaCredentials.Endpoint")
if err != nil {
return params.Organization{}, errors.Wrap(err, "fetching org")
}
@ -257,7 +256,9 @@ func (s *sqlDatabase) getOrg(_ context.Context, name, endpointName string) (Orga
q := s.conn.Where("name = ? COLLATE NOCASE and endpoint_name = ? COLLATE NOCASE", name, endpointName).
Preload("Credentials").
Preload("GiteaCredentials").
Preload("Credentials.Endpoint").
Preload("GiteaCredentials.Endpoint").
Preload("Endpoint").
First(&org)
if q.Error != nil {

View file

@ -53,9 +53,11 @@ type OrgTestSuite struct {
adminCtx context.Context
adminUserID string
testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint
testCreds params.ForgeCredentials
testCredsGitea params.ForgeCredentials
secondaryTestCreds params.ForgeCredentials
githubEndpoint params.ForgeEndpoint
giteaEndpoint params.ForgeEndpoint
}
func (s *OrgTestSuite) equalInstancesByName(expected, actual []params.Instance) {
@ -91,7 +93,9 @@ func (s *OrgTestSuite) SetupTest() {
s.Require().NotEmpty(s.adminUserID)
s.githubEndpoint = garmTesting.CreateDefaultGithubEndpoint(adminCtx, db, s.T())
s.giteaEndpoint = garmTesting.CreateDefaultGiteaEndpoint(adminCtx, db, s.T())
s.testCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), s.githubEndpoint)
s.testCredsGitea = garmTesting.CreateTestGiteaCredentials(adminCtx, "new-creds", db, s.T(), s.giteaEndpoint)
s.secondaryTestCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "secondary-creds", db, s.T(), s.githubEndpoint)
// create some organization objects in the database, for testing purposes
@ -100,7 +104,7 @@ func (s *OrgTestSuite) SetupTest() {
org, err := db.CreateOrganization(
s.adminCtx,
fmt.Sprintf("test-org-%d", i),
s.testCreds.Name,
s.testCreds,
fmt.Sprintf("test-webhook-secret-%d", i),
params.PoolBalancerTypeRoundRobin,
)
@ -179,7 +183,7 @@ func (s *OrgTestSuite) TestCreateOrganization() {
org, err := s.Store.CreateOrganization(
s.adminCtx,
s.Fixtures.CreateOrgParams.Name,
s.Fixtures.CreateOrgParams.CredentialsName,
s.testCreds,
s.Fixtures.CreateOrgParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin)
@ -192,6 +196,62 @@ func (s *OrgTestSuite) TestCreateOrganization() {
s.Require().Equal(storeOrg.Name, org.Name)
s.Require().Equal(storeOrg.Credentials.Name, org.Credentials.Name)
s.Require().Equal(storeOrg.WebhookSecret, org.WebhookSecret)
entity, err := org.GetEntity()
s.Require().Nil(err)
s.Require().Equal(entity.EntityType, params.ForgeEntityTypeOrganization)
s.Require().Equal(entity.ID, org.ID)
forgeType, err := entity.GetForgeType()
s.Require().Nil(err)
s.Require().Equal(forgeType, params.GithubEndpointType)
}
func (s *OrgTestSuite) TestCreateOrgForGitea() {
// call tested function
org, err := s.Store.CreateOrganization(
s.adminCtx,
s.Fixtures.CreateOrgParams.Name,
s.testCredsGitea,
s.Fixtures.CreateOrgParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin)
// assertions
s.Require().Nil(err)
storeOrg, err := s.Store.GetOrganizationByID(s.adminCtx, org.ID)
if err != nil {
s.FailNow(fmt.Sprintf("failed to get organization by id: %v", err))
}
s.Require().Equal(storeOrg.Name, org.Name)
s.Require().Equal(storeOrg.Credentials.Name, org.Credentials.Name)
s.Require().Equal(storeOrg.WebhookSecret, org.WebhookSecret)
entity, err := org.GetEntity()
s.Require().Nil(err)
s.Require().Equal(entity.EntityType, params.ForgeEntityTypeOrganization)
s.Require().Equal(entity.ID, org.ID)
forgeType, err := entity.GetForgeType()
s.Require().Nil(err)
s.Require().Equal(forgeType, params.GiteaEndpointType)
}
func (s *OrgTestSuite) TestCreateOrganizationInvalidForgeType() {
credentials := params.ForgeCredentials{
Name: "test-creds",
Endpoint: s.githubEndpoint,
ID: 99,
ForgeType: params.EndpointType("invalid-forge-type"),
}
_, err := s.Store.CreateOrganization(
s.adminCtx,
s.Fixtures.CreateOrgParams.Name,
credentials,
s.Fixtures.CreateOrgParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin)
s.Require().NotNil(err)
s.Require().Equal("creating org: unsupported credentials type: invalid request", err.Error())
}
func (s *OrgTestSuite) TestCreateOrganizationInvalidDBPassphrase() {
@ -210,7 +270,7 @@ func (s *OrgTestSuite) TestCreateOrganizationInvalidDBPassphrase() {
_, err = sqlDB.CreateOrganization(
s.adminCtx,
s.Fixtures.CreateOrgParams.Name,
s.Fixtures.CreateOrgParams.CredentialsName,
s.testCreds,
s.Fixtures.CreateOrgParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin)
@ -220,15 +280,6 @@ func (s *OrgTestSuite) TestCreateOrganizationInvalidDBPassphrase() {
func (s *OrgTestSuite) TestCreateOrganizationDBCreateErr() {
s.Fixtures.SQLMock.ExpectBegin()
s.Fixtures.SQLMock.
ExpectQuery(regexp.QuoteMeta("SELECT * FROM `github_credentials` WHERE user_id = ? AND name = ? AND `github_credentials`.`deleted_at` IS NULL ORDER BY `github_credentials`.`id` LIMIT ?")).
WithArgs(s.adminUserID, s.Fixtures.Orgs[0].CredentialsName, 1).
WillReturnRows(sqlmock.NewRows([]string{"id", "endpoint_name"}).
AddRow(s.testCreds.ID, s.githubEndpoint.Name))
s.Fixtures.SQLMock.ExpectQuery(regexp.QuoteMeta("SELECT * FROM `github_endpoints` WHERE `github_endpoints`.`name` = ? AND `github_endpoints`.`deleted_at` IS NULL")).
WithArgs(s.testCreds.Endpoint.Name).
WillReturnRows(sqlmock.NewRows([]string{"name"}).
AddRow(s.githubEndpoint.Name))
s.Fixtures.SQLMock.
ExpectExec(regexp.QuoteMeta("INSERT INTO `organizations`")).
WillReturnError(fmt.Errorf("creating org mock error"))
@ -237,7 +288,7 @@ func (s *OrgTestSuite) TestCreateOrganizationDBCreateErr() {
_, err := s.StoreSQLMocked.CreateOrganization(
s.adminCtx,
s.Fixtures.CreateOrgParams.Name,
s.Fixtures.CreateOrgParams.CredentialsName,
s.testCreds,
s.Fixtures.CreateOrgParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin)
@ -492,9 +543,9 @@ func (s *OrgTestSuite) TestCreateOrganizationPoolMissingTags() {
}
func (s *OrgTestSuite) TestCreateOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
_, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams)
@ -640,9 +691,9 @@ func (s *OrgTestSuite) TestListOrgPools() {
}
func (s *OrgTestSuite) TestListOrgPoolsInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
_, err := s.Store.ListEntityPools(s.adminCtx, entity)
@ -665,9 +716,9 @@ func (s *OrgTestSuite) TestGetOrganizationPool() {
}
func (s *OrgTestSuite) TestGetOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
_, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -691,9 +742,9 @@ func (s *OrgTestSuite) TestDeleteOrganizationPool() {
}
func (s *OrgTestSuite) TestDeleteOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -748,9 +799,9 @@ func (s *OrgTestSuite) TestListOrgInstances() {
}
func (s *OrgTestSuite) TestListOrgInstancesInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
_, err := s.Store.ListEntityInstances(s.adminCtx, entity)
@ -776,9 +827,9 @@ func (s *OrgTestSuite) TestUpdateOrganizationPool() {
}
func (s *OrgTestSuite) TestUpdateOrganizationPoolInvalidOrgID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-org-id",
EntityType: params.GithubEntityTypeOrganization,
EntityType: params.ForgeEntityTypeOrganization,
}
_, err := s.Store.UpdateEntityPool(s.adminCtx, entity, "dummy-pool-id", s.Fixtures.UpdatePoolParams)

View file

@ -86,7 +86,7 @@ func (s *sqlDatabase) DeletePoolByID(_ context.Context, poolID string) (err erro
return nil
}
func (s *sqlDatabase) getEntityPool(tx *gorm.DB, entityType params.GithubEntityType, entityID, poolID string, preload ...string) (Pool, error) {
func (s *sqlDatabase) getEntityPool(tx *gorm.DB, entityType params.ForgeEntityType, entityID, poolID string, preload ...string) (Pool, error) {
if entityID == "" {
return Pool{}, errors.Wrap(runnerErrors.ErrBadRequest, "missing entity id")
}
@ -99,13 +99,13 @@ func (s *sqlDatabase) getEntityPool(tx *gorm.DB, entityType params.GithubEntityT
var fieldName string
var entityField string
switch entityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
entityField = repositoryFieldName
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
entityField = organizationFieldName
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
entityField = enterpriseFieldName
default:
@ -135,7 +135,7 @@ func (s *sqlDatabase) getEntityPool(tx *gorm.DB, entityType params.GithubEntityT
return pool, nil
}
func (s *sqlDatabase) listEntityPools(tx *gorm.DB, entityType params.GithubEntityType, entityID string, preload ...string) ([]Pool, error) {
func (s *sqlDatabase) listEntityPools(tx *gorm.DB, entityType params.ForgeEntityType, entityID string, preload ...string) ([]Pool, error) {
if _, err := uuid.Parse(entityID); err != nil {
return nil, errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
}
@ -147,13 +147,13 @@ func (s *sqlDatabase) listEntityPools(tx *gorm.DB, entityType params.GithubEntit
var preloadEntity string
var fieldName string
switch entityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
preloadEntity = "Repository"
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
preloadEntity = "Organization"
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
preloadEntity = "Enterprise"
default:
@ -184,7 +184,7 @@ func (s *sqlDatabase) listEntityPools(tx *gorm.DB, entityType params.GithubEntit
return pools, nil
}
func (s *sqlDatabase) findPoolByTags(id string, poolType params.GithubEntityType, tags []string) ([]params.Pool, error) {
func (s *sqlDatabase) findPoolByTags(id string, poolType params.ForgeEntityType, tags []string) ([]params.Pool, error) {
if len(tags) == 0 {
return nil, runnerErrors.NewBadRequestError("missing tags")
}
@ -195,11 +195,11 @@ func (s *sqlDatabase) findPoolByTags(id string, poolType params.GithubEntityType
var fieldName string
switch poolType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
default:
return nil, fmt.Errorf("invalid poolType: %v", poolType)
@ -238,7 +238,7 @@ func (s *sqlDatabase) findPoolByTags(id string, poolType params.GithubEntityType
return ret, nil
}
func (s *sqlDatabase) FindPoolsMatchingAllTags(_ context.Context, entityType params.GithubEntityType, entityID string, tags []string) ([]params.Pool, error) {
func (s *sqlDatabase) FindPoolsMatchingAllTags(_ context.Context, entityType params.ForgeEntityType, entityID string, tags []string) ([]params.Pool, error) {
if len(tags) == 0 {
return nil, runnerErrors.NewBadRequestError("missing tags")
}
@ -254,7 +254,7 @@ func (s *sqlDatabase) FindPoolsMatchingAllTags(_ context.Context, entityType par
return pools, nil
}
func (s *sqlDatabase) CreateEntityPool(_ context.Context, entity params.GithubEntity, param params.CreatePoolParams) (pool params.Pool, err error) {
func (s *sqlDatabase) CreateEntityPool(_ context.Context, entity params.ForgeEntity, param params.CreatePoolParams) (pool params.Pool, err error) {
if len(param.Tags) == 0 {
return params.Pool{}, runnerErrors.NewBadRequestError("no tags specified")
}
@ -289,11 +289,11 @@ func (s *sqlDatabase) CreateEntityPool(_ context.Context, entity params.GithubEn
}
switch entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
newPool.RepoID = &entityID
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
newPool.OrgID = &entityID
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
newPool.EnterpriseID = &entityID
}
err = s.conn.Transaction(func(tx *gorm.DB) error {
@ -334,7 +334,7 @@ func (s *sqlDatabase) CreateEntityPool(_ context.Context, entity params.GithubEn
return s.sqlToCommonPool(dbPool)
}
func (s *sqlDatabase) GetEntityPool(_ context.Context, entity params.GithubEntity, poolID string) (params.Pool, error) {
func (s *sqlDatabase) GetEntityPool(_ context.Context, entity params.ForgeEntity, poolID string) (params.Pool, error) {
pool, err := s.getEntityPool(s.conn, entity.EntityType, entity.ID, poolID, "Tags", "Instances")
if err != nil {
return params.Pool{}, fmt.Errorf("fetching pool: %w", err)
@ -342,7 +342,7 @@ func (s *sqlDatabase) GetEntityPool(_ context.Context, entity params.GithubEntit
return s.sqlToCommonPool(pool)
}
func (s *sqlDatabase) DeleteEntityPool(_ context.Context, entity params.GithubEntity, poolID string) (err error) {
func (s *sqlDatabase) DeleteEntityPool(_ context.Context, entity params.ForgeEntity, poolID string) (err error) {
entityID, err := uuid.Parse(entity.ID)
if err != nil {
return errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
@ -363,11 +363,11 @@ func (s *sqlDatabase) DeleteEntityPool(_ context.Context, entity params.GithubEn
}
var fieldName string
switch entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
default:
return fmt.Errorf("invalid entityType: %v", entity.EntityType)
@ -379,7 +379,7 @@ func (s *sqlDatabase) DeleteEntityPool(_ context.Context, entity params.GithubEn
return nil
}
func (s *sqlDatabase) UpdateEntityPool(_ context.Context, entity params.GithubEntity, poolID string, param params.UpdatePoolParams) (updatedPool params.Pool, err error) {
func (s *sqlDatabase) UpdateEntityPool(_ context.Context, entity params.ForgeEntity, poolID string, param params.UpdatePoolParams) (updatedPool params.Pool, err error) {
defer func() {
if err == nil {
s.sendNotify(common.PoolEntityType, common.UpdateOperation, updatedPool)
@ -403,7 +403,7 @@ func (s *sqlDatabase) UpdateEntityPool(_ context.Context, entity params.GithubEn
return updatedPool, nil
}
func (s *sqlDatabase) ListEntityPools(_ context.Context, entity params.GithubEntity) ([]params.Pool, error) {
func (s *sqlDatabase) ListEntityPools(_ context.Context, entity params.ForgeEntity) ([]params.Pool, error) {
pools, err := s.listEntityPools(s.conn, entity.EntityType, entity.ID, "Tags")
if err != nil {
return nil, errors.Wrap(err, "fetching pools")
@ -420,7 +420,7 @@ func (s *sqlDatabase) ListEntityPools(_ context.Context, entity params.GithubEnt
return ret, nil
}
func (s *sqlDatabase) ListEntityInstances(_ context.Context, entity params.GithubEntity) ([]params.Instance, error) {
func (s *sqlDatabase) ListEntityInstances(_ context.Context, entity params.ForgeEntity) ([]params.Instance, error) {
pools, err := s.listEntityPools(s.conn, entity.EntityType, entity.ID, "Instances", "Instances.Job")
if err != nil {
return nil, errors.Wrap(err, "fetching entity")

View file

@ -81,7 +81,7 @@ func (s *PoolsTestSuite) SetupTest() {
creds := garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), githubEndpoint)
// create an organization for testing purposes
org, err := s.Store.CreateOrganization(s.adminCtx, "test-org", creds.Name, "test-webhookSecret", params.PoolBalancerTypeRoundRobin)
org, err := s.Store.CreateOrganization(s.adminCtx, "test-org", creds, "test-webhookSecret", params.PoolBalancerTypeRoundRobin)
if err != nil {
s.FailNow(fmt.Sprintf("failed to create org: %s", err))
}
@ -211,7 +211,7 @@ func (s *PoolsTestSuite) TestEntityPoolOperations() {
ep := garmTesting.CreateDefaultGithubEndpoint(s.ctx, s.Store, s.T())
creds := garmTesting.CreateTestGithubCredentials(s.ctx, "test-creds", s.Store, s.T(), ep)
s.T().Cleanup(func() { s.Store.DeleteGithubCredentials(s.ctx, creds.ID) })
repo, err := s.Store.CreateRepository(s.ctx, "test-owner", "test-repo", creds.Name, "test-secret", params.PoolBalancerTypeRoundRobin)
repo, err := s.Store.CreateRepository(s.ctx, "test-owner", "test-repo", creds, "test-secret", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotEmpty(repo.ID)
s.T().Cleanup(func() { s.Store.DeleteRepository(s.ctx, repo.ID) })
@ -291,7 +291,7 @@ func (s *PoolsTestSuite) TestListEntityInstances() {
ep := garmTesting.CreateDefaultGithubEndpoint(s.ctx, s.Store, s.T())
creds := garmTesting.CreateTestGithubCredentials(s.ctx, "test-creds", s.Store, s.T(), ep)
s.T().Cleanup(func() { s.Store.DeleteGithubCredentials(s.ctx, creds.ID) })
repo, err := s.Store.CreateRepository(s.ctx, "test-owner", "test-repo", creds.Name, "test-secret", params.PoolBalancerTypeRoundRobin)
repo, err := s.Store.CreateRepository(s.ctx, "test-owner", "test-repo", creds, "test-secret", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotEmpty(repo.ID)
s.T().Cleanup(func() { s.Store.DeleteRepository(s.ctx, repo.ID) })

View file

@ -29,7 +29,7 @@ import (
"github.com/cloudbase/garm/params"
)
func (s *sqlDatabase) CreateRepository(ctx context.Context, owner, name, credentialsName, webhookSecret string, poolBalancerType params.PoolBalancerType) (param params.Repository, err error) {
func (s *sqlDatabase) CreateRepository(ctx context.Context, owner, name string, credentials params.ForgeCredentials, webhookSecret string, poolBalancerType params.PoolBalancerType) (param params.Repository, err error) {
defer func() {
if err == nil {
s.sendNotify(common.RepositoryEntityType, common.CreateOperation, param)
@ -51,32 +51,32 @@ func (s *sqlDatabase) CreateRepository(ctx context.Context, owner, name, credent
PoolBalancerType: poolBalancerType,
}
err = s.conn.Transaction(func(tx *gorm.DB) error {
creds, err := s.getGithubCredentialsByName(ctx, tx, credentialsName, false)
if err != nil {
return errors.Wrap(err, "creating repository")
switch credentials.ForgeType {
case params.GithubEndpointType:
newRepo.CredentialsID = &credentials.ID
case params.GiteaEndpointType:
newRepo.GiteaCredentialsID = &credentials.ID
default:
return errors.Wrap(runnerErrors.ErrBadRequest, "unsupported credentials type")
}
if creds.EndpointName == nil {
return errors.Wrap(runnerErrors.ErrUnprocessable, "credentials have no endpoint")
}
newRepo.CredentialsID = &creds.ID
newRepo.CredentialsName = creds.Name
newRepo.EndpointName = creds.EndpointName
newRepo.EndpointName = &credentials.Endpoint.Name
q := tx.Create(&newRepo)
if q.Error != nil {
return errors.Wrap(q.Error, "creating repository")
}
newRepo.Credentials = creds
newRepo.Endpoint = creds.Endpoint
return nil
})
if err != nil {
return params.Repository{}, errors.Wrap(err, "creating repository")
}
param, err = s.sqlToCommonRepository(newRepo, true)
repo, err := s.getRepoByID(ctx, s.conn, newRepo.ID.String(), "Endpoint", "Credentials", "GiteaCredentials", "Credentials.Endpoint", "GiteaCredentials.Endpoint")
if err != nil {
return params.Repository{}, errors.Wrap(err, "creating repository")
}
param, err = s.sqlToCommonRepository(repo, true)
if err != nil {
return params.Repository{}, errors.Wrap(err, "creating repository")
}
@ -102,7 +102,9 @@ func (s *sqlDatabase) ListRepositories(_ context.Context) ([]params.Repository,
var repos []Repository
q := s.conn.
Preload("Credentials").
Preload("GiteaCredentials").
Preload("Credentials.Endpoint").
Preload("GiteaCredentials.Endpoint").
Preload("Endpoint").
Find(&repos)
if q.Error != nil {
@ -122,7 +124,7 @@ func (s *sqlDatabase) ListRepositories(_ context.Context) ([]params.Repository,
}
func (s *sqlDatabase) DeleteRepository(ctx context.Context, repoID string) (err error) {
repo, err := s.getRepoByID(ctx, s.conn, repoID, "Endpoint", "Credentials", "Credentials.Endpoint")
repo, err := s.getRepoByID(ctx, s.conn, repoID, "Endpoint", "Credentials", "Credentials.Endpoint", "GiteaCredentials", "GiteaCredentials.Endpoint")
if err != nil {
return errors.Wrap(err, "fetching repo")
}
@ -165,7 +167,6 @@ func (s *sqlDatabase) UpdateRepository(ctx context.Context, repoID string, param
}
if param.CredentialsName != "" {
repo.CredentialsName = param.CredentialsName
creds, err = s.getGithubCredentialsByName(ctx, tx, param.CredentialsName, false)
if err != nil {
return errors.Wrap(err, "fetching credentials")
@ -203,7 +204,7 @@ func (s *sqlDatabase) UpdateRepository(ctx context.Context, repoID string, param
return params.Repository{}, errors.Wrap(err, "saving repo")
}
repo, err = s.getRepoByID(ctx, s.conn, repoID, "Endpoint", "Credentials", "Credentials.Endpoint")
repo, err = s.getRepoByID(ctx, s.conn, repoID, "Endpoint", "Credentials", "Credentials.Endpoint", "GiteaCredentials", "GiteaCredentials.Endpoint")
if err != nil {
return params.Repository{}, errors.Wrap(err, "updating enterprise")
}
@ -216,7 +217,7 @@ func (s *sqlDatabase) UpdateRepository(ctx context.Context, repoID string, param
}
func (s *sqlDatabase) GetRepositoryByID(ctx context.Context, repoID string) (params.Repository, error) {
repo, err := s.getRepoByID(ctx, s.conn, repoID, "Pools", "Credentials", "Endpoint", "Credentials.Endpoint")
repo, err := s.getRepoByID(ctx, s.conn, repoID, "Pools", "Credentials", "Endpoint", "Credentials.Endpoint", "GiteaCredentials", "GiteaCredentials.Endpoint")
if err != nil {
return params.Repository{}, errors.Wrap(err, "fetching repo")
}
@ -234,6 +235,8 @@ func (s *sqlDatabase) getRepo(_ context.Context, owner, name, endpointName strin
q := s.conn.Where("name = ? COLLATE NOCASE and owner = ? COLLATE NOCASE and endpoint_name = ? COLLATE NOCASE", name, owner, endpointName).
Preload("Credentials").
Preload("Credentials.Endpoint").
Preload("GiteaCredentials").
Preload("GiteaCredentials.Endpoint").
Preload("Endpoint").
First(&repo)

View file

@ -58,9 +58,11 @@ type RepoTestSuite struct {
adminCtx context.Context
adminUserID string
testCreds params.GithubCredentials
secondaryTestCreds params.GithubCredentials
githubEndpoint params.GithubEndpoint
testCreds params.ForgeCredentials
testCredsGitea params.ForgeCredentials
secondaryTestCreds params.ForgeCredentials
githubEndpoint params.ForgeEndpoint
giteaEndpoint params.ForgeEndpoint
}
func (s *RepoTestSuite) equalReposByName(expected, actual []params.Repository) {
@ -109,7 +111,9 @@ func (s *RepoTestSuite) SetupTest() {
s.Require().NotEmpty(s.adminUserID)
s.githubEndpoint = garmTesting.CreateDefaultGithubEndpoint(adminCtx, db, s.T())
s.giteaEndpoint = garmTesting.CreateDefaultGiteaEndpoint(adminCtx, db, s.T())
s.testCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), s.githubEndpoint)
s.testCredsGitea = garmTesting.CreateTestGiteaCredentials(adminCtx, "new-creds", db, s.T(), s.giteaEndpoint)
s.secondaryTestCreds = garmTesting.CreateTestGithubCredentials(adminCtx, "secondary-creds", db, s.T(), s.githubEndpoint)
// create some repository objects in the database, for testing purposes
@ -119,7 +123,7 @@ func (s *RepoTestSuite) SetupTest() {
adminCtx,
fmt.Sprintf("test-owner-%d", i),
fmt.Sprintf("test-repo-%d", i),
s.testCreds.Name,
s.testCreds,
fmt.Sprintf("test-webhook-secret-%d", i),
params.PoolBalancerTypeRoundRobin,
)
@ -204,7 +208,7 @@ func (s *RepoTestSuite) TestCreateRepository() {
s.adminCtx,
s.Fixtures.CreateRepoParams.Owner,
s.Fixtures.CreateRepoParams.Name,
s.Fixtures.CreateRepoParams.CredentialsName,
s.testCreds,
s.Fixtures.CreateRepoParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin,
)
@ -219,6 +223,68 @@ func (s *RepoTestSuite) TestCreateRepository() {
s.Require().Equal(storeRepo.Name, repo.Name)
s.Require().Equal(storeRepo.Credentials.Name, repo.Credentials.Name)
s.Require().Equal(storeRepo.WebhookSecret, repo.WebhookSecret)
entity, err := repo.GetEntity()
s.Require().Nil(err)
s.Require().Equal(s.Fixtures.CreateRepoParams.Owner, entity.Owner)
s.Require().Equal(entity.EntityType, params.ForgeEntityTypeRepository)
forgeType, err := entity.GetForgeType()
s.Require().Nil(err)
s.Require().Equal(forgeType, params.GithubEndpointType)
}
func (s *RepoTestSuite) TestCreateRepositoryGitea() {
// call tested function
repo, err := s.Store.CreateRepository(
s.adminCtx,
s.Fixtures.CreateRepoParams.Owner,
s.Fixtures.CreateRepoParams.Name,
s.testCredsGitea,
s.Fixtures.CreateRepoParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin,
)
// assertions
s.Require().Nil(err)
storeRepo, err := s.Store.GetRepositoryByID(s.adminCtx, repo.ID)
if err != nil {
s.FailNow(fmt.Sprintf("failed to get repository by id: %v", err))
}
s.Require().Equal(storeRepo.Owner, repo.Owner)
s.Require().Equal(storeRepo.Name, repo.Name)
s.Require().Equal(storeRepo.Credentials.Name, repo.Credentials.Name)
s.Require().Equal(storeRepo.WebhookSecret, repo.WebhookSecret)
entity, err := repo.GetEntity()
s.Require().Nil(err)
s.Require().Equal(repo.ID, entity.ID)
s.Require().Equal(entity.EntityType, params.ForgeEntityTypeRepository)
forgeType, err := entity.GetForgeType()
s.Require().Nil(err)
s.Require().Equal(forgeType, params.GiteaEndpointType)
}
func (s *RepoTestSuite) TestCreateRepositoryInvalidForgeType() {
// call tested function
_, err := s.Store.CreateRepository(
s.adminCtx,
s.Fixtures.CreateRepoParams.Owner,
s.Fixtures.CreateRepoParams.Name,
params.ForgeCredentials{
Name: "test-creds",
ForgeType: "invalid-forge-type",
Endpoint: params.ForgeEndpoint{
Name: "test-endpoint",
},
},
s.Fixtures.CreateRepoParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin,
)
s.Require().NotNil(err)
s.Require().Equal("creating repository: unsupported credentials type: invalid request", err.Error())
}
func (s *RepoTestSuite) TestCreateRepositoryInvalidDBPassphrase() {
@ -238,7 +304,7 @@ func (s *RepoTestSuite) TestCreateRepositoryInvalidDBPassphrase() {
s.adminCtx,
s.Fixtures.CreateRepoParams.Owner,
s.Fixtures.CreateRepoParams.Name,
s.Fixtures.CreateRepoParams.CredentialsName,
s.testCreds,
s.Fixtures.CreateRepoParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin,
)
@ -249,15 +315,6 @@ func (s *RepoTestSuite) TestCreateRepositoryInvalidDBPassphrase() {
func (s *RepoTestSuite) TestCreateRepositoryInvalidDBCreateErr() {
s.Fixtures.SQLMock.ExpectBegin()
s.Fixtures.SQLMock.
ExpectQuery(regexp.QuoteMeta("SELECT * FROM `github_credentials` WHERE user_id = ? AND name = ? AND `github_credentials`.`deleted_at` IS NULL ORDER BY `github_credentials`.`id` LIMIT ?")).
WithArgs(s.adminUserID, s.Fixtures.Repos[0].CredentialsName, 1).
WillReturnRows(sqlmock.NewRows([]string{"id", "endpoint_name"}).
AddRow(s.testCreds.ID, s.githubEndpoint.Name))
s.Fixtures.SQLMock.ExpectQuery(regexp.QuoteMeta("SELECT * FROM `github_endpoints` WHERE `github_endpoints`.`name` = ? AND `github_endpoints`.`deleted_at` IS NULL")).
WithArgs(s.testCreds.Endpoint.Name).
WillReturnRows(sqlmock.NewRows([]string{"name"}).
AddRow(s.githubEndpoint.Name))
s.Fixtures.SQLMock.
ExpectExec(regexp.QuoteMeta("INSERT INTO `repositories`")).
WillReturnError(fmt.Errorf("creating repo mock error"))
@ -267,7 +324,7 @@ func (s *RepoTestSuite) TestCreateRepositoryInvalidDBCreateErr() {
s.adminCtx,
s.Fixtures.CreateRepoParams.Owner,
s.Fixtures.CreateRepoParams.Name,
s.Fixtures.CreateRepoParams.CredentialsName,
s.testCreds,
s.Fixtures.CreateRepoParams.WebhookSecret,
params.PoolBalancerTypeRoundRobin,
)
@ -541,9 +598,9 @@ func (s *RepoTestSuite) TestCreateRepositoryPoolMissingTags() {
}
func (s *RepoTestSuite) TestCreateRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
_, err := s.Store.CreateEntityPool(s.adminCtx, entity, s.Fixtures.CreatePoolParams)
@ -692,9 +749,9 @@ func (s *RepoTestSuite) TestListRepoPools() {
}
func (s *RepoTestSuite) TestListRepoPoolsInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
_, err := s.Store.ListEntityPools(s.adminCtx, entity)
@ -717,9 +774,9 @@ func (s *RepoTestSuite) TestGetRepositoryPool() {
}
func (s *RepoTestSuite) TestGetRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
_, err := s.Store.GetEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -743,9 +800,9 @@ func (s *RepoTestSuite) TestDeleteRepositoryPool() {
}
func (s *RepoTestSuite) TestDeleteRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
err := s.Store.DeleteEntityPool(s.adminCtx, entity, "dummy-pool-id")
@ -799,9 +856,9 @@ func (s *RepoTestSuite) TestListRepoInstances() {
}
func (s *RepoTestSuite) TestListRepoInstancesInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
_, err := s.Store.ListEntityInstances(s.adminCtx, entity)
@ -827,9 +884,9 @@ func (s *RepoTestSuite) TestUpdateRepositoryPool() {
}
func (s *RepoTestSuite) TestUpdateRepositoryPoolInvalidRepoID() {
entity := params.GithubEntity{
entity := params.ForgeEntity{
ID: "dummy-repo-id",
EntityType: params.GithubEntityTypeRepository,
EntityType: params.ForgeEntityTypeRepository,
}
_, err := s.Store.UpdateEntityPool(s.adminCtx, entity, "dummy-repo-id", s.Fixtures.UpdatePoolParams)

View file

@ -1,3 +1,17 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package sql
import (

View file

@ -1,16 +1,16 @@
// Copyright 2024 Cloudbase Solutions SRL
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package sql
@ -53,7 +53,7 @@ func (s *sqlDatabase) ListAllScaleSets(_ context.Context) ([]params.ScaleSet, er
return ret, nil
}
func (s *sqlDatabase) CreateEntityScaleSet(_ context.Context, entity params.GithubEntity, param params.CreateScaleSetParams) (scaleSet params.ScaleSet, err error) {
func (s *sqlDatabase) CreateEntityScaleSet(_ context.Context, entity params.ForgeEntity, param params.CreateScaleSetParams) (scaleSet params.ScaleSet, err error) {
if err := param.Validate(); err != nil {
return params.ScaleSet{}, fmt.Errorf("failed to validate create params: %w", err)
}
@ -92,11 +92,11 @@ func (s *sqlDatabase) CreateEntityScaleSet(_ context.Context, entity params.Gith
}
switch entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
newScaleSet.RepoID = &entityID
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
newScaleSet.OrgID = &entityID
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
newScaleSet.EnterpriseID = &entityID
}
err = s.conn.Transaction(func(tx *gorm.DB) error {
@ -123,7 +123,7 @@ func (s *sqlDatabase) CreateEntityScaleSet(_ context.Context, entity params.Gith
return s.sqlToCommonScaleSet(dbScaleSet)
}
func (s *sqlDatabase) listEntityScaleSets(tx *gorm.DB, entityType params.GithubEntityType, entityID string, preload ...string) ([]ScaleSet, error) {
func (s *sqlDatabase) listEntityScaleSets(tx *gorm.DB, entityType params.ForgeEntityType, entityID string, preload ...string) ([]ScaleSet, error) {
if _, err := uuid.Parse(entityID); err != nil {
return nil, errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
}
@ -135,13 +135,13 @@ func (s *sqlDatabase) listEntityScaleSets(tx *gorm.DB, entityType params.GithubE
var preloadEntity string
var fieldName string
switch entityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
preloadEntity = repositoryFieldName
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
preloadEntity = organizationFieldName
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
preloadEntity = enterpriseFieldName
default:
@ -173,7 +173,7 @@ func (s *sqlDatabase) listEntityScaleSets(tx *gorm.DB, entityType params.GithubE
return scaleSets, nil
}
func (s *sqlDatabase) ListEntityScaleSets(_ context.Context, entity params.GithubEntity) ([]params.ScaleSet, error) {
func (s *sqlDatabase) ListEntityScaleSets(_ context.Context, entity params.ForgeEntity) ([]params.ScaleSet, error) {
scaleSets, err := s.listEntityScaleSets(s.conn, entity.EntityType, entity.ID)
if err != nil {
return nil, errors.Wrap(err, "fetching scale sets")
@ -190,7 +190,7 @@ func (s *sqlDatabase) ListEntityScaleSets(_ context.Context, entity params.Githu
return ret, nil
}
func (s *sqlDatabase) UpdateEntityScaleSet(_ context.Context, entity params.GithubEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(old, newSet params.ScaleSet) error) (updatedScaleSet params.ScaleSet, err error) {
func (s *sqlDatabase) UpdateEntityScaleSet(_ context.Context, entity params.ForgeEntity, scaleSetID uint, param params.UpdateScaleSetParams, callback func(old, newSet params.ScaleSet) error) (updatedScaleSet params.ScaleSet, err error) {
defer func() {
if err == nil {
s.sendNotify(common.ScaleSetEntityType, common.UpdateOperation, updatedScaleSet)
@ -225,7 +225,7 @@ func (s *sqlDatabase) UpdateEntityScaleSet(_ context.Context, entity params.Gith
return updatedScaleSet, nil
}
func (s *sqlDatabase) getEntityScaleSet(tx *gorm.DB, entityType params.GithubEntityType, entityID string, scaleSetID uint, preload ...string) (ScaleSet, error) {
func (s *sqlDatabase) getEntityScaleSet(tx *gorm.DB, entityType params.ForgeEntityType, entityID string, scaleSetID uint, preload ...string) (ScaleSet, error) {
if entityID == "" {
return ScaleSet{}, errors.Wrap(runnerErrors.ErrBadRequest, "missing entity id")
}
@ -237,13 +237,13 @@ func (s *sqlDatabase) getEntityScaleSet(tx *gorm.DB, entityType params.GithubEnt
var fieldName string
var entityField string
switch entityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
fieldName = entityTypeRepoName
entityField = "Repository"
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
fieldName = entityTypeOrgName
entityField = "Organization"
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
fieldName = entityTypeEnterpriseName
entityField = "Enterprise"
default:

View file

@ -1,3 +1,17 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package sql
import (
@ -19,15 +33,15 @@ type ScaleSetsTestSuite struct {
suite.Suite
Store dbCommon.Store
adminCtx context.Context
creds params.GithubCredentials
creds params.ForgeCredentials
org params.Organization
repo params.Repository
enterprise params.Enterprise
orgEntity params.GithubEntity
repoEntity params.GithubEntity
enterpriseEntity params.GithubEntity
orgEntity params.ForgeEntity
repoEntity params.ForgeEntity
enterpriseEntity params.ForgeEntity
}
func (s *ScaleSetsTestSuite) SetupTest() {
@ -48,17 +62,17 @@ func (s *ScaleSetsTestSuite) SetupTest() {
s.creds = garmTesting.CreateTestGithubCredentials(adminCtx, "new-creds", db, s.T(), githubEndpoint)
// create an organization for testing purposes
s.org, err = s.Store.CreateOrganization(s.adminCtx, "test-org", s.creds.Name, "test-webhookSecret", params.PoolBalancerTypeRoundRobin)
s.org, err = s.Store.CreateOrganization(s.adminCtx, "test-org", s.creds, "test-webhookSecret", params.PoolBalancerTypeRoundRobin)
if err != nil {
s.FailNow(fmt.Sprintf("failed to create org: %s", err))
}
s.repo, err = s.Store.CreateRepository(s.adminCtx, "test-org", "test-repo", s.creds.Name, "test-webhookSecret", params.PoolBalancerTypeRoundRobin)
s.repo, err = s.Store.CreateRepository(s.adminCtx, "test-org", "test-repo", s.creds, "test-webhookSecret", params.PoolBalancerTypeRoundRobin)
if err != nil {
s.FailNow(fmt.Sprintf("failed to create repo: %s", err))
}
s.enterprise, err = s.Store.CreateEnterprise(s.adminCtx, "test-enterprise", s.creds.Name, "test-webhookSecret", params.PoolBalancerTypeRoundRobin)
s.enterprise, err = s.Store.CreateEnterprise(s.adminCtx, "test-enterprise", s.creds, "test-webhookSecret", params.PoolBalancerTypeRoundRobin)
if err != nil {
s.FailNow(fmt.Sprintf("failed to create enterprise: %s", err))
}
@ -298,7 +312,7 @@ func (s *ScaleSetsTestSuite) TestScaleSetOperations() {
})
s.T().Run("update scaleset with invalid entity", func(_ *testing.T) {
_, err = s.Store.UpdateEntityScaleSet(s.adminCtx, params.GithubEntity{}, enterpriseScaleSet.ID, params.UpdateScaleSetParams{}, nil)
_, err = s.Store.UpdateEntityScaleSet(s.adminCtx, params.ForgeEntity{}, enterpriseScaleSet.ID, params.UpdateScaleSetParams{}, nil)
s.Require().Error(err)
s.Require().Contains(err.Error(), "missing entity id")
})

View file

@ -299,7 +299,7 @@ func (s *sqlDatabase) migrateCredentialsToDB() (err error) {
CACertBundle: certBundle,
}
var endpoint params.GithubEndpoint
var endpoint params.ForgeEndpoint
endpoint, err = s.GetGithubEndpoint(adminCtx, hostname)
if err != nil {
if !errors.Is(err, runnerErrors.ErrNotFound) {
@ -315,10 +315,10 @@ func (s *sqlDatabase) migrateCredentialsToDB() (err error) {
Name: cred.Name,
Description: cred.Description,
Endpoint: endpoint.Name,
AuthType: params.GithubAuthType(cred.GetAuthType()),
AuthType: params.ForgeAuthType(cred.GetAuthType()),
}
switch credParams.AuthType {
case params.GithubAuthTypeApp:
case params.ForgeAuthTypeApp:
keyBytes, err := cred.App.PrivateKeyBytes()
if err != nil {
return errors.Wrap(err, "getting private key bytes")
@ -332,7 +332,7 @@ func (s *sqlDatabase) migrateCredentialsToDB() (err error) {
if err := credParams.App.Validate(); err != nil {
return errors.Wrap(err, "validating app credentials")
}
case params.GithubAuthTypePAT:
case params.ForgeAuthTypePAT:
token := cred.PAT.OAuth2Token
if token == "" {
token = cred.OAuth2Token
@ -409,6 +409,17 @@ func (s *sqlDatabase) migrateDB() error {
}
}
if s.conn.Migrator().HasTable(&GithubEndpoint{}) {
if !s.conn.Migrator().HasColumn(&GithubEndpoint{}, "endpoint_type") {
if err := s.conn.Migrator().AutoMigrate(&GithubEndpoint{}); err != nil {
return errors.Wrap(err, "migrating github endpoints")
}
if err := s.conn.Exec("update github_endpoints set endpoint_type = 'github' where endpoint_type is null").Error; err != nil {
return errors.Wrap(err, "updating github endpoints")
}
}
}
var needsCredentialMigration bool
if !s.conn.Migrator().HasTable(&GithubCredentials{}) || !s.conn.Migrator().HasTable(&GithubEndpoint{}) {
needsCredentialMigration = true
@ -424,6 +435,7 @@ func (s *sqlDatabase) migrateDB() error {
&User{},
&GithubEndpoint{},
&GithubCredentials{},
&GiteaCredentials{},
&Tag{},
&Pool{},
&Repository{},

View file

@ -27,6 +27,7 @@ import (
runnerErrors "github.com/cloudbase/garm-provider-common/errors"
commonParams "github.com/cloudbase/garm-provider-common/params"
"github.com/cloudbase/garm-provider-common/util"
"github.com/cloudbase/garm/auth"
dbCommon "github.com/cloudbase/garm/database/common"
"github.com/cloudbase/garm/params"
)
@ -150,16 +151,24 @@ func (s *sqlDatabase) sqlToCommonOrganization(org Organization, detailed bool) (
UpdatedAt: org.UpdatedAt,
}
var forgeCreds params.ForgeCredentials
if org.CredentialsID != nil {
ret.CredentialsID = *org.CredentialsID
forgeCreds, err = s.sqlToCommonForgeCredentials(org.Credentials)
}
if org.GiteaCredentialsID != nil {
ret.CredentialsID = *org.GiteaCredentialsID
forgeCreds, err = s.sqlGiteaToCommonForgeCredentials(org.GiteaCredentials)
}
if err != nil {
return params.Organization{}, errors.Wrap(err, "converting credentials")
}
if detailed {
creds, err := s.sqlToCommonGithubCredentials(org.Credentials)
if err != nil {
return params.Organization{}, errors.Wrap(err, "converting credentials")
}
ret.Credentials = creds
ret.Credentials = forgeCreds
ret.CredentialsName = forgeCreds.Name
}
if ret.PoolBalancerType == "" {
@ -206,7 +215,7 @@ func (s *sqlDatabase) sqlToCommonEnterprise(enterprise Enterprise, detailed bool
}
if detailed {
creds, err := s.sqlToCommonGithubCredentials(enterprise.Credentials)
creds, err := s.sqlToCommonForgeCredentials(enterprise.Credentials)
if err != nil {
return params.Enterprise{}, errors.Wrap(err, "converting credentials")
}
@ -371,16 +380,28 @@ func (s *sqlDatabase) sqlToCommonRepository(repo Repository, detailed bool) (par
Endpoint: endpoint,
}
if repo.CredentialsID != nil && repo.GiteaCredentialsID != nil {
return params.Repository{}, runnerErrors.NewConflictError("both gitea and github credentials are set for repo %s", repo.Name)
}
var forgeCreds params.ForgeCredentials
if repo.CredentialsID != nil {
ret.CredentialsID = *repo.CredentialsID
forgeCreds, err = s.sqlToCommonForgeCredentials(repo.Credentials)
}
if repo.GiteaCredentialsID != nil {
ret.CredentialsID = *repo.GiteaCredentialsID
forgeCreds, err = s.sqlGiteaToCommonForgeCredentials(repo.GiteaCredentials)
}
if err != nil {
return params.Repository{}, errors.Wrap(err, "converting credentials")
}
if detailed {
creds, err := s.sqlToCommonGithubCredentials(repo.Credentials)
if err != nil {
return params.Repository{}, errors.Wrap(err, "converting credentials")
}
ret.Credentials = creds
ret.Credentials = forgeCreds
ret.CredentialsName = forgeCreds.Name
}
if ret.PoolBalancerType == "" {
@ -546,18 +567,18 @@ func (s *sqlDatabase) getScaleSetByID(tx *gorm.DB, scaleSetID uint, preload ...s
return scaleSet, nil
}
func (s *sqlDatabase) hasGithubEntity(tx *gorm.DB, entityType params.GithubEntityType, entityID string) error {
func (s *sqlDatabase) hasGithubEntity(tx *gorm.DB, entityType params.ForgeEntityType, entityID string) error {
u, err := uuid.Parse(entityID)
if err != nil {
return errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
}
var q *gorm.DB
switch entityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
q = tx.Model(&Repository{}).Where("id = ?", u)
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
q = tx.Model(&Organization{}).Where("id = ?", u)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
q = tx.Model(&Enterprise{}).Where("id = ?", u)
default:
return errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type")
@ -608,26 +629,26 @@ func (s *sqlDatabase) sendNotify(entityType dbCommon.DatabaseEntityType, op dbCo
return s.producer.Notify(message)
}
func (s *sqlDatabase) GetGithubEntity(_ context.Context, entityType params.GithubEntityType, entityID string) (params.GithubEntity, error) {
func (s *sqlDatabase) GetForgeEntity(_ context.Context, entityType params.ForgeEntityType, entityID string) (params.ForgeEntity, error) {
var ghEntity params.EntityGetter
var err error
switch entityType {
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
ghEntity, err = s.GetEnterpriseByID(s.ctx, entityID)
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
ghEntity, err = s.GetOrganizationByID(s.ctx, entityID)
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
ghEntity, err = s.GetRepositoryByID(s.ctx, entityID)
default:
return params.GithubEntity{}, errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type")
return params.ForgeEntity{}, errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type")
}
if err != nil {
return params.GithubEntity{}, errors.Wrap(err, "failed to get ")
return params.ForgeEntity{}, errors.Wrap(err, "failed to get ")
}
entity, err := ghEntity.GetEntity()
if err != nil {
return params.GithubEntity{}, errors.Wrap(err, "failed to get entity")
return params.ForgeEntity{}, errors.Wrap(err, "failed to get entity")
}
return entity, nil
}
@ -638,7 +659,7 @@ func (s *sqlDatabase) addRepositoryEvent(ctx context.Context, repoID string, eve
return errors.Wrap(err, "updating instance")
}
msg := InstanceStatusUpdate{
msg := RepositoryEvent{
Message: statusMessage,
EventType: event,
EventLevel: eventLevel,
@ -653,8 +674,8 @@ func (s *sqlDatabase) addRepositoryEvent(ctx context.Context, repoID string, eve
if err != nil {
return errors.Wrap(runnerErrors.ErrBadRequest, "parsing id")
}
var latestEvents []OrganizationEvent
q := s.conn.Model(&OrganizationEvent{}).
var latestEvents []RepositoryEvent
q := s.conn.Model(&RepositoryEvent{}).
Limit(maxEvents).Order("id desc").
Where("repo_id = ?", repoID).Find(&latestEvents)
if q.Error != nil {
@ -662,7 +683,7 @@ func (s *sqlDatabase) addRepositoryEvent(ctx context.Context, repoID string, eve
}
if len(latestEvents) == maxEvents {
lastInList := latestEvents[len(latestEvents)-1]
if err := s.conn.Where("repo_id = ? and id < ?", repoID, lastInList.ID).Unscoped().Delete(&OrganizationEvent{}).Error; err != nil {
if err := s.conn.Where("repo_id = ? and id < ?", repoID, lastInList.ID).Unscoped().Delete(&RepositoryEvent{}).Error; err != nil {
return errors.Wrap(err, "deleting old events")
}
}
@ -676,7 +697,7 @@ func (s *sqlDatabase) addOrgEvent(ctx context.Context, orgID string, event param
return errors.Wrap(err, "updating instance")
}
msg := InstanceStatusUpdate{
msg := OrganizationEvent{
Message: statusMessage,
EventType: event,
EventLevel: eventLevel,
@ -714,7 +735,7 @@ func (s *sqlDatabase) addEnterpriseEvent(ctx context.Context, entID string, even
return errors.Wrap(err, "updating instance")
}
msg := InstanceStatusUpdate{
msg := EnterpriseEvent{
Message: statusMessage,
EventType: event,
EventLevel: eventLevel,
@ -747,19 +768,151 @@ func (s *sqlDatabase) addEnterpriseEvent(ctx context.Context, entID string, even
return nil
}
func (s *sqlDatabase) AddEntityEvent(ctx context.Context, entity params.GithubEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error {
func (s *sqlDatabase) AddEntityEvent(ctx context.Context, entity params.ForgeEntity, event params.EventType, eventLevel params.EventLevel, statusMessage string, maxEvents int) error {
if maxEvents == 0 {
return errors.Wrap(runnerErrors.ErrBadRequest, "max events cannot be 0")
}
switch entity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
return s.addRepositoryEvent(ctx, entity.ID, event, eventLevel, statusMessage, maxEvents)
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
return s.addOrgEvent(ctx, entity.ID, event, eventLevel, statusMessage, maxEvents)
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
return s.addEnterpriseEvent(ctx, entity.ID, event, eventLevel, statusMessage, maxEvents)
default:
return errors.Wrap(runnerErrors.ErrBadRequest, "invalid entity type")
}
}
func (s *sqlDatabase) sqlToCommonForgeCredentials(creds GithubCredentials) (params.ForgeCredentials, error) {
if len(creds.Payload) == 0 {
return params.ForgeCredentials{}, errors.New("empty credentials payload")
}
data, err := util.Unseal(creds.Payload, []byte(s.cfg.Passphrase))
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "unsealing credentials")
}
ep, err := s.sqlToCommonGithubEndpoint(creds.Endpoint)
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "converting github endpoint")
}
commonCreds := params.ForgeCredentials{
ID: creds.ID,
Name: creds.Name,
Description: creds.Description,
APIBaseURL: creds.Endpoint.APIBaseURL,
BaseURL: creds.Endpoint.BaseURL,
UploadBaseURL: creds.Endpoint.UploadBaseURL,
CABundle: creds.Endpoint.CACertBundle,
AuthType: creds.AuthType,
CreatedAt: creds.CreatedAt,
UpdatedAt: creds.UpdatedAt,
ForgeType: creds.Endpoint.EndpointType,
Endpoint: ep,
CredentialsPayload: data,
}
for _, repo := range creds.Repositories {
commonRepo, err := s.sqlToCommonRepository(repo, false)
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "converting github repository")
}
commonCreds.Repositories = append(commonCreds.Repositories, commonRepo)
}
for _, org := range creds.Organizations {
commonOrg, err := s.sqlToCommonOrganization(org, false)
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "converting github organization")
}
commonCreds.Organizations = append(commonCreds.Organizations, commonOrg)
}
for _, ent := range creds.Enterprises {
commonEnt, err := s.sqlToCommonEnterprise(ent, false)
if err != nil {
return params.ForgeCredentials{}, errors.Wrapf(err, "converting github enterprise: %s", ent.Name)
}
commonCreds.Enterprises = append(commonCreds.Enterprises, commonEnt)
}
return commonCreds, nil
}
func (s *sqlDatabase) sqlGiteaToCommonForgeCredentials(creds GiteaCredentials) (params.ForgeCredentials, error) {
if len(creds.Payload) == 0 {
return params.ForgeCredentials{}, errors.New("empty credentials payload")
}
data, err := util.Unseal(creds.Payload, []byte(s.cfg.Passphrase))
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "unsealing credentials")
}
ep, err := s.sqlToCommonGithubEndpoint(creds.Endpoint)
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "converting github endpoint")
}
commonCreds := params.ForgeCredentials{
ID: creds.ID,
Name: creds.Name,
Description: creds.Description,
APIBaseURL: creds.Endpoint.APIBaseURL,
BaseURL: creds.Endpoint.BaseURL,
CABundle: creds.Endpoint.CACertBundle,
AuthType: creds.AuthType,
CreatedAt: creds.CreatedAt,
UpdatedAt: creds.UpdatedAt,
ForgeType: creds.Endpoint.EndpointType,
Endpoint: ep,
CredentialsPayload: data,
}
for _, repo := range creds.Repositories {
commonRepo, err := s.sqlToCommonRepository(repo, false)
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "converting github repository")
}
commonCreds.Repositories = append(commonCreds.Repositories, commonRepo)
}
for _, org := range creds.Organizations {
commonOrg, err := s.sqlToCommonOrganization(org, false)
if err != nil {
return params.ForgeCredentials{}, errors.Wrap(err, "converting github organization")
}
commonCreds.Organizations = append(commonCreds.Organizations, commonOrg)
}
return commonCreds, nil
}
func (s *sqlDatabase) sqlToCommonGithubEndpoint(ep GithubEndpoint) (params.ForgeEndpoint, error) {
return params.ForgeEndpoint{
Name: ep.Name,
Description: ep.Description,
APIBaseURL: ep.APIBaseURL,
BaseURL: ep.BaseURL,
UploadBaseURL: ep.UploadBaseURL,
CACertBundle: ep.CACertBundle,
CreatedAt: ep.CreatedAt,
EndpointType: ep.EndpointType,
UpdatedAt: ep.UpdatedAt,
}, nil
}
func getUIDFromContext(ctx context.Context) (uuid.UUID, error) {
userID := auth.UserID(ctx)
if userID == "" {
return uuid.Nil, errors.Wrap(runnerErrors.ErrUnauthorized, "getting UID from context")
}
asUUID, err := uuid.Parse(userID)
if err != nil {
return uuid.Nil, errors.Wrap(runnerErrors.ErrUnauthorized, "parsing UID from context")
}
return asUUID, nil
}

View file

@ -1,3 +1,17 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package watcher
import (

View file

@ -1,3 +1,17 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package watcher
import (
@ -63,7 +77,7 @@ func WithOperationTypeFilter(operationType dbCommon.OperationType) dbCommon.Payl
// WithEntityPoolFilter returns true if the change payload is a pool that belongs to the
// supplied Github entity. This is useful when an entity worker wants to watch for changes
// in pools that belong to it.
func WithEntityPoolFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFunc {
func WithEntityPoolFilter(ghEntity params.ForgeEntity) dbCommon.PayloadFilterFunc {
return func(payload dbCommon.ChangePayload) bool {
switch payload.EntityType {
case dbCommon.PoolEntityType:
@ -72,11 +86,11 @@ func WithEntityPoolFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFu
return false
}
switch ghEntity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
return pool.RepoID == ghEntity.ID
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
return pool.OrgID == ghEntity.ID
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
return pool.EnterpriseID == ghEntity.ID
default:
return false
@ -87,11 +101,20 @@ func WithEntityPoolFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFu
}
}
// WithEntityPoolFilter returns true if the change payload is a pool that belongs to the
// supplied Github entity. This is useful when an entity worker wants to watch for changes
// in pools that belong to it.
func WithEntityScaleSetFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFunc {
// WithEntityScaleSetFilter returns true if the change payload is a scale set that belongs to the
// supplied Github entity.
func WithEntityScaleSetFilter(ghEntity params.ForgeEntity) dbCommon.PayloadFilterFunc {
return func(payload dbCommon.ChangePayload) bool {
forgeType, err := ghEntity.GetForgeType()
if err != nil {
return false
}
// Gitea does not have scale sets.
if forgeType == params.GiteaEndpointType {
return false
}
switch payload.EntityType {
case dbCommon.ScaleSetEntityType:
scaleSet, ok := payload.Payload.(params.ScaleSet)
@ -99,11 +122,11 @@ func WithEntityScaleSetFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilt
return false
}
switch ghEntity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
return scaleSet.RepoID == ghEntity.ID
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
return scaleSet.OrgID == ghEntity.ID
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
return scaleSet.EnterpriseID == ghEntity.ID
default:
return false
@ -116,26 +139,26 @@ func WithEntityScaleSetFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilt
// WithEntityFilter returns a filter function that filters payloads by entity.
// Change payloads that match the entity type and ID will return true.
func WithEntityFilter(entity params.GithubEntity) dbCommon.PayloadFilterFunc {
func WithEntityFilter(entity params.ForgeEntity) dbCommon.PayloadFilterFunc {
return func(payload dbCommon.ChangePayload) bool {
if params.GithubEntityType(payload.EntityType) != entity.EntityType {
if params.ForgeEntityType(payload.EntityType) != entity.EntityType {
return false
}
var ent IDGetter
var ok bool
switch payload.EntityType {
case dbCommon.RepositoryEntityType:
if entity.EntityType != params.GithubEntityTypeRepository {
if entity.EntityType != params.ForgeEntityTypeRepository {
return false
}
ent, ok = payload.Payload.(params.Repository)
case dbCommon.OrganizationEntityType:
if entity.EntityType != params.GithubEntityTypeOrganization {
if entity.EntityType != params.ForgeEntityTypeOrganization {
return false
}
ent, ok = payload.Payload.(params.Organization)
case dbCommon.EnterpriseEntityType:
if entity.EntityType != params.GithubEntityTypeEnterprise {
if entity.EntityType != params.ForgeEntityTypeEnterprise {
return false
}
ent, ok = payload.Payload.(params.Enterprise)
@ -149,7 +172,7 @@ func WithEntityFilter(entity params.GithubEntity) dbCommon.PayloadFilterFunc {
}
}
func WithEntityJobFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFunc {
func WithEntityJobFilter(ghEntity params.ForgeEntity) dbCommon.PayloadFilterFunc {
return func(payload dbCommon.ChangePayload) bool {
switch payload.EntityType {
case dbCommon.JobEntityType:
@ -159,15 +182,15 @@ func WithEntityJobFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFun
}
switch ghEntity.EntityType {
case params.GithubEntityTypeRepository:
case params.ForgeEntityTypeRepository:
if job.RepoID != nil && job.RepoID.String() != ghEntity.ID {
return false
}
case params.GithubEntityTypeOrganization:
case params.ForgeEntityTypeOrganization:
if job.OrgID != nil && job.OrgID.String() != ghEntity.ID {
return false
}
case params.GithubEntityTypeEnterprise:
case params.ForgeEntityTypeEnterprise:
if job.EnterpriseID != nil && job.EnterpriseID.String() != ghEntity.ID {
return false
}
@ -182,17 +205,26 @@ func WithEntityJobFilter(ghEntity params.GithubEntity) dbCommon.PayloadFilterFun
}
}
// WithGithubCredentialsFilter returns a filter function that filters payloads by Github credentials.
func WithGithubCredentialsFilter(creds params.GithubCredentials) dbCommon.PayloadFilterFunc {
// WithForgeCredentialsFilter returns a filter function that filters payloads by Github or Gitea credentials.
func WithForgeCredentialsFilter(creds params.ForgeCredentials) dbCommon.PayloadFilterFunc {
return func(payload dbCommon.ChangePayload) bool {
if payload.EntityType != dbCommon.GithubCredentialsEntityType {
var forgeCreds params.ForgeCredentials
var ok bool
switch payload.EntityType {
case dbCommon.GithubCredentialsEntityType, dbCommon.GiteaCredentialsEntityType:
forgeCreds, ok = payload.Payload.(params.ForgeCredentials)
default:
return false
}
credsPayload, ok := payload.Payload.(params.GithubCredentials)
if !ok {
return false
}
return credsPayload.ID == creds.ID
// Gite and Github creds have different models. The ID is uint, so we
// need to explicitly check their type, or risk a clash.
if forgeCreds.ForgeType != creds.ForgeType {
return false
}
return forgeCreds.GetID() == creds.GetID()
}
}

View file

@ -1,3 +1,17 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package watcher
import (

View file

@ -1,6 +1,19 @@
//go:build testing
// +build testing
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package watcher
import "github.com/cloudbase/garm/database/common"

View file

@ -0,0 +1,16 @@
package watcher_test
import (
"time"
"github.com/cloudbase/garm/database/common"
)
func waitForPayload(ch <-chan common.ChangePayload, timeout time.Duration) *common.ChangePayload {
select {
case payload := <-ch:
return &payload
case <-time.After(timeout):
return nil
}
}

View file

@ -1,3 +1,17 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package watcher
import (

View file

@ -1,3 +1,17 @@
// Copyright 2025 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
package watcher_test
import (
@ -155,7 +169,7 @@ func (s *WatcherStoreTestSuite) TestInstanceWatcher() {
creds := garmTesting.CreateTestGithubCredentials(s.ctx, "test-creds", s.store, s.T(), ep)
s.T().Cleanup(func() { s.store.DeleteGithubCredentials(s.ctx, creds.ID) })
repo, err := s.store.CreateRepository(s.ctx, "test-owner", "test-repo", creds.Name, "test-secret", params.PoolBalancerTypeRoundRobin)
repo, err := s.store.CreateRepository(s.ctx, "test-owner", "test-repo", creds, "test-secret", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotEmpty(repo.ID)
s.T().Cleanup(func() { s.store.DeleteRepository(s.ctx, repo.ID) })
@ -259,7 +273,7 @@ func (s *WatcherStoreTestSuite) TestScaleSetInstanceWatcher() {
creds := garmTesting.CreateTestGithubCredentials(s.ctx, "test-creds", s.store, s.T(), ep)
s.T().Cleanup(func() { s.store.DeleteGithubCredentials(s.ctx, creds.ID) })
repo, err := s.store.CreateRepository(s.ctx, "test-owner", "test-repo", creds.Name, "test-secret", params.PoolBalancerTypeRoundRobin)
repo, err := s.store.CreateRepository(s.ctx, "test-owner", "test-repo", creds, "test-secret", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotEmpty(repo.ID)
s.T().Cleanup(func() { s.store.DeleteRepository(s.ctx, repo.ID) })
@ -369,7 +383,7 @@ func (s *WatcherStoreTestSuite) TestPoolWatcher() {
}
})
repo, err := s.store.CreateRepository(s.ctx, "test-owner", "test-repo", creds.Name, "test-secret", params.PoolBalancerTypeRoundRobin)
repo, err := s.store.CreateRepository(s.ctx, "test-owner", "test-repo", creds, "test-secret", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotEmpty(repo.ID)
s.T().Cleanup(func() { s.store.DeleteRepository(s.ctx, repo.ID) })
@ -490,7 +504,7 @@ func (s *WatcherStoreTestSuite) TestScaleSetWatcher() {
}
})
repo, err := s.store.CreateRepository(s.ctx, "test-owner", "test-repo", creds.Name, "test-secret", params.PoolBalancerTypeRoundRobin)
repo, err := s.store.CreateRepository(s.ctx, "test-owner", "test-repo", creds, "test-secret", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotEmpty(repo.ID)
s.T().Cleanup(func() { s.store.DeleteRepository(s.ctx, repo.ID) })
@ -646,7 +660,7 @@ func (s *WatcherStoreTestSuite) TestEnterpriseWatcher() {
creds := garmTesting.CreateTestGithubCredentials(s.ctx, "test-creds", s.store, s.T(), ep)
s.T().Cleanup(func() { s.store.DeleteGithubCredentials(s.ctx, creds.ID) })
ent, err := s.store.CreateEnterprise(s.ctx, "test-enterprise", creds.Name, "test-secret", params.PoolBalancerTypeRoundRobin)
ent, err := s.store.CreateEnterprise(s.ctx, "test-enterprise", creds, "test-secret", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotEmpty(ent.ID)
@ -713,7 +727,7 @@ func (s *WatcherStoreTestSuite) TestOrgWatcher() {
creds := garmTesting.CreateTestGithubCredentials(s.ctx, "test-creds", s.store, s.T(), ep)
s.T().Cleanup(func() { s.store.DeleteGithubCredentials(s.ctx, creds.ID) })
org, err := s.store.CreateOrganization(s.ctx, "test-org", creds.Name, "test-secret", params.PoolBalancerTypeRoundRobin)
org, err := s.store.CreateOrganization(s.ctx, "test-org", creds, "test-secret", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotEmpty(org.ID)
@ -780,7 +794,7 @@ func (s *WatcherStoreTestSuite) TestRepoWatcher() {
creds := garmTesting.CreateTestGithubCredentials(s.ctx, "test-creds", s.store, s.T(), ep)
s.T().Cleanup(func() { s.store.DeleteGithubCredentials(s.ctx, creds.ID) })
repo, err := s.store.CreateRepository(s.ctx, "test-owner", "test-repo", creds.Name, "test-secret", params.PoolBalancerTypeRoundRobin)
repo, err := s.store.CreateRepository(s.ctx, "test-owner", "test-repo", creds, "test-secret", params.PoolBalancerTypeRoundRobin)
s.Require().NoError(err)
s.Require().NotEmpty(repo.ID)
@ -848,7 +862,7 @@ func (s *WatcherStoreTestSuite) TestGithubCredentialsWatcher() {
Name: "test-creds",
Description: "test credentials",
Endpoint: "github.com",
AuthType: params.GithubAuthTypePAT,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "bogus",
},
@ -898,13 +912,105 @@ func (s *WatcherStoreTestSuite) TestGithubCredentialsWatcher() {
EntityType: common.GithubCredentialsEntityType,
Operation: common.DeleteOperation,
// We only get the ID and Name of the deleted entity
Payload: params.GithubCredentials{ID: ghCred.ID, Name: ghCred.Name},
Payload: params.ForgeCredentials{ID: ghCred.ID, Name: ghCred.Name},
}, event)
case <-time.After(1 * time.Second):
s.T().Fatal("expected payload not received")
}
}
func (s *WatcherStoreTestSuite) TestGiteaCredentialsWatcher() {
consumer, err := watcher.RegisterConsumer(
s.ctx, "gitea-cred-test",
watcher.WithEntityTypeFilter(common.GiteaCredentialsEntityType),
watcher.WithAny(
watcher.WithOperationTypeFilter(common.CreateOperation),
watcher.WithOperationTypeFilter(common.UpdateOperation),
watcher.WithOperationTypeFilter(common.DeleteOperation)),
)
s.Require().NoError(err)
s.Require().NotNil(consumer)
s.T().Cleanup(func() { consumer.Close() })
consumeEvents(consumer)
testEndpointParams := params.CreateGiteaEndpointParams{
Name: "test",
Description: "test endpoint",
APIBaseURL: "https://api.gitea.example.com",
BaseURL: "https://gitea.example.com",
}
testEndpoint, err := s.store.CreateGiteaEndpoint(s.ctx, testEndpointParams)
s.Require().NoError(err)
s.Require().NotEmpty(testEndpoint.Name)
s.T().Cleanup(func() {
if err := s.store.DeleteGiteaEndpoint(s.ctx, testEndpoint.Name); err != nil {
s.T().Logf("failed to delete Gitea endpoint: %v", err)
}
consumeEvents(consumer)
})
giteaCredParams := params.CreateGiteaCredentialsParams{
Name: "test-creds",
Description: "test credentials",
Endpoint: testEndpoint.Name,
AuthType: params.ForgeAuthTypePAT,
PAT: params.GithubPAT{
OAuth2Token: "bogus",
},
}
giteaCred, err := s.store.CreateGiteaCredentials(s.ctx, giteaCredParams)
s.Require().NoError(err)
s.Require().NotEmpty(giteaCred.ID)
select {
case event := <-consumer.Watch():
s.Require().Equal(common.ChangePayload{
EntityType: common.GiteaCredentialsEntityType,
Operation: common.CreateOperation,
Payload: giteaCred,
}, event)
case <-time.After(1 * time.Second):
s.T().Fatal("expected payload not received")
}
newDesc := "updated test description"
updateParams := params.UpdateGiteaCredentialsParams{
Description: &newDesc,
}
updatedGiteaCred, err := s.store.UpdateGiteaCredentials(s.ctx, giteaCred.ID, updateParams)
s.Require().NoError(err)
s.Require().Equal(newDesc, updatedGiteaCred.Description)
select {
case event := <-consumer.Watch():
s.Require().Equal(common.ChangePayload{
EntityType: common.GiteaCredentialsEntityType,
Operation: common.UpdateOperation,
Payload: updatedGiteaCred,
}, event)
case <-time.After(1 * time.Second):
s.T().Fatal("expected payload not received")
}
err = s.store.DeleteGiteaCredentials(s.ctx, giteaCred.ID)
s.Require().NoError(err)
select {
case event := <-consumer.Watch():
asCreds, ok := event.Payload.(params.ForgeCredentials)
s.Require().True(ok)
s.Require().Equal(event.Operation, common.DeleteOperation)
s.Require().Equal(event.EntityType, common.GiteaCredentialsEntityType)
s.Require().Equal(asCreds.ID, updatedGiteaCred.ID)
case <-time.After(1 * time.Second):
s.T().Fatal("expected payload not received")
}
}
func (s *WatcherStoreTestSuite) TestGithubEndpointWatcher() {
consumer, err := watcher.RegisterConsumer(
s.ctx, "gh-ep-test",
@ -971,7 +1077,7 @@ func (s *WatcherStoreTestSuite) TestGithubEndpointWatcher() {
EntityType: common.GithubEndpointEntityType,
Operation: common.DeleteOperation,
// We only get the name of the deleted entity
Payload: params.GithubEndpoint{Name: ghEp.Name},
Payload: params.ForgeEndpoint{Name: ghEp.Name},
}, event)
case <-time.After(1 * time.Second):
s.T().Fatal("expected payload not received")
@ -987,7 +1093,7 @@ consume:
if !ok {
return
}
case <-time.After(100 * time.Millisecond):
case <-time.After(20 * time.Millisecond):
break consume
}
}

Some files were not shown because too many files have changed in this diff Show more