-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Map from Requests to Domain models (#298)
Implements many of the translators from Request models to Domain models. Wires us up for hooking-up the sync response handling.
- Loading branch information
Showing
22 changed files
with
545 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod policy; | ||
|
||
pub use policy::Policy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use std::collections::HashMap; | ||
|
||
use bitwarden_api_api::models::PolicyResponseModel; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_repr::{Deserialize_repr, Serialize_repr}; | ||
use uuid::Uuid; | ||
|
||
use crate::error::{Error, Result}; | ||
|
||
#[derive(Serialize, Deserialize, Debug, JsonSchema)] | ||
pub struct Policy { | ||
id: Uuid, | ||
organization_id: Uuid, | ||
r#type: PolicyType, | ||
data: Option<HashMap<String, serde_json::Value>>, | ||
enabled: bool, | ||
} | ||
|
||
#[derive(Serialize_repr, Deserialize_repr, Debug, JsonSchema)] | ||
#[repr(u8)] | ||
pub enum PolicyType { | ||
TwoFactorAuthentication = 0, // Requires users to have 2fa enabled | ||
MasterPassword = 1, // Sets minimum requirements for master password complexity | ||
PasswordGenerator = 2, // Sets minimum requirements/default type for generated passwords/passphrases | ||
SingleOrg = 3, // Allows users to only be apart of one organization | ||
RequireSso = 4, // Requires users to authenticate with SSO | ||
PersonalOwnership = 5, // Disables personal vault ownership for adding/cloning items | ||
DisableSend = 6, // Disables the ability to create and edit Bitwarden Sends | ||
SendOptions = 7, // Sets restrictions or defaults for Bitwarden Sends | ||
ResetPassword = 8, // Allows orgs to use reset password : also can enable auto-enrollment during invite flow | ||
MaximumVaultTimeout = 9, // Sets the maximum allowed vault timeout | ||
DisablePersonalVaultExport = 10, // Disable personal vault export | ||
ActivateAutofill = 11, // Activates autofill with page load on the browser extension | ||
} | ||
|
||
impl TryFrom<PolicyResponseModel> for Policy { | ||
type Error = Error; | ||
|
||
fn try_from(policy: PolicyResponseModel) -> Result<Self> { | ||
Ok(Self { | ||
id: policy.id.ok_or(Error::MissingFields)?, | ||
organization_id: policy.organization_id.ok_or(Error::MissingFields)?, | ||
r#type: policy.r#type.ok_or(Error::MissingFields)?.into(), | ||
data: policy.data, | ||
enabled: policy.enabled.ok_or(Error::MissingFields)?, | ||
}) | ||
} | ||
} | ||
|
||
impl From<bitwarden_api_api::models::PolicyType> for PolicyType { | ||
fn from(policy_type: bitwarden_api_api::models::PolicyType) -> Self { | ||
match policy_type { | ||
bitwarden_api_api::models::PolicyType::Variant0 => PolicyType::TwoFactorAuthentication, | ||
bitwarden_api_api::models::PolicyType::Variant1 => PolicyType::MasterPassword, | ||
bitwarden_api_api::models::PolicyType::Variant2 => PolicyType::PasswordGenerator, | ||
bitwarden_api_api::models::PolicyType::Variant3 => PolicyType::SingleOrg, | ||
bitwarden_api_api::models::PolicyType::Variant4 => PolicyType::RequireSso, | ||
bitwarden_api_api::models::PolicyType::Variant5 => PolicyType::PersonalOwnership, | ||
bitwarden_api_api::models::PolicyType::Variant6 => PolicyType::DisableSend, | ||
bitwarden_api_api::models::PolicyType::Variant7 => PolicyType::SendOptions, | ||
bitwarden_api_api::models::PolicyType::Variant8 => PolicyType::ResetPassword, | ||
bitwarden_api_api::models::PolicyType::Variant9 => PolicyType::MaximumVaultTimeout, | ||
bitwarden_api_api::models::PolicyType::Variant10 => { | ||
PolicyType::DisablePersonalVaultExport | ||
} | ||
bitwarden_api_api::models::PolicyType::Variant11 => PolicyType::ActivateAutofill, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::error::{Error, Result}; | ||
|
||
#[derive(Serialize, Deserialize, Debug, JsonSchema)] | ||
pub struct GlobalDomains { | ||
pub r#type: i32, | ||
pub domains: Vec<String>, | ||
pub excluded: bool, | ||
} | ||
|
||
impl TryFrom<bitwarden_api_api::models::GlobalDomains> for GlobalDomains { | ||
type Error = Error; | ||
|
||
fn try_from(global_domains: bitwarden_api_api::models::GlobalDomains) -> Result<Self> { | ||
Ok(Self { | ||
r#type: global_domains.r#type.ok_or(Error::MissingFields)?, | ||
domains: global_domains.domains.ok_or(Error::MissingFields)?, | ||
excluded: global_domains.excluded.ok_or(Error::MissingFields)?, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
mod domain; | ||
mod generate_fingerprint; | ||
mod get_user_api_key; | ||
mod secret_verification_request; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.