Skip to content

Commit 42a5b3b

Browse files
authored
support configuration of saml connection configuration for an org (#57)
* support configuration of saml connection configuration for an org * formal enum for all valid idp providers * no message to deserialize on successful post/delete
1 parent 5a3d26e commit 42a5b3b

File tree

5 files changed

+343
-4
lines changed

5 files changed

+343
-4
lines changed

src/apis/org_service_api.rs

Lines changed: 212 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use reqwest;
1212

1313
use super::{configuration, Error};
1414
use crate::apis::ResponseContent;
15-
use crate::models::FetchOrgOrderBy;
15+
use crate::models::{FetchOrgOrderBy, SuccessfulResponse};
1616

1717
/// struct for passing parameters to the method [`add_user_to_org`]
1818
#[derive(Clone, Debug, Default)]
@@ -175,6 +175,42 @@ pub enum CreateSamlConnectionLinkError {
175175
UnknownValue(serde_json::Value),
176176
}
177177

178+
/// struct for typed errors of method [`fetch_saml_sp_metadata`]
179+
#[derive(Debug, Clone, Serialize, Deserialize)]
180+
#[serde(untagged)]
181+
pub enum FetchSamlSpMetadataError {
182+
Status401(serde_json::Value),
183+
Status404(serde_json::Value),
184+
UnknownValue(serde_json::Value),
185+
}
186+
187+
/// struct for typed errors of method [`set_saml_idp_metadata`]
188+
#[derive(Debug, Clone, Serialize, Deserialize)]
189+
#[serde(untagged)]
190+
pub enum SetSamlIdpMetadataError {
191+
Status401(serde_json::Value),
192+
Status404(serde_json::Value),
193+
UnknownValue(serde_json::Value),
194+
}
195+
196+
/// struct for typed errors of method [`saml_go_live`]
197+
#[derive(Debug, Clone, Serialize, Deserialize)]
198+
#[serde(untagged)]
199+
pub enum SamlGoLiveError {
200+
Status401(serde_json::Value),
201+
Status404(serde_json::Value),
202+
UnknownValue(serde_json::Value),
203+
}
204+
205+
/// struct for typed errors of method [`delete_saml_connection`]
206+
#[derive(Debug, Clone, Serialize, Deserialize)]
207+
#[serde(untagged)]
208+
pub enum DeleteSamlConnectionError {
209+
Status401(serde_json::Value),
210+
Status404(serde_json::Value),
211+
UnknownValue(serde_json::Value),
212+
}
213+
178214
/// struct for typed errors of method [`fetch_org`]
179215
#[derive(Debug, Clone, Serialize, Deserialize)]
180216
#[serde(untagged)]
@@ -551,6 +587,181 @@ pub async fn create_saml_connection_link(
551587
Err(Error::ResponseError(local_var_error))
552588
}
553589
}
590+
591+
pub async fn fetch_saml_sp_metadata(
592+
configuration: &configuration::Configuration,
593+
org_id: String,
594+
) -> Result<crate::models::FetchSamlSpMetadataResponse, Error<FetchSamlSpMetadataError>> {
595+
let local_var_configuration = configuration;
596+
597+
let local_var_client = &local_var_configuration.client;
598+
599+
let local_var_uri_str = format!(
600+
"{}/api/backend/v1/saml_sp_metadata/{org_id}",
601+
local_var_configuration.base_path,
602+
org_id = crate::apis::urlencode(org_id)
603+
);
604+
let mut local_var_req_builder =
605+
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
606+
607+
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
608+
local_var_req_builder =
609+
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent);
610+
}
611+
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
612+
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token);
613+
};
614+
615+
let local_var_req = local_var_req_builder.build()?;
616+
let local_var_resp = local_var_client.execute(local_var_req).await?;
617+
618+
let local_var_status = local_var_resp.status();
619+
let local_var_content = local_var_resp.text().await?;
620+
621+
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
622+
serde_json::from_str(&local_var_content).map_err(Error::from)
623+
} else {
624+
let local_var_entity: Option<FetchSamlSpMetadataError> =
625+
serde_json::from_str(&local_var_content).ok();
626+
let local_var_error = ResponseContent {
627+
status: local_var_status,
628+
content: local_var_content,
629+
entity: local_var_entity,
630+
};
631+
Err(Error::ResponseError(local_var_error))
632+
}
633+
}
634+
635+
pub async fn set_saml_idp_metadata(
636+
configuration: &configuration::Configuration,
637+
set_idp_request: crate::models::SetSamlIdpMetadataRequest,
638+
) -> Result<crate::models::SuccessfulResponse, Error<SetSamlIdpMetadataError>> {
639+
let local_var_configuration = configuration;
640+
641+
let local_var_client = &local_var_configuration.client;
642+
643+
let local_var_uri_str = format!(
644+
"{}/api/backend/v1/saml_idp_metadata",
645+
local_var_configuration.base_path,
646+
);
647+
let mut local_var_req_builder =
648+
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
649+
650+
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
651+
local_var_req_builder =
652+
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent);
653+
}
654+
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
655+
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token);
656+
};
657+
local_var_req_builder = local_var_req_builder.json(&set_idp_request);
658+
659+
let local_var_req = local_var_req_builder.build()?;
660+
let local_var_resp = local_var_client.execute(local_var_req).await?;
661+
662+
let local_var_status = local_var_resp.status();
663+
let local_var_content = local_var_resp.text().await?;
664+
665+
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
666+
Ok(SuccessfulResponse::new())
667+
} else {
668+
let local_var_entity: Option<SetSamlIdpMetadataError> =
669+
serde_json::from_str(&local_var_content).ok();
670+
let local_var_error = ResponseContent {
671+
status: local_var_status,
672+
content: local_var_content,
673+
entity: local_var_entity,
674+
};
675+
Err(Error::ResponseError(local_var_error))
676+
}
677+
}
678+
679+
pub async fn saml_go_live(
680+
configuration: &configuration::Configuration,
681+
org_id: String,
682+
) -> Result<crate::models::SuccessfulResponse, Error<SamlGoLiveError>> {
683+
let local_var_configuration = configuration;
684+
685+
let local_var_client = &local_var_configuration.client;
686+
687+
let local_var_uri_str = format!(
688+
"{}/api/backend/v1/saml_idp_metadata/go_live/{}",
689+
local_var_configuration.base_path, org_id
690+
);
691+
let mut local_var_req_builder =
692+
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
693+
694+
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
695+
local_var_req_builder =
696+
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent);
697+
}
698+
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
699+
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token);
700+
};
701+
702+
let local_var_req = local_var_req_builder.build()?;
703+
let local_var_resp = local_var_client.execute(local_var_req).await?;
704+
705+
let local_var_status = local_var_resp.status();
706+
let local_var_content = local_var_resp.text().await?;
707+
708+
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
709+
Ok(SuccessfulResponse::new())
710+
} else {
711+
let local_var_entity: Option<SamlGoLiveError> =
712+
serde_json::from_str(&local_var_content).ok();
713+
let local_var_error = ResponseContent {
714+
status: local_var_status,
715+
content: local_var_content,
716+
entity: local_var_entity,
717+
};
718+
Err(Error::ResponseError(local_var_error))
719+
}
720+
}
721+
722+
pub async fn delete_saml_connection(
723+
configuration: &configuration::Configuration,
724+
org_id: String,
725+
) -> Result<crate::models::SuccessfulResponse, Error<DeleteSamlConnectionError>> {
726+
let local_var_configuration = configuration;
727+
728+
let local_var_client = &local_var_configuration.client;
729+
730+
let local_var_uri_str = format!(
731+
"{}/api/backend/v1/saml_idp_metadata/{}",
732+
local_var_configuration.base_path, org_id
733+
);
734+
let mut local_var_req_builder =
735+
local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
736+
737+
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
738+
local_var_req_builder =
739+
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent);
740+
}
741+
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
742+
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token);
743+
};
744+
745+
let local_var_req = local_var_req_builder.build()?;
746+
let local_var_resp = local_var_client.execute(local_var_req).await?;
747+
748+
let local_var_status = local_var_resp.status();
749+
let local_var_content = local_var_resp.text().await?;
750+
751+
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
752+
Ok(SuccessfulResponse::new())
753+
} else {
754+
let local_var_entity: Option<DeleteSamlConnectionError> =
755+
serde_json::from_str(&local_var_content).ok();
756+
let local_var_error = ResponseContent {
757+
status: local_var_status,
758+
content: local_var_content,
759+
entity: local_var_entity,
760+
};
761+
Err(Error::ResponseError(local_var_error))
762+
}
763+
}
764+
554765
pub async fn fetch_org(
555766
configuration: &configuration::Configuration,
556767
params: FetchOrgParams,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[derive(Clone, Debug, PartialEq, Default, Deserialize)]
2+
pub struct FetchSamlSpMetadataResponse {
3+
#[serde(rename = "entity_id")]
4+
pub entity_id: String,
5+
#[serde(rename = "acs_url")]
6+
pub acs_url: String,
7+
#[serde(rename = "logout_url")]
8+
pub logout_url: String,
9+
}

src/models/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,7 @@ pub mod fetch_pending_invites;
109109
pub use self::fetch_pending_invites::FetchPendingInvitesResponse;
110110
pub mod revoke_pending_org_invite_request;
111111
pub use self::revoke_pending_org_invite_request::RevokePendingOrgInviteRequest;
112+
pub mod fetch_saml_sp_metadata_response;
113+
pub use self::fetch_saml_sp_metadata_response::FetchSamlSpMetadataResponse;
114+
pub mod set_saml_idp_metadata_request;
115+
pub use self::set_saml_idp_metadata_request::SetSamlIdpMetadataRequest;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#[derive(Clone, Debug, PartialEq, Serialize)]
2+
pub struct SetSamlIdpMetadataRequest {
3+
#[serde(rename = "org_id")]
4+
pub org_id: String,
5+
#[serde(rename = "idp_entity_id")]
6+
pub idp_entity_id: String,
7+
#[serde(rename = "idp_sso_url")]
8+
pub idp_sso_url: String,
9+
#[serde(rename = "idp_certificate")]
10+
pub idp_certificate: String,
11+
#[serde(rename = "provider")]
12+
pub provider: SamlIdpProvider,
13+
}
14+
15+
#[derive(Clone, Debug, PartialEq, Serialize)]
16+
pub enum SamlIdpProvider {
17+
Google,
18+
Rippling,
19+
OneLogin,
20+
JumpCloud,
21+
Okta,
22+
Azure,
23+
Duo,
24+
Generic,
25+
}

src/propelauth/org.rs

Lines changed: 93 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use crate::apis::org_service_api::{
88
};
99
use crate::models::{
1010
AddUserToOrgRequest, ChangeUserRoleInOrgRequest, CreateOrgRequest, CreateOrgResponse,
11-
CreateSamlConnectionLinkResponse, FetchOrgResponse, FetchOrgsResponse, InviteUserToOrgRequest,
12-
RemoveUserFromOrgRequest, RevokePendingOrgInviteRequest, SubscribeOrgToRoleMappingRequest,
13-
UpdateOrgRequest, UserPagedResponse,
11+
CreateSamlConnectionLinkResponse, FetchOrgResponse, FetchOrgsResponse,
12+
FetchSamlSpMetadataResponse, InviteUserToOrgRequest, RemoveUserFromOrgRequest,
13+
RevokePendingOrgInviteRequest, SubscribeOrgToRoleMappingRequest, UpdateOrgRequest,
14+
UserPagedResponse,
1415
};
1516
use crate::propelauth::errors::{
1617
CreateOrgError, ErrorsWithNotFound, FetchOrgsByQueryError, FetchUsersInOrgError,
@@ -379,6 +380,95 @@ impl OrgService<'_> {
379380
})
380381
}
381382

383+
pub async fn fetch_saml_sp_metadata(
384+
&self,
385+
org_id: String,
386+
) -> Result<FetchSamlSpMetadataResponse, ErrorsWithNotFound> {
387+
if !is_valid_id(&org_id) {
388+
return Err(ErrorsWithNotFound::NotFound);
389+
}
390+
391+
crate::apis::org_service_api::fetch_saml_sp_metadata(&self.config, org_id)
392+
.await
393+
.map_err(|err| {
394+
map_autogenerated_error(
395+
err,
396+
ErrorsWithNotFound::UnexpectedException,
397+
|status_code, _| match status_code.as_u16() {
398+
401 => ErrorsWithNotFound::InvalidApiKey,
399+
404 => ErrorsWithNotFound::NotFound,
400+
_ => ErrorsWithNotFound::UnexpectedException,
401+
},
402+
)
403+
})
404+
}
405+
406+
pub async fn set_saml_idp_metadata(
407+
&self,
408+
request: crate::models::SetSamlIdpMetadataRequest,
409+
) -> Result<(), ErrorsWithNotFound> {
410+
if !is_valid_id(&request.org_id) {
411+
return Err(ErrorsWithNotFound::NotFound);
412+
}
413+
414+
crate::apis::org_service_api::set_saml_idp_metadata(&self.config, request)
415+
.await
416+
.map_err(|err| {
417+
map_autogenerated_error(
418+
err,
419+
ErrorsWithNotFound::UnexpectedException,
420+
|status_code, _| match status_code.as_u16() {
421+
401 => ErrorsWithNotFound::InvalidApiKey,
422+
404 => ErrorsWithNotFound::NotFound,
423+
_ => ErrorsWithNotFound::UnexpectedException,
424+
},
425+
)
426+
})?;
427+
Ok(())
428+
}
429+
430+
pub async fn saml_go_live(&self, org_id: String) -> Result<(), ErrorsWithNotFound> {
431+
if !is_valid_id(&org_id) {
432+
return Err(ErrorsWithNotFound::NotFound);
433+
}
434+
435+
crate::apis::org_service_api::saml_go_live(&self.config, org_id)
436+
.await
437+
.map_err(|err| {
438+
map_autogenerated_error(
439+
err,
440+
ErrorsWithNotFound::UnexpectedException,
441+
|status_code, _| match status_code.as_u16() {
442+
401 => ErrorsWithNotFound::InvalidApiKey,
443+
404 => ErrorsWithNotFound::NotFound,
444+
_ => ErrorsWithNotFound::UnexpectedException,
445+
},
446+
)
447+
})?;
448+
Ok(())
449+
}
450+
451+
pub async fn delete_saml_connection(&self, org_id: String) -> Result<(), ErrorsWithNotFound> {
452+
if !is_valid_id(&org_id) {
453+
return Err(ErrorsWithNotFound::NotFound);
454+
}
455+
456+
crate::apis::org_service_api::delete_saml_connection(&self.config, org_id)
457+
.await
458+
.map_err(|err| {
459+
map_autogenerated_error(
460+
err,
461+
ErrorsWithNotFound::UnexpectedException,
462+
|status_code, _| match status_code.as_u16() {
463+
401 => ErrorsWithNotFound::InvalidApiKey,
464+
404 => ErrorsWithNotFound::NotFound,
465+
_ => ErrorsWithNotFound::UnexpectedException,
466+
},
467+
)
468+
})?;
469+
Ok(())
470+
}
471+
382472
pub async fn delete_org(&self, org_id: String) -> Result<(), ErrorsWithNotFound> {
383473
if !is_valid_id(&org_id) {
384474
return Err(ErrorsWithNotFound::NotFound);

0 commit comments

Comments
 (0)