feat(keycard): `DeleteKeypair` endpoint added
This commit is contained in:
parent
6072bd17ab
commit
d8e2884d4e
|
@ -324,7 +324,7 @@ func TestKeypairs(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
locked = true
|
locked = true
|
||||||
for _, kp := range rows {
|
for _, kp := range rows {
|
||||||
if kp.KeyUID == keyPair1.KeyUID {
|
if kp.KeycardUID == keycardUID {
|
||||||
locked = kp.KeycardLocked
|
locked = kp.KeycardLocked
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -337,11 +337,25 @@ func TestKeypairs(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, 1, len(rows))
|
require.Equal(t, 1, len(rows))
|
||||||
// Test if correct keycard is deleted
|
// Test if correct keycard is deleted
|
||||||
deletedKeyPair1 := true
|
deletedKeyCard := true
|
||||||
for _, kp := range rows {
|
for _, kp := range rows {
|
||||||
if kp.KeyUID == keyPair1.KeyUID {
|
if kp.KeycardUID == keycardUID {
|
||||||
deletedKeyPair1 = false
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,3 +263,21 @@ func (kp *KeyPairs) DeleteKeycard(kcUID string) (err error) {
|
||||||
|
|
||||||
return err
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -486,6 +486,10 @@ func (api *API) DeleteKeycard(ctx context.Context, kcUID string) error {
|
||||||
return api.db.DeleteKeycard(kcUID)
|
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 {
|
func (api *API) UpdateKeycardUID(ctx context.Context, oldKcUID string, newKcUID string) error {
|
||||||
return api.db.UpdateKeycardUID(oldKcUID, newKcUID)
|
return api.db.UpdateKeycardUID(oldKcUID, newKcUID)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue