feat(api_keys): add api keys route to api v2 (#5709)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Narayan Bhat
2024-08-28 18:57:36 +05:30
committed by GitHub
parent c85b4a3a27
commit 089a95069b
20 changed files with 865 additions and 426 deletions

View File

@ -100,6 +100,12 @@ Never share your secret api keys. Keep them guarded and secure.
// Routes for routing
routes::routing::routing_create_config,
routes::routing::routing_retrieve_config,
// Routes for api keys
routes::api_keys::api_key_create,
routes::api_keys::api_key_retrieve,
routes::api_keys::api_key_update,
routes::api_keys::api_key_revoke,
),
components(schemas(
common_utils::types::MinorUnit,

View File

@ -1,10 +1,11 @@
#[cfg(feature = "v1")]
/// API Key - Create
///
/// Create a new API Key for accessing our APIs from your servers. The plaintext API Key will be
/// displayed only once on creation, so ensure you store it securely.
#[utoipa::path(
post,
path = "/api_keys/{merchant_id)",
path = "/api_keys/{merchant_id}",
params(("merchant_id" = String, Path, description = "The unique identifier for the merchant account")),
request_body= CreateApiKeyRequest,
responses(
@ -17,6 +18,26 @@
)]
pub async fn api_key_create() {}
#[cfg(feature = "v2")]
/// API Key - Create
///
/// Create a new API Key for accessing our APIs from your servers. The plaintext API Key will be
/// displayed only once on creation, so ensure you store it securely.
#[utoipa::path(
post,
path = "/v2/api_keys",
request_body= CreateApiKeyRequest,
responses(
(status = 200, description = "API Key created", body = CreateApiKeyResponse),
(status = 400, description = "Invalid data")
),
tag = "API Key",
operation_id = "Create an API Key",
security(("admin_api_key" = []))
)]
pub async fn api_key_create() {}
#[cfg(feature = "v1")]
/// API Key - Retrieve
///
/// Retrieve information about the specified API Key.
@ -37,6 +58,27 @@ pub async fn api_key_create() {}
)]
pub async fn api_key_retrieve() {}
#[cfg(feature = "v2")]
/// API Key - Retrieve
///
/// Retrieve information about the specified API Key.
#[utoipa::path(
get,
path = "/v2/api_keys/{key_id}",
params (
("key_id" = String, Path, description = "The unique identifier for the API Key")
),
responses(
(status = 200, description = "API Key retrieved", body = RetrieveApiKeyResponse),
(status = 404, description = "API Key not found")
),
tag = "API Key",
operation_id = "Retrieve an API Key",
security(("admin_api_key" = []))
)]
pub async fn api_key_retrieve() {}
#[cfg(feature = "v1")]
/// API Key - Update
///
/// Update information for the specified API Key.
@ -58,13 +100,35 @@ pub async fn api_key_retrieve() {}
)]
pub async fn api_key_update() {}
#[cfg(feature = "v2")]
/// API Key - Update
///
/// Update information for the specified API Key.
#[utoipa::path(
put,
path = "/v2/api_keys/{key_id}",
request_body = UpdateApiKeyRequest,
params (
("key_id" = String, Path, description = "The unique identifier for the API Key")
),
responses(
(status = 200, description = "API Key updated", body = RetrieveApiKeyResponse),
(status = 404, description = "API Key not found")
),
tag = "API Key",
operation_id = "Update an API Key",
security(("admin_api_key" = []))
)]
pub async fn api_key_update() {}
#[cfg(feature = "v1")]
/// API Key - Revoke
///
/// Revoke the specified API Key. Once revoked, the API Key can no longer be used for
/// authenticating with our APIs.
#[utoipa::path(
delete,
path = "/api_keys/{merchant_id)/{key_id}",
path = "/api_keys/{merchant_id}/{key_id}",
params (
("merchant_id" = String, Path, description = "The unique identifier for the merchant account"),
("key_id" = String, Path, description = "The unique identifier for the API Key")
@ -78,3 +142,24 @@ pub async fn api_key_update() {}
security(("admin_api_key" = []))
)]
pub async fn api_key_revoke() {}
#[cfg(feature = "v2")]
/// API Key - Revoke
///
/// Revoke the specified API Key. Once revoked, the API Key can no longer be used for
/// authenticating with our APIs.
#[utoipa::path(
delete,
path = "/v2/api_keys/{key_id}",
params (
("key_id" = String, Path, description = "The unique identifier for the API Key")
),
responses(
(status = 200, description = "API Key revoked", body = RevokeApiKeyResponse),
(status = 404, description = "API Key not found")
),
tag = "API Key",
operation_id = "Revoke an API Key",
security(("admin_api_key" = []))
)]
pub async fn api_key_revoke() {}