feat(keycard): `DeleteKeypair` endpoint added

This commit is contained in:
Sale Djenic 2023-01-25 11:18:28 +01:00 committed by saledjenic
parent 6072bd17ab
commit d8e2884d4e
3 changed files with 41 additions and 5 deletions

View File

@ -324,7 +324,7 @@ func TestKeypairs(t *testing.T) {
require.NoError(t, err)
locked = true
for _, kp := range rows {
if kp.KeyUID == keyPair1.KeyUID {
if kp.KeycardUID == keycardUID {
locked = kp.KeycardLocked
}
}
@ -337,11 +337,25 @@ func TestKeypairs(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 1, len(rows))
// Test if correct keycard is deleted
deletedKeyPair1 := true
deletedKeyCard := true
for _, kp := range rows {
if kp.KeyUID == keyPair1.KeyUID {
deletedKeyPair1 = false
if kp.KeycardUID == keycardUID {
deletedKeyCard = false
}
}
require.Equal(t, true, deletedKeyPair1)
require.Equal(t, true, deletedKeyCard)
// Test detleting a keypair
err = db.DeleteKeypair(keyPair2.KeyUID)
require.NoError(t, err)
rows, err = db.GetAllMigratedKeyPairs()
require.NoError(t, err)
// Test if correct keycard is deleted
deletedKeyPair2And3 := true
for _, kp := range rows {
if kp.KeyUID == keyPair2.KeyUID {
deletedKeyPair2And3 = false
}
}
require.Equal(t, true, deletedKeyPair2And3)
}

View File

@ -263,3 +263,21 @@ func (kp *KeyPairs) DeleteKeycard(kcUID string) (err error) {
return err
}
func (kp *KeyPairs) DeleteKeypair(keyUID string) (err error) {
delete, err := kp.db.Prepare(`
DELETE
FROM
keypairs
WHERE
key_uid = ?
`)
if err != nil {
return err
}
defer delete.Close()
_, err = delete.Exec(keyUID)
return err
}

View File

@ -486,6 +486,10 @@ func (api *API) DeleteKeycard(ctx context.Context, kcUID string) error {
return api.db.DeleteKeycard(kcUID)
}
func (api *API) DeleteKeypair(ctx context.Context, keyUID string) error {
return api.db.DeleteKeypair(keyUID)
}
func (api *API) UpdateKeycardUID(ctx context.Context, oldKcUID string, newKcUID string) error {
return api.db.UpdateKeycardUID(oldKcUID, newKcUID)
}