From e24eb858d562b0d52b5c6c0a877eca545c6a3ad1 Mon Sep 17 00:00:00 2001 From: Vistaar Juneja Date: Wed, 9 Aug 2023 23:00:33 +0100 Subject: [PATCH] run make format and fix lint errors --- cmd/gitness/wire_gen.go | 1 + encrypt/encrypt.go | 4 +++ .../api/controller/execution/controller.go | 1 + internal/api/controller/execution/create.go | 11 +++++--- internal/api/controller/execution/delete.go | 8 +++++- internal/api/controller/execution/find.go | 8 +++++- internal/api/controller/execution/list.go | 3 +-- internal/api/controller/execution/wire.go | 3 ++- .../api/controller/pipeline/controller.go | 1 + internal/api/controller/pipeline/create.go | 1 - internal/api/controller/pipeline/delete.go | 1 - internal/api/controller/pipeline/find.go | 8 ++++-- internal/api/controller/pipeline/wire.go | 6 ++--- internal/api/controller/secret/controller.go | 1 + internal/api/controller/secret/create.go | 4 ++- internal/api/controller/secret/delete.go | 1 - internal/api/controller/secret/find.go | 8 ++++-- internal/api/controller/secret/update.go | 1 - internal/api/controller/secret/wire.go | 3 ++- internal/api/openapi/pipeline.go | 18 ++++++++----- internal/api/request/pipeline.go | 1 - internal/store/database.go | 4 +-- internal/store/database/execution.go | 15 +++++++---- internal/store/database/pipeline.go | 26 +++++++++++-------- internal/store/database/secret.go | 20 +++++++------- internal/store/database/wire.go | 6 ++--- mocks/mock_client.go | 3 ++- mocks/mock_store.go | 3 ++- types/execution.go | 2 +- 29 files changed, 110 insertions(+), 62 deletions(-) diff --git a/cmd/gitness/wire_gen.go b/cmd/gitness/wire_gen.go index 08d04cb70..81aca6116 100644 --- a/cmd/gitness/wire_gen.go +++ b/cmd/gitness/wire_gen.go @@ -8,6 +8,7 @@ package main import ( "context" + "github.com/harness/gitness/cli/server" "github.com/harness/gitness/events" "github.com/harness/gitness/gitrpc" diff --git a/encrypt/encrypt.go b/encrypt/encrypt.go index 5e365254a..403c866d5 100644 --- a/encrypt/encrypt.go +++ b/encrypt/encrypt.go @@ -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 import ( diff --git a/internal/api/controller/execution/controller.go b/internal/api/controller/execution/controller.go index 652637035..abfa572eb 100644 --- a/internal/api/controller/execution/controller.go +++ b/internal/api/controller/execution/controller.go @@ -7,6 +7,7 @@ package execution import ( "github.com/harness/gitness/internal/auth/authz" "github.com/harness/gitness/internal/store" + "github.com/jmoiron/sqlx" ) diff --git a/internal/api/controller/execution/create.go b/internal/api/controller/execution/create.go index 829ef6135..595def806 100644 --- a/internal/api/controller/execution/create.go +++ b/internal/api/controller/execution/create.go @@ -15,13 +15,18 @@ import ( "github.com/harness/gitness/types/enum" ) -// TODO: Add more as needed +// TODO: Add more as needed. type CreateInput struct { Status string `json:"status"` } -// Create creates a new execution -func (c *Controller) Create(ctx context.Context, session *auth.Session, spaceRef string, uid string, in *CreateInput) (*types.Execution, error) { +func (c *Controller) Create( + ctx context.Context, + session *auth.Session, + spaceRef string, + uid string, + in *CreateInput, +) (*types.Execution, error) { space, err := c.spaceStore.FindByRef(ctx, spaceRef) if err != nil { return nil, fmt.Errorf("could not find space: %w", err) diff --git a/internal/api/controller/execution/delete.go b/internal/api/controller/execution/delete.go index 357574092..9b2a84aa9 100644 --- a/internal/api/controller/execution/delete.go +++ b/internal/api/controller/execution/delete.go @@ -13,7 +13,13 @@ import ( "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) if err != nil { return fmt.Errorf("could not find parent space: %w", err) diff --git a/internal/api/controller/execution/find.go b/internal/api/controller/execution/find.go index 81bf08ba0..d597488fd 100644 --- a/internal/api/controller/execution/find.go +++ b/internal/api/controller/execution/find.go @@ -14,7 +14,13 @@ import ( "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) if err != nil { return nil, fmt.Errorf("could not find parent space: %w", err) diff --git a/internal/api/controller/execution/list.go b/internal/api/controller/execution/list.go index 5cbbde5d0..7d9c79488 100644 --- a/internal/api/controller/execution/list.go +++ b/internal/api/controller/execution/list.go @@ -14,7 +14,6 @@ import ( "github.com/harness/gitness/types/enum" ) -// List lists the executions in a pipeline. func (c *Controller) List( ctx context.Context, session *auth.Session, @@ -41,7 +40,7 @@ func (c *Controller) List( err = dbtx.New(c.db).WithTx(ctx, func(ctx context.Context) (err error) { var dbErr error - count, dbErr = c.executionStore.Count(ctx, pipeline.ID, filter) + count, dbErr = c.executionStore.Count(ctx, pipeline.ID) if dbErr != nil { return fmt.Errorf("failed to count child executions: %w", err) } diff --git a/internal/api/controller/execution/wire.go b/internal/api/controller/execution/wire.go index b2836ae35..c559831f9 100644 --- a/internal/api/controller/execution/wire.go +++ b/internal/api/controller/execution/wire.go @@ -5,9 +5,10 @@ package execution import ( - "github.com/google/wire" "github.com/harness/gitness/internal/auth/authz" "github.com/harness/gitness/internal/store" + + "github.com/google/wire" "github.com/jmoiron/sqlx" ) diff --git a/internal/api/controller/pipeline/controller.go b/internal/api/controller/pipeline/controller.go index 5c7f4ae44..61020c78a 100644 --- a/internal/api/controller/pipeline/controller.go +++ b/internal/api/controller/pipeline/controller.go @@ -8,6 +8,7 @@ import ( "github.com/harness/gitness/internal/auth/authz" "github.com/harness/gitness/internal/store" "github.com/harness/gitness/types/check" + "github.com/jmoiron/sqlx" ) diff --git a/internal/api/controller/pipeline/create.go b/internal/api/controller/pipeline/create.go index 16eeeff13..74cbedc8d 100644 --- a/internal/api/controller/pipeline/create.go +++ b/internal/api/controller/pipeline/create.go @@ -35,7 +35,6 @@ type CreateInput struct { 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) { parentSpace, err := c.spaceStore.FindByRef(ctx, in.SpaceRef) if err != nil { diff --git a/internal/api/controller/pipeline/delete.go b/internal/api/controller/pipeline/delete.go index fd266a5e9..cdae2a3cc 100644 --- a/internal/api/controller/pipeline/delete.go +++ b/internal/api/controller/pipeline/delete.go @@ -13,7 +13,6 @@ import ( "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 { space, err := c.spaceStore.FindByRef(ctx, spaceRef) if err != nil { diff --git a/internal/api/controller/pipeline/find.go b/internal/api/controller/pipeline/find.go index 22560502a..b065bc404 100644 --- a/internal/api/controller/pipeline/find.go +++ b/internal/api/controller/pipeline/find.go @@ -14,8 +14,12 @@ import ( "github.com/harness/gitness/types/enum" ) -// Find finds a pipeline. -func (c *Controller) Find(ctx context.Context, session *auth.Session, spaceRef string, uid string) (*types.Pipeline, error) { +func (c *Controller) Find( + ctx context.Context, + session *auth.Session, + spaceRef string, + uid string, +) (*types.Pipeline, error) { space, err := c.spaceStore.FindByRef(ctx, spaceRef) if err != nil { return nil, fmt.Errorf("could not find parent space: %w", err) diff --git a/internal/api/controller/pipeline/wire.go b/internal/api/controller/pipeline/wire.go index 70bd3ff44..d665a8ee6 100644 --- a/internal/api/controller/pipeline/wire.go +++ b/internal/api/controller/pipeline/wire.go @@ -5,12 +5,12 @@ package pipeline import ( - "github.com/google/wire" - "github.com/jmoiron/sqlx" - "github.com/harness/gitness/internal/auth/authz" "github.com/harness/gitness/internal/store" "github.com/harness/gitness/types/check" + + "github.com/google/wire" + "github.com/jmoiron/sqlx" ) // WireSet provides a wire set for this package. diff --git a/internal/api/controller/secret/controller.go b/internal/api/controller/secret/controller.go index 8bbd2082d..c979b6dcb 100644 --- a/internal/api/controller/secret/controller.go +++ b/internal/api/controller/secret/controller.go @@ -8,6 +8,7 @@ import ( "github.com/harness/gitness/internal/auth/authz" "github.com/harness/gitness/internal/store" "github.com/harness/gitness/types/check" + "github.com/jmoiron/sqlx" ) diff --git a/internal/api/controller/secret/create.go b/internal/api/controller/secret/create.go index d2573c08a..fe6da13f6 100644 --- a/internal/api/controller/secret/create.go +++ b/internal/api/controller/secret/create.go @@ -33,7 +33,6 @@ type CreateInput struct { Data string `json:"data"` } -// Create creates a new pipeline func (c *Controller) Create(ctx context.Context, session *auth.Session, in *CreateInput) (*types.Secret, error) { parentSpace, err := c.spaceStore.FindByRef(ctx, in.SpaceRef) if err != nil { @@ -73,6 +72,9 @@ func (c *Controller) Create(ctx context.Context, session *auth.Session, in *Crea } return nil }) + if err != nil { + return nil, err + } return secret, nil } diff --git a/internal/api/controller/secret/delete.go b/internal/api/controller/secret/delete.go index baf76584a..8e42ede62 100644 --- a/internal/api/controller/secret/delete.go +++ b/internal/api/controller/secret/delete.go @@ -13,7 +13,6 @@ import ( "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 { space, err := c.spaceStore.FindByRef(ctx, spaceRef) if err != nil { diff --git a/internal/api/controller/secret/find.go b/internal/api/controller/secret/find.go index 6f5278b65..91d2e492f 100644 --- a/internal/api/controller/secret/find.go +++ b/internal/api/controller/secret/find.go @@ -13,8 +13,12 @@ import ( "github.com/harness/gitness/types/enum" ) -// Find finds a secret. -func (c *Controller) Find(ctx context.Context, session *auth.Session, spaceRef string, uid string) (*types.Secret, error) { +func (c *Controller) Find( + ctx context.Context, + session *auth.Session, + spaceRef string, + uid string, +) (*types.Secret, error) { space, err := c.spaceStore.FindByRef(ctx, spaceRef) if err != nil { return nil, err diff --git a/internal/api/controller/secret/update.go b/internal/api/controller/secret/update.go index c872dcd1a..d495dc082 100644 --- a/internal/api/controller/secret/update.go +++ b/internal/api/controller/secret/update.go @@ -20,7 +20,6 @@ type UpdateInput struct { Data string `json:"data"` } -// Update updates a secret. func (c *Controller) Update( ctx context.Context, session *auth.Session, diff --git a/internal/api/controller/secret/wire.go b/internal/api/controller/secret/wire.go index 09b46cc52..8922a5dc1 100644 --- a/internal/api/controller/secret/wire.go +++ b/internal/api/controller/secret/wire.go @@ -5,10 +5,11 @@ package secret import ( - "github.com/google/wire" "github.com/harness/gitness/internal/auth/authz" "github.com/harness/gitness/internal/store" "github.com/harness/gitness/types/check" + + "github.com/google/wire" "github.com/jmoiron/sqlx" ) diff --git a/internal/api/openapi/pipeline.go b/internal/api/openapi/pipeline.go index ece281796..533e29a09 100644 --- a/internal/api/openapi/pipeline.go +++ b/internal/api/openapi/pipeline.go @@ -95,7 +95,8 @@ func pipelineOperations(reflector *openapi3.Reflector) { _ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusUnauthorized) _ = reflector.SetJSONResponse(&opUpdate, new(usererror.Error), http.StatusForbidden) _ = 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.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.StatusUnauthorized) _ = 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.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.StatusForbidden) _ = 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.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.StatusForbidden) _ = 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.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.StatusForbidden) _ = 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.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.StatusForbidden) _ = 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) } diff --git a/internal/api/request/pipeline.go b/internal/api/request/pipeline.go index a61f1b625..4dbb5abde 100644 --- a/internal/api/request/pipeline.go +++ b/internal/api/request/pipeline.go @@ -29,7 +29,6 @@ func GetPipelineRefFromPath(r *http.Request) (string, error) { func GetExecutionNumberFromPath(r *http.Request) (int64, error) { return PathParamAsPositiveInt64(r, ExecutionNumber) - } // ParsePipelineFilter extracts the pipeline filter from the url. diff --git a/internal/store/database.go b/internal/store/database.go index e9a006d01..87fe85cb9 100644 --- a/internal/store/database.go +++ b/internal/store/database.go @@ -510,7 +510,7 @@ type ( // Delete deletes an execution given a pipeline ID and an execution number Delete(ctx context.Context, pipelineID int64, num int64) error - // Count the number of executions in a space matching the given filter. - Count(ctx context.Context, parentID int64, opts *types.ExecutionFilter) (int64, error) + // Count the number of executions in a space + Count(ctx context.Context, parentID int64) (int64, error) } ) diff --git a/internal/store/database/execution.go b/internal/store/database/execution.go index af0918d1c..73e344beb 100644 --- a/internal/store/database/execution.go +++ b/internal/store/database/execution.go @@ -14,6 +14,7 @@ import ( "github.com/harness/gitness/store/database" "github.com/harness/gitness/store/database/dbtx" "github.com/harness/gitness/types" + "github.com/jmoiron/sqlx" "github.com/pkg/errors" ) @@ -183,7 +184,7 @@ const ( 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) { const findQueryStmt = executionQueryBase + ` 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 } -// List lists the executions for a given pipeline ID -func (s *executionStore) List(ctx context.Context, pipelineID int64, opts *types.ExecutionFilter) ([]types.Execution, error) { +// List lists the executions for a given pipeline ID. +func (s *executionStore) List( + ctx context.Context, + pipelineID int64, + opts *types.ExecutionFilter, +) ([]types.Execution, error) { stmt := database.Builder. Select(executionColumns). From("executions"). @@ -269,7 +274,7 @@ func (s *executionStore) List(ctx context.Context, pipelineID int64, opts *types } // 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. Select("count(*)"). From("executions"). @@ -290,7 +295,7 @@ func (s *executionStore) Count(ctx context.Context, pipelineID int64, opts *type 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 { const executionDeleteStmt = ` DELETE FROM executions diff --git a/internal/store/database/pipeline.go b/internal/store/database/pipeline.go index d43fa7032..1e36f9615 100644 --- a/internal/store/database/pipeline.go +++ b/internal/store/database/pipeline.go @@ -101,7 +101,7 @@ type pipelineStore struct { 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) { const findQueryStmt = pipelineQueryBase + ` WHERE pipeline_id = $1` @@ -114,7 +114,7 @@ func (s *pipelineStore) Find(ctx context.Context, id int64) (*types.Pipeline, er 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) { const findQueryStmt = pipelineQueryBase + ` 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 } -// Create creates a pipeline +// Create creates a pipeline. func (s *pipelineStore) Create(ctx context.Context, pipeline *types.Pipeline) error { db := dbtx.GetAccessor(ctx, s.db) @@ -143,6 +143,7 @@ func (s *pipelineStore) Create(ctx context.Context, pipeline *types.Pipeline) er return nil } +// Update updates a pipeline. func (s *pipelineStore) Update(ctx context.Context, pipeline *types.Pipeline) (*types.Pipeline, error) { updatedAt := time.Now() @@ -171,11 +172,14 @@ func (s *pipelineStore) Update(ctx context.Context, pipeline *types.Pipeline) (* } return pipeline, nil - } -// List lists all the pipelines present in a space -func (s *pipelineStore) List(ctx context.Context, parentID int64, opts *types.PipelineFilter) ([]types.Pipeline, error) { +// List lists all the pipelines present in a space. +func (s *pipelineStore) List( + ctx context.Context, + parentID int64, + opts *types.PipelineFilter, +) ([]types.Pipeline, error) { stmt := database.Builder. Select(pipelineColumns). From("pipelines"). @@ -229,7 +233,7 @@ func (s *pipelineStore) Count(ctx context.Context, parentID int64, opts *types.P 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 { const pipelineDeleteStmt = ` DELETE FROM pipelines @@ -244,7 +248,7 @@ func (s *pipelineStore) Delete(ctx context.Context, id int64) error { 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 { const pipelineDeleteStmt = ` DELETE FROM pipelines @@ -263,12 +267,12 @@ func (s *pipelineStore) DeleteByUID(ctx context.Context, spaceID int64, uid stri // of optimistic lock errors. func (s *pipelineStore) IncrementSeqNum(ctx context.Context, pipeline *types.Pipeline) (*types.Pipeline, error) { for { + var err error pipeline.Seq++ - pipeline, err := s.Update(ctx, pipeline) + pipeline, err = s.Update(ctx, pipeline) if err == nil { return pipeline, nil - } - if err != nil && err != gitness_store.ErrVersionConflict { + } else if !errors.Is(err, gitness_store.ErrVersionConflict) { return pipeline, errors.Wrap(err, "could not increment pipeline sequence number") } pipeline, err = s.Find(ctx, pipeline.ID) diff --git a/internal/store/database/secret.go b/internal/store/database/secret.go index bb3be1b83..a53a10db7 100644 --- a/internal/store/database/secret.go +++ b/internal/store/database/secret.go @@ -16,6 +16,7 @@ import ( "github.com/harness/gitness/store/database" "github.com/harness/gitness/store/database/dbtx" "github.com/harness/gitness/types" + "github.com/jmoiron/sqlx" "github.com/pkg/errors" ) @@ -82,7 +83,7 @@ type secretStore struct { 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) { const findQueryStmt = secretQueryBase + ` 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) } -// 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) { const findQueryStmt = secretQueryBase + ` 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) } -// Create creates a secret +// Create creates a secret. func (s *secretStore) Create(ctx context.Context, secret *types.Secret) error { db := dbtx.GetAccessor(ctx, s.db) @@ -162,10 +163,9 @@ func (s *secretStore) Update(ctx context.Context, secret *types.Secret) (*types. } 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) { stmt := database.Builder. Select(secretColumns). @@ -194,7 +194,7 @@ func (s *secretStore) List(ctx context.Context, parentID int64, opts *types.Secr 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 { const secretDeleteStmt = ` DELETE FROM secrets @@ -209,7 +209,7 @@ func (s *secretStore) Delete(ctx context.Context, id int64) error { 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 { const secretDeleteStmt = ` DELETE FROM secrets @@ -250,7 +250,7 @@ func (s *secretStore) Count(ctx context.Context, parentID int64, opts *types.Sec 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) { s := *secret ciphertext, err := encrypt.Encrypt(secret.Data) @@ -261,13 +261,13 @@ func enc(encrypt encrypt.Encrypter, secret *types.Secret) (*types.Secret, error) 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) { s := *secret plaintext, err := encrypt.Decrypt([]byte(secret.Data)) if err != nil { return nil, err } - s.Data = string(plaintext) + s.Data = plaintext return &s, nil } diff --git a/internal/store/database/wire.go b/internal/store/database/wire.go index 49cc72ba4..bd4b64cc1 100644 --- a/internal/store/database/wire.go +++ b/internal/store/database/wire.go @@ -63,7 +63,7 @@ func ProvidePrincipalStore(db *sqlx.DB, uidTransformation store.PrincipalUIDTran return NewPrincipalStore(db, uidTransformation) } -// ProvideEncryptor provides an encryptor implementation +// ProvideEncryptor provides an encryptor implementation. func ProvideEncryptor(config database.Config) (encrypt.Encrypter, error) { enc, err := encrypt.New(config.Secret) // 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) } -// ProvidePipelineStore provides a pipeline store. +// ProvideSecretStore provides a secret store. func ProvideSecretStore(enc encrypt.Encrypter, db *sqlx.DB) store.SecretStore { return NewSecretStore(enc, db) } -// ProvideExecutionStore provides a build store +// ProvideExecutionStore provides an execution store. func ProvideExecutionStore(db *sqlx.DB) store.ExecutionStore { return NewExecutionStore(db) } diff --git a/mocks/mock_client.go b/mocks/mock_client.go index b16a6490e..3cb746055 100644 --- a/mocks/mock_client.go +++ b/mocks/mock_client.go @@ -8,9 +8,10 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" user "github.com/harness/gitness/internal/api/controller/user" types "github.com/harness/gitness/types" + + gomock "github.com/golang/mock/gomock" ) // MockClient is a mock of Client interface. diff --git a/mocks/mock_store.go b/mocks/mock_store.go index 0af0bbc34..9310f3729 100644 --- a/mocks/mock_store.go +++ b/mocks/mock_store.go @@ -8,9 +8,10 @@ import ( context "context" reflect "reflect" - gomock "github.com/golang/mock/gomock" types "github.com/harness/gitness/types" enum "github.com/harness/gitness/types/enum" + + gomock "github.com/golang/mock/gomock" ) // MockPrincipalStore is a mock of PrincipalStore interface. diff --git a/types/execution.go b/types/execution.go index e29df4f8d..fde55504e 100644 --- a/types/execution.go +++ b/types/execution.go @@ -4,7 +4,7 @@ package types -// Execution represents an instance of a pipeline execution +// Execution represents an instance of a pipeline execution. type Execution struct { ID int64 `db:"execution_id" json:"id"` PipelineID int64 `db:"execution_pipeline_id" json:"pipeline_id"`