diff options
Diffstat (limited to 'internal/storage/sql_provider.go')
| -rw-r--r-- | internal/storage/sql_provider.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/storage/sql_provider.go b/internal/storage/sql_provider.go index bb5ac9895..6991e7021 100644 --- a/internal/storage/sql_provider.go +++ b/internal/storage/sql_provider.go @@ -56,6 +56,10 @@ func NewSQLProvider(config *schema.Configuration, name, driverName, dataSourceNa sqlUpdateWebauthnDeviceRecordSignIn: fmt.Sprintf(queryFmtUpdateWebauthnDeviceRecordSignIn, tableWebauthnDevices), sqlUpdateWebauthnDeviceRecordSignInByUsername: fmt.Sprintf(queryFmtUpdateWebauthnDeviceRecordSignInByUsername, tableWebauthnDevices), + sqlDeleteWebauthnDevice: fmt.Sprintf(queryFmtDeleteWebauthnDevice, tableWebauthnDevices), + sqlDeleteWebauthnDeviceByUsername: fmt.Sprintf(queryFmtDeleteWebauthnDeviceByUsername, tableWebauthnDevices), + sqlDeleteWebauthnDeviceByUsernameAndDescription: fmt.Sprintf(queryFmtDeleteWebauthnDeviceByUsernameAndDescription, tableWebauthnDevices), + sqlUpsertDuoDevice: fmt.Sprintf(queryFmtUpsertDuoDevice, tableDuoDevices), sqlDeleteDuoDevice: fmt.Sprintf(queryFmtDeleteDuoDevice, tableDuoDevices), sqlSelectDuoDevice: fmt.Sprintf(queryFmtSelectDuoDevice, tableDuoDevices), @@ -169,6 +173,10 @@ type SQLProvider struct { sqlUpdateWebauthnDeviceRecordSignIn string sqlUpdateWebauthnDeviceRecordSignInByUsername string + sqlDeleteWebauthnDevice string + sqlDeleteWebauthnDeviceByUsername string + sqlDeleteWebauthnDeviceByUsernameAndDescription string + // Table: duo_devices. sqlUpsertDuoDevice string sqlDeleteDuoDevice string @@ -841,6 +849,34 @@ func (p *SQLProvider) UpdateWebauthnDeviceSignIn(ctx context.Context, id int, rp return nil } +// DeleteWebauthnDevice deletes a registered Webauthn device. +func (p *SQLProvider) DeleteWebauthnDevice(ctx context.Context, kid string) (err error) { + if _, err = p.db.ExecContext(ctx, p.sqlDeleteWebauthnDevice, kid); err != nil { + return fmt.Errorf("error deleting webauthn device with kid '%s': %w", kid, err) + } + + return nil +} + +// DeleteWebauthnDeviceByUsername deletes registered Webauthn devices by username or username and description. +func (p *SQLProvider) DeleteWebauthnDeviceByUsername(ctx context.Context, username, description string) (err error) { + if len(username) == 0 { + return fmt.Errorf("error deleting webauthn device with username '%s' and description '%s': username must not be empty", username, description) + } + + if len(description) == 0 { + if _, err = p.db.ExecContext(ctx, p.sqlDeleteWebauthnDeviceByUsername, username); err != nil { + return fmt.Errorf("error deleting webauthn devices for username '%s': %w", username, err) + } + } else { + if _, err = p.db.ExecContext(ctx, p.sqlDeleteWebauthnDeviceByUsernameAndDescription, username, description); err != nil { + return fmt.Errorf("error deleting webauthn device with username '%s' and description '%s': %w", username, description, err) + } + } + + return nil +} + // LoadWebauthnDevices loads Webauthn device registrations. func (p *SQLProvider) LoadWebauthnDevices(ctx context.Context, limit, page int) (devices []model.WebauthnDevice, err error) { devices = make([]model.WebauthnDevice, 0, limit) |
