Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(database): move secret logic into separate package #782

Merged
merged 92 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 84 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
57e5162
Merge branch 'master' of github.com:go-vela/server
jbrockopp Feb 23, 2022
b6b840c
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 10, 2022
858c818
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 16, 2022
ceddb11
Merge branch 'master' of github.com:go-vela/server
jbrockopp Mar 28, 2022
331b2a2
Merge branch 'master' of github.com:go-vela/server
jbrockopp Apr 11, 2022
c4ec5fb
Merge branches 'master' and 'master' of github.com:go-vela/server
jbrockopp Apr 18, 2022
30c1151
Merge branch 'master' of github.com:go-vela/server
jbrockopp Apr 20, 2022
0ddc31c
Merge branch 'master' of github.com:go-vela/server
jbrockopp Apr 27, 2022
890f9fa
Merge branch 'master' of github.com:go-vela/server
jbrockopp May 9, 2022
cf4ca0e
Merge branch 'master' of github.com:go-vela/server
jbrockopp May 20, 2022
175e5c5
Merge branch 'master' of github.com:go-vela/server
jbrockopp May 31, 2022
1728dce
Merge branch 'master' of github.com:go-vela/server
jbrockopp Jun 12, 2022
88d3974
Merge branch 'master' of github.com:go-vela/server
jbrockopp Jun 22, 2022
de5ac75
feat(database): add user engine
jbrockopp Jun 22, 2022
8f2fce6
chore(database): remove old user logic
jbrockopp Jun 22, 2022
736a0e9
refactor(database): restructure DDL functions
jbrockopp Jun 22, 2022
c28ca23
chore: updates for database user engine
jbrockopp Jun 22, 2022
a4d8bbc
Merge branch 'master' of github.com:go-vela/server
jbrockopp Jun 26, 2022
c719ab0
Merge branch 'refactor/database/user' of github.com:go-vela/server in…
jbrockopp Jun 26, 2022
a147ce8
feat(database): add repo engine
jbrockopp Jun 27, 2022
b7e267f
Merge branch 'master' of github.com:go-vela/server into refactor/data…
jbrockopp Aug 20, 2022
ff5b8e1
chore: save work
jbrockopp Aug 27, 2022
ef70014
Merge branch 'master' of github.com:go-vela/server
jbrockopp Aug 27, 2022
ca230da
Merge branch 'master' of github.com:go-vela/server into refactor/data…
jbrockopp Aug 27, 2022
ab2f213
fix: Scan() -> Take()
jbrockopp Aug 27, 2022
68cf328
fix: sort by for listing repos
jbrockopp Sep 10, 2022
55862b2
Merge branch 'master' into refactor/database/repo
jbrockopp Sep 10, 2022
443c5d0
Merge branches 'master' and 'master' of github.com:go-vela/server
jbrockopp Sep 11, 2022
a47cf36
Merge branch 'refactor/database/repo' of github.com:go-vela/server in…
jbrockopp Sep 11, 2022
8e628be
feat(database): add worker engine
jbrockopp Sep 11, 2022
a827790
chore(database): remove old worker logic
jbrockopp Sep 11, 2022
a960f5d
chore: updates for database worker engine
jbrockopp Sep 11, 2022
3b7918f
Merge branch 'main' into refactor/database/worker
jbrockopp Sep 30, 2022
535b2bb
Merge branch 'refactor/database/worker' of github.com:go-vela/server …
jbrockopp Sep 30, 2022
acad4fd
fix: issues from merge conflict
jbrockopp Sep 30, 2022
72bc1f1
Merge branch 'main' into refactor/database/worker
jbrockopp Sep 30, 2022
3745fdf
Merge branch 'refactor/database/worker' of github.com:go-vela/server …
jbrockopp Sep 30, 2022
6fcc762
chore: address linter feedback
jbrockopp Sep 30, 2022
57206f9
chore: address linter feedback v2
jbrockopp Sep 30, 2022
af3cf83
Merge branch 'main' into refactor/database/worker
jbrockopp Oct 5, 2022
6cf8508
Merge branch 'main' into refactor/database/worker
jbrockopp Oct 7, 2022
b5254d7
Merge branch 'refactor/database/worker' of github.com:go-vela/server …
jbrockopp Oct 7, 2022
0648d24
Merge branch 'main' into refactor/database/worker
jbrockopp Oct 7, 2022
4ac392a
Merge branch 'refactor/database/worker' of github.com:go-vela/server …
jbrockopp Oct 7, 2022
a7994ec
Merge branch 'main' into refactor/database/worker
jbrockopp Oct 7, 2022
7c2b5b7
Merge branch 'refactor/database/worker' of github.com:go-vela/server …
jbrockopp Oct 7, 2022
c4d188d
Merge branch 'refactor/database/worker' of github.com:go-vela/server …
jbrockopp Oct 7, 2022
1171ce1
feat(database): add hook engine
jbrockopp Oct 7, 2022
286e06e
chore: remove Limit(1) with Take()
jbrockopp Oct 7, 2022
a28899c
Merge branch 'refactor/database/worker' of github.com:go-vela/server …
jbrockopp Oct 7, 2022
d9d2749
chore(database): remove old hook logic
jbrockopp Oct 7, 2022
6086c0a
chore: updates for database hook engine
jbrockopp Oct 7, 2022
7991f03
refactor(database/worker): name of index
jbrockopp Oct 8, 2022
5b90666
Merge branch 'refactor/database/worker' of github.com:go-vela/server …
jbrockopp Oct 8, 2022
feb5118
Merge branch 'refactor/database/hook' of github.com:go-vela/server
jbrockopp Oct 8, 2022
dc7187e
feat(database): add log engine
jbrockopp Oct 10, 2022
877639d
chore(database): remove old log logic
jbrockopp Oct 10, 2022
0ffb84b
chore: updates for database log engine
jbrockopp Oct 10, 2022
74626c9
Merge branch 'main' of github.com:go-vela/server
jbrockopp Feb 14, 2023
11c8518
Merge branch 'main' of github.com:go-vela/server into refactor/databa…
jbrockopp Feb 14, 2023
6bf3448
chore: update copyright year
jbrockopp Feb 14, 2023
b42ca0e
chore: address linter feedback
jbrockopp Feb 14, 2023
a6652af
chore: address linter feedback
jbrockopp Feb 14, 2023
15efe25
Merge branch 'refactor/database/log' of github.com:go-vela/server int…
jbrockopp Feb 18, 2023
5bac0e1
chore: save work
jbrockopp Mar 3, 2023
8c50f6f
Merge branch 'main' into refactor/database/secret
jbrockopp Mar 4, 2023
2c4dae6
Merge branch 'refactor/database/secret' of github.com:go-vela/server …
jbrockopp Mar 4, 2023
578ba46
chore: save work
jbrockopp Mar 4, 2023
7fae370
chore: finalize testing
jbrockopp Mar 6, 2023
d2a38f8
chore: save work
jbrockopp Mar 9, 2023
5425fb7
chore: finalize changes
jbrockopp Mar 16, 2023
3534e03
Merge branch 'main' into refactor/database/secret
jbrockopp Mar 16, 2023
1bb7c78
Merge branch 'refactor/database/secret' of github.com:go-vela/server …
jbrockopp Mar 16, 2023
bf8b15e
fix: failing tests
jbrockopp Mar 16, 2023
284f61a
chore: address linter feedback
jbrockopp Mar 16, 2023
4455db1
Merge branch 'main' into refactor/database/secret
jbrockopp Mar 20, 2023
be7b476
chore: add missing tests
jbrockopp Mar 20, 2023
131b2c8
Merge branch 'refactor/database/secret' of github.com:go-vela/server …
jbrockopp Mar 20, 2023
bce065f
chore: address linter feedback
jbrockopp Mar 20, 2023
f1b7827
Merge branch 'main' into refactor/database/secret
jbrockopp Mar 22, 2023
92f0836
Merge branch 'main' into refactor/database/secret
jbrockopp Mar 23, 2023
44c0355
chore: address review feedback
jbrockopp Mar 27, 2023
7ed38f7
Merge branch 'refactor/database/secret' of github.com:go-vela/server …
jbrockopp Mar 27, 2023
b6609c0
Merge branch 'main' into refactor/database/secret
jbrockopp Mar 27, 2023
81f41ef
Merge branch 'main' into refactor/database/secret
jbrockopp Mar 30, 2023
e4b5d37
chore: address review feedback
jbrockopp Apr 3, 2023
282a6d5
Merge branch 'refactor/database/secret' of github.com:go-vela/server …
jbrockopp Apr 3, 2023
662917e
Merge branch 'main' into refactor/database/secret
jbrockopp Apr 3, 2023
414343d
Merge branch 'main' into refactor/database/secret
jbrockopp Apr 5, 2023
ce0954c
Merge branch 'main' into refactor/database/secret
jbrockopp Apr 8, 2023
02b9e35
Merge branch 'main' into refactor/database/secret
cognifloyd Apr 8, 2023
a0f0dd2
Merge branch 'main' into refactor/database/secret
ecrupper Apr 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ func renameRepository(h *library.Hook, r *library.Repo, c *gin.Context, m *types
}

// get total number of secrets associated with repository
t, err := database.FromContext(c).GetTypeSecretCount(constants.SecretRepo, r.GetOrg(), previousName, []string{})
t, err := database.FromContext(c).CountSecretsForRepo(dbR, map[string]interface{}{})
if err != nil {
return fmt.Errorf("unable to get secret count for repo %s/%s: %w", r.GetOrg(), previousName, err)
}
Expand All @@ -863,7 +863,7 @@ func renameRepository(h *library.Hook, r *library.Repo, c *gin.Context, m *types
page := 1
// capture all secrets belonging to certain repo in database
for repoSecrets := int64(0); repoSecrets < t; repoSecrets += 100 {
s, err := database.FromContext(c).GetTypeSecretList(constants.SecretRepo, r.GetOrg(), previousName, page, 100, []string{})
s, _, err := database.FromContext(c).ListSecretsForRepo(dbR, map[string]interface{}{}, page, 100)
if err != nil {
return fmt.Errorf("unable to get secret list for repo %s/%s: %w", r.GetOrg(), previousName, err)
}
Expand Down
65 changes: 0 additions & 65 deletions database/postgres/ddl/secret.go

This file was deleted.

146 changes: 0 additions & 146 deletions database/postgres/dml/secret.go

This file was deleted.

45 changes: 21 additions & 24 deletions database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/go-vela/server/database/pipeline"
"github.com/go-vela/server/database/postgres/ddl"
"github.com/go-vela/server/database/repo"
"github.com/go-vela/server/database/secret"
jbrockopp marked this conversation as resolved.
Show resolved Hide resolved
"github.com/go-vela/server/database/user"
"github.com/go-vela/server/database/worker"
"github.com/go-vela/types/constants"
Expand Down Expand Up @@ -55,6 +56,8 @@ type (
pipeline.PipelineService
// https://pkg.go.dev/github.com/go-vela/server/database/repo#RepoService
repo.RepoService
// https://pkg.go.dev/github.com/go-vela/server/database/secret#SecretService
secret.SecretService
// https://pkg.go.dev/github.com/go-vela/server/database/user#UserService
user.UserService
// https://pkg.go.dev/github.com/go-vela/server/database/worker#WorkerService
Expand Down Expand Up @@ -167,6 +170,11 @@ func NewTest() (*client, sqlmock.Sqlmock, error) {
// ensure the mock expects the repo queries
_mock.ExpectExec(repo.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(repo.CreateOrgNameIndex).WillReturnResult(sqlmock.NewResult(1, 1))
// ensure the mock expects the secret queries
_mock.ExpectExec(secret.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(secret.CreateTypeOrgRepo).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(secret.CreateTypeOrgTeam).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(secret.CreateTypeOrg).WillReturnResult(sqlmock.NewResult(1, 1))
// ensure the mock expects the user queries
_mock.ExpectExec(user.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(user.CreateUserRefreshIndex).WillReturnResult(sqlmock.NewResult(1, 1))
Expand Down Expand Up @@ -259,12 +267,6 @@ func createTables(c *client) error {
return fmt.Errorf("unable to create %s table: %w", constants.TableBuild, err)
}

// create the secrets table
err = c.Postgres.Exec(ddl.CreateSecretTable).Error
if err != nil {
return fmt.Errorf("unable to create %s table: %w", constants.TableSecret, err)
}

// create the services table
err = c.Postgres.Exec(ddl.CreateServiceTable).Error
if err != nil {
Expand Down Expand Up @@ -309,24 +311,6 @@ func createIndexes(c *client) error {
return fmt.Errorf("unable to create builds_source index for the %s table: %w", constants.TableBuild, err)
}

// create the secrets_type_org_repo index for the secrets table
err = c.Postgres.Exec(ddl.CreateSecretTypeOrgRepo).Error
if err != nil {
return fmt.Errorf("unable to create secrets_type_org_repo index for the %s table: %w", constants.TableSecret, err)
}

// create the secrets_type_org_team index for the secrets table
err = c.Postgres.Exec(ddl.CreateSecretTypeOrgTeam).Error
if err != nil {
return fmt.Errorf("unable to create secrets_type_org_team index for the %s table: %w", constants.TableSecret, err)
}

// create the secrets_type_org index for the secrets table
err = c.Postgres.Exec(ddl.CreateSecretTypeOrg).Error
if err != nil {
return fmt.Errorf("unable to create secrets_type_org index for the %s table: %w", constants.TableSecret, err)
}

return nil
}

Expand Down Expand Up @@ -385,6 +369,19 @@ func createServices(c *client) error {
return err
}

// create the database agnostic secret service
//
// https://pkg.go.dev/github.com/go-vela/server/database/secret#New
c.SecretService, err = secret.New(
secret.WithClient(c.Postgres),
secret.WithEncryptionKey(c.config.EncryptionKey),
secret.WithLogger(c.Logger),
secret.WithSkipCreation(c.config.SkipCreation),
)
if err != nil {
return err
}

// create the database agnostic user service
//
// https://pkg.go.dev/github.com/go-vela/server/database/user#New
Expand Down
19 changes: 11 additions & 8 deletions database/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/go-vela/server/database/pipeline"
"github.com/go-vela/server/database/postgres/ddl"
"github.com/go-vela/server/database/repo"
"github.com/go-vela/server/database/secret"
"github.com/go-vela/server/database/user"
"github.com/go-vela/server/database/worker"
"github.com/go-vela/types/library"
Expand Down Expand Up @@ -80,7 +81,6 @@ func TestPostgres_setupDatabase(t *testing.T) {

// ensure the mock expects the table queries
_mock.ExpectExec(ddl.CreateBuildTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateSecretTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateServiceTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateStepTable).WillReturnResult(sqlmock.NewResult(1, 1))

Expand All @@ -89,9 +89,6 @@ func TestPostgres_setupDatabase(t *testing.T) {
_mock.ExpectExec(ddl.CreateBuildStatusIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateBuildCreatedIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateBuildSourceIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateSecretTypeOrgRepo).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateSecretTypeOrgTeam).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateSecretTypeOrg).WillReturnResult(sqlmock.NewResult(1, 1))

// ensure the mock expects the hook queries
_mock.ExpectExec(hook.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1))
Expand All @@ -105,6 +102,11 @@ func TestPostgres_setupDatabase(t *testing.T) {
// ensure the mock expects the repo queries
_mock.ExpectExec(repo.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(repo.CreateOrgNameIndex).WillReturnResult(sqlmock.NewResult(1, 1))
// ensure the mock expects the secret queries
_mock.ExpectExec(secret.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(secret.CreateTypeOrgRepo).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(secret.CreateTypeOrgTeam).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(secret.CreateTypeOrg).WillReturnResult(sqlmock.NewResult(1, 1))
// ensure the mock expects the user queries
_mock.ExpectExec(user.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(user.CreateUserRefreshIndex).WillReturnResult(sqlmock.NewResult(1, 1))
Expand Down Expand Up @@ -172,7 +174,6 @@ func TestPostgres_createTables(t *testing.T) {

// ensure the mock expects the table queries
_mock.ExpectExec(ddl.CreateBuildTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateSecretTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateServiceTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateStepTable).WillReturnResult(sqlmock.NewResult(1, 1))

Expand Down Expand Up @@ -217,9 +218,6 @@ func TestPostgres_createIndexes(t *testing.T) {
_mock.ExpectExec(ddl.CreateBuildStatusIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateBuildCreatedIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateBuildSourceIndex).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateSecretTypeOrgRepo).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateSecretTypeOrgTeam).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(ddl.CreateSecretTypeOrg).WillReturnResult(sqlmock.NewResult(1, 1))

tests := []struct {
failure bool
Expand Down Expand Up @@ -269,6 +267,11 @@ func TestPostgres_createServices(t *testing.T) {
// ensure the mock expects the repo queries
_mock.ExpectExec(repo.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(repo.CreateOrgNameIndex).WillReturnResult(sqlmock.NewResult(1, 1))
// ensure the mock expects the secret queries
_mock.ExpectExec(secret.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(secret.CreateTypeOrgRepo).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(secret.CreateTypeOrgTeam).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(secret.CreateTypeOrg).WillReturnResult(sqlmock.NewResult(1, 1))
// ensure the mock expects the user queries
_mock.ExpectExec(user.CreatePostgresTable).WillReturnResult(sqlmock.NewResult(1, 1))
_mock.ExpectExec(user.CreateUserRefreshIndex).WillReturnResult(sqlmock.NewResult(1, 1))
Expand Down
Loading