From 78789048da82acb300eccd5b9c729003ff614ee4 Mon Sep 17 00:00:00 2001 From: jay-dee7 Date: Thu, 21 Dec 2023 15:38:39 +0530 Subject: [PATCH] fix: Skip Mock DFS config parsing if not set Signed-off-by: jay-dee7 --- cmd/migrations/migrations.go | 2 +- config/yaml.go | 10 ++++++++++ store/v1/emails/emails_impl.go | 7 ++++--- store/v1/users/users_impl.go | 4 ++-- store/v1/webauthn/webauthn_impl.go | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/cmd/migrations/migrations.go b/cmd/migrations/migrations.go index 7bd03bb1..7e20a2ac 100644 --- a/cmd/migrations/migrations.go +++ b/cmd/migrations/migrations.go @@ -223,7 +223,7 @@ func createOpenRegistryDatabase(ctx *cli.Context, opts *databaseOptions) (*bun.D _, err = adminDB. ExecContext( ctx.Context, - "GRANT ALL PRIVILEGES ON DATABASE ?0 to ?1", + "GRANT ALL PRIVILEGES ON DATABASE ? to ?", bun.Ident(opts.database), bun.Ident(opts.username), ) diff --git a/config/yaml.go b/config/yaml.go index ff5d5bb5..6fafc46c 100644 --- a/config/yaml.go +++ b/config/yaml.go @@ -150,6 +150,16 @@ func setDefaultsForDatabaseStore(cfg *OpenRegistryConfig) { } func parseAndSetMockStorageDriverOptions(cfg *OpenRegistryConfig) { + mockConfig := viper.GetStringMap("dfs.mock") + keys := make([]string, 0, len(mockConfig)) + for k := range mockConfig { + keys = append(keys, k) + } + + // skip is mock config is absent + if len(keys) == 0 { + return + } mockDFSType := viper.GetString("dfs.mock.type") if mockDFSType == "MemMapped" { viper.Set("dfs.mock.type", MockStorageBackendMemMapped) diff --git a/store/v1/emails/emails_impl.go b/store/v1/emails/emails_impl.go index 03dfd0fb..825ca660 100644 --- a/store/v1/emails/emails_impl.go +++ b/store/v1/emails/emails_impl.go @@ -34,7 +34,7 @@ func (es *emailStore) AddVerifyEmail(ctx context.Context, userID uuid.UUID, toke } func (es *emailStore) DeleteVerifyEmail(ctx context.Context, userID uuid.UUID) error { - if _, err := es.db.NewDelete().Model(&types.Email{}).Where("user_id = ?1", userID).Exec(ctx); err != nil { + if _, err := es.db.NewDelete().Model(&types.Email{}).Where("user_id = ?", userID).Exec(ctx); err != nil { return v2.WrapDatabaseError(err, v2.DatabaseOperationDelete) } @@ -42,8 +42,9 @@ func (es *emailStore) DeleteVerifyEmail(ctx context.Context, userID uuid.UUID) e } func (es *emailStore) GetVerifyEmail(ctx context.Context, userID uuid.UUID) (uuid.UUID, error) { - email := &types.Email{} - if err := es.db.NewSelect().Model(email).Where("user_id = ?1", userID).Scan(ctx); err != nil { + var email types.Email + + if err := es.db.NewSelect().Model(&email).Where("user_id = ?", userID).Scan(ctx); err != nil { return uuid.UUID{}, v2.WrapDatabaseError(err, v2.DatabaseOperationRead) } diff --git a/store/v1/users/users_impl.go b/store/v1/users/users_impl.go index f6a8ba27..615031cb 100644 --- a/store/v1/users/users_impl.go +++ b/store/v1/users/users_impl.go @@ -191,7 +191,7 @@ func (us *userStore) githubUserExists(ctx context.Context, username, email strin NewSelect(). Model(&types.User{}). Where( - "identities->'github'->>'email' = ?1 or identities->'github'->>'username' = ?", + "identities->'github'->>'email' = ? or identities->'github'->>'username' = ?", bun.Ident(email), bun.Ident(username), ). @@ -210,7 +210,7 @@ func (us *userStore) webAuthnUserExists(ctx context.Context, username, email str NewSelect(). Model(&types.User{}). Where( - "identities->'webauthn'->>'email' = ?1 or identities->'webauthn'->>'username' = ?", + "identities->'webauthn'->>'email' = ? or identities->'webauthn'->>'username' = ?", bun.Ident(email), bun.Ident(username), ). diff --git a/store/v1/webauthn/webauthn_impl.go b/store/v1/webauthn/webauthn_impl.go index e1674070..b5ae8765 100644 --- a/store/v1/webauthn/webauthn_impl.go +++ b/store/v1/webauthn/webauthn_impl.go @@ -158,7 +158,7 @@ func (ws *webauthnStore) WebauthnUserExists(ctx context.Context, email, username NewSelect(). Model(&types.User{}). Where( - "identities->'webauthn'->>'email' = ?1 or identities->'webauthn'->>'username' = ?", + "identities->'webauthn'->>'email' = ? or identities->'webauthn'->>'username' = ?", bun.Ident(email), bun.Ident(username), ).