mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 05:59:44 -04:00
Refactor User.webauthn_credentials into a ModelList
This saves a bit of repetition, and lets us attach other methods to the collection, rather than having multiple methods on the user object prefixed with the same name, or random functions floating about.
This commit is contained in:
@@ -6,7 +6,8 @@ from fido2.cose import UnsupportedKey
|
||||
from fido2.ctap2 import AttestationObject, AttestedCredentialData
|
||||
from flask import current_app
|
||||
|
||||
from app.models import JSONModel
|
||||
from app.models import JSONModel, ModelList
|
||||
from app.notify_client.user_api_client import user_api_client
|
||||
|
||||
|
||||
class RegistrationError(Exception):
|
||||
@@ -60,3 +61,16 @@ class WebAuthnCredential(JSONModel):
|
||||
'credential_data': self.credential_data,
|
||||
'registration_response': self.registration_response,
|
||||
}
|
||||
|
||||
|
||||
class WebAuthnCredentials(ModelList):
|
||||
|
||||
model = WebAuthnCredential
|
||||
client_method = user_api_client.get_webauthn_credentials_for_user
|
||||
|
||||
@property
|
||||
def as_cbor(self):
|
||||
return [credential.to_credential_data() for credential in self]
|
||||
|
||||
def by_id(self, key_id):
|
||||
return next((key for key in self if key.id == key_id), None)
|
||||
|
||||
Reference in New Issue
Block a user