use super::{AuthorisationKind, Type};
use crate::{AppPermissions, Error, PublicKey, Response, XorName};
use serde::{Deserialize, Serialize};
use std::{borrow::Cow, fmt};
#[derive(Hash, Eq, PartialEq, PartialOrd, Ord, Clone, Serialize, Deserialize)]
pub enum ClientRequest {
ListAuthKeysAndVersion,
InsAuthKey {
key: PublicKey,
version: u64,
permissions: AppPermissions,
},
DelAuthKey {
key: PublicKey,
version: u64,
},
}
impl ClientRequest {
pub fn get_type(&self) -> Type {
use ClientRequest::*;
match *self {
ListAuthKeysAndVersion => Type::PrivateGet,
InsAuthKey { .. } | DelAuthKey { .. } => Type::Mutation,
}
}
pub fn error_response(&self, error: Error) -> Response {
use ClientRequest::*;
match *self {
ListAuthKeysAndVersion => Response::ListAuthKeysAndVersion(Err(error)),
InsAuthKey { .. } | DelAuthKey { .. } => Response::Mutation(Err(error)),
}
}
pub fn authorisation_kind(&self) -> AuthorisationKind {
AuthorisationKind::ManageAppKeys
}
pub fn dest_address(&self) -> Option<Cow<XorName>> {
None
}
}
impl fmt::Debug for ClientRequest {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
use ClientRequest::*;
write!(
formatter,
"Request::{}",
match *self {
ListAuthKeysAndVersion => "ListAuthKeysAndVersion",
InsAuthKey { .. } => "InsAuthKey",
DelAuthKey { .. } => "DelAuthKey",
}
)
}
}