Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "propelauth"
version = "0.23.3"
version = "0.23.4"
authors = ["support@propelauth.com"]
description = "A Rust crate for managing authentication and authorization with support for multi-tenant / B2B products, powered by PropelAuth"
keywords = ["authentication", "auth", "authorization", "b2b", "tenant"]
Expand Down
170 changes: 169 additions & 1 deletion src/apis/api_key_service_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ pub struct CreateApiKeyParams {
pub org_id: Option<String>,
}

/// struct for passing parameters to the method [`import_api_key`]
#[derive(Clone, Debug, Default, Serialize)]
pub struct ImportApiKeyParams {
pub imported_api_key: String,
pub expires_at_seconds: Option<i64>,
pub metadata: Option<serde_json::Value>,
pub user_id: Option<String>,
pub org_id: Option<String>,
}

/// struct for passing parameters to the method [`update_api_key`]
#[derive(Clone, Debug, Default, Serialize)]
pub struct UpdateApiKeyParams {
Expand All @@ -38,12 +48,21 @@ pub struct UpdateApiKeyParams {
pub set_to_never_expire: Option<bool>,
}

/// struct for passing parameters to the method [`validate_api_key`]
/// struct for passing parameters to the method [`validate_api_key`] and [`validate_imported_api_key`]
#[derive(Clone, Debug, Default, Serialize)]
pub struct ValidateApiKeyParams {
pub api_key_token: String,
}

/// struct for passing parameters to the method [`fetch_api_key_usage`]
#[derive(Clone, Debug, Default, Serialize)]
pub struct FetchApiKeyUsageParams {
pub date: String,
pub user_id: Option<String>,
pub org_id: Option<String>,
pub api_key_id: Option<String>,
}

// struct for typed errors on the api keys service
#[derive(Debug, Clone, Deserialize)]
#[serde(untagged)]
Expand Down Expand Up @@ -79,6 +98,21 @@ pub enum ApiKeyValidationErrorResponse {
},
}

#[derive(Debug, Clone, Deserialize)]
#[serde(untagged)]
pub enum FetchApiKeyUsageError {
InvalidIntegrationAPIKey,
RateLimited {
wait_seconds: f64,
user_facing_error: String,
},
PropelAuthRateLimit,
NotFound,
UnknownValue(serde_json::Value),
UnknownError,
UnexpectedExceptionWithSDK,
}

pub async fn fetch_current_api_keys(
configuration: &configuration::Configuration,
params: ApiKeyQueryParams,
Expand Down Expand Up @@ -404,3 +438,137 @@ pub async fn validate_api_key(
Err(Error::ResponseError(error))
}
}

pub async fn fetch_api_key_usage(
configuration: &configuration::Configuration,
params: FetchApiKeyUsageParams,
) -> Result<crate::models::FetchApiKeyUsageResponse, Error<FetchApiKeyUsageError>> {
let client = &configuration.client;

let date = params.date;
let uri = format!(
"{}/api/backend/v1/end_user_api_keys/usage",
configuration.base_path
);
let mut req_builder = client.request(reqwest::Method::GET, uri.as_str());

// assemble the query parameters
req_builder = req_builder.query(&[("date", &date.to_string())]);
if let Some(ref user_id) = params.user_id {
req_builder = req_builder.query(&[("user_id", user_id)]);
}
if let Some(ref org_id) = params.org_id {
req_builder = req_builder.query(&[("org_id", org_id)]);
}
if let Some(ref api_key_id) = params.api_key_id {
req_builder = req_builder.query(&[("api_key_id", api_key_id)]);
}

if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref bearer_token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(bearer_token.to_owned());
}
req_builder = req_builder.header(AUTH_HOSTNAME_HEADER, configuration.auth_hostname.to_owned());

let req = req_builder.build()?;
let resp = client.execute(req).await?;

let status = resp.status();
let content = resp.text().await?;

if !status.is_client_error() && !status.is_server_error() {
serde_json::from_str(&content).map_err(Error::from)
} else {
let entity: Option<FetchApiKeyUsageError> = serde_json::from_str(&content).ok();
let error: ResponseContent<FetchApiKeyUsageError> = ResponseContent {
status,
content,
entity,
};
Err(Error::ResponseError(error))
}
}

pub async fn import_api_key(
configuration: &configuration::Configuration,
params: ImportApiKeyParams,
) -> Result<crate::models::ImportApiKeyResponse, Error<ApiKeyError>> {
let client = &configuration.client;

let uri = format!(
"{}/api/backend/v1/end_user_api_keys/import",
configuration.base_path
);
let mut req_builder = client.request(reqwest::Method::POST, uri.as_str());

if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref bearer_token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(bearer_token.to_owned());
}
req_builder = req_builder.header(AUTH_HOSTNAME_HEADER, configuration.auth_hostname.to_owned());

req_builder = req_builder.json(&params);

let req = req_builder.build()?;
let resp = client.execute(req).await?;

let status = resp.status();
let content = resp.text().await?;

if !status.is_client_error() && !status.is_server_error() {
serde_json::from_str(&content).map_err(Error::from)
} else {
let entity: Option<ApiKeyError> = serde_json::from_str(&content).ok();
let error = ResponseContent {
status,
content,
entity,
};
Err(Error::ResponseError(error))
}
}

pub async fn validate_imported_api_key(
configuration: &configuration::Configuration,
params: ValidateApiKeyParams,
) -> Result<crate::models::ValidateApiKeyResponse, Error<ApiKeyValidationErrorResponse>> {
let client = &configuration.client;

let uri = format!(
"{}/api/backend/v1/end_user_api_keys/validate_imported",
configuration.base_path
);
let mut req_builder = client.request(reqwest::Method::POST, uri.as_str());

if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref bearer_token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(bearer_token.to_owned());
}
req_builder = req_builder.header(AUTH_HOSTNAME_HEADER, configuration.auth_hostname.to_owned());

req_builder = req_builder.json(&params);

let req = req_builder.build()?;
let resp = client.execute(req).await?;

let status = resp.status();
let content = resp.text().await?;

if !status.is_client_error() && !status.is_server_error() {
serde_json::from_str(&content).map_err(Error::from)
} else {
let entity: Option<ApiKeyValidationErrorResponse> = serde_json::from_str(&content).ok();
let error = ResponseContent {
status,
content,
entity,
};
Err(Error::ResponseError(error))
}
}
89 changes: 89 additions & 0 deletions src/apis/employee_service_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* propelauth
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
* Generated by: https://openapi-generator.tech
*/

use reqwest;

use super::{configuration, Error};
use crate::propelauth::auth::AUTH_HOSTNAME_HEADER;
use crate::apis::ResponseContent;

/// struct for passing parameters to the method [`fetch_employee_by_id`]
#[derive(Clone, Debug, Default)]
pub struct FetchEmployeeByIdParams {
pub employee_id: String,
}

#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct Employee {
#[serde(rename = "email")]
pub email: String,
}

/// struct for typed errors of method [`fetch_employee_by_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FetchEmployeeByIdError {
Status401(serde_json::Value),
Status404(serde_json::Value),
UnknownValue(serde_json::Value),
}


pub async fn fetch_employee_by_id(
configuration: &configuration::Configuration,
params: FetchEmployeeByIdParams,
) -> Result<Employee, Error<FetchEmployeeByIdError>> {
let local_var_configuration = configuration;

// unbox the parameters
let employee_id = params.employee_id;

let local_var_client = &local_var_configuration.client;

let local_var_uri_str = format!(
"{}/api/backend/v1/employee/{employee_id}",
local_var_configuration.base_path,
employee_id = crate::apis::urlencode(employee_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
local_var_req_builder = local_var_req_builder.header(
AUTH_HOSTNAME_HEADER,
local_var_configuration.auth_hostname.to_owned(),
);

let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;

let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;

if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<FetchEmployeeByIdError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error: crate::apis::ResponseContent<FetchEmployeeByIdError> = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}

Loading
Loading