Skip to content

Commit

Permalink
fix: Skip Mock DFS config parsing if not set
Browse files Browse the repository at this point in the history
Signed-off-by: jay-dee7 <[email protected]>
  • Loading branch information
jay-dee7 committed Dec 21, 2023
1 parent 124cf89 commit 7878904
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down
10 changes: 10 additions & 0 deletions config/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions store/v1/emails/emails_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ 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)
}

return nil
}

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)
}

Expand Down
4 changes: 2 additions & 2 deletions store/v1/users/users_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
).
Expand All @@ -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),
).
Expand Down
2 changes: 1 addition & 1 deletion store/v1/webauthn/webauthn_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
).
Expand Down

0 comments on commit 7878904

Please sign in to comment.