From 87dd4db7638c7762ae961872a7b9718333644754 Mon Sep 17 00:00:00 2001 From: augustuswm Date: Fri, 16 Feb 2024 10:54:47 -0600 Subject: [PATCH] Ignore rustfmt on macro --- v-api/src/endpoints/handlers.rs | 1093 ++++++++++++++++--------------- 1 file changed, 548 insertions(+), 545 deletions(-) diff --git a/v-api/src/endpoints/handlers.rs b/v-api/src/endpoints/handlers.rs index ab9e5f8..9e0358d 100644 --- a/v-api/src/endpoints/handlers.rs +++ b/v-api/src/endpoints/handlers.rs @@ -1,550 +1,553 @@ -#[macro_export] -macro_rules! v_system_endpoints { - ($context_type:ident) => { - use dropshot::{ - endpoint, HttpError, HttpResponseCreated, HttpResponseOk, - HttpResponseTemporaryRedirect, HttpResponseUpdatedNoContent, Path, Query, - RequestContext, TypedBody, - }; - use http::Response; - use hyper::Body; - use v_model::{Mapper, OAuthClient, OAuthClientRedirectUri, OAuthClientSecret}; - - use v_api::endpoints::{ - api_user::{ - add_api_user_to_group_op, create_api_user_op, create_api_user_token_op, - delete_api_user_token_op, get_api_user_op, get_api_user_token_op, get_self_op, - link_provider_op, list_api_user_tokens_op, remove_api_user_from_group_op, - update_api_user_op, AddGroupBody, ApiKeyCreateParams, ApiKeyResponse, ApiUserPath, - ApiUserProviderLinkPayload, ApiUserRemoveGroupPath, ApiUserTokenPath, - ApiUserUpdateParams, GetUserResponse, InitialApiKeyResponse, UserResponse, - }, - api_user_provider::{ - create_link_token_op, ApiUserLinkRequestPayload, ApiUserLinkRequestResponse, - ApiUserProviderPath, - }, - group::{ - create_group_op, delete_group_op, get_groups_op, update_group_op, AccessGroupPath, - AccessGroupUpdateParams, GroupResponse, - }, - login::oauth::{ - client::{ - create_oauth_client_op, create_oauth_client_redirect_uri_op, - create_oauth_client_secret_op, delete_oauth_client_redirect_uri_op, - delete_oauth_client_secret_op, get_oauth_client_op, list_oauth_clients_op, - AddOAuthClientRedirectBody, AddOAuthClientRedirectPath, - AddOAuthClientSecretPath, DeleteOAuthClientRedirectPath, - DeleteOAuthClientSecretPath, GetOAuthClientPath, - InitialOAuthClientSecretResponse, +#[rustfmt::skip] +mod macros { + #[macro_export] + macro_rules! v_system_endpoints { + ($context_type:ident) => { + use dropshot::{ + endpoint, HttpError, HttpResponseCreated, HttpResponseOk, + HttpResponseTemporaryRedirect, HttpResponseUpdatedNoContent, Path, Query, + RequestContext, TypedBody, + }; + use http::Response; + use hyper::Body; + use v_model::{Mapper, OAuthClient, OAuthClientRedirectUri, OAuthClientSecret}; + + use v_api::endpoints::{ + api_user::{ + add_api_user_to_group_op, create_api_user_op, create_api_user_token_op, + delete_api_user_token_op, get_api_user_op, get_api_user_token_op, get_self_op, + link_provider_op, list_api_user_tokens_op, remove_api_user_from_group_op, + update_api_user_op, AddGroupBody, ApiKeyCreateParams, ApiKeyResponse, ApiUserPath, + ApiUserProviderLinkPayload, ApiUserRemoveGroupPath, ApiUserTokenPath, + ApiUserUpdateParams, GetUserResponse, InitialApiKeyResponse, UserResponse, + }, + api_user_provider::{ + create_link_token_op, ApiUserLinkRequestPayload, ApiUserLinkRequestResponse, + ApiUserProviderPath, + }, + group::{ + create_group_op, delete_group_op, get_groups_op, update_group_op, AccessGroupPath, + AccessGroupUpdateParams, GroupResponse, }, - code::{ - authz_code_callback_op, authz_code_exchange_op, authz_code_redirect_op, - OAuthAuthzCodeExchangeBody, OAuthAuthzCodeExchangeResponse, - OAuthAuthzCodeQuery, OAuthAuthzCodeReturnQuery, + login::oauth::{ + client::{ + create_oauth_client_op, create_oauth_client_redirect_uri_op, + create_oauth_client_secret_op, delete_oauth_client_redirect_uri_op, + delete_oauth_client_secret_op, get_oauth_client_op, list_oauth_clients_op, + AddOAuthClientRedirectBody, AddOAuthClientRedirectPath, + AddOAuthClientSecretPath, DeleteOAuthClientRedirectPath, + DeleteOAuthClientSecretPath, GetOAuthClientPath, + InitialOAuthClientSecretResponse, + }, + code::{ + authz_code_callback_op, authz_code_exchange_op, authz_code_redirect_op, + OAuthAuthzCodeExchangeBody, OAuthAuthzCodeExchangeResponse, + OAuthAuthzCodeQuery, OAuthAuthzCodeReturnQuery, + }, + device_token::{ + exchange_device_token_op, get_device_provider_op, AccessTokenExchangeRequest, + }, + OAuthProviderInfo, OAuthProviderNameParam, }, - device_token::{ - exchange_device_token_op, get_device_provider_op, AccessTokenExchangeRequest, + mappers::{ + create_mapper_op, delete_mapper_op, get_mappers_op, CreateMapper, ListMappersQuery, + MapperPath, }, - OAuthProviderInfo, OAuthProviderNameParam, - }, - mappers::{ - create_mapper_op, delete_mapper_op, get_mappers_op, CreateMapper, ListMappersQuery, - MapperPath, - }, - well_known::{jwks_json_op, openid_configuration_op, Jwks, OpenIdConfiguration}, + well_known::{jwks_json_op, openid_configuration_op, Jwks, OpenIdConfiguration}, + }; + + // OAUTH CLIENT + + /// List OAuth clients + #[endpoint { + method = GET, + path = "/oauth/client" + }] + pub async fn list_oauth_clients( + rqctx: RequestContext<$context_type>, + ) -> Result>, HttpError> { + list_oauth_clients_op(&rqctx).await + } + + /// Create a new OAuth Client + #[endpoint { + method = POST, + path = "/oauth/client" + }] + pub async fn create_oauth_client( + rqctx: RequestContext<$context_type>, + ) -> Result, HttpError> { + create_oauth_client_op(&rqctx).await + } + + /// Get an new OAuth Client + #[endpoint { + method = GET, + path = "/oauth/client/{client_id}" + }] + pub async fn get_oauth_client( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result, HttpError> { + get_oauth_client_op(&rqctx, path).await + } + + /// Add an OAuth client secret + #[endpoint { + method = POST, + path = "/oauth/client/{client_id}/secret" + }] + pub async fn create_oauth_client_secret( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result, HttpError> { + create_oauth_client_secret_op(&rqctx, path).await + } + + /// Delete an OAuth client secret + #[endpoint { + method = DELETE, + path = "/oauth/client/{client_id}/secret/{secret_id}" + }] + pub async fn delete_oauth_client_secret( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result, HttpError> { + delete_oauth_client_secret_op(&rqctx, path).await + } + + /// Add an OAuth client redirect uri + #[endpoint { + method = POST, + path = "/oauth/client/{client_id}/redirect_uri" + }] + pub async fn create_oauth_client_redirect_uri( + rqctx: RequestContext<$context_type>, + path: Path, + body: TypedBody, + ) -> Result, HttpError> { + create_oauth_client_redirect_uri_op(&rqctx, path, body).await + } + + /// Delete an OAuth client redirect uri + #[endpoint { + method = DELETE, + path = "/oauth/client/{client_id}/redirect_uri/{redirect_uri_id}" + }] + pub async fn delete_oauth_client_redirect_uri( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result, HttpError> { + delete_oauth_client_redirect_uri_op(&rqctx, path).await + } + + // AUTHZ CODE + + /// Generate the remote provider login url and redirect the user + #[endpoint { + method = GET, + path = "/login/oauth/{provider}/code/authorize" + }] + pub async fn authz_code_redirect( + rqctx: RequestContext<$context_type>, + path: Path, + query: Query, + ) -> Result, HttpError> { + authz_code_redirect_op(&rqctx, path, query).await + } + + /// Handle return calls from a remote OAuth provider + #[endpoint { + method = GET, + path = "/login/oauth/{provider}/code/callback" + }] + pub async fn authz_code_callback( + rqctx: RequestContext<$context_type>, + path: Path, + query: Query, + ) -> Result { + authz_code_callback_op(&rqctx, path, query).await + } + + /// Exchange an authorization code for an access token + #[endpoint { + method = POST, + path = "/login/oauth/{provider}/code/token", + content_type = "application/x-www-form-urlencoded", + }] + pub async fn authz_code_exchange( + rqctx: RequestContext<$context_type>, + path: Path, + body: TypedBody, + ) -> Result, HttpError> { + authz_code_exchange_op(&rqctx, path, body).await + } + + // DEVICE CODE + + // Get the metadata about an OAuth provider necessary to begin a device code exchange + #[endpoint { + method = GET, + path = "/login/oauth/{provider}/device" + }] + pub async fn get_device_provider( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result, HttpError> { + get_device_provider_op(&rqctx, path).await + } + + #[endpoint { + method = POST, + path = "/login/oauth/{provider}/device/exchange", + content_type = "application/x-www-form-urlencoded", + }] + pub async fn exchange_device_token( + rqctx: RequestContext<$context_type>, + path: Path, + body: TypedBody, + ) -> Result, HttpError> { + exchange_device_token_op(&rqctx, path, body).await + } + + // WELL KNOWN + + #[endpoint { + method = GET, + path = "/.well-known/openid-configuration", + }] + pub async fn openid_configuration( + rqctx: RequestContext<$context_type>, + ) -> Result, HttpError> { + openid_configuration_op(&rqctx).await + } + + #[endpoint { + method = GET, + path = "/.well-known/jwks.json", + }] + pub async fn jwks_json( + rqctx: RequestContext<$context_type>, + ) -> Result, HttpError> { + jwks_json_op(&rqctx).await + } + + // API USER PROVIDER + + /// Create a new link token for linking this provider to a different api user + #[endpoint { + method = POST, + path = "/api-user-provider/{identifier}/link-token", + }] + pub async fn create_link_token( + rqctx: RequestContext<$context_type>, + path: Path, + body: TypedBody, + ) -> Result, HttpError> { + create_link_token_op(&rqctx, path, body).await + } + + // API USER + + /// Retrieve the user information of the calling user + #[endpoint { + method = GET, + path = "/self", + }] + pub async fn get_self( + rqctx: RequestContext<$context_type>, + ) -> Result, HttpError> { + get_self_op(&rqctx).await + } + + /// Get user information for a given user id + #[endpoint { + method = GET, + path = "/api-user/{identifier}", + }] + pub async fn get_api_user( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result, HttpError> { + get_api_user_op(&rqctx, path).await + } + + /// Create a new user with a given set of permissions + #[endpoint { + method = POST, + path = "/api-user", + }] + pub async fn create_api_user( + rqctx: RequestContext<$context_type>, + body: TypedBody, + ) -> Result, HttpError> { + create_api_user_op(&rqctx, body).await + } + + /// Update the permissions assigned to a given user + #[endpoint { + method = POST, + path = "/api-user/{identifier}", + }] + pub async fn update_api_user( + rqctx: RequestContext<$context_type>, + path: Path, + body: TypedBody, + ) -> Result, HttpError> { + update_api_user_op(&rqctx, path.into_inner(), body.into_inner()).await + } + + /// List the active and expired API tokens for a given user + #[endpoint { + method = GET, + path = "/api-user/{identifier}/token", + }] + pub async fn list_api_user_tokens( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result>, HttpError> { + list_api_user_tokens_op(&rqctx, path.into_inner()).await + } + + // Create a new API token for a given user with a specific set of permissions and expiration. This + // is the only time that the returned token will be accessible + #[endpoint { + method = POST, + path = "/api-user/{identifier}/token", + }] + pub async fn create_api_user_token( + rqctx: RequestContext<$context_type>, + path: Path, + body: TypedBody, + ) -> Result, HttpError> { + create_api_user_token_op(&rqctx, path.into_inner(), body.into_inner()).await + } + + // Get details for a specific API token + #[endpoint { + method = GET, + path = "/api-user/{identifier}/token/{token_identifier}", + }] + pub async fn get_api_user_token( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result, HttpError> { + get_api_user_token_op(&rqctx, path.into_inner()).await + } + + // Revoke a specific API token so it can no longer be used + #[endpoint { + method = DELETE, + path = "/api-user/{identifier}/token/{token_identifier}", + }] + pub async fn delete_api_user_token( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result, HttpError> { + delete_api_user_token_op(&rqctx, path.into_inner()).await + } + + #[endpoint { + method = POST, + path = "/api-user/{identifier}/group", + }] + pub async fn add_api_user_to_group( + rqctx: RequestContext<$context_type>, + path: Path, + body: TypedBody, + ) -> Result, HttpError> { + add_api_user_to_group_op(&rqctx, path.into_inner(), body.into_inner()).await + } + + #[endpoint { + method = DELETE, + path = "/api-user/{identifier}/group/{group_id}", + }] + pub async fn remove_api_user_from_group( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result, HttpError> { + remove_api_user_from_group_op(&rqctx, path.into_inner()).await + } + + /// Link an existing login provider to this user + #[endpoint { + method = POST, + path = "/api-user/{identifier}/link", + }] + pub async fn link_provider( + rqctx: RequestContext<$context_type>, + path: Path, + body: TypedBody, + ) -> Result { + link_provider_op(&rqctx, path.into_inner(), body.into_inner()).await + } + + // GROUPS + + #[endpoint { + method = GET, + path = "/group", + }] + pub async fn get_groups( + rqctx: RequestContext<$context_type>, + ) -> Result>, HttpError> { + get_groups_op(&rqctx).await + } + + #[endpoint { + method = POST, + path = "/group", + }] + pub async fn create_group( + rqctx: RequestContext<$context_type>, + body: TypedBody, + ) -> Result, HttpError> { + create_group_op(&rqctx, body.into_inner()).await + } + + #[endpoint { + method = PUT, + path = "/group/{group_id}", + }] + pub async fn update_group( + rqctx: RequestContext<$context_type>, + path: Path, + body: TypedBody, + ) -> Result, HttpError> { + update_group_op(&rqctx, path.into_inner(), body.into_inner()).await + } + + #[endpoint { + method = DELETE, + path = "/group/{group_id}", + }] + pub async fn delete_group( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result, HttpError> { + delete_group_op(&rqctx, path.into_inner()).await + } + + // MAPPERS + + #[endpoint { + method = GET, + path = "/mapper", + }] + pub async fn get_mappers( + rqctx: RequestContext<$context_type>, + query: Query, + ) -> Result>, HttpError> { + get_mappers_op(&rqctx, query.into_inner()).await + } + + #[endpoint { + method = POST, + path = "/mapper", + }] + pub async fn create_mapper( + rqctx: RequestContext<$context_type>, + body: TypedBody, + ) -> Result, HttpError> { + create_mapper_op(&rqctx, body.into_inner()).await + } + + #[endpoint { + method = DELETE, + path = "/mapper/{identifier}", + }] + pub async fn delete_mapper( + rqctx: RequestContext<$context_type>, + path: Path, + ) -> Result, HttpError> { + delete_mapper_op(&rqctx, path.into_inner()).await + } }; - - // OAUTH CLIENT - - /// List OAuth clients - #[endpoint { - method = GET, - path = "/oauth/client" - }] - pub async fn list_oauth_clients( - rqctx: RequestContext<$context_type>, - ) -> Result>, HttpError> { - list_oauth_clients_op(&rqctx).await - } - - /// Create a new OAuth Client - #[endpoint { - method = POST, - path = "/oauth/client" - }] - pub async fn create_oauth_client( - rqctx: RequestContext<$context_type>, - ) -> Result, HttpError> { - create_oauth_client_op(&rqctx).await - } - - /// Get an new OAuth Client - #[endpoint { - method = GET, - path = "/oauth/client/{client_id}" - }] - pub async fn get_oauth_client( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result, HttpError> { - get_oauth_client_op(&rqctx, path).await - } - - /// Add an OAuth client secret - #[endpoint { - method = POST, - path = "/oauth/client/{client_id}/secret" - }] - pub async fn create_oauth_client_secret( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result, HttpError> { - create_oauth_client_secret_op(&rqctx, path).await - } - - /// Delete an OAuth client secret - #[endpoint { - method = DELETE, - path = "/oauth/client/{client_id}/secret/{secret_id}" - }] - pub async fn delete_oauth_client_secret( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result, HttpError> { - delete_oauth_client_secret_op(&rqctx, path).await - } - - /// Add an OAuth client redirect uri - #[endpoint { - method = POST, - path = "/oauth/client/{client_id}/redirect_uri" - }] - pub async fn create_oauth_client_redirect_uri( - rqctx: RequestContext<$context_type>, - path: Path, - body: TypedBody, - ) -> Result, HttpError> { - create_oauth_client_redirect_uri_op(&rqctx, path, body).await - } - - /// Delete an OAuth client redirect uri - #[endpoint { - method = DELETE, - path = "/oauth/client/{client_id}/redirect_uri/{redirect_uri_id}" - }] - pub async fn delete_oauth_client_redirect_uri( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result, HttpError> { - delete_oauth_client_redirect_uri_op(&rqctx, path).await - } - - // AUTHZ CODE - - /// Generate the remote provider login url and redirect the user - #[endpoint { - method = GET, - path = "/login/oauth/{provider}/code/authorize" - }] - pub async fn authz_code_redirect( - rqctx: RequestContext<$context_type>, - path: Path, - query: Query, - ) -> Result, HttpError> { - authz_code_redirect_op(&rqctx, path, query).await - } - - /// Handle return calls from a remote OAuth provider - #[endpoint { - method = GET, - path = "/login/oauth/{provider}/code/callback" - }] - pub async fn authz_code_callback( - rqctx: RequestContext<$context_type>, - path: Path, - query: Query, - ) -> Result { - authz_code_callback_op(&rqctx, path, query).await - } - - /// Exchange an authorization code for an access token - #[endpoint { - method = POST, - path = "/login/oauth/{provider}/code/token", - content_type = "application/x-www-form-urlencoded", - }] - pub async fn authz_code_exchange( - rqctx: RequestContext<$context_type>, - path: Path, - body: TypedBody, - ) -> Result, HttpError> { - authz_code_exchange_op(&rqctx, path, body).await - } - - // DEVICE CODE - - // Get the metadata about an OAuth provider necessary to begin a device code exchange - #[endpoint { - method = GET, - path = "/login/oauth/{provider}/device" - }] - pub async fn get_device_provider( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result, HttpError> { - get_device_provider_op(&rqctx, path).await - } - - #[endpoint { - method = POST, - path = "/login/oauth/{provider}/device/exchange", - content_type = "application/x-www-form-urlencoded", - }] - pub async fn exchange_device_token( - rqctx: RequestContext<$context_type>, - path: Path, - body: TypedBody, - ) -> Result, HttpError> { - exchange_device_token_op(&rqctx, path, body).await - } - - // WELL KNOWN - - #[endpoint { - method = GET, - path = "/.well-known/openid-configuration", - }] - pub async fn openid_configuration( - rqctx: RequestContext<$context_type>, - ) -> Result, HttpError> { - openid_configuration_op(&rqctx).await - } - - #[endpoint { - method = GET, - path = "/.well-known/jwks.json", - }] - pub async fn jwks_json( - rqctx: RequestContext<$context_type>, - ) -> Result, HttpError> { - jwks_json_op(&rqctx).await - } - - // API USER PROVIDER - - /// Create a new link token for linking this provider to a different api user - #[endpoint { - method = POST, - path = "/api-user-provider/{identifier}/link-token", - }] - pub async fn create_link_token( - rqctx: RequestContext<$context_type>, - path: Path, - body: TypedBody, - ) -> Result, HttpError> { - create_link_token_op(&rqctx, path, body).await - } - - // API USER - - /// Retrieve the user information of the calling user - #[endpoint { - method = GET, - path = "/self", - }] - pub async fn get_self( - rqctx: RequestContext<$context_type>, - ) -> Result, HttpError> { - get_self_op(&rqctx).await - } - - /// Get user information for a given user id - #[endpoint { - method = GET, - path = "/api-user/{identifier}", - }] - pub async fn get_api_user( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result, HttpError> { - get_api_user_op(&rqctx, path).await - } - - /// Create a new user with a given set of permissions - #[endpoint { - method = POST, - path = "/api-user", - }] - pub async fn create_api_user( - rqctx: RequestContext<$context_type>, - body: TypedBody, - ) -> Result, HttpError> { - create_api_user_op(&rqctx, body).await - } - - /// Update the permissions assigned to a given user - #[endpoint { - method = POST, - path = "/api-user/{identifier}", - }] - pub async fn update_api_user( - rqctx: RequestContext<$context_type>, - path: Path, - body: TypedBody, - ) -> Result, HttpError> { - update_api_user_op(&rqctx, path.into_inner(), body.into_inner()).await - } - - /// List the active and expired API tokens for a given user - #[endpoint { - method = GET, - path = "/api-user/{identifier}/token", - }] - pub async fn list_api_user_tokens( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result>, HttpError> { - list_api_user_tokens_op(&rqctx, path.into_inner()).await - } - - // Create a new API token for a given user with a specific set of permissions and expiration. This - // is the only time that the returned token will be accessible - #[endpoint { - method = POST, - path = "/api-user/{identifier}/token", - }] - pub async fn create_api_user_token( - rqctx: RequestContext<$context_type>, - path: Path, - body: TypedBody, - ) -> Result, HttpError> { - create_api_user_token_op(&rqctx, path.into_inner(), body.into_inner()).await - } - - // Get details for a specific API token - #[endpoint { - method = GET, - path = "/api-user/{identifier}/token/{token_identifier}", - }] - pub async fn get_api_user_token( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result, HttpError> { - get_api_user_token_op(&rqctx, path.into_inner()).await - } - - // Revoke a specific API token so it can no longer be used - #[endpoint { - method = DELETE, - path = "/api-user/{identifier}/token/{token_identifier}", - }] - pub async fn delete_api_user_token( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result, HttpError> { - delete_api_user_token_op(&rqctx, path.into_inner()).await - } - - #[endpoint { - method = POST, - path = "/api-user/{identifier}/group", - }] - pub async fn add_api_user_to_group( - rqctx: RequestContext<$context_type>, - path: Path, - body: TypedBody, - ) -> Result, HttpError> { - add_api_user_to_group_op(&rqctx, path.into_inner(), body.into_inner()).await - } - - #[endpoint { - method = DELETE, - path = "/api-user/{identifier}/group/{group_id}", - }] - pub async fn remove_api_user_from_group( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result, HttpError> { - remove_api_user_from_group_op(&rqctx, path.into_inner()).await - } - - /// Link an existing login provider to this user - #[endpoint { - method = POST, - path = "/api-user/{identifier}/link", - }] - pub async fn link_provider( - rqctx: RequestContext<$context_type>, - path: Path, - body: TypedBody, - ) -> Result { - link_provider_op(&rqctx, path.into_inner(), body.into_inner()).await - } - - // GROUPS - - #[endpoint { - method = GET, - path = "/group", - }] - pub async fn get_groups( - rqctx: RequestContext<$context_type>, - ) -> Result>, HttpError> { - get_groups_op(&rqctx).await - } - - #[endpoint { - method = POST, - path = "/group", - }] - pub async fn create_group( - rqctx: RequestContext<$context_type>, - body: TypedBody, - ) -> Result, HttpError> { - create_group_op(&rqctx, body.into_inner()).await - } - - #[endpoint { - method = PUT, - path = "/group/{group_id}", - }] - pub async fn update_group( - rqctx: RequestContext<$context_type>, - path: Path, - body: TypedBody, - ) -> Result, HttpError> { - update_group_op(&rqctx, path.into_inner(), body.into_inner()).await - } - - #[endpoint { - method = DELETE, - path = "/group/{group_id}", - }] - pub async fn delete_group( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result, HttpError> { - delete_group_op(&rqctx, path.into_inner()).await - } - - // MAPPERS - - #[endpoint { - method = GET, - path = "/mapper", - }] - pub async fn get_mappers( - rqctx: RequestContext<$context_type>, - query: Query, - ) -> Result>, HttpError> { - get_mappers_op(&rqctx, query.into_inner()).await - } - - #[endpoint { - method = POST, - path = "/mapper", - }] - pub async fn create_mapper( - rqctx: RequestContext<$context_type>, - body: TypedBody, - ) -> Result, HttpError> { - create_mapper_op(&rqctx, body.into_inner()).await - } - - #[endpoint { - method = DELETE, - path = "/mapper/{identifier}", - }] - pub async fn delete_mapper( - rqctx: RequestContext<$context_type>, - path: Path, - ) -> Result, HttpError> { - delete_mapper_op(&rqctx, path.into_inner()).await - } - }; -} - -#[macro_export] -macro_rules! inject_endpoints { - ($api:ident) => { - // .well-known - $api.register(openid_configuration) - .expect("Failed to register endpoint"); - $api.register(jwks_json) - .expect("Failed to register endpoint"); - - // User Management - $api.register(get_self) - .expect("Failed to register endpoint"); - $api.register(get_api_user) - .expect("Failed to register endpoint"); - $api.register(create_api_user) - .expect("Failed to register endpoint"); - $api.register(update_api_user) - .expect("Failed to register endpoint"); - $api.register(list_api_user_tokens) - .expect("Failed to register endpoint"); - $api.register(get_api_user_token) - .expect("Failed to register endpoint"); - $api.register(create_api_user_token) - .expect("Failed to register endpoint"); - $api.register(delete_api_user_token) - .expect("Failed to register endpoint"); - $api.register(add_api_user_to_group) - .expect("Failed to register endpoint"); - $api.register(remove_api_user_from_group) - .expect("Failed to register endpoint"); - $api.register(link_provider) - .expect("Failed to register endpoint"); - $api.register(create_link_token) - .expect("Failed to register endpoint"); - - // Group Management - $api.register(get_groups) - .expect("Failed to register endpoint"); - $api.register(create_group) - .expect("Failed to register endpoint"); - $api.register(update_group) - .expect("Failed to register endpoint"); - $api.register(delete_group) - .expect("Failed to register endpoint"); - - // Mapper Management - $api.register(get_mappers) - .expect("Failed to register endpoint"); - $api.register(create_mapper) - .expect("Failed to register endpoint"); - $api.register(delete_mapper) - .expect("Failed to register endpoint"); - - // OAuth Client Management - $api.register(list_oauth_clients) - .expect("Failed to register endpoint"); - $api.register(create_oauth_client) - .expect("Failed to register endpoint"); - $api.register(get_oauth_client) - .expect("Failed to register endpoint"); - $api.register(create_oauth_client_secret) - .expect("Failed to register endpoint"); - $api.register(delete_oauth_client_secret) - .expect("Failed to register endpoint"); - $api.register(create_oauth_client_redirect_uri) - .expect("Failed to register endpoint"); - $api.register(delete_oauth_client_redirect_uri) - .expect("Failed to register endpoint"); - - // OAuth Authorization Login - $api.register(authz_code_redirect) - .expect("Failed to register endpoint"); - $api.register(authz_code_callback) - .expect("Failed to register endpoint"); - $api.register(authz_code_exchange) - .expect("Failed to register endpoint"); - - // OAuth Device Login - $api.register(get_device_provider) - .expect("Failed to register endpoint"); - $api.register(exchange_device_token) - .expect("Failed to register endpoint"); - }; + } + + #[macro_export] + macro_rules! inject_endpoints { + ($api:ident) => { + // .well-known + $api.register(openid_configuration) + .expect("Failed to register endpoint"); + $api.register(jwks_json) + .expect("Failed to register endpoint"); + + // User Management + $api.register(get_self) + .expect("Failed to register endpoint"); + $api.register(get_api_user) + .expect("Failed to register endpoint"); + $api.register(create_api_user) + .expect("Failed to register endpoint"); + $api.register(update_api_user) + .expect("Failed to register endpoint"); + $api.register(list_api_user_tokens) + .expect("Failed to register endpoint"); + $api.register(get_api_user_token) + .expect("Failed to register endpoint"); + $api.register(create_api_user_token) + .expect("Failed to register endpoint"); + $api.register(delete_api_user_token) + .expect("Failed to register endpoint"); + $api.register(add_api_user_to_group) + .expect("Failed to register endpoint"); + $api.register(remove_api_user_from_group) + .expect("Failed to register endpoint"); + $api.register(link_provider) + .expect("Failed to register endpoint"); + $api.register(create_link_token) + .expect("Failed to register endpoint"); + + // Group Management + $api.register(get_groups) + .expect("Failed to register endpoint"); + $api.register(create_group) + .expect("Failed to register endpoint"); + $api.register(update_group) + .expect("Failed to register endpoint"); + $api.register(delete_group) + .expect("Failed to register endpoint"); + + // Mapper Management + $api.register(get_mappers) + .expect("Failed to register endpoint"); + $api.register(create_mapper) + .expect("Failed to register endpoint"); + $api.register(delete_mapper) + .expect("Failed to register endpoint"); + + // OAuth Client Management + $api.register(list_oauth_clients) + .expect("Failed to register endpoint"); + $api.register(create_oauth_client) + .expect("Failed to register endpoint"); + $api.register(get_oauth_client) + .expect("Failed to register endpoint"); + $api.register(create_oauth_client_secret) + .expect("Failed to register endpoint"); + $api.register(delete_oauth_client_secret) + .expect("Failed to register endpoint"); + $api.register(create_oauth_client_redirect_uri) + .expect("Failed to register endpoint"); + $api.register(delete_oauth_client_redirect_uri) + .expect("Failed to register endpoint"); + + // OAuth Authorization Login + $api.register(authz_code_redirect) + .expect("Failed to register endpoint"); + $api.register(authz_code_callback) + .expect("Failed to register endpoint"); + $api.register(authz_code_exchange) + .expect("Failed to register endpoint"); + + // OAuth Device Login + $api.register(get_device_provider) + .expect("Failed to register endpoint"); + $api.register(exchange_device_token) + .expect("Failed to register endpoint"); + }; + } }