Skip to content

Commit d182159

Browse files
committed
isolated org apis
1 parent e83ad7a commit d182159

File tree

7 files changed

+147
-8
lines changed

7 files changed

+147
-8
lines changed

src/apis/org_service_api.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ pub struct RevokePendingOrgInviteParams {
120120
pub revoke_pending_org_invite_request: crate::models::RevokePendingOrgInviteRequest,
121121
}
122122

123+
/// struct for passing parameters to the method [`migrate_org_to_isolated`]
124+
#[derive(Clone, Debug, Default)]
125+
pub struct MigrateOrgToIsolatedParams {
126+
pub org_id: String,
127+
}
128+
123129
/// struct for typed errors of method [`add_user_to_org`]
124130
#[derive(Debug, Clone, Serialize, Deserialize)]
125131
#[serde(untagged)]
@@ -304,6 +310,16 @@ pub enum DeleteOrgError {
304310
UnknownValue(serde_json::Value),
305311
}
306312

313+
/// struct for typed errors of method [`migrate_org_to_isolated`]
314+
#[derive(Debug, Clone, Serialize, Deserialize)]
315+
#[serde(untagged)]
316+
pub enum MigrateOrgToIsolatedError {
317+
Status400(serde_json::Value),
318+
Status401(serde_json::Value),
319+
Status404(serde_json::Value),
320+
UnknownValue(serde_json::Value),
321+
}
322+
307323
pub async fn add_user_to_org(
308324
configuration: &configuration::Configuration,
309325
params: AddUserToOrgParams,
@@ -1385,3 +1401,59 @@ pub async fn delete_org(
13851401
Err(Error::ResponseError(local_var_error))
13861402
}
13871403
}
1404+
1405+
pub async fn migrate_org_to_isolated(
1406+
configuration: &configuration::Configuration,
1407+
params: MigrateOrgToIsolatedParams,
1408+
) -> Result<crate::models::SuccessfulResponse, Error<MigrateOrgToIsolatedError>> {
1409+
let local_var_configuration = configuration;
1410+
1411+
// unbox the parameters
1412+
let org_id = params.org_id;
1413+
1414+
let local_var_client = &local_var_configuration.client;
1415+
1416+
let local_var_uri_str = format!(
1417+
"{}/api/backend/v1/isolate_org",
1418+
local_var_configuration.base_path
1419+
);
1420+
let mut local_var_req_builder =
1421+
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
1422+
1423+
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
1424+
local_var_req_builder =
1425+
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
1426+
}
1427+
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
1428+
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
1429+
};
1430+
local_var_req_builder = local_var_req_builder.header(
1431+
AUTH_HOSTNAME_HEADER,
1432+
local_var_configuration.auth_hostname.to_owned(),
1433+
);
1434+
1435+
let request = serde_json::json!({
1436+
"org_id": org_id,
1437+
});
1438+
1439+
local_var_req_builder = local_var_req_builder.json(&request);
1440+
1441+
let local_var_req = local_var_req_builder.build()?;
1442+
let local_var_resp = local_var_client.execute(local_var_req).await?;
1443+
1444+
let local_var_status = local_var_resp.status();
1445+
let local_var_content = local_var_resp.text().await?;
1446+
1447+
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
1448+
serde_json::from_str(&local_var_content).map_err(Error::from)
1449+
} else {
1450+
let local_var_entity: Option<MigrateOrgToIsolatedError> =
1451+
serde_json::from_str(&local_var_content).ok();
1452+
let local_var_error = ResponseContent {
1453+
status: local_var_status,
1454+
content: local_var_content,
1455+
entity: local_var_entity,
1456+
};
1457+
Err(Error::ResponseError(local_var_error))
1458+
}
1459+
}

src/apis/user_service_api.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub struct FetchUserByEmailParams {
5757
pub email: String,
5858
/// Defaults to false
5959
pub include_orgs: Option<bool>,
60+
pub isolated_org_id: Option<String>
6061
}
6162

6263
/// struct for passing parameters to the method [`fetch_user_by_id`]
@@ -85,6 +86,7 @@ pub struct FetchUserByUsernameParams {
8586
pub username: String,
8687
/// Defaults to false
8788
pub include_orgs: Option<bool>,
89+
pub isolated_org_id: Option<String>
8890
}
8991

9092
/// struct for passing parameters to the method [`fetch_users_by_emails`]
@@ -112,6 +114,7 @@ pub struct FetchUsersByQueryParams {
112114
pub email_or_username: Option<String>,
113115
pub include_orgs: Option<bool>,
114116
pub legacy_user_id: Option<String>,
117+
pub isolated_org_id: Option<String>
115118
}
116119

117120
/// struct for passing parameters to the method [`fetch_users_by_usernames`]
@@ -773,6 +776,7 @@ pub async fn fetch_user_by_email(
773776
// unbox the parameters
774777
let email = params.email;
775778
let include_orgs = params.include_orgs;
779+
let isolated_org_id = params.isolated_org_id;
776780

777781
let local_var_client = &local_var_configuration.client;
778782

@@ -788,6 +792,10 @@ pub async fn fetch_user_by_email(
788792
local_var_req_builder =
789793
local_var_req_builder.query(&[("include_orgs", &local_var_str.to_string())]);
790794
}
795+
if let Some(ref local_var_str) = isolated_org_id {
796+
local_var_req_builder =
797+
local_var_req_builder.query(&[("isolated_org_id", &local_var_str.to_string())]);
798+
}
791799
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
792800
local_var_req_builder =
793801
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
@@ -885,6 +893,7 @@ pub async fn fetch_user_by_username(
885893
// unbox the parameters
886894
let username = params.username;
887895
let include_orgs = params.include_orgs;
896+
let isolated_org_id = params.isolated_org_id;
888897

889898
let local_var_client = &local_var_configuration.client;
890899

@@ -899,6 +908,10 @@ pub async fn fetch_user_by_username(
899908
local_var_req_builder =
900909
local_var_req_builder.query(&[("include_orgs", &local_var_str.to_string())]);
901910
}
911+
if let Some(ref local_var_str) = isolated_org_id {
912+
local_var_req_builder =
913+
local_var_req_builder.query(&[("isolated_org_id", &local_var_str.to_string())]);
914+
}
902915
local_var_req_builder = local_var_req_builder.query(&[("username", &username.to_string())]);
903916
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
904917
local_var_req_builder =
@@ -1059,6 +1072,7 @@ pub async fn fetch_users_by_query(
10591072
let email_or_username = params.email_or_username;
10601073
let include_orgs = params.include_orgs;
10611074
let legacy_user_id = params.legacy_user_id;
1075+
let isolated_org_id = params.isolated_org_id;
10621076

10631077
let local_var_client = &local_var_configuration.client;
10641078

@@ -1093,6 +1107,10 @@ pub async fn fetch_users_by_query(
10931107
local_var_req_builder =
10941108
local_var_req_builder.query(&[("legacy_user_id", &local_var_str.to_string())]);
10951109
}
1110+
if let Some(ref local_var_str) = isolated_org_id {
1111+
local_var_req_builder =
1112+
local_var_req_builder.query(&[("isolated_org_id", &local_var_str.to_string())]);
1113+
}
10961114
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
10971115
local_var_req_builder =
10981116
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());

src/models/fetch_org_response.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub struct FetchOrgResponse {
4545
pub extra_domains: Vec<String>,
4646
pub domain_autojoin: bool,
4747
pub domain_restrict: bool,
48+
pub isolated: bool
4849
}
4950

5051
impl FetchOrgResponse {
@@ -58,6 +59,7 @@ impl FetchOrgResponse {
5859
is_saml_in_test_mode: bool,
5960
domain_autojoin: bool,
6061
domain_restrict: bool,
62+
isolated: bool,
6163
) -> FetchOrgResponse {
6264
FetchOrgResponse {
6365
org_id,
@@ -74,6 +76,7 @@ impl FetchOrgResponse {
7476
extra_domains: Vec::new(),
7577
domain_autojoin,
7678
domain_restrict,
79+
isolated
7780
}
7881
}
7982
}

src/models/fetch_orgs_response.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ pub struct FetchOrgsResponse {
2323
pub page_size: i64,
2424
#[serde(rename = "has_more_results")]
2525
pub has_more_results: bool,
26+
#[serde(rename = "isolated")]
27+
pub isolated: bool,
2628
}
2729

2830
impl FetchOrgsResponse {
29-
pub fn new(orgs: Vec<crate::models::FetchOrgBasicResponse>, total_orgs: i64, current_page: i64, page_size: i64, has_more_results: bool) -> FetchOrgsResponse {
31+
pub fn new(orgs: Vec<crate::models::FetchOrgBasicResponse>, total_orgs: i64, current_page: i64, page_size: i64, has_more_results: bool, isolated: bool) -> FetchOrgsResponse {
3032
FetchOrgsResponse {
3133
orgs,
3234
total_orgs,
3335
current_page,
3436
page_size,
3537
has_more_results,
38+
isolated
3639
}
3740
}
3841
}

src/models/update_org_request.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ pub struct UpdateOrgRequest {
3434
pub require_2fa_by: Option<String>,
3535
#[serde(rename = "extra_domains", skip_serializing_if = "Option::is_none")]
3636
pub extra_domains: Option<Vec<String>>,
37+
#[serde(rename = "sso_trust_level", skip_serializing_if = "Option::is_none")]
38+
pub sso_trust_level: Option<String>,
3739
}
3840

3941
impl UpdateOrgRequest {
@@ -49,6 +51,7 @@ impl UpdateOrgRequest {
4951
legacy_org_id: None,
5052
require_2fa_by: None,
5153
extra_domains: None,
54+
sso_trust_level: None
5255
}
5356
}
5457
}

src/propelauth/errors.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,25 @@ pub enum OrgMissingOrRoleError {
300300
UnexpectedException,
301301
}
302302

303+
304+
#[derive(Error, Debug, Eq, PartialEq, Copy, Clone)]
305+
pub enum OrgMissingOrMigrateError {
306+
#[error("Invalid API Key")]
307+
InvalidApiKey,
308+
309+
#[error("Rate limited by PropelAuth")]
310+
PropelAuthRateLimit,
311+
312+
#[error("Migrate Org Exception")]
313+
MigrateOrgToIsolatedException,
314+
315+
#[error("Not found")]
316+
NotFound,
317+
318+
#[error("Unexpected exception, please try again")]
319+
UnexpectedException,
320+
}
321+
303322
#[derive(Error, Debug, PartialEq, Clone)]
304323
pub enum FetchUsersInOrgError {
305324
#[error("Invalid API Key")]

src/propelauth/org.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
use crate::apis::configuration::Configuration;
22
use crate::apis::org_service_api::{
3-
AddUserToOrgParams, AllowOrgToEnableSamlParams, ChangeUserRoleInOrgParams, CreateOrgParams,
4-
CreateSamlConnectionLinkParams, DeleteOrgParams, DisallowSamlParams, FetchOrgParams,
5-
FetchOrgsByQueryParams, FetchPendingInvitesParams, FetchUsersInOrgParams,
6-
RemoveUserFromOrgParams, RevokePendingOrgInviteParams, SubscribeOrgToRoleMappingParams,
7-
UpdateOrgParams,
3+
AddUserToOrgParams, AllowOrgToEnableSamlParams, ChangeUserRoleInOrgParams, CreateOrgParams, CreateSamlConnectionLinkParams, DeleteOrgParams, DisallowSamlParams, FetchOrgParams, FetchOrgsByQueryParams, FetchPendingInvitesParams, FetchUsersInOrgParams, MigrateOrgToIsolatedParams, RemoveUserFromOrgParams, RevokePendingOrgInviteParams, SubscribeOrgToRoleMappingParams, UpdateOrgParams
84
};
95
use crate::models::{
106
AddUserToOrgRequest, ChangeUserRoleInOrgRequest, CreateOrgRequest, CreateOrgResponse,
@@ -14,8 +10,7 @@ use crate::models::{
1410
UserPagedResponse,
1511
};
1612
use crate::propelauth::errors::{
17-
CreateOrgError, ErrorsWithNotFound, FetchOrgsByQueryError, FetchUsersInOrgError,
18-
OrgMissingOrRoleError, UpdateOrgError,
13+
CreateOrgError, ErrorsWithNotFound, FetchOrgsByQueryError, FetchUsersInOrgError, OrgMissingOrMigrateError, OrgMissingOrRoleError, UpdateOrgError
1914
};
2015
use crate::propelauth::helpers::{is_valid_id, map_autogenerated_error};
2116

@@ -566,4 +561,30 @@ impl OrgService<'_> {
566561
})?;
567562
Ok(())
568563
}
564+
565+
pub async fn migrate_org_to_isolated(
566+
&self,
567+
params: MigrateOrgToIsolatedParams,
568+
) -> Result<(), OrgMissingOrMigrateError> {
569+
if !is_valid_id(&params.org_id) {
570+
return Err(OrgMissingOrMigrateError::NotFound);
571+
}
572+
573+
crate::apis::org_service_api::migrate_org_to_isolated(&self.config, params)
574+
.await
575+
.map_err(|err| {
576+
map_autogenerated_error(
577+
err,
578+
OrgMissingOrMigrateError::UnexpectedException,
579+
|status_code, _| match status_code.as_u16() {
580+
400 => OrgMissingOrMigrateError::MigrateOrgToIsolatedException,
581+
401 => OrgMissingOrMigrateError::InvalidApiKey,
582+
429 => OrgMissingOrMigrateError::PropelAuthRateLimit,
583+
404 => OrgMissingOrMigrateError::NotFound,
584+
_ => OrgMissingOrMigrateError::UnexpectedException,
585+
},
586+
)
587+
})?;
588+
Ok(())
589+
}
569590
}

0 commit comments

Comments
 (0)