mirror of
https://github.com/harness/drone.git
synced 2025-05-17 09:30:00 +08:00
run make format and fix lint errors
This commit is contained in:
parent
5574fcac47
commit
e24eb858d5
@ -8,6 +8,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/harness/gitness/cli/server"
|
"github.com/harness/gitness/cli/server"
|
||||||
"github.com/harness/gitness/events"
|
"github.com/harness/gitness/events"
|
||||||
"github.com/harness/gitness/gitrpc"
|
"github.com/harness/gitness/gitrpc"
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
// Copyright 2022 Harness Inc. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Polyform Free Trial License
|
||||||
|
// that can be found in the LICENSE.md file for this repository.
|
||||||
|
|
||||||
package encrypt
|
package encrypt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -7,6 +7,7 @@ package execution
|
|||||||
import (
|
import (
|
||||||
"github.com/harness/gitness/internal/auth/authz"
|
"github.com/harness/gitness/internal/auth/authz"
|
||||||
"github.com/harness/gitness/internal/store"
|
"github.com/harness/gitness/internal/store"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,13 +15,18 @@ import (
|
|||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Add more as needed
|
// TODO: Add more as needed.
|
||||||
type CreateInput struct {
|
type CreateInput struct {
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a new execution
|
func (c *Controller) Create(
|
||||||
func (c *Controller) Create(ctx context.Context, session *auth.Session, spaceRef string, uid string, in *CreateInput) (*types.Execution, error) {
|
ctx context.Context,
|
||||||
|
session *auth.Session,
|
||||||
|
spaceRef string,
|
||||||
|
uid string,
|
||||||
|
in *CreateInput,
|
||||||
|
) (*types.Execution, error) {
|
||||||
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not find space: %w", err)
|
return nil, fmt.Errorf("could not find space: %w", err)
|
||||||
|
@ -13,7 +13,13 @@ import (
|
|||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Controller) Delete(ctx context.Context, session *auth.Session, spaceRef string, pipelineUID string, executionNum int64) error {
|
func (c *Controller) Delete(
|
||||||
|
ctx context.Context,
|
||||||
|
session *auth.Session,
|
||||||
|
spaceRef string,
|
||||||
|
pipelineUID string,
|
||||||
|
executionNum int64,
|
||||||
|
) error {
|
||||||
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not find parent space: %w", err)
|
return fmt.Errorf("could not find parent space: %w", err)
|
||||||
|
@ -14,7 +14,13 @@ import (
|
|||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Controller) Find(ctx context.Context, session *auth.Session, spaceRef string, pipelineUID string, executionNum int64) (*types.Execution, error) {
|
func (c *Controller) Find(
|
||||||
|
ctx context.Context,
|
||||||
|
session *auth.Session,
|
||||||
|
spaceRef string,
|
||||||
|
pipelineUID string,
|
||||||
|
executionNum int64,
|
||||||
|
) (*types.Execution, error) {
|
||||||
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not find parent space: %w", err)
|
return nil, fmt.Errorf("could not find parent space: %w", err)
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
)
|
)
|
||||||
|
|
||||||
// List lists the executions in a pipeline.
|
|
||||||
func (c *Controller) List(
|
func (c *Controller) List(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
session *auth.Session,
|
session *auth.Session,
|
||||||
@ -41,7 +40,7 @@ func (c *Controller) List(
|
|||||||
|
|
||||||
err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) {
|
err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) {
|
||||||
var dbErr error
|
var dbErr error
|
||||||
count, dbErr = c.executionStore.Count(ctx, pipeline.ID, filter)
|
count, dbErr = c.executionStore.Count(ctx, pipeline.ID)
|
||||||
if dbErr != nil {
|
if dbErr != nil {
|
||||||
return fmt.Errorf("failed to count child executions: %w", err)
|
return fmt.Errorf("failed to count child executions: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,10 @@
|
|||||||
package execution
|
package execution
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/wire"
|
|
||||||
"github.com/harness/gitness/internal/auth/authz"
|
"github.com/harness/gitness/internal/auth/authz"
|
||||||
"github.com/harness/gitness/internal/store"
|
"github.com/harness/gitness/internal/store"
|
||||||
|
|
||||||
|
"github.com/google/wire"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/harness/gitness/internal/auth/authz"
|
"github.com/harness/gitness/internal/auth/authz"
|
||||||
"github.com/harness/gitness/internal/store"
|
"github.com/harness/gitness/internal/store"
|
||||||
"github.com/harness/gitness/types/check"
|
"github.com/harness/gitness/types/check"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -35,7 +35,6 @@ type CreateInput struct {
|
|||||||
ConfigPath string `json:"config_path"`
|
ConfigPath string `json:"config_path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a new pipeline
|
|
||||||
func (c *Controller) Create(ctx context.Context, session *auth.Session, in *CreateInput) (*types.Pipeline, error) {
|
func (c *Controller) Create(ctx context.Context, session *auth.Session, in *CreateInput) (*types.Pipeline, error) {
|
||||||
parentSpace, err := c.spaceStore.FindByRef(ctx, in.SpaceRef)
|
parentSpace, err := c.spaceStore.FindByRef(ctx, in.SpaceRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Delete deletes a pipeline.
|
|
||||||
func (c *Controller) Delete(ctx context.Context, session *auth.Session, spaceRef string, uid string) error {
|
func (c *Controller) Delete(ctx context.Context, session *auth.Session, spaceRef string, uid string) error {
|
||||||
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -14,8 +14,12 @@ import (
|
|||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Find finds a pipeline.
|
func (c *Controller) Find(
|
||||||
func (c *Controller) Find(ctx context.Context, session *auth.Session, spaceRef string, uid string) (*types.Pipeline, error) {
|
ctx context.Context,
|
||||||
|
session *auth.Session,
|
||||||
|
spaceRef string,
|
||||||
|
uid string,
|
||||||
|
) (*types.Pipeline, error) {
|
||||||
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not find parent space: %w", err)
|
return nil, fmt.Errorf("could not find parent space: %w", err)
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
package pipeline
|
package pipeline
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/wire"
|
|
||||||
"github.com/jmoiron/sqlx"
|
|
||||||
|
|
||||||
"github.com/harness/gitness/internal/auth/authz"
|
"github.com/harness/gitness/internal/auth/authz"
|
||||||
"github.com/harness/gitness/internal/store"
|
"github.com/harness/gitness/internal/store"
|
||||||
"github.com/harness/gitness/types/check"
|
"github.com/harness/gitness/types/check"
|
||||||
|
|
||||||
|
"github.com/google/wire"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WireSet provides a wire set for this package.
|
// WireSet provides a wire set for this package.
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/harness/gitness/internal/auth/authz"
|
"github.com/harness/gitness/internal/auth/authz"
|
||||||
"github.com/harness/gitness/internal/store"
|
"github.com/harness/gitness/internal/store"
|
||||||
"github.com/harness/gitness/types/check"
|
"github.com/harness/gitness/types/check"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ type CreateInput struct {
|
|||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a new pipeline
|
|
||||||
func (c *Controller) Create(ctx context.Context, session *auth.Session, in *CreateInput) (*types.Secret, error) {
|
func (c *Controller) Create(ctx context.Context, session *auth.Session, in *CreateInput) (*types.Secret, error) {
|
||||||
parentSpace, err := c.spaceStore.FindByRef(ctx, in.SpaceRef)
|
parentSpace, err := c.spaceStore.FindByRef(ctx, in.SpaceRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -73,6 +72,9 @@ func (c *Controller) Create(ctx context.Context, session *auth.Session, in *Crea
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return secret, nil
|
return secret, nil
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Delete deletes a secret.
|
|
||||||
func (c *Controller) Delete(ctx context.Context, session *auth.Session, spaceRef string, uid string) error {
|
func (c *Controller) Delete(ctx context.Context, session *auth.Session, spaceRef string, uid string) error {
|
||||||
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,8 +13,12 @@ import (
|
|||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Find finds a secret.
|
func (c *Controller) Find(
|
||||||
func (c *Controller) Find(ctx context.Context, session *auth.Session, spaceRef string, uid string) (*types.Secret, error) {
|
ctx context.Context,
|
||||||
|
session *auth.Session,
|
||||||
|
spaceRef string,
|
||||||
|
uid string,
|
||||||
|
) (*types.Secret, error) {
|
||||||
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
space, err := c.spaceStore.FindByRef(ctx, spaceRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -20,7 +20,6 @@ type UpdateInput struct {
|
|||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update updates a secret.
|
|
||||||
func (c *Controller) Update(
|
func (c *Controller) Update(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
session *auth.Session,
|
session *auth.Session,
|
||||||
|
@ -5,10 +5,11 @@
|
|||||||
package secret
|
package secret
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/google/wire"
|
|
||||||
"github.com/harness/gitness/internal/auth/authz"
|
"github.com/harness/gitness/internal/auth/authz"
|
||||||
"github.com/harness/gitness/internal/store"
|
"github.com/harness/gitness/internal/store"
|
||||||
"github.com/harness/gitness/types/check"
|
"github.com/harness/gitness/types/check"
|
||||||
|
|
||||||
|
"github.com/google/wire"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -95,7 +95,8 @@ func pipelineOperations(reflector *openapi3.Reflector) {
|
|||||||
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusUnauthorized)
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusUnauthorized)
|
||||||
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusForbidden)
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusForbidden)
|
||||||
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusNotFound)
|
_ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusNotFound)
|
||||||
_ = reflector.Spec.AddOperation(http.MethodPatch, "/pipelines/{pipeline_ref}", opUpdate)
|
_ = reflector.Spec.AddOperation(http.MethodPatch,
|
||||||
|
"/pipelines/{pipeline_ref}", opUpdate)
|
||||||
|
|
||||||
executionCreate := openapi3.Operation{}
|
executionCreate := openapi3.Operation{}
|
||||||
executionCreate.WithTags("pipeline")
|
executionCreate.WithTags("pipeline")
|
||||||
@ -106,7 +107,8 @@ func pipelineOperations(reflector *openapi3.Reflector) {
|
|||||||
_ = reflector.SetJSONResponse(&executionCreate, new(usererror.Error), http.StatusInternalServerError)
|
_ = reflector.SetJSONResponse(&executionCreate, new(usererror.Error), http.StatusInternalServerError)
|
||||||
_ = reflector.SetJSONResponse(&executionCreate, new(usererror.Error), http.StatusUnauthorized)
|
_ = reflector.SetJSONResponse(&executionCreate, new(usererror.Error), http.StatusUnauthorized)
|
||||||
_ = reflector.SetJSONResponse(&executionCreate, new(usererror.Error), http.StatusForbidden)
|
_ = reflector.SetJSONResponse(&executionCreate, new(usererror.Error), http.StatusForbidden)
|
||||||
_ = reflector.Spec.AddOperation(http.MethodPost, "/pipelines/{pipeline_ref}/executions", executionCreate)
|
_ = reflector.Spec.AddOperation(http.MethodPost,
|
||||||
|
"/pipelines/{pipeline_ref}/executions", executionCreate)
|
||||||
|
|
||||||
executionFind := openapi3.Operation{}
|
executionFind := openapi3.Operation{}
|
||||||
executionFind.WithTags("pipeline")
|
executionFind.WithTags("pipeline")
|
||||||
@ -117,7 +119,8 @@ func pipelineOperations(reflector *openapi3.Reflector) {
|
|||||||
_ = reflector.SetJSONResponse(&executionFind, new(usererror.Error), http.StatusUnauthorized)
|
_ = reflector.SetJSONResponse(&executionFind, new(usererror.Error), http.StatusUnauthorized)
|
||||||
_ = reflector.SetJSONResponse(&executionFind, new(usererror.Error), http.StatusForbidden)
|
_ = reflector.SetJSONResponse(&executionFind, new(usererror.Error), http.StatusForbidden)
|
||||||
_ = reflector.SetJSONResponse(&executionFind, new(usererror.Error), http.StatusNotFound)
|
_ = reflector.SetJSONResponse(&executionFind, new(usererror.Error), http.StatusNotFound)
|
||||||
_ = reflector.Spec.AddOperation(http.MethodGet, "/pipelines/{pipeline_ref}/executions/{execution_number}", executionFind)
|
_ = reflector.Spec.AddOperation(http.MethodGet,
|
||||||
|
"/pipelines/{pipeline_ref}/executions/{execution_number}", executionFind)
|
||||||
|
|
||||||
executionDelete := openapi3.Operation{}
|
executionDelete := openapi3.Operation{}
|
||||||
executionDelete.WithTags("pipeline")
|
executionDelete.WithTags("pipeline")
|
||||||
@ -128,7 +131,8 @@ func pipelineOperations(reflector *openapi3.Reflector) {
|
|||||||
_ = reflector.SetJSONResponse(&executionDelete, new(usererror.Error), http.StatusUnauthorized)
|
_ = reflector.SetJSONResponse(&executionDelete, new(usererror.Error), http.StatusUnauthorized)
|
||||||
_ = reflector.SetJSONResponse(&executionDelete, new(usererror.Error), http.StatusForbidden)
|
_ = reflector.SetJSONResponse(&executionDelete, new(usererror.Error), http.StatusForbidden)
|
||||||
_ = reflector.SetJSONResponse(&executionDelete, new(usererror.Error), http.StatusNotFound)
|
_ = reflector.SetJSONResponse(&executionDelete, new(usererror.Error), http.StatusNotFound)
|
||||||
_ = reflector.Spec.AddOperation(http.MethodDelete, "/pipelines/{pipeline_ref}/executions/{execution_number}", executionDelete)
|
_ = reflector.Spec.AddOperation(http.MethodDelete,
|
||||||
|
"/pipelines/{pipeline_ref}/executions/{execution_number}", executionDelete)
|
||||||
|
|
||||||
executionUpdate := openapi3.Operation{}
|
executionUpdate := openapi3.Operation{}
|
||||||
executionUpdate.WithTags("pipeline")
|
executionUpdate.WithTags("pipeline")
|
||||||
@ -140,7 +144,8 @@ func pipelineOperations(reflector *openapi3.Reflector) {
|
|||||||
_ = reflector.SetJSONResponse(&executionUpdate, new(usererror.Error), http.StatusUnauthorized)
|
_ = reflector.SetJSONResponse(&executionUpdate, new(usererror.Error), http.StatusUnauthorized)
|
||||||
_ = reflector.SetJSONResponse(&executionUpdate, new(usererror.Error), http.StatusForbidden)
|
_ = reflector.SetJSONResponse(&executionUpdate, new(usererror.Error), http.StatusForbidden)
|
||||||
_ = reflector.SetJSONResponse(&executionUpdate, new(usererror.Error), http.StatusNotFound)
|
_ = reflector.SetJSONResponse(&executionUpdate, new(usererror.Error), http.StatusNotFound)
|
||||||
_ = reflector.Spec.AddOperation(http.MethodPatch, "/pipelines/{pipeline_ref}/executions/{execution_number}", executionUpdate)
|
_ = reflector.Spec.AddOperation(http.MethodPatch,
|
||||||
|
"/pipelines/{pipeline_ref}/executions/{execution_number}", executionUpdate)
|
||||||
|
|
||||||
executionList := openapi3.Operation{}
|
executionList := openapi3.Operation{}
|
||||||
executionList.WithTags("pipeline")
|
executionList.WithTags("pipeline")
|
||||||
@ -152,5 +157,6 @@ func pipelineOperations(reflector *openapi3.Reflector) {
|
|||||||
_ = reflector.SetJSONResponse(&executionList, new(usererror.Error), http.StatusUnauthorized)
|
_ = reflector.SetJSONResponse(&executionList, new(usererror.Error), http.StatusUnauthorized)
|
||||||
_ = reflector.SetJSONResponse(&executionList, new(usererror.Error), http.StatusForbidden)
|
_ = reflector.SetJSONResponse(&executionList, new(usererror.Error), http.StatusForbidden)
|
||||||
_ = reflector.SetJSONResponse(&executionList, new(usererror.Error), http.StatusNotFound)
|
_ = reflector.SetJSONResponse(&executionList, new(usererror.Error), http.StatusNotFound)
|
||||||
_ = reflector.Spec.AddOperation(http.MethodGet, "/pipelines/{pipeline_ref}/executions", executionList)
|
_ = reflector.Spec.AddOperation(http.MethodGet,
|
||||||
|
"/pipelines/{pipeline_ref}/executions", executionList)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ func GetPipelineRefFromPath(r *http.Request) (string, error) {
|
|||||||
|
|
||||||
func GetExecutionNumberFromPath(r *http.Request) (int64, error) {
|
func GetExecutionNumberFromPath(r *http.Request) (int64, error) {
|
||||||
return PathParamAsPositiveInt64(r, ExecutionNumber)
|
return PathParamAsPositiveInt64(r, ExecutionNumber)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParsePipelineFilter extracts the pipeline filter from the url.
|
// ParsePipelineFilter extracts the pipeline filter from the url.
|
||||||
|
@ -510,7 +510,7 @@ type (
|
|||||||
// Delete deletes an execution given a pipeline ID and an execution number
|
// Delete deletes an execution given a pipeline ID and an execution number
|
||||||
Delete(ctx context.Context, pipelineID int64, num int64) error
|
Delete(ctx context.Context, pipelineID int64, num int64) error
|
||||||
|
|
||||||
// Count the number of executions in a space matching the given filter.
|
// Count the number of executions in a space
|
||||||
Count(ctx context.Context, parentID int64, opts *types.ExecutionFilter) (int64, error)
|
Count(ctx context.Context, parentID int64) (int64, error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/harness/gitness/store/database"
|
"github.com/harness/gitness/store/database"
|
||||||
"github.com/harness/gitness/store/database/dbtx"
|
"github.com/harness/gitness/store/database/dbtx"
|
||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -183,7 +184,7 @@ const (
|
|||||||
WHERE execution_id = :execution_id AND execution_version = :execution_version - 1`
|
WHERE execution_id = :execution_id AND execution_version = :execution_version - 1`
|
||||||
)
|
)
|
||||||
|
|
||||||
// Find returns an execution given a pipeline ID and an execution number
|
// Find returns an execution given a pipeline ID and an execution number.
|
||||||
func (s *executionStore) Find(ctx context.Context, pipelineID int64, executionNum int64) (*types.Execution, error) {
|
func (s *executionStore) Find(ctx context.Context, pipelineID int64, executionNum int64) (*types.Execution, error) {
|
||||||
const findQueryStmt = executionQueryBase + `
|
const findQueryStmt = executionQueryBase + `
|
||||||
WHERE execution_pipeline_id = $1 AND execution_number = $2`
|
WHERE execution_pipeline_id = $1 AND execution_number = $2`
|
||||||
@ -243,8 +244,12 @@ func (s *executionStore) Update(ctx context.Context, execution *types.Execution)
|
|||||||
return execution, nil
|
return execution, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// List lists the executions for a given pipeline ID
|
// List lists the executions for a given pipeline ID.
|
||||||
func (s *executionStore) List(ctx context.Context, pipelineID int64, opts *types.ExecutionFilter) ([]types.Execution, error) {
|
func (s *executionStore) List(
|
||||||
|
ctx context.Context,
|
||||||
|
pipelineID int64,
|
||||||
|
opts *types.ExecutionFilter,
|
||||||
|
) ([]types.Execution, error) {
|
||||||
stmt := database.Builder.
|
stmt := database.Builder.
|
||||||
Select(executionColumns).
|
Select(executionColumns).
|
||||||
From("executions").
|
From("executions").
|
||||||
@ -269,7 +274,7 @@ func (s *executionStore) List(ctx context.Context, pipelineID int64, opts *types
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Count of executions in a space.
|
// Count of executions in a space.
|
||||||
func (s *executionStore) Count(ctx context.Context, pipelineID int64, opts *types.ExecutionFilter) (int64, error) {
|
func (s *executionStore) Count(ctx context.Context, pipelineID int64) (int64, error) {
|
||||||
stmt := database.Builder.
|
stmt := database.Builder.
|
||||||
Select("count(*)").
|
Select("count(*)").
|
||||||
From("executions").
|
From("executions").
|
||||||
@ -290,7 +295,7 @@ func (s *executionStore) Count(ctx context.Context, pipelineID int64, opts *type
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes an execution given a pipeline ID and an execution number
|
// Delete deletes an execution given a pipeline ID and an execution number.
|
||||||
func (s *executionStore) Delete(ctx context.Context, pipelineID int64, executionNum int64) error {
|
func (s *executionStore) Delete(ctx context.Context, pipelineID int64, executionNum int64) error {
|
||||||
const executionDeleteStmt = `
|
const executionDeleteStmt = `
|
||||||
DELETE FROM executions
|
DELETE FROM executions
|
||||||
|
@ -101,7 +101,7 @@ type pipelineStore struct {
|
|||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find returns a pipeline given a pipeline ID
|
// Find returns a pipeline given a pipeline ID.
|
||||||
func (s *pipelineStore) Find(ctx context.Context, id int64) (*types.Pipeline, error) {
|
func (s *pipelineStore) Find(ctx context.Context, id int64) (*types.Pipeline, error) {
|
||||||
const findQueryStmt = pipelineQueryBase + `
|
const findQueryStmt = pipelineQueryBase + `
|
||||||
WHERE pipeline_id = $1`
|
WHERE pipeline_id = $1`
|
||||||
@ -114,7 +114,7 @@ func (s *pipelineStore) Find(ctx context.Context, id int64) (*types.Pipeline, er
|
|||||||
return dst, nil
|
return dst, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindByUID returns a pipeline in a given space with a given UID
|
// FindByUID returns a pipeline in a given space with a given UID.
|
||||||
func (s *pipelineStore) FindByUID(ctx context.Context, spaceID int64, uid string) (*types.Pipeline, error) {
|
func (s *pipelineStore) FindByUID(ctx context.Context, spaceID int64, uid string) (*types.Pipeline, error) {
|
||||||
const findQueryStmt = pipelineQueryBase + `
|
const findQueryStmt = pipelineQueryBase + `
|
||||||
WHERE pipeline_space_id = $1 AND pipeline_uid = $2`
|
WHERE pipeline_space_id = $1 AND pipeline_uid = $2`
|
||||||
@ -127,7 +127,7 @@ func (s *pipelineStore) FindByUID(ctx context.Context, spaceID int64, uid string
|
|||||||
return dst, nil
|
return dst, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a pipeline
|
// Create creates a pipeline.
|
||||||
func (s *pipelineStore) Create(ctx context.Context, pipeline *types.Pipeline) error {
|
func (s *pipelineStore) Create(ctx context.Context, pipeline *types.Pipeline) error {
|
||||||
db := dbtx.GetAccessor(ctx, s.db)
|
db := dbtx.GetAccessor(ctx, s.db)
|
||||||
|
|
||||||
@ -143,6 +143,7 @@ func (s *pipelineStore) Create(ctx context.Context, pipeline *types.Pipeline) er
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update updates a pipeline.
|
||||||
func (s *pipelineStore) Update(ctx context.Context, pipeline *types.Pipeline) (*types.Pipeline, error) {
|
func (s *pipelineStore) Update(ctx context.Context, pipeline *types.Pipeline) (*types.Pipeline, error) {
|
||||||
updatedAt := time.Now()
|
updatedAt := time.Now()
|
||||||
|
|
||||||
@ -171,11 +172,14 @@ func (s *pipelineStore) Update(ctx context.Context, pipeline *types.Pipeline) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
return pipeline, nil
|
return pipeline, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// List lists all the pipelines present in a space
|
// List lists all the pipelines present in a space.
|
||||||
func (s *pipelineStore) List(ctx context.Context, parentID int64, opts *types.PipelineFilter) ([]types.Pipeline, error) {
|
func (s *pipelineStore) List(
|
||||||
|
ctx context.Context,
|
||||||
|
parentID int64,
|
||||||
|
opts *types.PipelineFilter,
|
||||||
|
) ([]types.Pipeline, error) {
|
||||||
stmt := database.Builder.
|
stmt := database.Builder.
|
||||||
Select(pipelineColumns).
|
Select(pipelineColumns).
|
||||||
From("pipelines").
|
From("pipelines").
|
||||||
@ -229,7 +233,7 @@ func (s *pipelineStore) Count(ctx context.Context, parentID int64, opts *types.P
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes a pipeline given a pipeline ID
|
// Delete deletes a pipeline given a pipeline ID.
|
||||||
func (s *pipelineStore) Delete(ctx context.Context, id int64) error {
|
func (s *pipelineStore) Delete(ctx context.Context, id int64) error {
|
||||||
const pipelineDeleteStmt = `
|
const pipelineDeleteStmt = `
|
||||||
DELETE FROM pipelines
|
DELETE FROM pipelines
|
||||||
@ -244,7 +248,7 @@ func (s *pipelineStore) Delete(ctx context.Context, id int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteByUID deletes a pipeline with a given UID in a space
|
// DeleteByUID deletes a pipeline with a given UID in a space.
|
||||||
func (s *pipelineStore) DeleteByUID(ctx context.Context, spaceID int64, uid string) error {
|
func (s *pipelineStore) DeleteByUID(ctx context.Context, spaceID int64, uid string) error {
|
||||||
const pipelineDeleteStmt = `
|
const pipelineDeleteStmt = `
|
||||||
DELETE FROM pipelines
|
DELETE FROM pipelines
|
||||||
@ -263,12 +267,12 @@ func (s *pipelineStore) DeleteByUID(ctx context.Context, spaceID int64, uid stri
|
|||||||
// of optimistic lock errors.
|
// of optimistic lock errors.
|
||||||
func (s *pipelineStore) IncrementSeqNum(ctx context.Context, pipeline *types.Pipeline) (*types.Pipeline, error) {
|
func (s *pipelineStore) IncrementSeqNum(ctx context.Context, pipeline *types.Pipeline) (*types.Pipeline, error) {
|
||||||
for {
|
for {
|
||||||
|
var err error
|
||||||
pipeline.Seq++
|
pipeline.Seq++
|
||||||
pipeline, err := s.Update(ctx, pipeline)
|
pipeline, err = s.Update(ctx, pipeline)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return pipeline, nil
|
return pipeline, nil
|
||||||
}
|
} else if !errors.Is(err, gitness_store.ErrVersionConflict) {
|
||||||
if err != nil && err != gitness_store.ErrVersionConflict {
|
|
||||||
return pipeline, errors.Wrap(err, "could not increment pipeline sequence number")
|
return pipeline, errors.Wrap(err, "could not increment pipeline sequence number")
|
||||||
}
|
}
|
||||||
pipeline, err = s.Find(ctx, pipeline.ID)
|
pipeline, err = s.Find(ctx, pipeline.ID)
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/harness/gitness/store/database"
|
"github.com/harness/gitness/store/database"
|
||||||
"github.com/harness/gitness/store/database/dbtx"
|
"github.com/harness/gitness/store/database/dbtx"
|
||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@ -82,7 +83,7 @@ type secretStore struct {
|
|||||||
enc encrypt.Encrypter
|
enc encrypt.Encrypter
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find returns a secret given a secret ID
|
// Find returns a secret given a secret ID.
|
||||||
func (s *secretStore) Find(ctx context.Context, id int64) (*types.Secret, error) {
|
func (s *secretStore) Find(ctx context.Context, id int64) (*types.Secret, error) {
|
||||||
const findQueryStmt = secretQueryBase + `
|
const findQueryStmt = secretQueryBase + `
|
||||||
WHERE secret_id = $1`
|
WHERE secret_id = $1`
|
||||||
@ -95,7 +96,7 @@ func (s *secretStore) Find(ctx context.Context, id int64) (*types.Secret, error)
|
|||||||
return dec(s.enc, dst)
|
return dec(s.enc, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindByUID returns a secret in a given space with a given UID
|
// FindByUID returns a secret in a given space with a given UID.
|
||||||
func (s *secretStore) FindByUID(ctx context.Context, spaceID int64, uid string) (*types.Secret, error) {
|
func (s *secretStore) FindByUID(ctx context.Context, spaceID int64, uid string) (*types.Secret, error) {
|
||||||
const findQueryStmt = secretQueryBase + `
|
const findQueryStmt = secretQueryBase + `
|
||||||
WHERE secret_space_id = $1 AND secret_uid = $2`
|
WHERE secret_space_id = $1 AND secret_uid = $2`
|
||||||
@ -108,7 +109,7 @@ func (s *secretStore) FindByUID(ctx context.Context, spaceID int64, uid string)
|
|||||||
return dec(s.enc, dst)
|
return dec(s.enc, dst)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create creates a secret
|
// Create creates a secret.
|
||||||
func (s *secretStore) Create(ctx context.Context, secret *types.Secret) error {
|
func (s *secretStore) Create(ctx context.Context, secret *types.Secret) error {
|
||||||
db := dbtx.GetAccessor(ctx, s.db)
|
db := dbtx.GetAccessor(ctx, s.db)
|
||||||
|
|
||||||
@ -162,10 +163,9 @@ func (s *secretStore) Update(ctx context.Context, secret *types.Secret) (*types.
|
|||||||
}
|
}
|
||||||
|
|
||||||
return secret, nil
|
return secret, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// List lists all the secrets present in a space
|
// List lists all the secrets present in a space.
|
||||||
func (s *secretStore) List(ctx context.Context, parentID int64, opts *types.SecretFilter) ([]types.Secret, error) {
|
func (s *secretStore) List(ctx context.Context, parentID int64, opts *types.SecretFilter) ([]types.Secret, error) {
|
||||||
stmt := database.Builder.
|
stmt := database.Builder.
|
||||||
Select(secretColumns).
|
Select(secretColumns).
|
||||||
@ -194,7 +194,7 @@ func (s *secretStore) List(ctx context.Context, parentID int64, opts *types.Secr
|
|||||||
return dst, nil
|
return dst, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes a secret given a secret ID
|
// Delete deletes a secret given a secret ID.
|
||||||
func (s *secretStore) Delete(ctx context.Context, id int64) error {
|
func (s *secretStore) Delete(ctx context.Context, id int64) error {
|
||||||
const secretDeleteStmt = `
|
const secretDeleteStmt = `
|
||||||
DELETE FROM secrets
|
DELETE FROM secrets
|
||||||
@ -209,7 +209,7 @@ func (s *secretStore) Delete(ctx context.Context, id int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteByUID deletes a secret with a given UID in a space
|
// DeleteByUID deletes a secret with a given UID in a space.
|
||||||
func (s *secretStore) DeleteByUID(ctx context.Context, spaceID int64, uid string) error {
|
func (s *secretStore) DeleteByUID(ctx context.Context, spaceID int64, uid string) error {
|
||||||
const secretDeleteStmt = `
|
const secretDeleteStmt = `
|
||||||
DELETE FROM secrets
|
DELETE FROM secrets
|
||||||
@ -250,7 +250,7 @@ func (s *secretStore) Count(ctx context.Context, parentID int64, opts *types.Sec
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function returns the same secret with encrypted data
|
// helper function returns the same secret with encrypted data.
|
||||||
func enc(encrypt encrypt.Encrypter, secret *types.Secret) (*types.Secret, error) {
|
func enc(encrypt encrypt.Encrypter, secret *types.Secret) (*types.Secret, error) {
|
||||||
s := *secret
|
s := *secret
|
||||||
ciphertext, err := encrypt.Encrypt(secret.Data)
|
ciphertext, err := encrypt.Encrypt(secret.Data)
|
||||||
@ -261,13 +261,13 @@ func enc(encrypt encrypt.Encrypter, secret *types.Secret) (*types.Secret, error)
|
|||||||
return &s, nil
|
return &s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function returns the same secret with decrypted data
|
// helper function returns the same secret with decrypted data.
|
||||||
func dec(encrypt encrypt.Encrypter, secret *types.Secret) (*types.Secret, error) {
|
func dec(encrypt encrypt.Encrypter, secret *types.Secret) (*types.Secret, error) {
|
||||||
s := *secret
|
s := *secret
|
||||||
plaintext, err := encrypt.Decrypt([]byte(secret.Data))
|
plaintext, err := encrypt.Decrypt([]byte(secret.Data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
s.Data = string(plaintext)
|
s.Data = plaintext
|
||||||
return &s, nil
|
return &s, nil
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func ProvidePrincipalStore(db *sqlx.DB, uidTransformation store.PrincipalUIDTran
|
|||||||
return NewPrincipalStore(db, uidTransformation)
|
return NewPrincipalStore(db, uidTransformation)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProvideEncryptor provides an encryptor implementation
|
// ProvideEncryptor provides an encryptor implementation.
|
||||||
func ProvideEncryptor(config database.Config) (encrypt.Encrypter, error) {
|
func ProvideEncryptor(config database.Config) (encrypt.Encrypter, error) {
|
||||||
enc, err := encrypt.New(config.Secret)
|
enc, err := encrypt.New(config.Secret)
|
||||||
// mixed-content mode should be set to true if the database
|
// mixed-content mode should be set to true if the database
|
||||||
@ -104,12 +104,12 @@ func ProvidePipelineStore(db *sqlx.DB) store.PipelineStore {
|
|||||||
return NewPipelineStore(db)
|
return NewPipelineStore(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProvidePipelineStore provides a pipeline store.
|
// ProvideSecretStore provides a secret store.
|
||||||
func ProvideSecretStore(enc encrypt.Encrypter, db *sqlx.DB) store.SecretStore {
|
func ProvideSecretStore(enc encrypt.Encrypter, db *sqlx.DB) store.SecretStore {
|
||||||
return NewSecretStore(enc, db)
|
return NewSecretStore(enc, db)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProvideExecutionStore provides a build store
|
// ProvideExecutionStore provides an execution store.
|
||||||
func ProvideExecutionStore(db *sqlx.DB) store.ExecutionStore {
|
func ProvideExecutionStore(db *sqlx.DB) store.ExecutionStore {
|
||||||
return NewExecutionStore(db)
|
return NewExecutionStore(db)
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,10 @@ import (
|
|||||||
context "context"
|
context "context"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
|
|
||||||
gomock "github.com/golang/mock/gomock"
|
|
||||||
user "github.com/harness/gitness/internal/api/controller/user"
|
user "github.com/harness/gitness/internal/api/controller/user"
|
||||||
types "github.com/harness/gitness/types"
|
types "github.com/harness/gitness/types"
|
||||||
|
|
||||||
|
gomock "github.com/golang/mock/gomock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MockClient is a mock of Client interface.
|
// MockClient is a mock of Client interface.
|
||||||
|
@ -8,9 +8,10 @@ import (
|
|||||||
context "context"
|
context "context"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
|
|
||||||
gomock "github.com/golang/mock/gomock"
|
|
||||||
types "github.com/harness/gitness/types"
|
types "github.com/harness/gitness/types"
|
||||||
enum "github.com/harness/gitness/types/enum"
|
enum "github.com/harness/gitness/types/enum"
|
||||||
|
|
||||||
|
gomock "github.com/golang/mock/gomock"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MockPrincipalStore is a mock of PrincipalStore interface.
|
// MockPrincipalStore is a mock of PrincipalStore interface.
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
package types
|
package types
|
||||||
|
|
||||||
// Execution represents an instance of a pipeline execution
|
// Execution represents an instance of a pipeline execution.
|
||||||
type Execution struct {
|
type Execution struct {
|
||||||
ID int64 `db:"execution_id" json:"id"`
|
ID int64 `db:"execution_id" json:"id"`
|
||||||
PipelineID int64 `db:"execution_pipeline_id" json:"pipeline_id"`
|
PipelineID int64 `db:"execution_pipeline_id" json:"pipeline_id"`
|
||||||
|
Loading…
Reference in New Issue
Block a user