refactor: reorganize modules and types for improved structure and clarity
ZhenYi committed
Added lib/auth/src/client/local/access_key.rs lib/auth/src/client/local/access_key.rs +69 −0 View lib/auth/src/client/local/access_key.rs
@@ -0,0 +1,69 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::v1::access_key_service_server::AccessKeyService;
7use crate::server::grpc::access_key::AccessKeyApi;
8
9pub struct AccessKeyClient {
10 api: AccessKeyApi,
11}
12
13impl AccessKeyClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: AccessKeyApi::new(service),
17 }
18 }
19 pub async fn verify_access_key(
20 &mut self,
21 mut request: Request<crate::protos::auth::v1::VerifyAccessKeyRequest>,
22 ) -> Result<Response<crate::protos::auth::v1::VerifyAccessKeyResponse>, Status> {
23 request.extensions_mut().insert(RequestMeta {
24 request_id: Uuid::now_v7().to_string(),
25 caller_service: "kenapi".to_owned(),
26 });
27 self.api.verify_access_key(request).await
28 }
29 pub async fn create_access_key(
30 &mut self,
31 mut request: Request<crate::protos::auth::v1::CreateAccessKeyRequest>,
32 ) -> Result<Response<crate::protos::auth::v1::CreateAccessKeyResponse>, Status> {
33 request.extensions_mut().insert(RequestMeta {
34 request_id: Uuid::now_v7().to_string(),
35 caller_service: "kenapi".to_owned(),
36 });
37 self.api.create_access_key(request).await
38 }
39 pub async fn rotate_access_key(
40 &mut self,
41 mut request: Request<crate::protos::auth::v1::RotateAccessKeyRequest>,
42 ) -> Result<Response<crate::protos::auth::v1::RotateAccessKeyResponse>, Status> {
43 request.extensions_mut().insert(RequestMeta {
44 request_id: Uuid::now_v7().to_string(),
45 caller_service: "kenapi".to_owned(),
46 });
47 self.api.rotate_access_key(request).await
48 }
49 pub async fn list_access_keys(
50 &mut self,
51 mut request: Request<crate::protos::auth::v1::ListAccessKeysRequest>,
52 ) -> Result<Response<crate::protos::auth::v1::ListAccessKeysResponse>, Status> {
53 request.extensions_mut().insert(RequestMeta {
54 request_id: Uuid::now_v7().to_string(),
55 caller_service: "kenapi".to_owned(),
56 });
57 self.api.list_access_keys(request).await
58 }
59 pub async fn revoke_access_key(
60 &mut self,
61 mut request: Request<crate::protos::auth::v1::RevokeAccessKeyRequest>,
62 ) -> Result<Response<crate::protos::auth::v1::RevokeAccessKeyResponse>, Status> {
63 request.extensions_mut().insert(RequestMeta {
64 request_id: Uuid::now_v7().to_string(),
65 caller_service: "kenapi".to_owned(),
66 });
67 self.api.revoke_access_key(request).await
68 }
69}
Added lib/auth/src/client/local/agreement.rs lib/auth/src/client/local/agreement.rs +39 −0 View lib/auth/src/client/local/agreement.rs
@@ -0,0 +1,39 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::v1::agreement_service_server::AgreementService;
7use crate::server::grpc::agreement::AgreementApi;
8
9pub struct AgreementClient {
10 api: AgreementApi,
11}
12
13impl AgreementClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: AgreementApi::new(service),
17 }
18 }
19 pub async fn list_agreements(
20 &mut self,
21 mut request: Request<crate::protos::auth::v1::ListAgreementsRequest>,
22 ) -> Result<Response<crate::protos::auth::v1::ListAgreementsResponse>, Status> {
23 request.extensions_mut().insert(RequestMeta {
24 request_id: Uuid::now_v7().to_string(),
25 caller_service: "kenapi".to_owned(),
26 });
27 self.api.list_agreements(request).await
28 }
29 pub async fn check_agreements_accepted(
30 &mut self,
31 mut request: Request<crate::protos::auth::v1::CheckAgreementsAcceptedRequest>,
32 ) -> Result<Response<crate::protos::auth::v1::CheckAgreementsAcceptedResponse>, Status> {
33 request.extensions_mut().insert(RequestMeta {
34 request_id: Uuid::now_v7().to_string(),
35 caller_service: "kenapi".to_owned(),
36 });
37 self.api.check_agreements_accepted(request).await
38 }
39}
Added lib/auth/src/client/local/authority.rs lib/auth/src/client/local/authority.rs +121 −0 View lib/auth/src/client/local/authority.rs
@@ -0,0 +1,121 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::internal::v1::authority_service_server::AuthorityService;
7use crate::server::grpc::authority::AuthorityApi;
8
9pub struct AuthorityClient {
10 api: AuthorityApi,
11}
12
13impl AuthorityClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: AuthorityApi::new(service),
17 }
18 }
19 pub async fn redeem_socket_ticket(
20 &mut self,
21 mut request: Request<crate::protos::auth::internal::v1::RedeemSocketTicketRequest>,
22 ) -> Result<Response<crate::protos::auth::internal::v1::RedeemSocketTicketResponse>, Status>
23 {
24 request.extensions_mut().insert(RequestMeta {
25 request_id: Uuid::now_v7().to_string(),
26 caller_service: "kenapi".to_owned(),
27 });
28 self.api.redeem_socket_ticket(request).await
29 }
30 pub async fn validate(
31 &mut self,
32 mut request: Request<crate::protos::auth::internal::v1::ValidateRequest>,
33 ) -> Result<Response<crate::protos::auth::internal::v1::ValidateResponse>, Status> {
34 request.extensions_mut().insert(RequestMeta {
35 request_id: Uuid::now_v7().to_string(),
36 caller_service: "kenapi".to_owned(),
37 });
38 self.api.validate(request).await
39 }
40 pub async fn get_user(
41 &mut self,
42 mut request: Request<crate::protos::auth::internal::v1::GetUserRequest>,
43 ) -> Result<Response<crate::protos::auth::internal::v1::GetUserResponse>, Status> {
44 request.extensions_mut().insert(RequestMeta {
45 request_id: Uuid::now_v7().to_string(),
46 caller_service: "kenapi".to_owned(),
47 });
48 self.api.get_user(request).await
49 }
50 pub async fn batch_get_user(
51 &mut self,
52 mut request: Request<crate::protos::auth::internal::v1::BatchGetUserRequest>,
53 ) -> Result<Response<crate::protos::auth::internal::v1::BatchGetUserResponse>, Status> {
54 request.extensions_mut().insert(RequestMeta {
55 request_id: Uuid::now_v7().to_string(),
56 caller_service: "kenapi".to_owned(),
57 });
58 self.api.batch_get_user(request).await
59 }
60 pub async fn get_session(
61 &mut self,
62 mut request: Request<crate::protos::auth::internal::v1::GetSessionRequest>,
63 ) -> Result<Response<crate::protos::auth::internal::v1::GetSessionResponse>, Status> {
64 request.extensions_mut().insert(RequestMeta {
65 request_id: Uuid::now_v7().to_string(),
66 caller_service: "kenapi".to_owned(),
67 });
68 self.api.get_session(request).await
69 }
70 pub async fn update_user(
71 &mut self,
72 mut request: Request<crate::protos::auth::internal::v1::UpdateUserRequest>,
73 ) -> Result<Response<crate::protos::auth::internal::v1::UpdateUserResponse>, Status> {
74 request.extensions_mut().insert(RequestMeta {
75 request_id: Uuid::now_v7().to_string(),
76 caller_service: "kenapi".to_owned(),
77 });
78 self.api.update_user(request).await
79 }
80 pub async fn delete_account(
81 &mut self,
82 mut request: Request<crate::protos::auth::internal::v1::DeleteAccountRequest>,
83 ) -> Result<Response<crate::protos::auth::internal::v1::DeleteAccountResponse>, Status> {
84 request.extensions_mut().insert(RequestMeta {
85 request_id: Uuid::now_v7().to_string(),
86 caller_service: "kenapi".to_owned(),
87 });
88 self.api.delete_account(request).await
89 }
90 pub async fn cancel_account_deletion(
91 &mut self,
92 mut request: Request<crate::protos::auth::internal::v1::CancelAccountDeletionRequest>,
93 ) -> Result<Response<crate::protos::auth::internal::v1::CancelAccountDeletionResponse>, Status>
94 {
95 request.extensions_mut().insert(RequestMeta {
96 request_id: Uuid::now_v7().to_string(),
97 caller_service: "kenapi".to_owned(),
98 });
99 self.api.cancel_account_deletion(request).await
100 }
101 pub async fn purge_account(
102 &mut self,
103 mut request: Request<crate::protos::auth::internal::v1::PurgeAccountRequest>,
104 ) -> Result<Response<crate::protos::auth::internal::v1::PurgeAccountResponse>, Status> {
105 request.extensions_mut().insert(RequestMeta {
106 request_id: Uuid::now_v7().to_string(),
107 caller_service: "kenapi".to_owned(),
108 });
109 self.api.purge_account(request).await
110 }
111 pub async fn list_users(
112 &mut self,
113 mut request: Request<crate::protos::auth::internal::v1::ListUsersRequest>,
114 ) -> Result<Response<crate::protos::auth::internal::v1::ListUsersResponse>, Status> {
115 request.extensions_mut().insert(RequestMeta {
116 request_id: Uuid::now_v7().to_string(),
117 caller_service: "kenapi".to_owned(),
118 });
119 self.api.list_users(request).await
120 }
121}
Added lib/auth/src/client/local/authorization.rs lib/auth/src/client/local/authorization.rs +59 −0 View lib/auth/src/client/local/authorization.rs
@@ -0,0 +1,59 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::v1::authorization_service_server::AuthorizationService;
7use crate::server::grpc::authorization::AuthorizationApi;
8
9pub struct AuthorizationClient {
10 api: AuthorizationApi,
11}
12
13impl AuthorizationClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: AuthorizationApi::new(service),
17 }
18 }
19 pub async fn authorize(
20 &mut self,
21 mut request: Request<crate::protos::auth::v1::AuthorizeRequest>,
22 ) -> Result<Response<crate::protos::auth::v1::AuthorizeResponse>, Status> {
23 request.extensions_mut().insert(RequestMeta {
24 request_id: Uuid::now_v7().to_string(),
25 caller_service: "kenapi".to_owned(),
26 });
27 self.api.authorize(request).await
28 }
29 pub async fn batch_authorize(
30 &mut self,
31 mut request: Request<crate::protos::auth::v1::BatchAuthorizeRequest>,
32 ) -> Result<Response<crate::protos::auth::v1::BatchAuthorizeResponse>, Status> {
33 request.extensions_mut().insert(RequestMeta {
34 request_id: Uuid::now_v7().to_string(),
35 caller_service: "kenapi".to_owned(),
36 });
37 self.api.batch_authorize(request).await
38 }
39 pub async fn is_platform_admin(
40 &mut self,
41 mut request: Request<crate::protos::auth::v1::IsPlatformAdminRequest>,
42 ) -> Result<Response<crate::protos::auth::v1::IsPlatformAdminResponse>, Status> {
43 request.extensions_mut().insert(RequestMeta {
44 request_id: Uuid::now_v7().to_string(),
45 caller_service: "kenapi".to_owned(),
46 });
47 self.api.is_platform_admin(request).await
48 }
49 pub async fn get_capabilities(
50 &mut self,
51 mut request: Request<crate::protos::auth::v1::GetCapabilitiesRequest>,
52 ) -> Result<Response<crate::protos::auth::v1::GetCapabilitiesResponse>, Status> {
53 request.extensions_mut().insert(RequestMeta {
54 request_id: Uuid::now_v7().to_string(),
55 caller_service: "kenapi".to_owned(),
56 });
57 self.api.get_capabilities(request).await
58 }
59}
Added lib/auth/src/client/local/email.rs lib/auth/src/client/local/email.rs +59 −0 View lib/auth/src/client/local/email.rs
@@ -0,0 +1,59 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::internal::v1::email_service_server::EmailService;
7use crate::server::grpc::email::EmailApi;
8
9pub struct EmailClient {
10 api: EmailApi,
11}
12
13impl EmailClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: EmailApi::new(service),
17 }
18 }
19 pub async fn send_email(
20 &mut self,
21 mut request: Request<crate::protos::auth::internal::v1::SendEmailRequest>,
22 ) -> Result<Response<crate::protos::auth::internal::v1::SendEmailResponse>, Status> {
23 request.extensions_mut().insert(RequestMeta {
24 request_id: Uuid::now_v7().to_string(),
25 caller_service: "kenapi".to_owned(),
26 });
27 self.api.send_email(request).await
28 }
29 pub async fn send_batch_email(
30 &mut self,
31 mut request: Request<crate::protos::auth::internal::v1::SendBatchEmailRequest>,
32 ) -> Result<Response<crate::protos::auth::internal::v1::SendBatchEmailResponse>, Status> {
33 request.extensions_mut().insert(RequestMeta {
34 request_id: Uuid::now_v7().to_string(),
35 caller_service: "kenapi".to_owned(),
36 });
37 self.api.send_batch_email(request).await
38 }
39 pub async fn render_and_send_email(
40 &mut self,
41 mut request: Request<crate::protos::auth::internal::v1::RenderAndSendEmailRequest>,
42 ) -> Result<Response<crate::protos::auth::internal::v1::SendEmailResponse>, Status> {
43 request.extensions_mut().insert(RequestMeta {
44 request_id: Uuid::now_v7().to_string(),
45 caller_service: "kenapi".to_owned(),
46 });
47 self.api.render_and_send_email(request).await
48 }
49 pub async fn get_queue_status(
50 &mut self,
51 mut request: Request<crate::protos::auth::internal::v1::EmailQueueStatusRequest>,
52 ) -> Result<Response<crate::protos::auth::internal::v1::EmailQueueStatus>, Status> {
53 request.extensions_mut().insert(RequestMeta {
54 request_id: Uuid::now_v7().to_string(),
55 caller_service: "kenapi".to_owned(),
56 });
57 self.api.get_queue_status(request).await
58 }
59}
Added lib/auth/src/client/local/identity.rs lib/auth/src/client/local/identity.rs +89 −0 View lib/auth/src/client/local/identity.rs
@@ -0,0 +1,89 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::v1::identity_service_server::IdentityService;
7use crate::server::grpc::identity::IdentityApi;
8
9pub struct IdentityClient {
10 api: IdentityApi,
11}
12
13impl IdentityClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: IdentityApi::new(service),
17 }
18 }
19 pub async fn authenticate(
20 &mut self,
21 mut request: Request<crate::protos::auth::v1::AuthenticateRequest>,
22 ) -> Result<Response<crate::protos::auth::v1::AuthenticateResponse>, Status> {
23 request.extensions_mut().insert(RequestMeta {
24 request_id: Uuid::now_v7().to_string(),
25 caller_service: "kenapi".to_owned(),
26 });
27 self.api.authenticate(request).await
28 }
29 pub async fn verify_credential(
30 &mut self,
31 mut request: Request<crate::protos::auth::v1::VerifyCredentialRequest>,
32 ) -> Result<Response<crate::protos::auth::v1::VerifyCredentialResponse>, Status> {
33 request.extensions_mut().insert(RequestMeta {
34 request_id: Uuid::now_v7().to_string(),
35 caller_service: "kenapi".to_owned(),
36 });
37 self.api.verify_credential(request).await
38 }
39 pub async fn get_user_public(
40 &mut self,
41 mut request: Request<crate::protos::auth::v1::GetUserPublicRequest>,
42 ) -> Result<Response<crate::protos::auth::v1::GetUserPublicResponse>, Status> {
43 request.extensions_mut().insert(RequestMeta {
44 request_id: Uuid::now_v7().to_string(),
45 caller_service: "kenapi".to_owned(),
46 });
47 self.api.get_user_public(request).await
48 }
49 pub async fn batch_get_user_public(
50 &mut self,
51 mut request: Request<crate::protos::auth::v1::BatchGetUserPublicRequest>,
52 ) -> Result<Response<crate::protos::auth::v1::BatchGetUserPublicResponse>, Status> {
53 request.extensions_mut().insert(RequestMeta {
54 request_id: Uuid::now_v7().to_string(),
55 caller_service: "kenapi".to_owned(),
56 });
57 self.api.batch_get_user_public(request).await
58 }
59 pub async fn get_user_status(
60 &mut self,
61 mut request: Request<crate::protos::auth::v1::GetUserStatusRequest>,
62 ) -> Result<Response<crate::protos::auth::v1::GetUserStatusResponse>, Status> {
63 request.extensions_mut().insert(RequestMeta {
64 request_id: Uuid::now_v7().to_string(),
65 caller_service: "kenapi".to_owned(),
66 });
67 self.api.get_user_status(request).await
68 }
69 pub async fn ensure_bot_user(
70 &mut self,
71 mut request: Request<crate::protos::auth::v1::EnsureBotUserRequest>,
72 ) -> Result<Response<crate::protos::auth::v1::EnsureBotUserResponse>, Status> {
73 request.extensions_mut().insert(RequestMeta {
74 request_id: Uuid::now_v7().to_string(),
75 caller_service: "kenapi".to_owned(),
76 });
77 self.api.ensure_bot_user(request).await
78 }
79 pub async fn change_password(
80 &mut self,
81 mut request: Request<crate::protos::auth::v1::ChangePasswordRequest>,
82 ) -> Result<Response<crate::protos::auth::v1::ChangePasswordResponse>, Status> {
83 request.extensions_mut().insert(RequestMeta {
84 request_id: Uuid::now_v7().to_string(),
85 caller_service: "kenapi".to_owned(),
86 });
87 self.api.change_password(request).await
88 }
89}
Added lib/auth/src/client/local/mfa.rs lib/auth/src/client/local/mfa.rs +89 −0 View lib/auth/src/client/local/mfa.rs
@@ -0,0 +1,89 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::v1::mfa_service_server::MfaService;
7use crate::server::grpc::mfa::MfaApi;
8
9pub struct MfaClient {
10 api: MfaApi,
11}
12
13impl MfaClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: MfaApi::new(service),
17 }
18 }
19 pub async fn get_mfa_status(
20 &mut self,
21 mut request: Request<crate::protos::auth::v1::GetMfaStatusRequest>,
22 ) -> Result<Response<crate::protos::auth::v1::GetMfaStatusResponse>, Status> {
23 request.extensions_mut().insert(RequestMeta {
24 request_id: Uuid::now_v7().to_string(),
25 caller_service: "kenapi".to_owned(),
26 });
27 self.api.get_mfa_status(request).await
28 }
29 pub async fn verify_totp(
30 &mut self,
31 mut request: Request<crate::protos::auth::v1::VerifyTotpRequest>,
32 ) -> Result<Response<crate::protos::auth::v1::VerifyTotpResponse>, Status> {
33 request.extensions_mut().insert(RequestMeta {
34 request_id: Uuid::now_v7().to_string(),
35 caller_service: "kenapi".to_owned(),
36 });
37 self.api.verify_totp(request).await
38 }
39 pub async fn redeem_recovery_code(
40 &mut self,
41 mut request: Request<crate::protos::auth::v1::RedeemRecoveryCodeRequest>,
42 ) -> Result<Response<crate::protos::auth::v1::RedeemRecoveryCodeResponse>, Status> {
43 request.extensions_mut().insert(RequestMeta {
44 request_id: Uuid::now_v7().to_string(),
45 caller_service: "kenapi".to_owned(),
46 });
47 self.api.redeem_recovery_code(request).await
48 }
49 pub async fn configure_totp(
50 &mut self,
51 mut request: Request<crate::protos::auth::v1::ConfigureTotpRequest>,
52 ) -> Result<Response<crate::protos::auth::v1::ConfigureTotpResponse>, Status> {
53 request.extensions_mut().insert(RequestMeta {
54 request_id: Uuid::now_v7().to_string(),
55 caller_service: "kenapi".to_owned(),
56 });
57 self.api.configure_totp(request).await
58 }
59 pub async fn enable_totp(
60 &mut self,
61 mut request: Request<crate::protos::auth::v1::EnableTotpRequest>,
62 ) -> Result<Response<crate::protos::auth::v1::EnableTotpResponse>, Status> {
63 request.extensions_mut().insert(RequestMeta {
64 request_id: Uuid::now_v7().to_string(),
65 caller_service: "kenapi".to_owned(),
66 });
67 self.api.enable_totp(request).await
68 }
69 pub async fn disable_totp(
70 &mut self,
71 mut request: Request<crate::protos::auth::v1::DisableTotpRequest>,
72 ) -> Result<Response<crate::protos::auth::v1::DisableTotpResponse>, Status> {
73 request.extensions_mut().insert(RequestMeta {
74 request_id: Uuid::now_v7().to_string(),
75 caller_service: "kenapi".to_owned(),
76 });
77 self.api.disable_totp(request).await
78 }
79 pub async fn regenerate_recovery_codes(
80 &mut self,
81 mut request: Request<crate::protos::auth::v1::RegenerateRecoveryCodesRequest>,
82 ) -> Result<Response<crate::protos::auth::v1::RegenerateRecoveryCodesResponse>, Status> {
83 request.extensions_mut().insert(RequestMeta {
84 request_id: Uuid::now_v7().to_string(),
85 caller_service: "kenapi".to_owned(),
86 });
87 self.api.regenerate_recovery_codes(request).await
88 }
89}
Added lib/auth/src/client/local/mod.rs lib/auth/src/client/local/mod.rs +23 −0 View lib/auth/src/client/local/mod.rs
@@ -0,0 +1,23 @@
1mod access_key;
2mod agreement;
3mod authority;
4mod authorization;
5mod email;
6mod identity;
7mod mfa;
8mod organization;
9mod session;
10mod ssh_key;
11mod token;
12
13pub use access_key::AccessKeyClient;
14pub use agreement::AgreementClient;
15pub use authority::AuthorityClient;
16pub use authorization::AuthorizationClient;
17pub use email::EmailClient;
18pub use identity::IdentityClient;
19pub use mfa::MfaClient;
20pub use organization::OrganizationClient;
21pub use session::SessionClient;
22pub use ssh_key::SshKeyClient;
23pub use token::TokenClient;
Added lib/auth/src/client/local/organization.rs lib/auth/src/client/local/organization.rs +509 −0 View lib/auth/src/client/local/organization.rs
@@ -0,0 +1,509 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::v1::organization_service_server::OrganizationService;
7use crate::server::grpc::organization::OrganizationApi;
8
9pub struct OrganizationClient {
10 api: OrganizationApi,
11}
12
13impl OrganizationClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: OrganizationApi::new(service),
17 }
18 }
19 pub async fn create_organization(
20 &mut self,
21 mut request: Request<crate::protos::auth::v1::CreateOrganizationRequest>,
22 ) -> Result<Response<crate::protos::auth::v1::CreateOrganizationResponse>, Status> {
23 request.extensions_mut().insert(RequestMeta {
24 request_id: Uuid::now_v7().to_string(),
25 caller_service: "kenapi".to_owned(),
26 });
27 self.api.create_organization(request).await
28 }
29 pub async fn get_organization(
30 &mut self,
31 mut request: Request<crate::protos::auth::v1::GetOrganizationRequest>,
32 ) -> Result<Response<crate::protos::auth::v1::GetOrganizationResponse>, Status> {
33 request.extensions_mut().insert(RequestMeta {
34 request_id: Uuid::now_v7().to_string(),
35 caller_service: "kenapi".to_owned(),
36 });
37 self.api.get_organization(request).await
38 }
39 pub async fn list_organizations(
40 &mut self,
41 mut request: Request<crate::protos::auth::v1::ListOrganizationsRequest>,
42 ) -> Result<Response<crate::protos::auth::v1::ListOrganizationsResponse>, Status> {
43 request.extensions_mut().insert(RequestMeta {
44 request_id: Uuid::now_v7().to_string(),
45 caller_service: "kenapi".to_owned(),
46 });
47 self.api.list_organizations(request).await
48 }
49 pub async fn list_public_organizations(
50 &mut self,
51 mut request: Request<crate::protos::auth::v1::ListPublicOrganizationsRequest>,
52 ) -> Result<Response<crate::protos::auth::v1::ListPublicOrganizationsResponse>, Status> {
53 request.extensions_mut().insert(RequestMeta {
54 request_id: Uuid::now_v7().to_string(),
55 caller_service: "kenapi".to_owned(),
56 });
57 self.api.list_public_organizations(request).await
58 }
59 pub async fn update_organization(
60 &mut self,
61 mut request: Request<crate::protos::auth::v1::UpdateOrganizationRequest>,
62 ) -> Result<Response<crate::protos::auth::v1::UpdateOrganizationResponse>, Status> {
63 request.extensions_mut().insert(RequestMeta {
64 request_id: Uuid::now_v7().to_string(),
65 caller_service: "kenapi".to_owned(),
66 });
67 self.api.update_organization(request).await
68 }
69 pub async fn archive_organization(
70 &mut self,
71 mut request: Request<crate::protos::auth::v1::ArchiveOrganizationRequest>,
72 ) -> Result<Response<crate::protos::auth::v1::ArchiveOrganizationResponse>, Status> {
73 request.extensions_mut().insert(RequestMeta {
74 request_id: Uuid::now_v7().to_string(),
75 caller_service: "kenapi".to_owned(),
76 });
77 self.api.archive_organization(request).await
78 }
79 pub async fn restore_organization(
80 &mut self,
81 mut request: Request<crate::protos::auth::v1::RestoreOrganizationRequest>,
82 ) -> Result<Response<crate::protos::auth::v1::RestoreOrganizationResponse>, Status> {
83 request.extensions_mut().insert(RequestMeta {
84 request_id: Uuid::now_v7().to_string(),
85 caller_service: "kenapi".to_owned(),
86 });
87 self.api.restore_organization(request).await
88 }
89 pub async fn delete_organization(
90 &mut self,
91 mut request: Request<crate::protos::auth::v1::DeleteOrganizationRequest>,
92 ) -> Result<Response<crate::protos::auth::v1::DeleteOrganizationResponse>, Status> {
93 request.extensions_mut().insert(RequestMeta {
94 request_id: Uuid::now_v7().to_string(),
95 caller_service: "kenapi".to_owned(),
96 });
97 self.api.delete_organization(request).await
98 }
99 pub async fn transfer_ownership(
100 &mut self,
101 mut request: Request<crate::protos::auth::v1::TransferOwnershipRequest>,
102 ) -> Result<Response<crate::protos::auth::v1::TransferOwnershipResponse>, Status> {
103 request.extensions_mut().insert(RequestMeta {
104 request_id: Uuid::now_v7().to_string(),
105 caller_service: "kenapi".to_owned(),
106 });
107 self.api.transfer_ownership(request).await
108 }
109 pub async fn add_member(
110 &mut self,
111 mut request: Request<crate::protos::auth::v1::AddMemberRequest>,
112 ) -> Result<Response<crate::protos::auth::v1::AddMemberResponse>, Status> {
113 request.extensions_mut().insert(RequestMeta {
114 request_id: Uuid::now_v7().to_string(),
115 caller_service: "kenapi".to_owned(),
116 });
117 self.api.add_member(request).await
118 }
119 pub async fn remove_member(
120 &mut self,
121 mut request: Request<crate::protos::auth::v1::RemoveMemberRequest>,
122 ) -> Result<Response<crate::protos::auth::v1::RemoveMemberResponse>, Status> {
123 request.extensions_mut().insert(RequestMeta {
124 request_id: Uuid::now_v7().to_string(),
125 caller_service: "kenapi".to_owned(),
126 });
127 self.api.remove_member(request).await
128 }
129 pub async fn leave_organization(
130 &mut self,
131 mut request: Request<crate::protos::auth::v1::LeaveOrganizationRequest>,
132 ) -> Result<Response<crate::protos::auth::v1::LeaveOrganizationResponse>, Status> {
133 request.extensions_mut().insert(RequestMeta {
134 request_id: Uuid::now_v7().to_string(),
135 caller_service: "kenapi".to_owned(),
136 });
137 self.api.leave_organization(request).await
138 }
139 pub async fn list_members(
140 &mut self,
141 mut request: Request<crate::protos::auth::v1::ListMembersRequest>,
142 ) -> Result<Response<crate::protos::auth::v1::ListMembersResponse>, Status> {
143 request.extensions_mut().insert(RequestMeta {
144 request_id: Uuid::now_v7().to_string(),
145 caller_service: "kenapi".to_owned(),
146 });
147 self.api.list_members(request).await
148 }
149 pub async fn set_member_role(
150 &mut self,
151 mut request: Request<crate::protos::auth::v1::SetMemberRoleRequest>,
152 ) -> Result<Response<crate::protos::auth::v1::SetMemberRoleResponse>, Status> {
153 request.extensions_mut().insert(RequestMeta {
154 request_id: Uuid::now_v7().to_string(),
155 caller_service: "kenapi".to_owned(),
156 });
157 self.api.set_member_role(request).await
158 }
159 pub async fn ban_member(
160 &mut self,
161 mut request: Request<crate::protos::auth::v1::BanMemberRequest>,
162 ) -> Result<Response<crate::protos::auth::v1::BanMemberResponse>, Status> {
163 request.extensions_mut().insert(RequestMeta {
164 request_id: Uuid::now_v7().to_string(),
165 caller_service: "kenapi".to_owned(),
166 });
167 self.api.ban_member(request).await
168 }
169 pub async fn unban_member(
170 &mut self,
171 mut request: Request<crate::protos::auth::v1::UnbanMemberRequest>,
172 ) -> Result<Response<crate::protos::auth::v1::UnbanMemberResponse>, Status> {
173 request.extensions_mut().insert(RequestMeta {
174 request_id: Uuid::now_v7().to_string(),
175 caller_service: "kenapi".to_owned(),
176 });
177 self.api.unban_member(request).await
178 }
179 pub async fn get_member(
180 &mut self,
181 mut request: Request<crate::protos::auth::v1::GetMemberRequest>,
182 ) -> Result<Response<crate::protos::auth::v1::GetMemberResponse>, Status> {
183 request.extensions_mut().insert(RequestMeta {
184 request_id: Uuid::now_v7().to_string(),
185 caller_service: "kenapi".to_owned(),
186 });
187 self.api.get_member(request).await
188 }
189 pub async fn update_member(
190 &mut self,
191 mut request: Request<crate::protos::auth::v1::UpdateMemberRequest>,
192 ) -> Result<Response<crate::protos::auth::v1::UpdateMemberResponse>, Status> {
193 request.extensions_mut().insert(RequestMeta {
194 request_id: Uuid::now_v7().to_string(),
195 caller_service: "kenapi".to_owned(),
196 });
197 self.api.update_member(request).await
198 }
199 pub async fn update_self_member(
200 &mut self,
201 mut request: Request<crate::protos::auth::v1::UpdateMemberRequest>,
202 ) -> Result<Response<crate::protos::auth::v1::UpdateMemberResponse>, Status> {
203 request.extensions_mut().insert(RequestMeta {
204 request_id: Uuid::now_v7().to_string(),
205 caller_service: "kenapi".to_owned(),
206 });
207 self.api.update_self_member(request).await
208 }
209 pub async fn list_bans(
210 &mut self,
211 mut request: Request<crate::protos::auth::v1::ListBansRequest>,
212 ) -> Result<Response<crate::protos::auth::v1::ListBansResponse>, Status> {
213 request.extensions_mut().insert(RequestMeta {
214 request_id: Uuid::now_v7().to_string(),
215 caller_service: "kenapi".to_owned(),
216 });
217 self.api.list_bans(request).await
218 }
219 pub async fn get_ban(
220 &mut self,
221 mut request: Request<crate::protos::auth::v1::GetBanRequest>,
222 ) -> Result<Response<crate::protos::auth::v1::GetBanResponse>, Status> {
223 request.extensions_mut().insert(RequestMeta {
224 request_id: Uuid::now_v7().to_string(),
225 caller_service: "kenapi".to_owned(),
226 });
227 self.api.get_ban(request).await
228 }
229 pub async fn update_ban(
230 &mut self,
231 mut request: Request<crate::protos::auth::v1::UpdateBanRequest>,
232 ) -> Result<Response<crate::protos::auth::v1::UpdateBanResponse>, Status> {
233 request.extensions_mut().insert(RequestMeta {
234 request_id: Uuid::now_v7().to_string(),
235 caller_service: "kenapi".to_owned(),
236 });
237 self.api.update_ban(request).await
238 }
239 pub async fn get_role(
240 &mut self,
241 mut request: Request<crate::protos::auth::v1::GetRoleRequest>,
242 ) -> Result<Response<crate::protos::auth::v1::GetRoleResponse>, Status> {
243 request.extensions_mut().insert(RequestMeta {
244 request_id: Uuid::now_v7().to_string(),
245 caller_service: "kenapi".to_owned(),
246 });
247 self.api.get_role(request).await
248 }
249 pub async fn join_role(
250 &mut self,
251 mut request: Request<crate::protos::auth::v1::JoinRoleRequest>,
252 ) -> Result<Response<crate::protos::auth::v1::JoinRoleResponse>, Status> {
253 request.extensions_mut().insert(RequestMeta {
254 request_id: Uuid::now_v7().to_string(),
255 caller_service: "kenapi".to_owned(),
256 });
257 self.api.join_role(request).await
258 }
259 pub async fn leave_role(
260 &mut self,
261 mut request: Request<crate::protos::auth::v1::LeaveRoleRequest>,
262 ) -> Result<Response<crate::protos::auth::v1::LeaveRoleResponse>, Status> {
263 request.extensions_mut().insert(RequestMeta {
264 request_id: Uuid::now_v7().to_string(),
265 caller_service: "kenapi".to_owned(),
266 });
267 self.api.leave_role(request).await
268 }
269 pub async fn create_role(
270 &mut self,
271 mut request: Request<crate::protos::auth::v1::CreateRoleRequest>,
272 ) -> Result<Response<crate::protos::auth::v1::CreateRoleResponse>, Status> {
273 request.extensions_mut().insert(RequestMeta {
274 request_id: Uuid::now_v7().to_string(),
275 caller_service: "kenapi".to_owned(),
276 });
277 self.api.create_role(request).await
278 }
279 pub async fn update_role(
280 &mut self,
281 mut request: Request<crate::protos::auth::v1::UpdateRoleRequest>,
282 ) -> Result<Response<crate::protos::auth::v1::UpdateRoleResponse>, Status> {
283 request.extensions_mut().insert(RequestMeta {
284 request_id: Uuid::now_v7().to_string(),
285 caller_service: "kenapi".to_owned(),
286 });
287 self.api.update_role(request).await
288 }
289 pub async fn delete_role(
290 &mut self,
291 mut request: Request<crate::protos::auth::v1::DeleteRoleRequest>,
292 ) -> Result<Response<crate::protos::auth::v1::DeleteRoleResponse>, Status> {
293 request.extensions_mut().insert(RequestMeta {
294 request_id: Uuid::now_v7().to_string(),
295 caller_service: "kenapi".to_owned(),
296 });
297 self.api.delete_role(request).await
298 }
299 pub async fn list_roles(
300 &mut self,
301 mut request: Request<crate::protos::auth::v1::ListRolesRequest>,
302 ) -> Result<Response<crate::protos::auth::v1::ListRolesResponse>, Status> {
303 request.extensions_mut().insert(RequestMeta {
304 request_id: Uuid::now_v7().to_string(),
305 caller_service: "kenapi".to_owned(),
306 });
307 self.api.list_roles(request).await
308 }
309 pub async fn set_role_permissions(
310 &mut self,
311 mut request: Request<crate::protos::auth::v1::SetRolePermissionsRequest>,
312 ) -> Result<Response<crate::protos::auth::v1::SetRolePermissionsResponse>, Status> {
313 request.extensions_mut().insert(RequestMeta {
314 request_id: Uuid::now_v7().to_string(),
315 caller_service: "kenapi".to_owned(),
316 });
317 self.api.set_role_permissions(request).await
318 }
319 pub async fn assign_role(
320 &mut self,
321 mut request: Request<crate::protos::auth::v1::AssignRoleRequest>,
322 ) -> Result<Response<crate::protos::auth::v1::AssignRoleResponse>, Status> {
323 request.extensions_mut().insert(RequestMeta {
324 request_id: Uuid::now_v7().to_string(),
325 caller_service: "kenapi".to_owned(),
326 });
327 self.api.assign_role(request).await
328 }
329 pub async fn unassign_role(
330 &mut self,
331 mut request: Request<crate::protos::auth::v1::UnassignRoleRequest>,
332 ) -> Result<Response<crate::protos::auth::v1::UnassignRoleResponse>, Status> {
333 request.extensions_mut().insert(RequestMeta {
334 request_id: Uuid::now_v7().to_string(),
335 caller_service: "kenapi".to_owned(),
336 });
337 self.api.unassign_role(request).await
338 }
339 pub async fn set_member_permissions(
340 &mut self,
341 mut request: Request<crate::protos::auth::v1::SetMemberPermissionsRequest>,
342 ) -> Result<Response<crate::protos::auth::v1::SetMemberPermissionsResponse>, Status> {
343 request.extensions_mut().insert(RequestMeta {
344 request_id: Uuid::now_v7().to_string(),
345 caller_service: "kenapi".to_owned(),
346 });
347 self.api.set_member_permissions(request).await
348 }
349 pub async fn check_permission(
350 &mut self,
351 mut request: Request<crate::protos::auth::v1::CheckPermissionRequest>,
352 ) -> Result<Response<crate::protos::auth::v1::CheckPermissionResponse>, Status> {
353 request.extensions_mut().insert(RequestMeta {
354 request_id: Uuid::now_v7().to_string(),
355 caller_service: "kenapi".to_owned(),
356 });
357 self.api.check_permission(request).await
358 }
359 pub async fn check_permissions(
360 &mut self,
361 mut request: Request<crate::protos::auth::v1::CheckPermissionsRequest>,
362 ) -> Result<Response<crate::protos::auth::v1::CheckPermissionsResponse>, Status> {
363 request.extensions_mut().insert(RequestMeta {
364 request_id: Uuid::now_v7().to_string(),
365 caller_service: "kenapi".to_owned(),
366 });
367 self.api.check_permissions(request).await
368 }
369 pub async fn create_invite(
370 &mut self,
371 mut request: Request<crate::protos::auth::v1::CreateInviteRequest>,
372 ) -> Result<Response<crate::protos::auth::v1::CreateInviteResponse>, Status> {
373 request.extensions_mut().insert(RequestMeta {
374 request_id: Uuid::now_v7().to_string(),
375 caller_service: "kenapi".to_owned(),
376 });
377 self.api.create_invite(request).await
378 }
379 pub async fn revoke_invite(
380 &mut self,
381 mut request: Request<crate::protos::auth::v1::RevokeInviteRequest>,
382 ) -> Result<Response<crate::protos::auth::v1::RevokeInviteResponse>, Status> {
383 request.extensions_mut().insert(RequestMeta {
384 request_id: Uuid::now_v7().to_string(),
385 caller_service: "kenapi".to_owned(),
386 });
387 self.api.revoke_invite(request).await
388 }
389 pub async fn list_invites(
390 &mut self,
391 mut request: Request<crate::protos::auth::v1::ListInvitesRequest>,
392 ) -> Result<Response<crate::protos::auth::v1::ListInvitesResponse>, Status> {
393 request.extensions_mut().insert(RequestMeta {
394 request_id: Uuid::now_v7().to_string(),
395 caller_service: "kenapi".to_owned(),
396 });
397 self.api.list_invites(request).await
398 }
399 pub async fn redeem_invite(
400 &mut self,
401 mut request: Request<crate::protos::auth::v1::RedeemInviteRequest>,
402 ) -> Result<Response<crate::protos::auth::v1::RedeemInviteResponse>, Status> {
403 request.extensions_mut().insert(RequestMeta {
404 request_id: Uuid::now_v7().to_string(),
405 caller_service: "kenapi".to_owned(),
406 });
407 self.api.redeem_invite(request).await
408 }
409 pub async fn create_join_rule(
410 &mut self,
411 mut request: Request<crate::protos::auth::v1::CreateJoinRuleRequest>,
412 ) -> Result<Response<crate::protos::auth::v1::CreateJoinRuleResponse>, Status> {
413 request.extensions_mut().insert(RequestMeta {
414 request_id: Uuid::now_v7().to_string(),
415 caller_service: "kenapi".to_owned(),
416 });
417 self.api.create_join_rule(request).await
418 }
419 pub async fn update_join_rule(
420 &mut self,
421 mut request: Request<crate::protos::auth::v1::UpdateJoinRuleRequest>,
422 ) -> Result<Response<crate::protos::auth::v1::UpdateJoinRuleResponse>, Status> {
423 request.extensions_mut().insert(RequestMeta {
424 request_id: Uuid::now_v7().to_string(),
425 caller_service: "kenapi".to_owned(),
426 });
427 self.api.update_join_rule(request).await
428 }
429 pub async fn delete_join_rule(
430 &mut self,
431 mut request: Request<crate::protos::auth::v1::DeleteJoinRuleRequest>,
432 ) -> Result<Response<crate::protos::auth::v1::DeleteJoinRuleResponse>, Status> {
433 request.extensions_mut().insert(RequestMeta {
434 request_id: Uuid::now_v7().to_string(),
435 caller_service: "kenapi".to_owned(),
436 });
437 self.api.delete_join_rule(request).await
438 }
439 pub async fn list_join_rules(
440 &mut self,
441 mut request: Request<crate::protos::auth::v1::ListJoinRulesRequest>,
442 ) -> Result<Response<crate::protos::auth::v1::ListJoinRulesResponse>, Status> {
443 request.extensions_mut().insert(RequestMeta {
444 request_id: Uuid::now_v7().to_string(),
445 caller_service: "kenapi".to_owned(),
446 });
447 self.api.list_join_rules(request).await
448 }
449 pub async fn create_join_request(
450 &mut self,
451 mut request: Request<crate::protos::auth::v1::CreateJoinRequestRequest>,
452 ) -> Result<Response<crate::protos::auth::v1::CreateJoinRequestResponse>, Status> {
453 request.extensions_mut().insert(RequestMeta {
454 request_id: Uuid::now_v7().to_string(),
455 caller_service: "kenapi".to_owned(),
456 });
457 self.api.create_join_request(request).await
458 }
459 pub async fn list_join_requests(
460 &mut self,
461 mut request: Request<crate::protos::auth::v1::ListJoinRequestsRequest>,
462 ) -> Result<Response<crate::protos::auth::v1::ListJoinRequestsResponse>, Status> {
463 request.extensions_mut().insert(RequestMeta {
464 request_id: Uuid::now_v7().to_string(),
465 caller_service: "kenapi".to_owned(),
466 });
467 self.api.list_join_requests(request).await
468 }
469 pub async fn withdraw_join_request(
470 &mut self,
471 mut request: Request<crate::protos::auth::v1::WithdrawJoinRequestRequest>,
472 ) -> Result<Response<crate::protos::auth::v1::WithdrawJoinRequestResponse>, Status> {
473 request.extensions_mut().insert(RequestMeta {
474 request_id: Uuid::now_v7().to_string(),
475 caller_service: "kenapi".to_owned(),
476 });
477 self.api.withdraw_join_request(request).await
478 }
479 pub async fn approve_join_request(
480 &mut self,
481 mut request: Request<crate::protos::auth::v1::ApproveJoinRequestRequest>,
482 ) -> Result<Response<crate::protos::auth::v1::ApproveJoinRequestResponse>, Status> {
483 request.extensions_mut().insert(RequestMeta {
484 request_id: Uuid::now_v7().to_string(),
485 caller_service: "kenapi".to_owned(),
486 });
487 self.api.approve_join_request(request).await
488 }
489 pub async fn reject_join_request(
490 &mut self,
491 mut request: Request<crate::protos::auth::v1::RejectJoinRequestRequest>,
492 ) -> Result<Response<crate::protos::auth::v1::RejectJoinRequestResponse>, Status> {
493 request.extensions_mut().insert(RequestMeta {
494 request_id: Uuid::now_v7().to_string(),
495 caller_service: "kenapi".to_owned(),
496 });
497 self.api.reject_join_request(request).await
498 }
499 pub async fn ensure_bot_member(
500 &mut self,
501 mut request: Request<crate::protos::auth::v1::EnsureBotMemberRequest>,
502 ) -> Result<Response<crate::protos::auth::v1::EnsureBotMemberResponse>, Status> {
503 request.extensions_mut().insert(RequestMeta {
504 request_id: Uuid::now_v7().to_string(),
505 caller_service: "kenapi".to_owned(),
506 });
507 self.api.ensure_bot_member(request).await
508 }
509}
Added lib/auth/src/client/local/session.rs lib/auth/src/client/local/session.rs +59 −0 View lib/auth/src/client/local/session.rs
@@ -0,0 +1,59 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::v1::session_service_server::SessionService;
7use crate::server::grpc::session::SessionApi;
8
9pub struct SessionClient {
10 api: SessionApi,
11}
12
13impl SessionClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: SessionApi::new(service),
17 }
18 }
19 pub async fn list_user_sessions(
20 &mut self,
21 mut request: Request<crate::protos::auth::v1::ListUserSessionsRequest>,
22 ) -> Result<Response<crate::protos::auth::v1::ListUserSessionsResponse>, Status> {
23 request.extensions_mut().insert(RequestMeta {
24 request_id: Uuid::now_v7().to_string(),
25 caller_service: "kenapi".to_owned(),
26 });
27 self.api.list_user_sessions(request).await
28 }
29 pub async fn revoke_session(
30 &mut self,
31 mut request: Request<crate::protos::auth::v1::RevokeSessionRequest>,
32 ) -> Result<Response<crate::protos::auth::v1::RevokeSessionResponse>, Status> {
33 request.extensions_mut().insert(RequestMeta {
34 request_id: Uuid::now_v7().to_string(),
35 caller_service: "kenapi".to_owned(),
36 });
37 self.api.revoke_session(request).await
38 }
39 pub async fn revoke_user_sessions(
40 &mut self,
41 mut request: Request<crate::protos::auth::v1::RevokeUserSessionsRequest>,
42 ) -> Result<Response<crate::protos::auth::v1::RevokeUserSessionsResponse>, Status> {
43 request.extensions_mut().insert(RequestMeta {
44 request_id: Uuid::now_v7().to_string(),
45 caller_service: "kenapi".to_owned(),
46 });
47 self.api.revoke_user_sessions(request).await
48 }
49 pub async fn bump_security_version(
50 &mut self,
51 mut request: Request<crate::protos::auth::v1::BumpSecurityVersionRequest>,
52 ) -> Result<Response<crate::protos::auth::v1::BumpSecurityVersionResponse>, Status> {
53 request.extensions_mut().insert(RequestMeta {
54 request_id: Uuid::now_v7().to_string(),
55 caller_service: "kenapi".to_owned(),
56 });
57 self.api.bump_security_version(request).await
58 }
59}
Added lib/auth/src/client/local/ssh_key.rs lib/auth/src/client/local/ssh_key.rs +59 −0 View lib/auth/src/client/local/ssh_key.rs
@@ -0,0 +1,59 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::v1::ssh_key_service_server::SshKeyService;
7use crate::server::grpc::ssh_key::SshKeyApi;
8
9pub struct SshKeyClient {
10 api: SshKeyApi,
11}
12
13impl SshKeyClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: SshKeyApi::new(service),
17 }
18 }
19 pub async fn lookup_ssh_key(
20 &mut self,
21 mut request: Request<crate::protos::auth::v1::LookupSshKeyRequest>,
22 ) -> Result<Response<crate::protos::auth::v1::LookupSshKeyResponse>, Status> {
23 request.extensions_mut().insert(RequestMeta {
24 request_id: Uuid::now_v7().to_string(),
25 caller_service: "kenapi".to_owned(),
26 });
27 self.api.lookup_ssh_key(request).await
28 }
29 pub async fn add_ssh_key(
30 &mut self,
31 mut request: Request<crate::protos::auth::v1::AddSshKeyRequest>,
32 ) -> Result<Response<crate::protos::auth::v1::AddSshKeyResponse>, Status> {
33 request.extensions_mut().insert(RequestMeta {
34 request_id: Uuid::now_v7().to_string(),
35 caller_service: "kenapi".to_owned(),
36 });
37 self.api.add_ssh_key(request).await
38 }
39 pub async fn list_user_ssh_keys(
40 &mut self,
41 mut request: Request<crate::protos::auth::v1::ListUserSshKeysRequest>,
42 ) -> Result<Response<crate::protos::auth::v1::ListUserSshKeysResponse>, Status> {
43 request.extensions_mut().insert(RequestMeta {
44 request_id: Uuid::now_v7().to_string(),
45 caller_service: "kenapi".to_owned(),
46 });
47 self.api.list_user_ssh_keys(request).await
48 }
49 pub async fn revoke_ssh_key(
50 &mut self,
51 mut request: Request<crate::protos::auth::v1::RevokeSshKeyRequest>,
52 ) -> Result<Response<crate::protos::auth::v1::RevokeSshKeyResponse>, Status> {
53 request.extensions_mut().insert(RequestMeta {
54 request_id: Uuid::now_v7().to_string(),
55 caller_service: "kenapi".to_owned(),
56 });
57 self.api.revoke_ssh_key(request).await
58 }
59}
Added lib/auth/src/client/local/token.rs lib/auth/src/client/local/token.rs +49 −0 View lib/auth/src/client/local/token.rs
@@ -0,0 +1,49 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::v1::token_service_server::TokenService;
7use crate::server::grpc::token::TokenApi;
8
9pub struct TokenClient {
10 api: TokenApi,
11}
12
13impl TokenClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: TokenApi::new(service),
17 }
18 }
19 pub async fn introspect_token(
20 &mut self,
21 mut request: Request<crate::protos::auth::v1::IntrospectTokenRequest>,
22 ) -> Result<Response<crate::protos::auth::v1::IntrospectTokenResponse>, Status> {
23 request.extensions_mut().insert(RequestMeta {
24 request_id: Uuid::now_v7().to_string(),
25 caller_service: "kenapi".to_owned(),
26 });
27 self.api.introspect_token(request).await
28 }
29 pub async fn issue_service_token(
30 &mut self,
31 mut request: Request<crate::protos::auth::v1::IssueServiceTokenRequest>,
32 ) -> Result<Response<crate::protos::auth::v1::IssueServiceTokenResponse>, Status> {
33 request.extensions_mut().insert(RequestMeta {
34 request_id: Uuid::now_v7().to_string(),
35 caller_service: "kenapi".to_owned(),
36 });
37 self.api.issue_service_token(request).await
38 }
39 pub async fn revoke_service_token(
40 &mut self,
41 mut request: Request<crate::protos::auth::v1::RevokeServiceTokenRequest>,
42 ) -> Result<Response<crate::protos::auth::v1::RevokeServiceTokenResponse>, Status> {
43 request.extensions_mut().insert(RequestMeta {
44 request_id: Uuid::now_v7().to_string(),
45 caller_service: "kenapi".to_owned(),
46 });
47 self.api.revoke_service_token(request).await
48 }
49}
Added lib/auth/src/client/client.rs lib/auth/src/client/client.rs +1565 −0 View lib/auth/src/client/client.rs
@@ -0,0 +1,1565 @@
1use std::collections::HashMap;
2use std::time::Duration;
3
4use crate::server::AuthSvc;
5use tonic::Request;
6use uuid::Uuid;
7
8use crate::client::error::KenAuthError;
9use crate::protos::auth as proto;
10
11#[derive(Clone)]
12pub struct KenAuthClient {
13 service: AuthSvc,
14 read_timeout: Duration,
15 write_timeout: Duration,
16}
17
18impl KenAuthClient {
19 pub fn local(service: AuthSvc, timeout_ms: u64) -> Self {
20 Self {
21 service,
22 read_timeout: Duration::from_millis(300),
23 write_timeout: Duration::from_millis(timeout_ms.max(2000)),
24 }
25 }
26
27 pub fn service(&self) -> &AuthSvc {
28 &self.service
29 }
30
31 pub async fn check_health(&self) -> Result<(), KenAuthError> {
32 self.service
33 .cache()
34 .ping()
35 .await
36 .map_err(|error| KenAuthError::Unavailable(error.to_string()))
37 }
38
39 pub fn identity(&self) -> crate::client::local::IdentityClient {
40 crate::client::local::IdentityClient::new(self.service.clone())
41 }
42
43 pub fn authority(&self) -> crate::client::local::AuthorityClient {
44 crate::client::local::AuthorityClient::new(self.service.clone())
45 }
46
47 pub fn email(&self) -> crate::client::local::EmailClient {
48 crate::client::local::EmailClient::new(self.service.clone())
49 }
50
51 pub fn session(&self) -> crate::client::local::SessionClient {
52 crate::client::local::SessionClient::new(self.service.clone())
53 }
54
55 pub fn organization(&self) -> crate::client::local::OrganizationClient {
56 crate::client::local::OrganizationClient::new(self.service.clone())
57 }
58
59 pub fn token(&self) -> crate::client::local::TokenClient {
60 crate::client::local::TokenClient::new(self.service.clone())
61 }
62
63 pub fn authorization(&self) -> crate::client::local::AuthorizationClient {
64 crate::client::local::AuthorizationClient::new(self.service.clone())
65 }
66
67 pub fn access_key(&self) -> crate::client::local::AccessKeyClient {
68 crate::client::local::AccessKeyClient::new(self.service.clone())
69 }
70
71 pub fn ssh_key(&self) -> crate::client::local::SshKeyClient {
72 crate::client::local::SshKeyClient::new(self.service.clone())
73 }
74
75 pub fn mfa(&self) -> crate::client::local::MfaClient {
76 crate::client::local::MfaClient::new(self.service.clone())
77 }
78
79 pub fn agreement(&self) -> crate::client::local::AgreementClient {
80 crate::client::local::AgreementClient::new(self.service.clone())
81 }
82
83 #[allow(clippy::too_many_arguments)]
84 pub async fn change_password(
85 &self,
86 user_id: i64,
87 old_password_hash: &str,
88 new_password_hash: &str,
89 keep_session_id: &str,
90 client_ip: &str,
91 ) -> Result<proto::v1::ChangePasswordResponse, KenAuthError> {
92 let mut client = self.identity();
93 client
94 .change_password(self.write_request(proto::v1::ChangePasswordRequest {
95 user_id,
96 old_password_hash: old_password_hash.to_string(),
97 new_password_hash: new_password_hash.to_string(),
98 keep_session_id: keep_session_id.to_string(),
99 client_ip: client_ip.to_string(),
100 }))
101 .await
102 .map_err(KenAuthError::from_status)
103 .map(|response| response.into_inner())
104 }
105
106 pub async fn get_mfa_status(
107 &self,
108 user_id: i64,
109 ) -> Result<proto::v1::GetMfaStatusResponse, KenAuthError> {
110 let mut client = self.mfa();
111 client
112 .get_mfa_status(self.read_request(proto::v1::GetMfaStatusRequest { user_id }))
113 .await
114 .map_err(KenAuthError::from_status)
115 .map(|response| response.into_inner())
116 }
117
118 pub async fn configure_totp(
119 &self,
120 user_id: i64,
121 name: &str,
122 client_ip: &str,
123 ) -> Result<proto::v1::ConfigureTotpResponse, KenAuthError> {
124 let mut client = self.mfa();
125 client
126 .configure_totp(self.write_request(proto::v1::ConfigureTotpRequest {
127 user_id,
128 name: name.to_string(),
129 client_ip: client_ip.to_string(),
130 }))
131 .await
132 .map_err(KenAuthError::from_status)
133 .map(|response| response.into_inner())
134 }
135
136 pub async fn enable_totp(
137 &self,
138 user_id: i64,
139 code: &str,
140 password_hash: &str,
141 client_ip: &str,
142 ) -> Result<proto::v1::EnableTotpResponse, KenAuthError> {
143 let mut client = self.mfa();
144 client
145 .enable_totp(self.write_request(proto::v1::EnableTotpRequest {
146 user_id,
147 code: code.to_string(),
148 password_hash: password_hash.to_string(),
149 client_ip: client_ip.to_string(),
150 }))
151 .await
152 .map_err(KenAuthError::from_status)
153 .map(|response| response.into_inner())
154 }
155
156 pub async fn disable_totp(
157 &self,
158 user_id: i64,
159 code: &str,
160 client_ip: &str,
161 ) -> Result<proto::v1::DisableTotpResponse, KenAuthError> {
162 let mut client = self.mfa();
163 client
164 .disable_totp(self.write_request(proto::v1::DisableTotpRequest {
165 user_id,
166 code: code.to_string(),
167 client_ip: client_ip.to_string(),
168 }))
169 .await
170 .map_err(KenAuthError::from_status)
171 .map(|response| response.into_inner())
172 }
173
174 pub async fn regenerate_recovery_codes(
175 &self,
176 user_id: i64,
177 password_hash: &str,
178 client_ip: &str,
179 ) -> Result<proto::v1::RegenerateRecoveryCodesResponse, KenAuthError> {
180 let mut client = self.mfa();
181 client
182 .regenerate_recovery_codes(self.write_request(
183 proto::v1::RegenerateRecoveryCodesRequest {
184 user_id,
185 password_hash: password_hash.to_string(),
186 client_ip: client_ip.to_string(),
187 },
188 ))
189 .await
190 .map_err(KenAuthError::from_status)
191 .map(|response| response.into_inner())
192 }
193
194 pub async fn list_access_keys(
195 &self,
196 user_id: i64,
197 include_revoked: bool,
198 page: proto::common::v1::PageRequest,
199 ) -> Result<proto::v1::ListAccessKeysResponse, KenAuthError> {
200 let mut client = self.access_key();
201 client
202 .list_access_keys(self.read_request(proto::v1::ListAccessKeysRequest {
203 user_id,
204 include_revoked,
205 page: Some(page),
206 }))
207 .await
208 .map_err(KenAuthError::from_status)
209 .map(|response| response.into_inner())
210 }
211
212 #[allow(clippy::too_many_arguments)]
213 pub async fn create_access_key(
214 &self,
215 user_id: i64,
216 name: &str,
217 description: &str,
218 scopes: Vec<i32>,
219 expires_in_secs: i64,
220 client_ip: &str,
221 ) -> Result<proto::v1::CreateAccessKeyResponse, KenAuthError> {
222 let mut client = self.access_key();
223 client
224 .create_access_key(self.write_request(proto::v1::CreateAccessKeyRequest {
225 user_id,
226 name: name.to_string(),
227 description: description.to_string(),
228 scopes,
229 expires_in_secs,
230 client_ip: client_ip.to_string(),
231 }))
232 .await
233 .map_err(KenAuthError::from_status)
234 .map(|response| response.into_inner())
235 }
236
237 pub async fn rotate_access_key(
238 &self,
239 user_id: i64,
240 access_key_id: &str,
241 client_ip: &str,
242 ) -> Result<proto::v1::RotateAccessKeyResponse, KenAuthError> {
243 let mut client = self.access_key();
244 client
245 .rotate_access_key(self.write_request(proto::v1::RotateAccessKeyRequest {
246 user_id,
247 access_key_id: access_key_id.to_string(),
248 client_ip: client_ip.to_string(),
249 }))
250 .await
251 .map_err(KenAuthError::from_status)
252 .map(|response| response.into_inner())
253 }
254
255 pub async fn revoke_access_key(
256 &self,
257 user_id: i64,
258 access_key_id: &str,
259 reason: &str,
260 ) -> Result<proto::v1::RevokeAccessKeyResponse, KenAuthError> {
261 let mut client = self.access_key();
262 client
263 .revoke_access_key(self.write_request(proto::v1::RevokeAccessKeyRequest {
264 user_id,
265 access_key_id: access_key_id.to_string(),
266 reason: reason.to_string(),
267 }))
268 .await
269 .map_err(KenAuthError::from_status)
270 .map(|response| response.into_inner())
271 }
272
273 pub async fn list_user_ssh_keys(
274 &self,
275 user_id: i64,
276 include_revoked: bool,
277 page: proto::common::v1::PageRequest,
278 ) -> Result<proto::v1::ListUserSshKeysResponse, KenAuthError> {
279 let mut client = self.ssh_key();
280 client
281 .list_user_ssh_keys(self.read_request(proto::v1::ListUserSshKeysRequest {
282 user_id,
283 include_revoked,
284 page: Some(page),
285 }))
286 .await
287 .map_err(KenAuthError::from_status)
288 .map(|response| response.into_inner())
289 }
290
291 pub async fn add_ssh_key(
292 &self,
293 user_id: i64,
294 name: &str,
295 public_key: &str,
296 description: &str,
297 client_ip: &str,
298 ) -> Result<proto::v1::AddSshKeyResponse, KenAuthError> {
299 let mut client = self.ssh_key();
300 client
301 .add_ssh_key(self.write_request(proto::v1::AddSshKeyRequest {
302 user_id,
303 name: name.to_string(),
304 public_key: public_key.to_string(),
305 description: description.to_string(),
306 client_ip: client_ip.to_string(),
307 }))
308 .await
309 .map_err(KenAuthError::from_status)
310 .map(|response| response.into_inner())
311 }
312
313 pub async fn revoke_ssh_key(
314 &self,
315 user_id: i64,
316 key_id: &str,
317 reason: &str,
318 bump_security_version: bool,
319 ) -> Result<proto::v1::RevokeSshKeyResponse, KenAuthError> {
320 let mut client = self.ssh_key();
321 client
322 .revoke_ssh_key(self.write_request(proto::v1::RevokeSshKeyRequest {
323 user_id,
324 key_id: key_id.to_string(),
325 reason: reason.to_string(),
326 bump_security_version,
327 }))
328 .await
329 .map_err(KenAuthError::from_status)
330 .map(|response| response.into_inner())
331 }
332
333 pub async fn list_user_sessions(
334 &self,
335 user_id: i64,
336 include_revoked: bool,
337 include_expired: bool,
338 page: proto::common::v1::PageRequest,
339 ) -> Result<proto::v1::ListUserSessionsResponse, KenAuthError> {
340 let mut client = self.session();
341 client
342 .list_user_sessions(self.read_request(proto::v1::ListUserSessionsRequest {
343 user_id,
344 include_revoked,
345 include_expired,
346 page: Some(page),
347 }))
348 .await
349 .map_err(KenAuthError::from_status)
350 .map(|response| response.into_inner())
351 }
352
353 pub async fn revoke_user_sessions(
354 &self,
355 user_id: i64,
356 except_session_id: &str,
357 reason: &str,
358 bump_security_version: bool,
359 ) -> Result<proto::v1::RevokeUserSessionsResponse, KenAuthError> {
360 let mut client = self.session();
361 client
362 .revoke_user_sessions(self.write_request(proto::v1::RevokeUserSessionsRequest {
363 user_id,
364 except_session_id: except_session_id.to_string(),
365 reason: reason.to_string(),
366 bump_security_version,
367 }))
368 .await
369 .map_err(KenAuthError::from_status)
370 .map(|response| response.into_inner())
371 }
372
373 pub fn read_request<T>(&self, message: T) -> Request<T> {
374 let mut request = Request::new(message);
375 request.set_timeout(self.read_timeout);
376 request
377 }
378
379 pub fn write_request<T>(&self, message: T) -> Request<T> {
380 let mut request = Request::new(message);
381 request.set_timeout(self.write_timeout);
382 request
383 }
384
385 /// Enqueue one plain text / HTML mail on `kenoauth`.
386 ///
387 /// `kenoauth` owns SMTP, retries and backpressure; a `Ok` here means the
388 /// message was accepted into its queue, while delivery outcome is visible
389 /// through `GetQueueStatus` / the delivery events on that side.
390 pub async fn send_mail(
391 &self,
392 to: &str,
393 subject: &str,
394 text: &str,
395 html: &str,
396 ) -> Result<(), KenAuthError> {
397 let mut client = self.email();
398 let request = proto::internal::v1::SendEmailRequest {
399 request_id: Uuid::now_v7().to_string(),
400 to: vec![proto::internal::v1::EmailAddress {
401 address: to.to_string(),
402 name: String::new(),
403 }],
404 cc: Vec::new(),
405 bcc: Vec::new(),
406 subject: subject.to_string(),
407 text: text.to_string(),
408 html: html.to_string(),
409 reply_to: None,
410 attachments: Vec::new(),
411 metadata: HashMap::new(),
412 trace_id: String::new(),
413 };
414 client
415 .send_email(self.write_request(request))
416 .await
417 .map_err(KenAuthError::from_status)?;
418 Ok(())
419 }
420
421 pub async fn get_session(
422 &self,
423 user_id: i64,
424 version: i32,
425 session_id: &str,
426 ) -> Result<proto::internal::v1::AuthorityAccess, KenAuthError> {
427 let mut client = self.authority();
428 client
429 .get_session(self.read_request(proto::internal::v1::GetSessionRequest {
430 user_id,
431 version,
432 session_id: session_id.to_string(),
433 }))
434 .await
435 .map_err(KenAuthError::from_status)
436 .map(|response| response.into_inner().access.unwrap_or_default())
437 }
438
439 pub async fn delete_account(&self, user_id: i64, reason: &str) -> Result<(), KenAuthError> {
440 let mut client = self.authority();
441 client
442 .delete_account(
443 self.write_request(proto::internal::v1::DeleteAccountRequest {
444 user_id,
445 reason: reason.to_string(),
446 }),
447 )
448 .await
449 .map_err(KenAuthError::from_status)?;
450 Ok(())
451 }
452
453 pub async fn cancel_account_deletion(&self, user_id: i64) -> Result<(), KenAuthError> {
454 let mut client = self.authority();
455 client
456 .cancel_account_deletion(
457 self.write_request(proto::internal::v1::CancelAccountDeletionRequest { user_id }),
458 )
459 .await
460 .map_err(KenAuthError::from_status)?;
461 Ok(())
462 }
463
464 pub async fn purge_account(&self, user_id: i64) -> Result<(), KenAuthError> {
465 let mut client = self.authority();
466 client
467 .purge_account(self.write_request(proto::internal::v1::PurgeAccountRequest { user_id }))
468 .await
469 .map_err(KenAuthError::from_status)?;
470 Ok(())
471 }
472
473 pub async fn batch_get_authority_users(
474 &self,
475 user_ids: Vec<i64>,
476 ) -> Result<Vec<proto::internal::v1::AuthorityUser>, KenAuthError> {
477 let mut client = self.authority();
478 client
479 .batch_get_user(
480 self.read_request(proto::internal::v1::BatchGetUserRequest { user_ids }),
481 )
482 .await
483 .map_err(KenAuthError::from_status)
484 .map(|response| response.into_inner().users)
485 }
486
487 pub async fn get_user_status(
488 &self,
489 user_id: i64,
490 ) -> Result<proto::common::v1::UserStatus, KenAuthError> {
491 let mut client = self.identity();
492 let user = Some(proto::common::v1::UserRef {
493 key: Some(proto::common::v1::user_ref::Key::UserId(user_id)),
494 });
495 client
496 .get_user_status(self.read_request(proto::v1::GetUserStatusRequest { user }))
497 .await
498 .map_err(KenAuthError::from_status)
499 .map(|response| response.into_inner().status.unwrap_or_default())
500 }
501
502 pub async fn get_user_public_by_ref(
503 &self,
504 key: proto::common::v1::user_ref::Key,
505 ) -> Result<proto::common::v1::UserPublic, KenAuthError> {
506 let mut client = self.identity();
507 let user = Some(proto::common::v1::UserRef { key: Some(key) });
508 client
509 .get_user_public(self.read_request(proto::v1::GetUserPublicRequest { user }))
510 .await
511 .map_err(KenAuthError::from_status)?
512 .into_inner()
513 .user
514 .ok_or(KenAuthError::NotFound)
515 }
516
517 pub async fn get_authority_user(
518 &self,
519 user_id: i64,
520 ) -> Result<proto::internal::v1::AuthorityUser, KenAuthError> {
521 let mut client = self.authority();
522 client
523 .get_user(self.read_request(proto::internal::v1::GetUserRequest { user_id }))
524 .await
525 .map_err(KenAuthError::from_status)?
526 .into_inner()
527 .user
528 .ok_or(KenAuthError::NotFound)
529 }
530
531 /// The only supported write path for `username` / `displayname`.
532 /// `version` is the account's current optimistic-lock version.
533 #[allow(clippy::too_many_arguments)]
534 pub async fn update_authority_user(
535 &self,
536 user_id: i64,
537 username: Option<String>,
538 displayname: Option<String>,
539 clear_displayname: bool,
540 public_show_email: Option<bool>,
541 version: i32,
542 ) -> Result<proto::internal::v1::AuthorityUser, KenAuthError> {
543 let mut client = self.authority();
544 client
545 .update_user(self.write_request(proto::internal::v1::UpdateUserRequest {
546 user_id,
547 patch: Some(proto::internal::v1::AuthorityUserPatch {
548 version,
549 username,
550 displayname,
551 clear_displayname,
552 public_show_email,
553 }),
554 }))
555 .await
556 .map_err(KenAuthError::from_status)?
557 .into_inner()
558 .user
559 .ok_or(KenAuthError::NotFound)
560 }
561
562 pub async fn batch_get_user_public(
563 &self,
564 user_ids: Vec<i64>,
565 ) -> Result<Vec<proto::common::v1::UserPublic>, KenAuthError> {
566 let mut client = self.identity();
567 client
568 .batch_get_user_public(
569 self.read_request(proto::v1::BatchGetUserPublicRequest { user_ids }),
570 )
571 .await
572 .map_err(KenAuthError::from_status)
573 .map(|response| response.into_inner().users)
574 }
575
576 pub async fn get_user_public(
577 &self,
578 user_id: i64,
579 ) -> Result<proto::common::v1::UserPublic, KenAuthError> {
580 let mut client = self.identity();
581 let user = Some(proto::common::v1::UserRef {
582 key: Some(proto::common::v1::user_ref::Key::UserId(user_id)),
583 });
584 client
585 .get_user_public(self.read_request(proto::v1::GetUserPublicRequest { user }))
586 .await
587 .map_err(KenAuthError::from_status)?
588 .into_inner()
589 .user
590 .ok_or(KenAuthError::NotFound)
591 }
592
593 pub async fn revoke_session(
594 &self,
595 user_id: i64,
596 session_id: &str,
597 reason: &str,
598 ) -> Result<(), KenAuthError> {
599 let mut client = self.session();
600 client
601 .revoke_session(self.write_request(proto::v1::RevokeSessionRequest {
602 user_id,
603 session_id: session_id.to_string(),
604 reason: reason.to_string(),
605 }))
606 .await
607 .map_err(KenAuthError::from_status)?;
608 Ok(())
609 }
610
611 pub async fn verify_access_key(
612 &self,
613 token: &str,
614 required_scopes: Vec<i32>,
615 ) -> Result<Option<proto::common::v1::Principal>, KenAuthError> {
616 let mut client = self.access_key();
617 let response = client
618 .verify_access_key(self.read_request(proto::v1::VerifyAccessKeyRequest {
619 access_key: token.to_string(),
620 required_scopes,
621 client_ip: String::new(),
622 }))
623 .await
624 .map_err(KenAuthError::from_status)?
625 .into_inner();
626 if !response.valid {
627 return Ok(None);
628 }
629 Ok(response.principal)
630 }
631
632 pub async fn issue_service_token(
633 &self,
634 user_id: i64,
635 audience: i32,
636 scopes: Vec<i32>,
637 ttl_seconds: u32,
638 event_id: &str,
639 ) -> Result<proto::v1::IssueServiceTokenResponse, KenAuthError> {
640 let mut client = self.token();
641 client
642 .issue_service_token(self.write_request(proto::v1::IssueServiceTokenRequest {
643 audience,
644 subject_user_id: user_id,
645 scopes,
646 ttl_seconds,
647 constraint: None,
648 event_id: event_id.to_string(),
649 }))
650 .await
651 .map_err(KenAuthError::from_status)
652 .map(|response| response.into_inner())
653 }
654
655 pub async fn introspect_token(
656 &self,
657 token: &str,
658 ) -> Result<proto::v1::IntrospectTokenResponse, KenAuthError> {
659 let mut client = self.token();
660 let credential = Some(proto::common::v1::Credential {
661 kind: Some(proto::common::v1::credential::Kind::ServiceToken(
662 token.to_string(),
663 )),
664 request_id: String::new(),
665 });
666 client
667 .introspect_token(self.read_request(proto::v1::IntrospectTokenRequest {
668 credential,
669 required_scopes: Vec::new(),
670 }))
671 .await
672 .map_err(KenAuthError::from_status)
673 .map(|response| response.into_inner())
674 }
675
676 pub async fn lookup_ssh_key(
677 &self,
678 public_key: &str,
679 ) -> Result<Option<proto::common::v1::Principal>, KenAuthError> {
680 let mut client = self.ssh_key();
681 let response = client
682 .lookup_ssh_key(self.read_request(proto::v1::LookupSshKeyRequest {
683 fingerprint: String::new(),
684 public_key: public_key.to_string(),
685 require_active: true,
686 }))
687 .await
688 .map_err(KenAuthError::from_status)?
689 .into_inner();
690 if !response.found {
691 return Ok(None);
692 }
693 Ok(response.principal)
694 }
695
696 pub async fn ensure_bot_user(
697 &self,
698 username: &str,
699 displayname: &str,
700 system: bool,
701 ) -> Result<proto::common::v1::UserPublic, KenAuthError> {
702 let mut client = self.identity();
703 client
704 .ensure_bot_user(self.write_request(proto::v1::EnsureBotUserRequest {
705 username: username.to_string(),
706 displayname: displayname.to_string(),
707 system,
708 }))
709 .await
710 .map_err(KenAuthError::from_status)?
711 .into_inner()
712 .user
713 .ok_or(KenAuthError::NotFound)
714 }
715
716 pub async fn ensure_bot_member(
717 &self,
718 organization_id: &str,
719 user_id: i64,
720 role_keys: Vec<String>,
721 role_ids: Vec<String>,
722 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
723 let mut client = self.organization();
724 client
725 .ensure_bot_member(self.write_request(proto::v1::EnsureBotMemberRequest {
726 organization_id: organization_id.to_string(),
727 user_id,
728 role_keys,
729 role_ids,
730 }))
731 .await
732 .map_err(KenAuthError::from_status)?
733 .into_inner()
734 .member
735 .ok_or(KenAuthError::NotFound)
736 }
737
738 pub async fn get_organization(
739 &self,
740 actor_user_id: i64,
741 organization_id: &str,
742 slug: &str,
743 ) -> Result<proto::v1::GetOrganizationResponse, KenAuthError> {
744 let mut client = self.organization();
745 client
746 .get_organization(self.read_request(proto::v1::GetOrganizationRequest {
747 actor_user_id,
748 organization_id: organization_id.to_string(),
749 slug: slug.to_string(),
750 }))
751 .await
752 .map_err(KenAuthError::from_status)
753 .map(|response| response.into_inner())
754 }
755
756 pub async fn get_member(
757 &self,
758 actor_user_id: i64,
759 organization_id: &str,
760 user_id: i64,
761 ) -> Result<Option<proto::v1::OrganizationMemberInfo>, KenAuthError> {
762 let mut client = self.organization();
763 match client
764 .get_member(self.read_request(proto::v1::GetMemberRequest {
765 actor_user_id,
766 organization_id: organization_id.to_string(),
767 member_id: String::new(),
768 user_id,
769 }))
770 .await
771 {
772 Ok(response) => Ok(response.into_inner().member),
773 Err(status) if status.code() == tonic::Code::NotFound => Ok(None),
774 Err(status) => Err(KenAuthError::from_status(status)),
775 }
776 }
777
778 pub async fn list_members(
779 &self,
780 actor_user_id: i64,
781 organization_id: &str,
782 include_inactive: bool,
783 include_banned: bool,
784 page: proto::common::v1::PageRequest,
785 ) -> Result<proto::v1::ListMembersResponse, KenAuthError> {
786 let mut client = self.organization();
787 client
788 .list_members(self.read_request(proto::v1::ListMembersRequest {
789 actor_user_id,
790 organization_id: organization_id.to_string(),
791 include_inactive,
792 include_banned,
793 page: Some(page),
794 }))
795 .await
796 .map_err(KenAuthError::from_status)
797 .map(|response| response.into_inner())
798 }
799
800 pub async fn list_organizations(
801 &self,
802 actor_user_id: i64,
803 user_id: i64,
804 include_archived: bool,
805 page: proto::common::v1::PageRequest,
806 ) -> Result<proto::v1::ListOrganizationsResponse, KenAuthError> {
807 let mut client = self.organization();
808 client
809 .list_organizations(self.read_request(proto::v1::ListOrganizationsRequest {
810 actor_user_id,
811 user_id,
812 include_archived,
813 page: Some(page),
814 }))
815 .await
816 .map_err(KenAuthError::from_status)
817 .map(|response| response.into_inner())
818 }
819
820 pub async fn list_public_organizations(
821 &self,
822 query: &str,
823 page: proto::common::v1::PageRequest,
824 ) -> Result<proto::v1::ListPublicOrganizationsResponse, KenAuthError> {
825 let mut client = self.organization();
826 client
827 .list_public_organizations(self.read_request(
828 proto::v1::ListPublicOrganizationsRequest {
829 query: query.to_string(),
830 page: Some(page),
831 },
832 ))
833 .await
834 .map_err(KenAuthError::from_status)
835 .map(|response| response.into_inner())
836 }
837
838 pub async fn check_permissions(
839 &self,
840 actor_user_id: i64,
841 organization_id: &str,
842 user_id: i64,
843 permissions: Vec<String>,
844 ) -> Result<proto::v1::CheckPermissionsResponse, KenAuthError> {
845 let mut client = self.organization();
846 client
847 .check_permissions(self.read_request(proto::v1::CheckPermissionsRequest {
848 actor_user_id,
849 organization_id: organization_id.to_string(),
850 user_id,
851 permissions,
852 }))
853 .await
854 .map_err(KenAuthError::from_status)
855 .map(|response| response.into_inner())
856 }
857
858 pub async fn create_organization(
859 &self,
860 actor_user_id: i64,
861 slug: &str,
862 name: &str,
863 description: &str,
864 avatar_url: &str,
865 join_policy: Option<i32>,
866 allow_join: Option<bool>,
867 require_email_verified: Option<bool>,
868 require_mfa: Option<bool>,
869 welcome_message: Option<String>,
870 member_must_enable_2fa: Option<bool>,
871 allow_invite: Option<bool>,
872 allow_join_level: Option<i32>,
873 ) -> Result<proto::v1::CreateOrganizationResponse, KenAuthError> {
874 let mut client = self.organization();
875 client
876 .create_organization(self.write_request(proto::v1::CreateOrganizationRequest {
877 actor_user_id,
878 slug: slug.to_string(),
879 name: name.to_string(),
880 description: description.to_string(),
881 avatar_url: avatar_url.to_string(),
882 join_policy,
883 allow_join,
884 require_email_verified,
885 require_mfa,
886 welcome_message,
887 member_must_enable_2fa,
888 allow_invite,
889 allow_join_level,
890 }))
891 .await
892 .map_err(KenAuthError::from_status)
893 .map(|response| response.into_inner())
894 }
895
896 #[allow(clippy::too_many_arguments)]
897 pub async fn update_organization(
898 &self,
899 actor_user_id: i64,
900 organization_id: &str,
901 name: Option<String>,
902 description: Option<String>,
903 avatar_url: Option<String>,
904 expected_version: i32,
905 join_policy: Option<i32>,
906 allow_join: Option<bool>,
907 require_email_verified: Option<bool>,
908 require_mfa: Option<bool>,
909 welcome_message: Option<String>,
910 member_must_enable_2fa: Option<bool>,
911 allow_invite: Option<bool>,
912 allow_join_level: Option<i32>,
913 ) -> Result<proto::v1::OrganizationInfo, KenAuthError> {
914 let mut client = self.organization();
915 client
916 .update_organization(self.write_request(proto::v1::UpdateOrganizationRequest {
917 actor_user_id,
918 organization_id: organization_id.to_string(),
919 name,
920 description,
921 avatar_url,
922 expected_version,
923 join_policy,
924 allow_join,
925 require_email_verified,
926 require_mfa,
927 welcome_message,
928 member_must_enable_2fa,
929 allow_invite,
930 allow_join_level,
931 }))
932 .await
933 .map_err(KenAuthError::from_status)?
934 .into_inner()
935 .organization
936 .ok_or(KenAuthError::NotFound)
937 }
938
939 pub async fn archive_organization(
940 &self,
941 actor_user_id: i64,
942 organization_id: &str,
943 reason: &str,
944 ) -> Result<(), KenAuthError> {
945 let mut client = self.organization();
946 client
947 .archive_organization(self.write_request(proto::v1::ArchiveOrganizationRequest {
948 actor_user_id,
949 organization_id: organization_id.to_string(),
950 reason: reason.to_string(),
951 }))
952 .await
953 .map_err(KenAuthError::from_status)?;
954 Ok(())
955 }
956
957 pub async fn restore_organization(
958 &self,
959 actor_user_id: i64,
960 organization_id: &str,
961 ) -> Result<(), KenAuthError> {
962 let mut client = self.organization();
963 client
964 .restore_organization(self.write_request(proto::v1::RestoreOrganizationRequest {
965 actor_user_id,
966 organization_id: organization_id.to_string(),
967 }))
968 .await
969 .map_err(KenAuthError::from_status)?;
970 Ok(())
971 }
972
973 pub async fn delete_organization(
974 &self,
975 actor_user_id: i64,
976 organization_id: &str,
977 force: bool,
978 reason: &str,
979 ) -> Result<(), KenAuthError> {
980 let mut client = self.organization();
981 client
982 .delete_organization(self.write_request(proto::v1::DeleteOrganizationRequest {
983 actor_user_id,
984 organization_id: organization_id.to_string(),
985 force,
986 reason: reason.to_string(),
987 }))
988 .await
989 .map_err(KenAuthError::from_status)?;
990 Ok(())
991 }
992 pub async fn add_member(
993 &self,
994 actor_user_id: i64,
995 organization_id: &str,
996 user_id: i64,
997 role: i32,
998 role_keys: Vec<String>,
999 ) -> Result<(proto::v1::OrganizationMemberInfo, bool), KenAuthError> {
1000 let mut client = self.organization();
1001 let response = client
1002 .add_member(self.write_request(proto::v1::AddMemberRequest {
1003 actor_user_id,
1004 organization_id: organization_id.to_string(),
1005 user_id,
1006 role,
1007 role_keys,
1008 }))
1009 .await
1010 .map_err(KenAuthError::from_status)?
1011 .into_inner();
1012 let member = response.member.ok_or(KenAuthError::NotFound)?;
1013 Ok((member, response.created))
1014 }
1015
1016 pub async fn remove_member(
1017 &self,
1018 actor_user_id: i64,
1019 organization_id: &str,
1020 user_id: i64,
1021 reason: &str,
1022 ) -> Result<bool, KenAuthError> {
1023 let mut client = self.organization();
1024 client
1025 .remove_member(self.write_request(proto::v1::RemoveMemberRequest {
1026 actor_user_id,
1027 organization_id: organization_id.to_string(),
1028 member_id: String::new(),
1029 user_id,
1030 reason: reason.to_string(),
1031 }))
1032 .await
1033 .map_err(KenAuthError::from_status)
1034 .map(|response| response.into_inner().removed)
1035 }
1036
1037 pub async fn leave_organization(
1038 &self,
1039 actor_user_id: i64,
1040 organization_id: &str,
1041 ) -> Result<bool, KenAuthError> {
1042 let mut client = self.organization();
1043 client
1044 .leave_organization(self.write_request(proto::v1::LeaveOrganizationRequest {
1045 actor_user_id,
1046 organization_id: organization_id.to_string(),
1047 }))
1048 .await
1049 .map_err(KenAuthError::from_status)
1050 .map(|response| response.into_inner().left)
1051 }
1052
1053 #[allow(clippy::too_many_arguments)]
1054 pub async fn update_member(
1055 &self,
1056 actor_user_id: i64,
1057 organization_id: &str,
1058 user_id: i64,
1059 alias_name: Option<Option<String>>,
1060 alias_avatar_url: Option<Option<String>>,
1061 message_notifications: Option<String>,
1062 muted: Option<bool>,
1063 mute_until: Option<Option<prost_types::Timestamp>>,
1064 mobile_push: Option<bool>,
1065 suppress_everyone: Option<bool>,
1066 suppress_roles: Option<bool>,
1067 hide_muted_channels: Option<bool>,
1068 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1069 let (clear_mute_until, mute_until) = match mute_until {
1070 Some(None) => (Some(true), None),
1071 Some(Some(value)) => (None, Some(value)),
1072 None => (None, None),
1073 };
1074 let mut client = self.organization();
1075 client
1076 .update_member(self.write_request(proto::v1::UpdateMemberRequest {
1077 actor_user_id,
1078 organization_id: organization_id.to_string(),
1079 member_id: String::new(),
1080 alias_name: alias_name.map(|value| value.unwrap_or_default()),
1081 alias_avatar_url: alias_avatar_url.map(|value| value.unwrap_or_default()),
1082 message_notifications,
1083 muted,
1084 clear_mute_until,
1085 mute_until,
1086 mobile_push,
1087 suppress_everyone,
1088 suppress_roles,
1089 hide_muted_channels,
1090 expected_version: 0,
1091 user_id,
1092 }))
1093 .await
1094 .map_err(KenAuthError::from_status)?
1095 .into_inner()
1096 .member
1097 .ok_or(KenAuthError::NotFound)
1098 }
1099
1100 pub async fn ban_member(
1101 &self,
1102 actor_user_id: i64,
1103 organization_id: &str,
1104 user_id: i64,
1105 reason: &str,
1106 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1107 let mut client = self.organization();
1108 client
1109 .ban_member(self.write_request(proto::v1::BanMemberRequest {
1110 actor_user_id,
1111 organization_id: organization_id.to_string(),
1112 member_id: String::new(),
1113 reason: reason.to_string(),
1114 user_id,
1115 }))
1116 .await
1117 .map_err(KenAuthError::from_status)?
1118 .into_inner()
1119 .member
1120 .ok_or(KenAuthError::NotFound)
1121 }
1122
1123 pub async fn unban_member(
1124 &self,
1125 actor_user_id: i64,
1126 organization_id: &str,
1127 user_id: i64,
1128 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1129 let mut client = self.organization();
1130 client
1131 .unban_member(self.write_request(proto::v1::UnbanMemberRequest {
1132 actor_user_id,
1133 organization_id: organization_id.to_string(),
1134 member_id: String::new(),
1135 user_id,
1136 }))
1137 .await
1138 .map_err(KenAuthError::from_status)?
1139 .into_inner()
1140 .member
1141 .ok_or(KenAuthError::NotFound)
1142 }
1143
1144 #[allow(clippy::too_many_arguments)]
1145 pub async fn update_ban(
1146 &self,
1147 actor_user_id: i64,
1148 organization_id: &str,
1149 user_id: i64,
1150 reason: Option<Option<String>>,
1151 expires_at: Option<Option<prost_types::Timestamp>>,
1152 allow_speak: Option<bool>,
1153 allow_push_repo: Option<bool>,
1154 allow_comment_any: Option<bool>,
1155 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1156 let (clear_expires_at, expires_at) = match expires_at {
1157 Some(None) => (Some(true), None),
1158 Some(Some(value)) => (None, Some(value)),
1159 None => (None, None),
1160 };
1161 let mut client = self.organization();
1162 client
1163 .update_ban(self.write_request(proto::v1::UpdateBanRequest {
1164 actor_user_id,
1165 organization_id: organization_id.to_string(),
1166 user_id,
1167 reason: reason.map(|value| value.unwrap_or_default()),
1168 clear_expires_at,
1169 expires_at,
1170 allow_agent_join: None,
1171 allow_speak,
1172 allow_push_repo,
1173 allow_comment_any,
1174 }))
1175 .await
1176 .map_err(KenAuthError::from_status)?
1177 .into_inner()
1178 .ban
1179 .ok_or(KenAuthError::NotFound)
1180 }
1181
1182 #[allow(clippy::too_many_arguments)]
1183 pub async fn create_role(
1184 &self,
1185 actor_user_id: i64,
1186 organization_id: &str,
1187 key: &str,
1188 name: &str,
1189 description: &str,
1190 rank: i32,
1191 self_assignable: bool,
1192 permissions: Vec<String>,
1193 ) -> Result<proto::v1::OrganizationRoleInfo, KenAuthError> {
1194 let mut client = self.organization();
1195 client
1196 .create_role(self.write_request(proto::v1::CreateRoleRequest {
1197 actor_user_id,
1198 organization_id: organization_id.to_string(),
1199 key: key.to_string(),
1200 name: name.to_string(),
1201 description: description.to_string(),
1202 rank,
1203 default_role: false,
1204 permissions: permissions.into_iter().map(allow_grant).collect(),
1205 self_assignable,
1206 }))
1207 .await
1208 .map_err(KenAuthError::from_status)?
1209 .into_inner()
1210 .role
1211 .ok_or(KenAuthError::NotFound)
1212 }
1213
1214 #[allow(clippy::too_many_arguments)]
1215 pub async fn update_role(
1216 &self,
1217 actor_user_id: i64,
1218 organization_id: &str,
1219 role_id: &str,
1220 name: Option<String>,
1221 description: Option<String>,
1222 rank: Option<i32>,
1223 self_assignable: Option<bool>,
1224 expected_version: i32,
1225 ) -> Result<proto::v1::OrganizationRoleInfo, KenAuthError> {
1226 let mut client = self.organization();
1227 client
1228 .update_role(self.write_request(proto::v1::UpdateRoleRequest {
1229 actor_user_id,
1230 organization_id: organization_id.to_string(),
1231 role_id: role_id.to_string(),
1232 name,
1233 description,
1234 rank,
1235 default_role: None,
1236 expected_version,
1237 self_assignable,
1238 }))
1239 .await
1240 .map_err(KenAuthError::from_status)?
1241 .into_inner()
1242 .role
1243 .ok_or(KenAuthError::NotFound)
1244 }
1245
1246 pub async fn set_role_permissions(
1247 &self,
1248 actor_user_id: i64,
1249 organization_id: &str,
1250 role_id: &str,
1251 permissions: Vec<String>,
1252 ) -> Result<proto::v1::OrganizationRoleInfo, KenAuthError> {
1253 let mut client = self.organization();
1254 client
1255 .set_role_permissions(self.write_request(proto::v1::SetRolePermissionsRequest {
1256 actor_user_id,
1257 organization_id: organization_id.to_string(),
1258 role_id: role_id.to_string(),
1259 permissions: permissions.into_iter().map(allow_grant).collect(),
1260 }))
1261 .await
1262 .map_err(KenAuthError::from_status)?
1263 .into_inner()
1264 .role
1265 .ok_or(KenAuthError::NotFound)
1266 }
1267
1268 pub async fn delete_role(
1269 &self,
1270 actor_user_id: i64,
1271 organization_id: &str,
1272 role_id: &str,
1273 ) -> Result<bool, KenAuthError> {
1274 let mut client = self.organization();
1275 client
1276 .delete_role(self.write_request(proto::v1::DeleteRoleRequest {
1277 actor_user_id,
1278 organization_id: organization_id.to_string(),
1279 role_id: role_id.to_string(),
1280 }))
1281 .await
1282 .map_err(KenAuthError::from_status)
1283 .map(|response| response.into_inner().deleted)
1284 }
1285
1286 pub async fn assign_role(
1287 &self,
1288 actor_user_id: i64,
1289 organization_id: &str,
1290 user_id: i64,
1291 role_id: &str,
1292 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1293 let mut client = self.organization();
1294 client
1295 .assign_role(self.write_request(proto::v1::AssignRoleRequest {
1296 actor_user_id,
1297 organization_id: organization_id.to_string(),
1298 member_id: String::new(),
1299 role_id: role_id.to_string(),
1300 user_id,
1301 }))
1302 .await
1303 .map_err(KenAuthError::from_status)?
1304 .into_inner()
1305 .member
1306 .ok_or(KenAuthError::NotFound)
1307 }
1308
1309 pub async fn unassign_role(
1310 &self,
1311 actor_user_id: i64,
1312 organization_id: &str,
1313 user_id: i64,
1314 role_id: &str,
1315 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1316 let mut client = self.organization();
1317 client
1318 .unassign_role(self.write_request(proto::v1::UnassignRoleRequest {
1319 actor_user_id,
1320 organization_id: organization_id.to_string(),
1321 member_id: String::new(),
1322 role_id: role_id.to_string(),
1323 user_id,
1324 }))
1325 .await
1326 .map_err(KenAuthError::from_status)?
1327 .into_inner()
1328 .member
1329 .ok_or(KenAuthError::NotFound)
1330 }
1331
1332 #[allow(clippy::too_many_arguments)]
1333 pub async fn create_invite(
1334 &self,
1335 actor_user_id: i64,
1336 organization_id: &str,
1337 method: i32,
1338 max_uses: i32,
1339 expires_at: Option<prost_types::Timestamp>,
1340 role_ids: Vec<String>,
1341 target_user_id: i64,
1342 email: &str,
1343 ) -> Result<(proto::v1::OrganizationInviteInfo, String), KenAuthError> {
1344 let mut client = self.organization();
1345 let response = client
1346 .create_invite(self.write_request(proto::v1::CreateInviteRequest {
1347 actor_user_id,
1348 organization_id: organization_id.to_string(),
1349 method,
1350 max_uses,
1351 expires_at,
1352 role_id: role_ids.first().cloned().unwrap_or_default(),
1353 target_user_id,
1354 email: email.to_string(),
1355 role_ids,
1356 }))
1357 .await
1358 .map_err(KenAuthError::from_status)?
1359 .into_inner();
1360 let invite = response.invite.ok_or(KenAuthError::NotFound)?;
1361 Ok((invite, response.token))
1362 }
1363
1364 pub async fn revoke_invite(
1365 &self,
1366 actor_user_id: i64,
1367 organization_id: &str,
1368 invite_id: &str,
1369 ) -> Result<bool, KenAuthError> {
1370 let mut client = self.organization();
1371 client
1372 .revoke_invite(self.write_request(proto::v1::RevokeInviteRequest {
1373 actor_user_id,
1374 organization_id: organization_id.to_string(),
1375 invite_id: invite_id.to_string(),
1376 }))
1377 .await
1378 .map_err(KenAuthError::from_status)
1379 .map(|response| response.into_inner().revoked)
1380 }
1381
1382 pub async fn redeem_invite(
1383 &self,
1384 actor_user_id: i64,
1385 token: &str,
1386 ) -> Result<proto::v1::RedeemInviteResponse, KenAuthError> {
1387 let mut client = self.organization();
1388 client
1389 .redeem_invite(self.write_request(proto::v1::RedeemInviteRequest {
1390 actor_user_id,
1391 token: token.to_string(),
1392 }))
1393 .await
1394 .map_err(KenAuthError::from_status)
1395 .map(|response| response.into_inner())
1396 }
1397
1398 pub async fn create_join_rule(
1399 &self,
1400 actor_user_id: i64,
1401 organization_id: &str,
1402 role_id: &str,
1403 trigger: &str,
1404 matcher: &str,
1405 enabled: bool,
1406 ) -> Result<proto::v1::JoinRuleInfo, KenAuthError> {
1407 let mut client = self.organization();
1408 client
1409 .create_join_rule(self.write_request(proto::v1::CreateJoinRuleRequest {
1410 actor_user_id,
1411 organization_id: organization_id.to_string(),
1412 role_id: role_id.to_string(),
1413 trigger: trigger.to_string(),
1414 matcher: matcher.to_string(),
1415 enabled,
1416 }))
1417 .await
1418 .map_err(KenAuthError::from_status)?
1419 .into_inner()
1420 .rule
1421 .ok_or(KenAuthError::NotFound)
1422 }
1423
1424 #[allow(clippy::too_many_arguments)]
1425 pub async fn update_join_rule(
1426 &self,
1427 actor_user_id: i64,
1428 organization_id: &str,
1429 rule_id: &str,
1430 role_id: Option<String>,
1431 trigger: Option<String>,
1432 matcher: Option<String>,
1433 enabled: Option<bool>,
1434 ) -> Result<proto::v1::JoinRuleInfo, KenAuthError> {
1435 let mut client = self.organization();
1436 client
1437 .update_join_rule(self.write_request(proto::v1::UpdateJoinRuleRequest {
1438 actor_user_id,
1439 organization_id: organization_id.to_string(),
1440 rule_id: rule_id.to_string(),
1441 role_id,
1442 trigger,
1443 matcher,
1444 enabled,
1445 }))
1446 .await
1447 .map_err(KenAuthError::from_status)?
1448 .into_inner()
1449 .rule
1450 .ok_or(KenAuthError::NotFound)
1451 }
1452
1453 pub async fn delete_join_rule(
1454 &self,
1455 actor_user_id: i64,
1456 organization_id: &str,
1457 rule_id: &str,
1458 ) -> Result<bool, KenAuthError> {
1459 let mut client = self.organization();
1460 client
1461 .delete_join_rule(self.write_request(proto::v1::DeleteJoinRuleRequest {
1462 actor_user_id,
1463 organization_id: organization_id.to_string(),
1464 rule_id: rule_id.to_string(),
1465 }))
1466 .await
1467 .map_err(KenAuthError::from_status)
1468 .map(|response| response.into_inner().deleted)
1469 }
1470
1471 pub async fn create_join_request(
1472 &self,
1473 actor_user_id: i64,
1474 organization_id: &str,
1475 note: &str,
1476 ) -> Result<proto::v1::JoinRequestInfo, KenAuthError> {
1477 let mut client = self.organization();
1478 client
1479 .create_join_request(self.write_request(proto::v1::CreateJoinRequestRequest {
1480 actor_user_id,
1481 organization_id: organization_id.to_string(),
1482 note: note.to_string(),
1483 }))
1484 .await
1485 .map_err(KenAuthError::from_status)?
1486 .into_inner()
1487 .request
1488 .ok_or(KenAuthError::NotFound)
1489 }
1490
1491 pub async fn withdraw_join_request(
1492 &self,
1493 actor_user_id: i64,
1494 organization_id: &str,
1495 request_id: &str,
1496 ) -> Result<proto::v1::JoinRequestInfo, KenAuthError> {
1497 let mut client = self.organization();
1498 client
1499 .withdraw_join_request(self.write_request(proto::v1::WithdrawJoinRequestRequest {
1500 actor_user_id,
1501 organization_id: organization_id.to_string(),
1502 request_id: request_id.to_string(),
1503 }))
1504 .await
1505 .map_err(KenAuthError::from_status)?
1506 .into_inner()
1507 .request
1508 .ok_or(KenAuthError::NotFound)
1509 }
1510
1511 pub async fn approve_join_request(
1512 &self,
1513 actor_user_id: i64,
1514 organization_id: &str,
1515 request_id: &str,
1516 ) -> Result<
1517 (
1518 proto::v1::JoinRequestInfo,
1519 Option<proto::v1::OrganizationMemberInfo>,
1520 ),
1521 KenAuthError,
1522 > {
1523 let mut client = self.organization();
1524 let response = client
1525 .approve_join_request(self.write_request(proto::v1::ApproveJoinRequestRequest {
1526 actor_user_id,
1527 organization_id: organization_id.to_string(),
1528 request_id: request_id.to_string(),
1529 }))
1530 .await
1531 .map_err(KenAuthError::from_status)?
1532 .into_inner();
1533 let request = response.request.ok_or(KenAuthError::NotFound)?;
1534 Ok((request, response.member))
1535 }
1536
1537 pub async fn reject_join_request(
1538 &self,
1539 actor_user_id: i64,
1540 organization_id: &str,
1541 request_id: &str,
1542 note: &str,
1543 ) -> Result<proto::v1::JoinRequestInfo, KenAuthError> {
1544 let mut client = self.organization();
1545 client
1546 .reject_join_request(self.write_request(proto::v1::RejectJoinRequestRequest {
1547 actor_user_id,
1548 organization_id: organization_id.to_string(),
1549 request_id: request_id.to_string(),
1550 note: note.to_string(),
1551 }))
1552 .await
1553 .map_err(KenAuthError::from_status)?
1554 .into_inner()
1555 .request
1556 .ok_or(KenAuthError::NotFound)
1557 }
1558}
1559
1560fn allow_grant(permission: String) -> proto::v1::OrganizationPermissionGrant {
1561 proto::v1::OrganizationPermissionGrant {
1562 permission,
1563 effect: proto::v1::PermissionEffect::Allow as i32,
1564 }
1565}
Deleted lib/auth/src/client/local.rs lib/auth/src/client/local.rs +0 −1161
@@ -1,1161 +0,0 @@
1use crate::server::AuthSvc;
2use crate::server::grpc::context::RequestMeta;
3use tonic::{Request, Response, Status};
4use uuid::Uuid;
5
6use crate::protos::auth::v1::identity_service_server::IdentityService;
7use crate::server::grpc::identity::IdentityApi;
8
9pub struct IdentityClient {
10 api: IdentityApi,
11}
12
13impl IdentityClient {
14 pub fn new(service: AuthSvc) -> Self {
15 Self {
16 api: IdentityApi::new(service),
17 }
18 }
19 pub async fn authenticate(
20 &mut self,
21 mut request: Request<crate::protos::auth::v1::AuthenticateRequest>,
22 ) -> Result<Response<crate::protos::auth::v1::AuthenticateResponse>, Status> {
23 request.extensions_mut().insert(RequestMeta {
24 request_id: Uuid::now_v7().to_string(),
25 caller_service: "kenapi".to_owned(),
26 });
27 self.api.authenticate(request).await
28 }
29 pub async fn verify_credential(
30 &mut self,
31 mut request: Request<crate::protos::auth::v1::VerifyCredentialRequest>,
32 ) -> Result<Response<crate::protos::auth::v1::VerifyCredentialResponse>, Status> {
33 request.extensions_mut().insert(RequestMeta {
34 request_id: Uuid::now_v7().to_string(),
35 caller_service: "kenapi".to_owned(),
36 });
37 self.api.verify_credential(request).await
38 }
39 pub async fn get_user_public(
40 &mut self,
41 mut request: Request<crate::protos::auth::v1::GetUserPublicRequest>,
42 ) -> Result<Response<crate::protos::auth::v1::GetUserPublicResponse>, Status> {
43 request.extensions_mut().insert(RequestMeta {
44 request_id: Uuid::now_v7().to_string(),
45 caller_service: "kenapi".to_owned(),
46 });
47 self.api.get_user_public(request).await
48 }
49 pub async fn batch_get_user_public(
50 &mut self,
51 mut request: Request<crate::protos::auth::v1::BatchGetUserPublicRequest>,
52 ) -> Result<Response<crate::protos::auth::v1::BatchGetUserPublicResponse>, Status> {
53 request.extensions_mut().insert(RequestMeta {
54 request_id: Uuid::now_v7().to_string(),
55 caller_service: "kenapi".to_owned(),
56 });
57 self.api.batch_get_user_public(request).await
58 }
59 pub async fn get_user_status(
60 &mut self,
61 mut request: Request<crate::protos::auth::v1::GetUserStatusRequest>,
62 ) -> Result<Response<crate::protos::auth::v1::GetUserStatusResponse>, Status> {
63 request.extensions_mut().insert(RequestMeta {
64 request_id: Uuid::now_v7().to_string(),
65 caller_service: "kenapi".to_owned(),
66 });
67 self.api.get_user_status(request).await
68 }
69 pub async fn ensure_bot_user(
70 &mut self,
71 mut request: Request<crate::protos::auth::v1::EnsureBotUserRequest>,
72 ) -> Result<Response<crate::protos::auth::v1::EnsureBotUserResponse>, Status> {
73 request.extensions_mut().insert(RequestMeta {
74 request_id: Uuid::now_v7().to_string(),
75 caller_service: "kenapi".to_owned(),
76 });
77 self.api.ensure_bot_user(request).await
78 }
79 pub async fn change_password(
80 &mut self,
81 mut request: Request<crate::protos::auth::v1::ChangePasswordRequest>,
82 ) -> Result<Response<crate::protos::auth::v1::ChangePasswordResponse>, Status> {
83 request.extensions_mut().insert(RequestMeta {
84 request_id: Uuid::now_v7().to_string(),
85 caller_service: "kenapi".to_owned(),
86 });
87 self.api.change_password(request).await
88 }
89}
90
91use crate::protos::auth::internal::v1::authority_service_server::AuthorityService;
92use crate::server::grpc::authority::AuthorityApi;
93
94pub struct AuthorityClient {
95 api: AuthorityApi,
96}
97
98impl AuthorityClient {
99 pub fn new(service: AuthSvc) -> Self {
100 Self {
101 api: AuthorityApi::new(service),
102 }
103 }
104 pub async fn redeem_socket_ticket(
105 &mut self,
106 mut request: Request<crate::protos::auth::internal::v1::RedeemSocketTicketRequest>,
107 ) -> Result<Response<crate::protos::auth::internal::v1::RedeemSocketTicketResponse>, Status>
108 {
109 request.extensions_mut().insert(RequestMeta {
110 request_id: Uuid::now_v7().to_string(),
111 caller_service: "kenapi".to_owned(),
112 });
113 self.api.redeem_socket_ticket(request).await
114 }
115 pub async fn validate(
116 &mut self,
117 mut request: Request<crate::protos::auth::internal::v1::ValidateRequest>,
118 ) -> Result<Response<crate::protos::auth::internal::v1::ValidateResponse>, Status> {
119 request.extensions_mut().insert(RequestMeta {
120 request_id: Uuid::now_v7().to_string(),
121 caller_service: "kenapi".to_owned(),
122 });
123 self.api.validate(request).await
124 }
125 pub async fn get_user(
126 &mut self,
127 mut request: Request<crate::protos::auth::internal::v1::GetUserRequest>,
128 ) -> Result<Response<crate::protos::auth::internal::v1::GetUserResponse>, Status> {
129 request.extensions_mut().insert(RequestMeta {
130 request_id: Uuid::now_v7().to_string(),
131 caller_service: "kenapi".to_owned(),
132 });
133 self.api.get_user(request).await
134 }
135 pub async fn batch_get_user(
136 &mut self,
137 mut request: Request<crate::protos::auth::internal::v1::BatchGetUserRequest>,
138 ) -> Result<Response<crate::protos::auth::internal::v1::BatchGetUserResponse>, Status> {
139 request.extensions_mut().insert(RequestMeta {
140 request_id: Uuid::now_v7().to_string(),
141 caller_service: "kenapi".to_owned(),
142 });
143 self.api.batch_get_user(request).await
144 }
145 pub async fn get_session(
146 &mut self,
147 mut request: Request<crate::protos::auth::internal::v1::GetSessionRequest>,
148 ) -> Result<Response<crate::protos::auth::internal::v1::GetSessionResponse>, Status> {
149 request.extensions_mut().insert(RequestMeta {
150 request_id: Uuid::now_v7().to_string(),
151 caller_service: "kenapi".to_owned(),
152 });
153 self.api.get_session(request).await
154 }
155 pub async fn update_user(
156 &mut self,
157 mut request: Request<crate::protos::auth::internal::v1::UpdateUserRequest>,
158 ) -> Result<Response<crate::protos::auth::internal::v1::UpdateUserResponse>, Status> {
159 request.extensions_mut().insert(RequestMeta {
160 request_id: Uuid::now_v7().to_string(),
161 caller_service: "kenapi".to_owned(),
162 });
163 self.api.update_user(request).await
164 }
165 pub async fn delete_account(
166 &mut self,
167 mut request: Request<crate::protos::auth::internal::v1::DeleteAccountRequest>,
168 ) -> Result<Response<crate::protos::auth::internal::v1::DeleteAccountResponse>, Status> {
169 request.extensions_mut().insert(RequestMeta {
170 request_id: Uuid::now_v7().to_string(),
171 caller_service: "kenapi".to_owned(),
172 });
173 self.api.delete_account(request).await
174 }
175 pub async fn cancel_account_deletion(
176 &mut self,
177 mut request: Request<crate::protos::auth::internal::v1::CancelAccountDeletionRequest>,
178 ) -> Result<Response<crate::protos::auth::internal::v1::CancelAccountDeletionResponse>, Status>
179 {
180 request.extensions_mut().insert(RequestMeta {
181 request_id: Uuid::now_v7().to_string(),
182 caller_service: "kenapi".to_owned(),
183 });
184 self.api.cancel_account_deletion(request).await
185 }
186 pub async fn purge_account(
187 &mut self,
188 mut request: Request<crate::protos::auth::internal::v1::PurgeAccountRequest>,
189 ) -> Result<Response<crate::protos::auth::internal::v1::PurgeAccountResponse>, Status> {
190 request.extensions_mut().insert(RequestMeta {
191 request_id: Uuid::now_v7().to_string(),
192 caller_service: "kenapi".to_owned(),
193 });
194 self.api.purge_account(request).await
195 }
196 pub async fn list_users(
197 &mut self,
198 mut request: Request<crate::protos::auth::internal::v1::ListUsersRequest>,
199 ) -> Result<Response<crate::protos::auth::internal::v1::ListUsersResponse>, Status> {
200 request.extensions_mut().insert(RequestMeta {
201 request_id: Uuid::now_v7().to_string(),
202 caller_service: "kenapi".to_owned(),
203 });
204 self.api.list_users(request).await
205 }
206}
207
208use crate::protos::auth::internal::v1::email_service_server::EmailService;
209use crate::server::grpc::email::EmailApi;
210
211pub struct EmailClient {
212 api: EmailApi,
213}
214
215impl EmailClient {
216 pub fn new(service: AuthSvc) -> Self {
217 Self {
218 api: EmailApi::new(service),
219 }
220 }
221 pub async fn send_email(
222 &mut self,
223 mut request: Request<crate::protos::auth::internal::v1::SendEmailRequest>,
224 ) -> Result<Response<crate::protos::auth::internal::v1::SendEmailResponse>, Status> {
225 request.extensions_mut().insert(RequestMeta {
226 request_id: Uuid::now_v7().to_string(),
227 caller_service: "kenapi".to_owned(),
228 });
229 self.api.send_email(request).await
230 }
231 pub async fn send_batch_email(
232 &mut self,
233 mut request: Request<crate::protos::auth::internal::v1::SendBatchEmailRequest>,
234 ) -> Result<Response<crate::protos::auth::internal::v1::SendBatchEmailResponse>, Status> {
235 request.extensions_mut().insert(RequestMeta {
236 request_id: Uuid::now_v7().to_string(),
237 caller_service: "kenapi".to_owned(),
238 });
239 self.api.send_batch_email(request).await
240 }
241 pub async fn render_and_send_email(
242 &mut self,
243 mut request: Request<crate::protos::auth::internal::v1::RenderAndSendEmailRequest>,
244 ) -> Result<Response<crate::protos::auth::internal::v1::SendEmailResponse>, Status> {
245 request.extensions_mut().insert(RequestMeta {
246 request_id: Uuid::now_v7().to_string(),
247 caller_service: "kenapi".to_owned(),
248 });
249 self.api.render_and_send_email(request).await
250 }
251 pub async fn get_queue_status(
252 &mut self,
253 mut request: Request<crate::protos::auth::internal::v1::EmailQueueStatusRequest>,
254 ) -> Result<Response<crate::protos::auth::internal::v1::EmailQueueStatus>, Status> {
255 request.extensions_mut().insert(RequestMeta {
256 request_id: Uuid::now_v7().to_string(),
257 caller_service: "kenapi".to_owned(),
258 });
259 self.api.get_queue_status(request).await
260 }
261}
262
263use crate::protos::auth::v1::session_service_server::SessionService;
264use crate::server::grpc::session::SessionApi;
265
266pub struct SessionClient {
267 api: SessionApi,
268}
269
270impl SessionClient {
271 pub fn new(service: AuthSvc) -> Self {
272 Self {
273 api: SessionApi::new(service),
274 }
275 }
276 pub async fn list_user_sessions(
277 &mut self,
278 mut request: Request<crate::protos::auth::v1::ListUserSessionsRequest>,
279 ) -> Result<Response<crate::protos::auth::v1::ListUserSessionsResponse>, Status> {
280 request.extensions_mut().insert(RequestMeta {
281 request_id: Uuid::now_v7().to_string(),
282 caller_service: "kenapi".to_owned(),
283 });
284 self.api.list_user_sessions(request).await
285 }
286 pub async fn revoke_session(
287 &mut self,
288 mut request: Request<crate::protos::auth::v1::RevokeSessionRequest>,
289 ) -> Result<Response<crate::protos::auth::v1::RevokeSessionResponse>, Status> {
290 request.extensions_mut().insert(RequestMeta {
291 request_id: Uuid::now_v7().to_string(),
292 caller_service: "kenapi".to_owned(),
293 });
294 self.api.revoke_session(request).await
295 }
296 pub async fn revoke_user_sessions(
297 &mut self,
298 mut request: Request<crate::protos::auth::v1::RevokeUserSessionsRequest>,
299 ) -> Result<Response<crate::protos::auth::v1::RevokeUserSessionsResponse>, Status> {
300 request.extensions_mut().insert(RequestMeta {
301 request_id: Uuid::now_v7().to_string(),
302 caller_service: "kenapi".to_owned(),
303 });
304 self.api.revoke_user_sessions(request).await
305 }
306 pub async fn bump_security_version(
307 &mut self,
308 mut request: Request<crate::protos::auth::v1::BumpSecurityVersionRequest>,
309 ) -> Result<Response<crate::protos::auth::v1::BumpSecurityVersionResponse>, Status> {
310 request.extensions_mut().insert(RequestMeta {
311 request_id: Uuid::now_v7().to_string(),
312 caller_service: "kenapi".to_owned(),
313 });
314 self.api.bump_security_version(request).await
315 }
316}
317
318use crate::protos::auth::v1::organization_service_server::OrganizationService;
319use crate::server::grpc::organization::OrganizationApi;
320
321pub struct OrganizationClient {
322 api: OrganizationApi,
323}
324
325impl OrganizationClient {
326 pub fn new(service: AuthSvc) -> Self {
327 Self {
328 api: OrganizationApi::new(service),
329 }
330 }
331 pub async fn create_organization(
332 &mut self,
333 mut request: Request<crate::protos::auth::v1::CreateOrganizationRequest>,
334 ) -> Result<Response<crate::protos::auth::v1::CreateOrganizationResponse>, Status> {
335 request.extensions_mut().insert(RequestMeta {
336 request_id: Uuid::now_v7().to_string(),
337 caller_service: "kenapi".to_owned(),
338 });
339 self.api.create_organization(request).await
340 }
341 pub async fn get_organization(
342 &mut self,
343 mut request: Request<crate::protos::auth::v1::GetOrganizationRequest>,
344 ) -> Result<Response<crate::protos::auth::v1::GetOrganizationResponse>, Status> {
345 request.extensions_mut().insert(RequestMeta {
346 request_id: Uuid::now_v7().to_string(),
347 caller_service: "kenapi".to_owned(),
348 });
349 self.api.get_organization(request).await
350 }
351 pub async fn list_organizations(
352 &mut self,
353 mut request: Request<crate::protos::auth::v1::ListOrganizationsRequest>,
354 ) -> Result<Response<crate::protos::auth::v1::ListOrganizationsResponse>, Status> {
355 request.extensions_mut().insert(RequestMeta {
356 request_id: Uuid::now_v7().to_string(),
357 caller_service: "kenapi".to_owned(),
358 });
359 self.api.list_organizations(request).await
360 }
361 pub async fn list_public_organizations(
362 &mut self,
363 mut request: Request<crate::protos::auth::v1::ListPublicOrganizationsRequest>,
364 ) -> Result<Response<crate::protos::auth::v1::ListPublicOrganizationsResponse>, Status> {
365 request.extensions_mut().insert(RequestMeta {
366 request_id: Uuid::now_v7().to_string(),
367 caller_service: "kenapi".to_owned(),
368 });
369 self.api.list_public_organizations(request).await
370 }
371 pub async fn update_organization(
372 &mut self,
373 mut request: Request<crate::protos::auth::v1::UpdateOrganizationRequest>,
374 ) -> Result<Response<crate::protos::auth::v1::UpdateOrganizationResponse>, Status> {
375 request.extensions_mut().insert(RequestMeta {
376 request_id: Uuid::now_v7().to_string(),
377 caller_service: "kenapi".to_owned(),
378 });
379 self.api.update_organization(request).await
380 }
381 pub async fn archive_organization(
382 &mut self,
383 mut request: Request<crate::protos::auth::v1::ArchiveOrganizationRequest>,
384 ) -> Result<Response<crate::protos::auth::v1::ArchiveOrganizationResponse>, Status> {
385 request.extensions_mut().insert(RequestMeta {
386 request_id: Uuid::now_v7().to_string(),
387 caller_service: "kenapi".to_owned(),
388 });
389 self.api.archive_organization(request).await
390 }
391 pub async fn restore_organization(
392 &mut self,
393 mut request: Request<crate::protos::auth::v1::RestoreOrganizationRequest>,
394 ) -> Result<Response<crate::protos::auth::v1::RestoreOrganizationResponse>, Status> {
395 request.extensions_mut().insert(RequestMeta {
396 request_id: Uuid::now_v7().to_string(),
397 caller_service: "kenapi".to_owned(),
398 });
399 self.api.restore_organization(request).await
400 }
401 pub async fn delete_organization(
402 &mut self,
403 mut request: Request<crate::protos::auth::v1::DeleteOrganizationRequest>,
404 ) -> Result<Response<crate::protos::auth::v1::DeleteOrganizationResponse>, Status> {
405 request.extensions_mut().insert(RequestMeta {
406 request_id: Uuid::now_v7().to_string(),
407 caller_service: "kenapi".to_owned(),
408 });
409 self.api.delete_organization(request).await
410 }
411 pub async fn transfer_ownership(
412 &mut self,
413 mut request: Request<crate::protos::auth::v1::TransferOwnershipRequest>,
414 ) -> Result<Response<crate::protos::auth::v1::TransferOwnershipResponse>, Status> {
415 request.extensions_mut().insert(RequestMeta {
416 request_id: Uuid::now_v7().to_string(),
417 caller_service: "kenapi".to_owned(),
418 });
419 self.api.transfer_ownership(request).await
420 }
421 pub async fn add_member(
422 &mut self,
423 mut request: Request<crate::protos::auth::v1::AddMemberRequest>,
424 ) -> Result<Response<crate::protos::auth::v1::AddMemberResponse>, Status> {
425 request.extensions_mut().insert(RequestMeta {
426 request_id: Uuid::now_v7().to_string(),
427 caller_service: "kenapi".to_owned(),
428 });
429 self.api.add_member(request).await
430 }
431 pub async fn remove_member(
432 &mut self,
433 mut request: Request<crate::protos::auth::v1::RemoveMemberRequest>,
434 ) -> Result<Response<crate::protos::auth::v1::RemoveMemberResponse>, Status> {
435 request.extensions_mut().insert(RequestMeta {
436 request_id: Uuid::now_v7().to_string(),
437 caller_service: "kenapi".to_owned(),
438 });
439 self.api.remove_member(request).await
440 }
441 pub async fn leave_organization(
442 &mut self,
443 mut request: Request<crate::protos::auth::v1::LeaveOrganizationRequest>,
444 ) -> Result<Response<crate::protos::auth::v1::LeaveOrganizationResponse>, Status> {
445 request.extensions_mut().insert(RequestMeta {
446 request_id: Uuid::now_v7().to_string(),
447 caller_service: "kenapi".to_owned(),
448 });
449 self.api.leave_organization(request).await
450 }
451 pub async fn list_members(
452 &mut self,
453 mut request: Request<crate::protos::auth::v1::ListMembersRequest>,
454 ) -> Result<Response<crate::protos::auth::v1::ListMembersResponse>, Status> {
455 request.extensions_mut().insert(RequestMeta {
456 request_id: Uuid::now_v7().to_string(),
457 caller_service: "kenapi".to_owned(),
458 });
459 self.api.list_members(request).await
460 }
461 pub async fn set_member_role(
462 &mut self,
463 mut request: Request<crate::protos::auth::v1::SetMemberRoleRequest>,
464 ) -> Result<Response<crate::protos::auth::v1::SetMemberRoleResponse>, Status> {
465 request.extensions_mut().insert(RequestMeta {
466 request_id: Uuid::now_v7().to_string(),
467 caller_service: "kenapi".to_owned(),
468 });
469 self.api.set_member_role(request).await
470 }
471 pub async fn ban_member(
472 &mut self,
473 mut request: Request<crate::protos::auth::v1::BanMemberRequest>,
474 ) -> Result<Response<crate::protos::auth::v1::BanMemberResponse>, Status> {
475 request.extensions_mut().insert(RequestMeta {
476 request_id: Uuid::now_v7().to_string(),
477 caller_service: "kenapi".to_owned(),
478 });
479 self.api.ban_member(request).await
480 }
481 pub async fn unban_member(
482 &mut self,
483 mut request: Request<crate::protos::auth::v1::UnbanMemberRequest>,
484 ) -> Result<Response<crate::protos::auth::v1::UnbanMemberResponse>, Status> {
485 request.extensions_mut().insert(RequestMeta {
486 request_id: Uuid::now_v7().to_string(),
487 caller_service: "kenapi".to_owned(),
488 });
489 self.api.unban_member(request).await
490 }
491 pub async fn get_member(
492 &mut self,
493 mut request: Request<crate::protos::auth::v1::GetMemberRequest>,
494 ) -> Result<Response<crate::protos::auth::v1::GetMemberResponse>, Status> {
495 request.extensions_mut().insert(RequestMeta {
496 request_id: Uuid::now_v7().to_string(),
497 caller_service: "kenapi".to_owned(),
498 });
499 self.api.get_member(request).await
500 }
501 pub async fn update_member(
502 &mut self,
503 mut request: Request<crate::protos::auth::v1::UpdateMemberRequest>,
504 ) -> Result<Response<crate::protos::auth::v1::UpdateMemberResponse>, Status> {
505 request.extensions_mut().insert(RequestMeta {
506 request_id: Uuid::now_v7().to_string(),
507 caller_service: "kenapi".to_owned(),
508 });
509 self.api.update_member(request).await
510 }
511 pub async fn update_self_member(
512 &mut self,
513 mut request: Request<crate::protos::auth::v1::UpdateMemberRequest>,
514 ) -> Result<Response<crate::protos::auth::v1::UpdateMemberResponse>, Status> {
515 request.extensions_mut().insert(RequestMeta {
516 request_id: Uuid::now_v7().to_string(),
517 caller_service: "kenapi".to_owned(),
518 });
519 self.api.update_self_member(request).await
520 }
521 pub async fn list_bans(
522 &mut self,
523 mut request: Request<crate::protos::auth::v1::ListBansRequest>,
524 ) -> Result<Response<crate::protos::auth::v1::ListBansResponse>, Status> {
525 request.extensions_mut().insert(RequestMeta {
526 request_id: Uuid::now_v7().to_string(),
527 caller_service: "kenapi".to_owned(),
528 });
529 self.api.list_bans(request).await
530 }
531 pub async fn get_ban(
532 &mut self,
533 mut request: Request<crate::protos::auth::v1::GetBanRequest>,
534 ) -> Result<Response<crate::protos::auth::v1::GetBanResponse>, Status> {
535 request.extensions_mut().insert(RequestMeta {
536 request_id: Uuid::now_v7().to_string(),
537 caller_service: "kenapi".to_owned(),
538 });
539 self.api.get_ban(request).await
540 }
541 pub async fn update_ban(
542 &mut self,
543 mut request: Request<crate::protos::auth::v1::UpdateBanRequest>,
544 ) -> Result<Response<crate::protos::auth::v1::UpdateBanResponse>, Status> {
545 request.extensions_mut().insert(RequestMeta {
546 request_id: Uuid::now_v7().to_string(),
547 caller_service: "kenapi".to_owned(),
548 });
549 self.api.update_ban(request).await
550 }
551 pub async fn get_role(
552 &mut self,
553 mut request: Request<crate::protos::auth::v1::GetRoleRequest>,
554 ) -> Result<Response<crate::protos::auth::v1::GetRoleResponse>, Status> {
555 request.extensions_mut().insert(RequestMeta {
556 request_id: Uuid::now_v7().to_string(),
557 caller_service: "kenapi".to_owned(),
558 });
559 self.api.get_role(request).await
560 }
561 pub async fn join_role(
562 &mut self,
563 mut request: Request<crate::protos::auth::v1::JoinRoleRequest>,
564 ) -> Result<Response<crate::protos::auth::v1::JoinRoleResponse>, Status> {
565 request.extensions_mut().insert(RequestMeta {
566 request_id: Uuid::now_v7().to_string(),
567 caller_service: "kenapi".to_owned(),
568 });
569 self.api.join_role(request).await
570 }
571 pub async fn leave_role(
572 &mut self,
573 mut request: Request<crate::protos::auth::v1::LeaveRoleRequest>,
574 ) -> Result<Response<crate::protos::auth::v1::LeaveRoleResponse>, Status> {
575 request.extensions_mut().insert(RequestMeta {
576 request_id: Uuid::now_v7().to_string(),
577 caller_service: "kenapi".to_owned(),
578 });
579 self.api.leave_role(request).await
580 }
581 pub async fn create_role(
582 &mut self,
583 mut request: Request<crate::protos::auth::v1::CreateRoleRequest>,
584 ) -> Result<Response<crate::protos::auth::v1::CreateRoleResponse>, Status> {
585 request.extensions_mut().insert(RequestMeta {
586 request_id: Uuid::now_v7().to_string(),
587 caller_service: "kenapi".to_owned(),
588 });
589 self.api.create_role(request).await
590 }
591 pub async fn update_role(
592 &mut self,
593 mut request: Request<crate::protos::auth::v1::UpdateRoleRequest>,
594 ) -> Result<Response<crate::protos::auth::v1::UpdateRoleResponse>, Status> {
595 request.extensions_mut().insert(RequestMeta {
596 request_id: Uuid::now_v7().to_string(),
597 caller_service: "kenapi".to_owned(),
598 });
599 self.api.update_role(request).await
600 }
601 pub async fn delete_role(
602 &mut self,
603 mut request: Request<crate::protos::auth::v1::DeleteRoleRequest>,
604 ) -> Result<Response<crate::protos::auth::v1::DeleteRoleResponse>, Status> {
605 request.extensions_mut().insert(RequestMeta {
606 request_id: Uuid::now_v7().to_string(),
607 caller_service: "kenapi".to_owned(),
608 });
609 self.api.delete_role(request).await
610 }
611 pub async fn list_roles(
612 &mut self,
613 mut request: Request<crate::protos::auth::v1::ListRolesRequest>,
614 ) -> Result<Response<crate::protos::auth::v1::ListRolesResponse>, Status> {
615 request.extensions_mut().insert(RequestMeta {
616 request_id: Uuid::now_v7().to_string(),
617 caller_service: "kenapi".to_owned(),
618 });
619 self.api.list_roles(request).await
620 }
621 pub async fn set_role_permissions(
622 &mut self,
623 mut request: Request<crate::protos::auth::v1::SetRolePermissionsRequest>,
624 ) -> Result<Response<crate::protos::auth::v1::SetRolePermissionsResponse>, Status> {
625 request.extensions_mut().insert(RequestMeta {
626 request_id: Uuid::now_v7().to_string(),
627 caller_service: "kenapi".to_owned(),
628 });
629 self.api.set_role_permissions(request).await
630 }
631 pub async fn assign_role(
632 &mut self,
633 mut request: Request<crate::protos::auth::v1::AssignRoleRequest>,
634 ) -> Result<Response<crate::protos::auth::v1::AssignRoleResponse>, Status> {
635 request.extensions_mut().insert(RequestMeta {
636 request_id: Uuid::now_v7().to_string(),
637 caller_service: "kenapi".to_owned(),
638 });
639 self.api.assign_role(request).await
640 }
641 pub async fn unassign_role(
642 &mut self,
643 mut request: Request<crate::protos::auth::v1::UnassignRoleRequest>,
644 ) -> Result<Response<crate::protos::auth::v1::UnassignRoleResponse>, Status> {
645 request.extensions_mut().insert(RequestMeta {
646 request_id: Uuid::now_v7().to_string(),
647 caller_service: "kenapi".to_owned(),
648 });
649 self.api.unassign_role(request).await
650 }
651 pub async fn set_member_permissions(
652 &mut self,
653 mut request: Request<crate::protos::auth::v1::SetMemberPermissionsRequest>,
654 ) -> Result<Response<crate::protos::auth::v1::SetMemberPermissionsResponse>, Status> {
655 request.extensions_mut().insert(RequestMeta {
656 request_id: Uuid::now_v7().to_string(),
657 caller_service: "kenapi".to_owned(),
658 });
659 self.api.set_member_permissions(request).await
660 }
661 pub async fn check_permission(
662 &mut self,
663 mut request: Request<crate::protos::auth::v1::CheckPermissionRequest>,
664 ) -> Result<Response<crate::protos::auth::v1::CheckPermissionResponse>, Status> {
665 request.extensions_mut().insert(RequestMeta {
666 request_id: Uuid::now_v7().to_string(),
667 caller_service: "kenapi".to_owned(),
668 });
669 self.api.check_permission(request).await
670 }
671 pub async fn check_permissions(
672 &mut self,
673 mut request: Request<crate::protos::auth::v1::CheckPermissionsRequest>,
674 ) -> Result<Response<crate::protos::auth::v1::CheckPermissionsResponse>, Status> {
675 request.extensions_mut().insert(RequestMeta {
676 request_id: Uuid::now_v7().to_string(),
677 caller_service: "kenapi".to_owned(),
678 });
679 self.api.check_permissions(request).await
680 }
681 pub async fn create_invite(
682 &mut self,
683 mut request: Request<crate::protos::auth::v1::CreateInviteRequest>,
684 ) -> Result<Response<crate::protos::auth::v1::CreateInviteResponse>, Status> {
685 request.extensions_mut().insert(RequestMeta {
686 request_id: Uuid::now_v7().to_string(),
687 caller_service: "kenapi".to_owned(),
688 });
689 self.api.create_invite(request).await
690 }
691 pub async fn revoke_invite(
692 &mut self,
693 mut request: Request<crate::protos::auth::v1::RevokeInviteRequest>,
694 ) -> Result<Response<crate::protos::auth::v1::RevokeInviteResponse>, Status> {
695 request.extensions_mut().insert(RequestMeta {
696 request_id: Uuid::now_v7().to_string(),
697 caller_service: "kenapi".to_owned(),
698 });
699 self.api.revoke_invite(request).await
700 }
701 pub async fn list_invites(
702 &mut self,
703 mut request: Request<crate::protos::auth::v1::ListInvitesRequest>,
704 ) -> Result<Response<crate::protos::auth::v1::ListInvitesResponse>, Status> {
705 request.extensions_mut().insert(RequestMeta {
706 request_id: Uuid::now_v7().to_string(),
707 caller_service: "kenapi".to_owned(),
708 });
709 self.api.list_invites(request).await
710 }
711 pub async fn redeem_invite(
712 &mut self,
713 mut request: Request<crate::protos::auth::v1::RedeemInviteRequest>,
714 ) -> Result<Response<crate::protos::auth::v1::RedeemInviteResponse>, Status> {
715 request.extensions_mut().insert(RequestMeta {
716 request_id: Uuid::now_v7().to_string(),
717 caller_service: "kenapi".to_owned(),
718 });
719 self.api.redeem_invite(request).await
720 }
721 pub async fn create_join_rule(
722 &mut self,
723 mut request: Request<crate::protos::auth::v1::CreateJoinRuleRequest>,
724 ) -> Result<Response<crate::protos::auth::v1::CreateJoinRuleResponse>, Status> {
725 request.extensions_mut().insert(RequestMeta {
726 request_id: Uuid::now_v7().to_string(),
727 caller_service: "kenapi".to_owned(),
728 });
729 self.api.create_join_rule(request).await
730 }
731 pub async fn update_join_rule(
732 &mut self,
733 mut request: Request<crate::protos::auth::v1::UpdateJoinRuleRequest>,
734 ) -> Result<Response<crate::protos::auth::v1::UpdateJoinRuleResponse>, Status> {
735 request.extensions_mut().insert(RequestMeta {
736 request_id: Uuid::now_v7().to_string(),
737 caller_service: "kenapi".to_owned(),
738 });
739 self.api.update_join_rule(request).await
740 }
741 pub async fn delete_join_rule(
742 &mut self,
743 mut request: Request<crate::protos::auth::v1::DeleteJoinRuleRequest>,
744 ) -> Result<Response<crate::protos::auth::v1::DeleteJoinRuleResponse>, Status> {
745 request.extensions_mut().insert(RequestMeta {
746 request_id: Uuid::now_v7().to_string(),
747 caller_service: "kenapi".to_owned(),
748 });
749 self.api.delete_join_rule(request).await
750 }
751 pub async fn list_join_rules(
752 &mut self,
753 mut request: Request<crate::protos::auth::v1::ListJoinRulesRequest>,
754 ) -> Result<Response<crate::protos::auth::v1::ListJoinRulesResponse>, Status> {
755 request.extensions_mut().insert(RequestMeta {
756 request_id: Uuid::now_v7().to_string(),
757 caller_service: "kenapi".to_owned(),
758 });
759 self.api.list_join_rules(request).await
760 }
761 pub async fn create_join_request(
762 &mut self,
763 mut request: Request<crate::protos::auth::v1::CreateJoinRequestRequest>,
764 ) -> Result<Response<crate::protos::auth::v1::CreateJoinRequestResponse>, Status> {
765 request.extensions_mut().insert(RequestMeta {
766 request_id: Uuid::now_v7().to_string(),
767 caller_service: "kenapi".to_owned(),
768 });
769 self.api.create_join_request(request).await
770 }
771 pub async fn list_join_requests(
772 &mut self,
773 mut request: Request<crate::protos::auth::v1::ListJoinRequestsRequest>,
774 ) -> Result<Response<crate::protos::auth::v1::ListJoinRequestsResponse>, Status> {
775 request.extensions_mut().insert(RequestMeta {
776 request_id: Uuid::now_v7().to_string(),
777 caller_service: "kenapi".to_owned(),
778 });
779 self.api.list_join_requests(request).await
780 }
781 pub async fn withdraw_join_request(
782 &mut self,
783 mut request: Request<crate::protos::auth::v1::WithdrawJoinRequestRequest>,
784 ) -> Result<Response<crate::protos::auth::v1::WithdrawJoinRequestResponse>, Status> {
785 request.extensions_mut().insert(RequestMeta {
786 request_id: Uuid::now_v7().to_string(),
787 caller_service: "kenapi".to_owned(),
788 });
789 self.api.withdraw_join_request(request).await
790 }
791 pub async fn approve_join_request(
792 &mut self,
793 mut request: Request<crate::protos::auth::v1::ApproveJoinRequestRequest>,
794 ) -> Result<Response<crate::protos::auth::v1::ApproveJoinRequestResponse>, Status> {
795 request.extensions_mut().insert(RequestMeta {
796 request_id: Uuid::now_v7().to_string(),
797 caller_service: "kenapi".to_owned(),
798 });
799 self.api.approve_join_request(request).await
800 }
801 pub async fn reject_join_request(
802 &mut self,
803 mut request: Request<crate::protos::auth::v1::RejectJoinRequestRequest>,
804 ) -> Result<Response<crate::protos::auth::v1::RejectJoinRequestResponse>, Status> {
805 request.extensions_mut().insert(RequestMeta {
806 request_id: Uuid::now_v7().to_string(),
807 caller_service: "kenapi".to_owned(),
808 });
809 self.api.reject_join_request(request).await
810 }
811 pub async fn ensure_bot_member(
812 &mut self,
813 mut request: Request<crate::protos::auth::v1::EnsureBotMemberRequest>,
814 ) -> Result<Response<crate::protos::auth::v1::EnsureBotMemberResponse>, Status> {
815 request.extensions_mut().insert(RequestMeta {
816 request_id: Uuid::now_v7().to_string(),
817 caller_service: "kenapi".to_owned(),
818 });
819 self.api.ensure_bot_member(request).await
820 }
821}
822
823use crate::protos::auth::v1::token_service_server::TokenService;
824use crate::server::grpc::token::TokenApi;
825
826pub struct TokenClient {
827 api: TokenApi,
828}
829
830impl TokenClient {
831 pub fn new(service: AuthSvc) -> Self {
832 Self {
833 api: TokenApi::new(service),
834 }
835 }
836 pub async fn introspect_token(
837 &mut self,
838 mut request: Request<crate::protos::auth::v1::IntrospectTokenRequest>,
839 ) -> Result<Response<crate::protos::auth::v1::IntrospectTokenResponse>, Status> {
840 request.extensions_mut().insert(RequestMeta {
841 request_id: Uuid::now_v7().to_string(),
842 caller_service: "kenapi".to_owned(),
843 });
844 self.api.introspect_token(request).await
845 }
846 pub async fn issue_service_token(
847 &mut self,
848 mut request: Request<crate::protos::auth::v1::IssueServiceTokenRequest>,
849 ) -> Result<Response<crate::protos::auth::v1::IssueServiceTokenResponse>, Status> {
850 request.extensions_mut().insert(RequestMeta {
851 request_id: Uuid::now_v7().to_string(),
852 caller_service: "kenapi".to_owned(),
853 });
854 self.api.issue_service_token(request).await
855 }
856 pub async fn revoke_service_token(
857 &mut self,
858 mut request: Request<crate::protos::auth::v1::RevokeServiceTokenRequest>,
859 ) -> Result<Response<crate::protos::auth::v1::RevokeServiceTokenResponse>, Status> {
860 request.extensions_mut().insert(RequestMeta {
861 request_id: Uuid::now_v7().to_string(),
862 caller_service: "kenapi".to_owned(),
863 });
864 self.api.revoke_service_token(request).await
865 }
866}
867
868use crate::protos::auth::v1::authorization_service_server::AuthorizationService;
869use crate::server::grpc::authorization::AuthorizationApi;
870
871pub struct AuthorizationClient {
872 api: AuthorizationApi,
873}
874
875impl AuthorizationClient {
876 pub fn new(service: AuthSvc) -> Self {
877 Self {
878 api: AuthorizationApi::new(service),
879 }
880 }
881 pub async fn authorize(
882 &mut self,
883 mut request: Request<crate::protos::auth::v1::AuthorizeRequest>,
884 ) -> Result<Response<crate::protos::auth::v1::AuthorizeResponse>, Status> {
885 request.extensions_mut().insert(RequestMeta {
886 request_id: Uuid::now_v7().to_string(),
887 caller_service: "kenapi".to_owned(),
888 });
889 self.api.authorize(request).await
890 }
891 pub async fn batch_authorize(
892 &mut self,
893 mut request: Request<crate::protos::auth::v1::BatchAuthorizeRequest>,
894 ) -> Result<Response<crate::protos::auth::v1::BatchAuthorizeResponse>, Status> {
895 request.extensions_mut().insert(RequestMeta {
896 request_id: Uuid::now_v7().to_string(),
897 caller_service: "kenapi".to_owned(),
898 });
899 self.api.batch_authorize(request).await
900 }
901 pub async fn is_platform_admin(
902 &mut self,
903 mut request: Request<crate::protos::auth::v1::IsPlatformAdminRequest>,
904 ) -> Result<Response<crate::protos::auth::v1::IsPlatformAdminResponse>, Status> {
905 request.extensions_mut().insert(RequestMeta {
906 request_id: Uuid::now_v7().to_string(),
907 caller_service: "kenapi".to_owned(),
908 });
909 self.api.is_platform_admin(request).await
910 }
911 pub async fn get_capabilities(
912 &mut self,
913 mut request: Request<crate::protos::auth::v1::GetCapabilitiesRequest>,
914 ) -> Result<Response<crate::protos::auth::v1::GetCapabilitiesResponse>, Status> {
915 request.extensions_mut().insert(RequestMeta {
916 request_id: Uuid::now_v7().to_string(),
917 caller_service: "kenapi".to_owned(),
918 });
919 self.api.get_capabilities(request).await
920 }
921}
922
923use crate::protos::auth::v1::access_key_service_server::AccessKeyService;
924use crate::server::grpc::access_key::AccessKeyApi;
925
926pub struct AccessKeyClient {
927 api: AccessKeyApi,
928}
929
930impl AccessKeyClient {
931 pub fn new(service: AuthSvc) -> Self {
932 Self {
933 api: AccessKeyApi::new(service),
934 }
935 }
936 pub async fn verify_access_key(
937 &mut self,
938 mut request: Request<crate::protos::auth::v1::VerifyAccessKeyRequest>,
939 ) -> Result<Response<crate::protos::auth::v1::VerifyAccessKeyResponse>, Status> {
940 request.extensions_mut().insert(RequestMeta {
941 request_id: Uuid::now_v7().to_string(),
942 caller_service: "kenapi".to_owned(),
943 });
944 self.api.verify_access_key(request).await
945 }
946 pub async fn create_access_key(
947 &mut self,
948 mut request: Request<crate::protos::auth::v1::CreateAccessKeyRequest>,
949 ) -> Result<Response<crate::protos::auth::v1::CreateAccessKeyResponse>, Status> {
950 request.extensions_mut().insert(RequestMeta {
951 request_id: Uuid::now_v7().to_string(),
952 caller_service: "kenapi".to_owned(),
953 });
954 self.api.create_access_key(request).await
955 }
956 pub async fn rotate_access_key(
957 &mut self,
958 mut request: Request<crate::protos::auth::v1::RotateAccessKeyRequest>,
959 ) -> Result<Response<crate::protos::auth::v1::RotateAccessKeyResponse>, Status> {
960 request.extensions_mut().insert(RequestMeta {
961 request_id: Uuid::now_v7().to_string(),
962 caller_service: "kenapi".to_owned(),
963 });
964 self.api.rotate_access_key(request).await
965 }
966 pub async fn list_access_keys(
967 &mut self,
968 mut request: Request<crate::protos::auth::v1::ListAccessKeysRequest>,
969 ) -> Result<Response<crate::protos::auth::v1::ListAccessKeysResponse>, Status> {
970 request.extensions_mut().insert(RequestMeta {
971 request_id: Uuid::now_v7().to_string(),
972 caller_service: "kenapi".to_owned(),
973 });
974 self.api.list_access_keys(request).await
975 }
976 pub async fn revoke_access_key(
977 &mut self,
978 mut request: Request<crate::protos::auth::v1::RevokeAccessKeyRequest>,
979 ) -> Result<Response<crate::protos::auth::v1::RevokeAccessKeyResponse>, Status> {
980 request.extensions_mut().insert(RequestMeta {
981 request_id: Uuid::now_v7().to_string(),
982 caller_service: "kenapi".to_owned(),
983 });
984 self.api.revoke_access_key(request).await
985 }
986}
987
988use crate::protos::auth::v1::ssh_key_service_server::SshKeyService;
989use crate::server::grpc::ssh_key::SshKeyApi;
990
991pub struct SshKeyClient {
992 api: SshKeyApi,
993}
994
995impl SshKeyClient {
996 pub fn new(service: AuthSvc) -> Self {
997 Self {
998 api: SshKeyApi::new(service),
999 }
1000 }
1001 pub async fn lookup_ssh_key(
1002 &mut self,
1003 mut request: Request<crate::protos::auth::v1::LookupSshKeyRequest>,
1004 ) -> Result<Response<crate::protos::auth::v1::LookupSshKeyResponse>, Status> {
1005 request.extensions_mut().insert(RequestMeta {
1006 request_id: Uuid::now_v7().to_string(),
1007 caller_service: "kenapi".to_owned(),
1008 });
1009 self.api.lookup_ssh_key(request).await
1010 }
1011 pub async fn add_ssh_key(
1012 &mut self,
1013 mut request: Request<crate::protos::auth::v1::AddSshKeyRequest>,
1014 ) -> Result<Response<crate::protos::auth::v1::AddSshKeyResponse>, Status> {
1015 request.extensions_mut().insert(RequestMeta {
1016 request_id: Uuid::now_v7().to_string(),
1017 caller_service: "kenapi".to_owned(),
1018 });
1019 self.api.add_ssh_key(request).await
1020 }
1021 pub async fn list_user_ssh_keys(
1022 &mut self,
1023 mut request: Request<crate::protos::auth::v1::ListUserSshKeysRequest>,
1024 ) -> Result<Response<crate::protos::auth::v1::ListUserSshKeysResponse>, Status> {
1025 request.extensions_mut().insert(RequestMeta {
1026 request_id: Uuid::now_v7().to_string(),
1027 caller_service: "kenapi".to_owned(),
1028 });
1029 self.api.list_user_ssh_keys(request).await
1030 }
1031 pub async fn revoke_ssh_key(
1032 &mut self,
1033 mut request: Request<crate::protos::auth::v1::RevokeSshKeyRequest>,
1034 ) -> Result<Response<crate::protos::auth::v1::RevokeSshKeyResponse>, Status> {
1035 request.extensions_mut().insert(RequestMeta {
1036 request_id: Uuid::now_v7().to_string(),
1037 caller_service: "kenapi".to_owned(),
1038 });
1039 self.api.revoke_ssh_key(request).await
1040 }
1041}
1042
1043use crate::protos::auth::v1::mfa_service_server::MfaService;
1044use crate::server::grpc::mfa::MfaApi;
1045
1046pub struct MfaClient {
1047 api: MfaApi,
1048}
1049
1050impl MfaClient {
1051 pub fn new(service: AuthSvc) -> Self {
1052 Self {
1053 api: MfaApi::new(service),
1054 }
1055 }
1056 pub async fn get_mfa_status(
1057 &mut self,
1058 mut request: Request<crate::protos::auth::v1::GetMfaStatusRequest>,
1059 ) -> Result<Response<crate::protos::auth::v1::GetMfaStatusResponse>, Status> {
1060 request.extensions_mut().insert(RequestMeta {
1061 request_id: Uuid::now_v7().to_string(),
1062 caller_service: "kenapi".to_owned(),
1063 });
1064 self.api.get_mfa_status(request).await
1065 }
1066 pub async fn verify_totp(
1067 &mut self,
1068 mut request: Request<crate::protos::auth::v1::VerifyTotpRequest>,
1069 ) -> Result<Response<crate::protos::auth::v1::VerifyTotpResponse>, Status> {
1070 request.extensions_mut().insert(RequestMeta {
1071 request_id: Uuid::now_v7().to_string(),
1072 caller_service: "kenapi".to_owned(),
1073 });
1074 self.api.verify_totp(request).await
1075 }
1076 pub async fn redeem_recovery_code(
1077 &mut self,
1078 mut request: Request<crate::protos::auth::v1::RedeemRecoveryCodeRequest>,
1079 ) -> Result<Response<crate::protos::auth::v1::RedeemRecoveryCodeResponse>, Status> {
1080 request.extensions_mut().insert(RequestMeta {
1081 request_id: Uuid::now_v7().to_string(),
1082 caller_service: "kenapi".to_owned(),
1083 });
1084 self.api.redeem_recovery_code(request).await
1085 }
1086 pub async fn configure_totp(
1087 &mut self,
1088 mut request: Request<crate::protos::auth::v1::ConfigureTotpRequest>,
1089 ) -> Result<Response<crate::protos::auth::v1::ConfigureTotpResponse>, Status> {
1090 request.extensions_mut().insert(RequestMeta {
1091 request_id: Uuid::now_v7().to_string(),
1092 caller_service: "kenapi".to_owned(),
1093 });
1094 self.api.configure_totp(request).await
1095 }
1096 pub async fn enable_totp(
1097 &mut self,
1098 mut request: Request<crate::protos::auth::v1::EnableTotpRequest>,
1099 ) -> Result<Response<crate::protos::auth::v1::EnableTotpResponse>, Status> {
1100 request.extensions_mut().insert(RequestMeta {
1101 request_id: Uuid::now_v7().to_string(),
1102 caller_service: "kenapi".to_owned(),
1103 });
1104 self.api.enable_totp(request).await
1105 }
1106 pub async fn disable_totp(
1107 &mut self,
1108 mut request: Request<crate::protos::auth::v1::DisableTotpRequest>,
1109 ) -> Result<Response<crate::protos::auth::v1::DisableTotpResponse>, Status> {
1110 request.extensions_mut().insert(RequestMeta {
1111 request_id: Uuid::now_v7().to_string(),
1112 caller_service: "kenapi".to_owned(),
1113 });
1114 self.api.disable_totp(request).await
1115 }
1116 pub async fn regenerate_recovery_codes(
1117 &mut self,
1118 mut request: Request<crate::protos::auth::v1::RegenerateRecoveryCodesRequest>,
1119 ) -> Result<Response<crate::protos::auth::v1::RegenerateRecoveryCodesResponse>, Status> {
1120 request.extensions_mut().insert(RequestMeta {
1121 request_id: Uuid::now_v7().to_string(),
1122 caller_service: "kenapi".to_owned(),
1123 });
1124 self.api.regenerate_recovery_codes(request).await
1125 }
1126}
1127
1128use crate::protos::auth::v1::agreement_service_server::AgreementService;
1129use crate::server::grpc::agreement::AgreementApi;
1130
1131pub struct AgreementClient {
1132 api: AgreementApi,
1133}
1134
1135impl AgreementClient {
1136 pub fn new(service: AuthSvc) -> Self {
1137 Self {
1138 api: AgreementApi::new(service),
1139 }
1140 }
1141 pub async fn list_agreements(
1142 &mut self,
1143 mut request: Request<crate::protos::auth::v1::ListAgreementsRequest>,
1144 ) -> Result<Response<crate::protos::auth::v1::ListAgreementsResponse>, Status> {
1145 request.extensions_mut().insert(RequestMeta {
1146 request_id: Uuid::now_v7().to_string(),
1147 caller_service: "kenapi".to_owned(),
1148 });
1149 self.api.list_agreements(request).await
1150 }
1151 pub async fn check_agreements_accepted(
1152 &mut self,
1153 mut request: Request<crate::protos::auth::v1::CheckAgreementsAcceptedRequest>,
1154 ) -> Result<Response<crate::protos::auth::v1::CheckAgreementsAcceptedResponse>, Status> {
1155 request.extensions_mut().insert(RequestMeta {
1156 request_id: Uuid::now_v7().to_string(),
1157 caller_service: "kenapi".to_owned(),
1158 });
1159 self.api.check_agreements_accepted(request).await
1160 }
1161}
Modified lib/auth/src/client/mod.rs lib/auth/src/client/mod.rs +2 −1565 View lib/auth/src/client/mod.rs
@@ -1,1568 +1,5 @@
1mod client;
12pub mod error;
23pub mod local;
34
4use std::collections::HashMap;
5use std::time::Duration;
6
7use crate::server::AuthSvc;
8use tonic::Request;
9use uuid::Uuid;
10
11use crate::client::error::KenAuthError;
12use crate::protos::auth as proto;
13
14#[derive(Clone)]
15pub struct KenAuthClient {
16 service: AuthSvc,
17 read_timeout: Duration,
18 write_timeout: Duration,
19}
20
21impl KenAuthClient {
22 pub fn local(service: AuthSvc, timeout_ms: u64) -> Self {
23 Self {
24 service,
25 read_timeout: Duration::from_millis(300),
26 write_timeout: Duration::from_millis(timeout_ms.max(2000)),
27 }
28 }
29
30 pub fn service(&self) -> &AuthSvc {
31 &self.service
32 }
33
34 pub async fn check_health(&self) -> Result<(), KenAuthError> {
35 self.service
36 .cache()
37 .ping()
38 .await
39 .map_err(|error| KenAuthError::Unavailable(error.to_string()))
40 }
41
42 pub fn identity(&self) -> self::local::IdentityClient {
43 self::local::IdentityClient::new(self.service.clone())
44 }
45
46 pub fn authority(&self) -> self::local::AuthorityClient {
47 self::local::AuthorityClient::new(self.service.clone())
48 }
49
50 pub fn email(&self) -> self::local::EmailClient {
51 self::local::EmailClient::new(self.service.clone())
52 }
53
54 pub fn session(&self) -> self::local::SessionClient {
55 self::local::SessionClient::new(self.service.clone())
56 }
57
58 pub fn organization(&self) -> self::local::OrganizationClient {
59 self::local::OrganizationClient::new(self.service.clone())
60 }
61
62 pub fn token(&self) -> self::local::TokenClient {
63 self::local::TokenClient::new(self.service.clone())
64 }
65
66 pub fn authorization(&self) -> self::local::AuthorizationClient {
67 self::local::AuthorizationClient::new(self.service.clone())
68 }
69
70 pub fn access_key(&self) -> self::local::AccessKeyClient {
71 self::local::AccessKeyClient::new(self.service.clone())
72 }
73
74 pub fn ssh_key(&self) -> self::local::SshKeyClient {
75 self::local::SshKeyClient::new(self.service.clone())
76 }
77
78 pub fn mfa(&self) -> self::local::MfaClient {
79 self::local::MfaClient::new(self.service.clone())
80 }
81
82 pub fn agreement(&self) -> self::local::AgreementClient {
83 self::local::AgreementClient::new(self.service.clone())
84 }
85
86 #[allow(clippy::too_many_arguments)]
87 pub async fn change_password(
88 &self,
89 user_id: i64,
90 old_password_hash: &str,
91 new_password_hash: &str,
92 keep_session_id: &str,
93 client_ip: &str,
94 ) -> Result<proto::v1::ChangePasswordResponse, KenAuthError> {
95 let mut client = self.identity();
96 client
97 .change_password(self.write_request(proto::v1::ChangePasswordRequest {
98 user_id,
99 old_password_hash: old_password_hash.to_string(),
100 new_password_hash: new_password_hash.to_string(),
101 keep_session_id: keep_session_id.to_string(),
102 client_ip: client_ip.to_string(),
103 }))
104 .await
105 .map_err(KenAuthError::from_status)
106 .map(|response| response.into_inner())
107 }
108
109 pub async fn get_mfa_status(
110 &self,
111 user_id: i64,
112 ) -> Result<proto::v1::GetMfaStatusResponse, KenAuthError> {
113 let mut client = self.mfa();
114 client
115 .get_mfa_status(self.read_request(proto::v1::GetMfaStatusRequest { user_id }))
116 .await
117 .map_err(KenAuthError::from_status)
118 .map(|response| response.into_inner())
119 }
120
121 pub async fn configure_totp(
122 &self,
123 user_id: i64,
124 name: &str,
125 client_ip: &str,
126 ) -> Result<proto::v1::ConfigureTotpResponse, KenAuthError> {
127 let mut client = self.mfa();
128 client
129 .configure_totp(self.write_request(proto::v1::ConfigureTotpRequest {
130 user_id,
131 name: name.to_string(),
132 client_ip: client_ip.to_string(),
133 }))
134 .await
135 .map_err(KenAuthError::from_status)
136 .map(|response| response.into_inner())
137 }
138
139 pub async fn enable_totp(
140 &self,
141 user_id: i64,
142 code: &str,
143 password_hash: &str,
144 client_ip: &str,
145 ) -> Result<proto::v1::EnableTotpResponse, KenAuthError> {
146 let mut client = self.mfa();
147 client
148 .enable_totp(self.write_request(proto::v1::EnableTotpRequest {
149 user_id,
150 code: code.to_string(),
151 password_hash: password_hash.to_string(),
152 client_ip: client_ip.to_string(),
153 }))
154 .await
155 .map_err(KenAuthError::from_status)
156 .map(|response| response.into_inner())
157 }
158
159 pub async fn disable_totp(
160 &self,
161 user_id: i64,
162 code: &str,
163 client_ip: &str,
164 ) -> Result<proto::v1::DisableTotpResponse, KenAuthError> {
165 let mut client = self.mfa();
166 client
167 .disable_totp(self.write_request(proto::v1::DisableTotpRequest {
168 user_id,
169 code: code.to_string(),
170 client_ip: client_ip.to_string(),
171 }))
172 .await
173 .map_err(KenAuthError::from_status)
174 .map(|response| response.into_inner())
175 }
176
177 pub async fn regenerate_recovery_codes(
178 &self,
179 user_id: i64,
180 password_hash: &str,
181 client_ip: &str,
182 ) -> Result<proto::v1::RegenerateRecoveryCodesResponse, KenAuthError> {
183 let mut client = self.mfa();
184 client
185 .regenerate_recovery_codes(self.write_request(
186 proto::v1::RegenerateRecoveryCodesRequest {
187 user_id,
188 password_hash: password_hash.to_string(),
189 client_ip: client_ip.to_string(),
190 },
191 ))
192 .await
193 .map_err(KenAuthError::from_status)
194 .map(|response| response.into_inner())
195 }
196
197 pub async fn list_access_keys(
198 &self,
199 user_id: i64,
200 include_revoked: bool,
201 page: proto::common::v1::PageRequest,
202 ) -> Result<proto::v1::ListAccessKeysResponse, KenAuthError> {
203 let mut client = self.access_key();
204 client
205 .list_access_keys(self.read_request(proto::v1::ListAccessKeysRequest {
206 user_id,
207 include_revoked,
208 page: Some(page),
209 }))
210 .await
211 .map_err(KenAuthError::from_status)
212 .map(|response| response.into_inner())
213 }
214
215 #[allow(clippy::too_many_arguments)]
216 pub async fn create_access_key(
217 &self,
218 user_id: i64,
219 name: &str,
220 description: &str,
221 scopes: Vec<i32>,
222 expires_in_secs: i64,
223 client_ip: &str,
224 ) -> Result<proto::v1::CreateAccessKeyResponse, KenAuthError> {
225 let mut client = self.access_key();
226 client
227 .create_access_key(self.write_request(proto::v1::CreateAccessKeyRequest {
228 user_id,
229 name: name.to_string(),
230 description: description.to_string(),
231 scopes,
232 expires_in_secs,
233 client_ip: client_ip.to_string(),
234 }))
235 .await
236 .map_err(KenAuthError::from_status)
237 .map(|response| response.into_inner())
238 }
239
240 pub async fn rotate_access_key(
241 &self,
242 user_id: i64,
243 access_key_id: &str,
244 client_ip: &str,
245 ) -> Result<proto::v1::RotateAccessKeyResponse, KenAuthError> {
246 let mut client = self.access_key();
247 client
248 .rotate_access_key(self.write_request(proto::v1::RotateAccessKeyRequest {
249 user_id,
250 access_key_id: access_key_id.to_string(),
251 client_ip: client_ip.to_string(),
252 }))
253 .await
254 .map_err(KenAuthError::from_status)
255 .map(|response| response.into_inner())
256 }
257
258 pub async fn revoke_access_key(
259 &self,
260 user_id: i64,
261 access_key_id: &str,
262 reason: &str,
263 ) -> Result<proto::v1::RevokeAccessKeyResponse, KenAuthError> {
264 let mut client = self.access_key();
265 client
266 .revoke_access_key(self.write_request(proto::v1::RevokeAccessKeyRequest {
267 user_id,
268 access_key_id: access_key_id.to_string(),
269 reason: reason.to_string(),
270 }))
271 .await
272 .map_err(KenAuthError::from_status)
273 .map(|response| response.into_inner())
274 }
275
276 pub async fn list_user_ssh_keys(
277 &self,
278 user_id: i64,
279 include_revoked: bool,
280 page: proto::common::v1::PageRequest,
281 ) -> Result<proto::v1::ListUserSshKeysResponse, KenAuthError> {
282 let mut client = self.ssh_key();
283 client
284 .list_user_ssh_keys(self.read_request(proto::v1::ListUserSshKeysRequest {
285 user_id,
286 include_revoked,
287 page: Some(page),
288 }))
289 .await
290 .map_err(KenAuthError::from_status)
291 .map(|response| response.into_inner())
292 }
293
294 pub async fn add_ssh_key(
295 &self,
296 user_id: i64,
297 name: &str,
298 public_key: &str,
299 description: &str,
300 client_ip: &str,
301 ) -> Result<proto::v1::AddSshKeyResponse, KenAuthError> {
302 let mut client = self.ssh_key();
303 client
304 .add_ssh_key(self.write_request(proto::v1::AddSshKeyRequest {
305 user_id,
306 name: name.to_string(),
307 public_key: public_key.to_string(),
308 description: description.to_string(),
309 client_ip: client_ip.to_string(),
310 }))
311 .await
312 .map_err(KenAuthError::from_status)
313 .map(|response| response.into_inner())
314 }
315
316 pub async fn revoke_ssh_key(
317 &self,
318 user_id: i64,
319 key_id: &str,
320 reason: &str,
321 bump_security_version: bool,
322 ) -> Result<proto::v1::RevokeSshKeyResponse, KenAuthError> {
323 let mut client = self.ssh_key();
324 client
325 .revoke_ssh_key(self.write_request(proto::v1::RevokeSshKeyRequest {
326 user_id,
327 key_id: key_id.to_string(),
328 reason: reason.to_string(),
329 bump_security_version,
330 }))
331 .await
332 .map_err(KenAuthError::from_status)
333 .map(|response| response.into_inner())
334 }
335
336 pub async fn list_user_sessions(
337 &self,
338 user_id: i64,
339 include_revoked: bool,
340 include_expired: bool,
341 page: proto::common::v1::PageRequest,
342 ) -> Result<proto::v1::ListUserSessionsResponse, KenAuthError> {
343 let mut client = self.session();
344 client
345 .list_user_sessions(self.read_request(proto::v1::ListUserSessionsRequest {
346 user_id,
347 include_revoked,
348 include_expired,
349 page: Some(page),
350 }))
351 .await
352 .map_err(KenAuthError::from_status)
353 .map(|response| response.into_inner())
354 }
355
356 pub async fn revoke_user_sessions(
357 &self,
358 user_id: i64,
359 except_session_id: &str,
360 reason: &str,
361 bump_security_version: bool,
362 ) -> Result<proto::v1::RevokeUserSessionsResponse, KenAuthError> {
363 let mut client = self.session();
364 client
365 .revoke_user_sessions(self.write_request(proto::v1::RevokeUserSessionsRequest {
366 user_id,
367 except_session_id: except_session_id.to_string(),
368 reason: reason.to_string(),
369 bump_security_version,
370 }))
371 .await
372 .map_err(KenAuthError::from_status)
373 .map(|response| response.into_inner())
374 }
375
376 pub fn read_request<T>(&self, message: T) -> Request<T> {
377 let mut request = Request::new(message);
378 request.set_timeout(self.read_timeout);
379 request
380 }
381
382 pub fn write_request<T>(&self, message: T) -> Request<T> {
383 let mut request = Request::new(message);
384 request.set_timeout(self.write_timeout);
385 request
386 }
387
388 /// Enqueue one plain text / HTML mail on `kenoauth`.
389 ///
390 /// `kenoauth` owns SMTP, retries and backpressure; a `Ok` here means the
391 /// message was accepted into its queue, while delivery outcome is visible
392 /// through `GetQueueStatus` / the delivery events on that side.
393 pub async fn send_mail(
394 &self,
395 to: &str,
396 subject: &str,
397 text: &str,
398 html: &str,
399 ) -> Result<(), KenAuthError> {
400 let mut client = self.email();
401 let request = proto::internal::v1::SendEmailRequest {
402 request_id: Uuid::now_v7().to_string(),
403 to: vec![proto::internal::v1::EmailAddress {
404 address: to.to_string(),
405 name: String::new(),
406 }],
407 cc: Vec::new(),
408 bcc: Vec::new(),
409 subject: subject.to_string(),
410 text: text.to_string(),
411 html: html.to_string(),
412 reply_to: None,
413 attachments: Vec::new(),
414 metadata: HashMap::new(),
415 trace_id: String::new(),
416 };
417 client
418 .send_email(self.write_request(request))
419 .await
420 .map_err(KenAuthError::from_status)?;
421 Ok(())
422 }
423
424 pub async fn get_session(
425 &self,
426 user_id: i64,
427 version: i32,
428 session_id: &str,
429 ) -> Result<proto::internal::v1::AuthorityAccess, KenAuthError> {
430 let mut client = self.authority();
431 client
432 .get_session(self.read_request(proto::internal::v1::GetSessionRequest {
433 user_id,
434 version,
435 session_id: session_id.to_string(),
436 }))
437 .await
438 .map_err(KenAuthError::from_status)
439 .map(|response| response.into_inner().access.unwrap_or_default())
440 }
441
442 pub async fn delete_account(&self, user_id: i64, reason: &str) -> Result<(), KenAuthError> {
443 let mut client = self.authority();
444 client
445 .delete_account(
446 self.write_request(proto::internal::v1::DeleteAccountRequest {
447 user_id,
448 reason: reason.to_string(),
449 }),
450 )
451 .await
452 .map_err(KenAuthError::from_status)?;
453 Ok(())
454 }
455
456 pub async fn cancel_account_deletion(&self, user_id: i64) -> Result<(), KenAuthError> {
457 let mut client = self.authority();
458 client
459 .cancel_account_deletion(
460 self.write_request(proto::internal::v1::CancelAccountDeletionRequest { user_id }),
461 )
462 .await
463 .map_err(KenAuthError::from_status)?;
464 Ok(())
465 }
466
467 pub async fn purge_account(&self, user_id: i64) -> Result<(), KenAuthError> {
468 let mut client = self.authority();
469 client
470 .purge_account(self.write_request(proto::internal::v1::PurgeAccountRequest { user_id }))
471 .await
472 .map_err(KenAuthError::from_status)?;
473 Ok(())
474 }
475
476 pub async fn batch_get_authority_users(
477 &self,
478 user_ids: Vec<i64>,
479 ) -> Result<Vec<proto::internal::v1::AuthorityUser>, KenAuthError> {
480 let mut client = self.authority();
481 client
482 .batch_get_user(
483 self.read_request(proto::internal::v1::BatchGetUserRequest { user_ids }),
484 )
485 .await
486 .map_err(KenAuthError::from_status)
487 .map(|response| response.into_inner().users)
488 }
489
490 pub async fn get_user_status(
491 &self,
492 user_id: i64,
493 ) -> Result<proto::common::v1::UserStatus, KenAuthError> {
494 let mut client = self.identity();
495 let user = Some(proto::common::v1::UserRef {
496 key: Some(proto::common::v1::user_ref::Key::UserId(user_id)),
497 });
498 client
499 .get_user_status(self.read_request(proto::v1::GetUserStatusRequest { user }))
500 .await
501 .map_err(KenAuthError::from_status)
502 .map(|response| response.into_inner().status.unwrap_or_default())
503 }
504
505 pub async fn get_user_public_by_ref(
506 &self,
507 key: proto::common::v1::user_ref::Key,
508 ) -> Result<proto::common::v1::UserPublic, KenAuthError> {
509 let mut client = self.identity();
510 let user = Some(proto::common::v1::UserRef { key: Some(key) });
511 client
512 .get_user_public(self.read_request(proto::v1::GetUserPublicRequest { user }))
513 .await
514 .map_err(KenAuthError::from_status)?
515 .into_inner()
516 .user
517 .ok_or(KenAuthError::NotFound)
518 }
519
520 pub async fn get_authority_user(
521 &self,
522 user_id: i64,
523 ) -> Result<proto::internal::v1::AuthorityUser, KenAuthError> {
524 let mut client = self.authority();
525 client
526 .get_user(self.read_request(proto::internal::v1::GetUserRequest { user_id }))
527 .await
528 .map_err(KenAuthError::from_status)?
529 .into_inner()
530 .user
531 .ok_or(KenAuthError::NotFound)
532 }
533
534 /// The only supported write path for `username` / `displayname`.
535 /// `version` is the account's current optimistic-lock version.
536 #[allow(clippy::too_many_arguments)]
537 pub async fn update_authority_user(
538 &self,
539 user_id: i64,
540 username: Option<String>,
541 displayname: Option<String>,
542 clear_displayname: bool,
543 public_show_email: Option<bool>,
544 version: i32,
545 ) -> Result<proto::internal::v1::AuthorityUser, KenAuthError> {
546 let mut client = self.authority();
547 client
548 .update_user(self.write_request(proto::internal::v1::UpdateUserRequest {
549 user_id,
550 patch: Some(proto::internal::v1::AuthorityUserPatch {
551 version,
552 username,
553 displayname,
554 clear_displayname,
555 public_show_email,
556 }),
557 }))
558 .await
559 .map_err(KenAuthError::from_status)?
560 .into_inner()
561 .user
562 .ok_or(KenAuthError::NotFound)
563 }
564
565 pub async fn batch_get_user_public(
566 &self,
567 user_ids: Vec<i64>,
568 ) -> Result<Vec<proto::common::v1::UserPublic>, KenAuthError> {
569 let mut client = self.identity();
570 client
571 .batch_get_user_public(
572 self.read_request(proto::v1::BatchGetUserPublicRequest { user_ids }),
573 )
574 .await
575 .map_err(KenAuthError::from_status)
576 .map(|response| response.into_inner().users)
577 }
578
579 pub async fn get_user_public(
580 &self,
581 user_id: i64,
582 ) -> Result<proto::common::v1::UserPublic, KenAuthError> {
583 let mut client = self.identity();
584 let user = Some(proto::common::v1::UserRef {
585 key: Some(proto::common::v1::user_ref::Key::UserId(user_id)),
586 });
587 client
588 .get_user_public(self.read_request(proto::v1::GetUserPublicRequest { user }))
589 .await
590 .map_err(KenAuthError::from_status)?
591 .into_inner()
592 .user
593 .ok_or(KenAuthError::NotFound)
594 }
595
596 pub async fn revoke_session(
597 &self,
598 user_id: i64,
599 session_id: &str,
600 reason: &str,
601 ) -> Result<(), KenAuthError> {
602 let mut client = self.session();
603 client
604 .revoke_session(self.write_request(proto::v1::RevokeSessionRequest {
605 user_id,
606 session_id: session_id.to_string(),
607 reason: reason.to_string(),
608 }))
609 .await
610 .map_err(KenAuthError::from_status)?;
611 Ok(())
612 }
613
614 pub async fn verify_access_key(
615 &self,
616 token: &str,
617 required_scopes: Vec<i32>,
618 ) -> Result<Option<proto::common::v1::Principal>, KenAuthError> {
619 let mut client = self.access_key();
620 let response = client
621 .verify_access_key(self.read_request(proto::v1::VerifyAccessKeyRequest {
622 access_key: token.to_string(),
623 required_scopes,
624 client_ip: String::new(),
625 }))
626 .await
627 .map_err(KenAuthError::from_status)?
628 .into_inner();
629 if !response.valid {
630 return Ok(None);
631 }
632 Ok(response.principal)
633 }
634
635 pub async fn issue_service_token(
636 &self,
637 user_id: i64,
638 audience: i32,
639 scopes: Vec<i32>,
640 ttl_seconds: u32,
641 event_id: &str,
642 ) -> Result<proto::v1::IssueServiceTokenResponse, KenAuthError> {
643 let mut client = self.token();
644 client
645 .issue_service_token(self.write_request(proto::v1::IssueServiceTokenRequest {
646 audience,
647 subject_user_id: user_id,
648 scopes,
649 ttl_seconds,
650 constraint: None,
651 event_id: event_id.to_string(),
652 }))
653 .await
654 .map_err(KenAuthError::from_status)
655 .map(|response| response.into_inner())
656 }
657
658 pub async fn introspect_token(
659 &self,
660 token: &str,
661 ) -> Result<proto::v1::IntrospectTokenResponse, KenAuthError> {
662 let mut client = self.token();
663 let credential = Some(proto::common::v1::Credential {
664 kind: Some(proto::common::v1::credential::Kind::ServiceToken(
665 token.to_string(),
666 )),
667 request_id: String::new(),
668 });
669 client
670 .introspect_token(self.read_request(proto::v1::IntrospectTokenRequest {
671 credential,
672 required_scopes: Vec::new(),
673 }))
674 .await
675 .map_err(KenAuthError::from_status)
676 .map(|response| response.into_inner())
677 }
678
679 pub async fn lookup_ssh_key(
680 &self,
681 public_key: &str,
682 ) -> Result<Option<proto::common::v1::Principal>, KenAuthError> {
683 let mut client = self.ssh_key();
684 let response = client
685 .lookup_ssh_key(self.read_request(proto::v1::LookupSshKeyRequest {
686 fingerprint: String::new(),
687 public_key: public_key.to_string(),
688 require_active: true,
689 }))
690 .await
691 .map_err(KenAuthError::from_status)?
692 .into_inner();
693 if !response.found {
694 return Ok(None);
695 }
696 Ok(response.principal)
697 }
698
699 pub async fn ensure_bot_user(
700 &self,
701 username: &str,
702 displayname: &str,
703 system: bool,
704 ) -> Result<proto::common::v1::UserPublic, KenAuthError> {
705 let mut client = self.identity();
706 client
707 .ensure_bot_user(self.write_request(proto::v1::EnsureBotUserRequest {
708 username: username.to_string(),
709 displayname: displayname.to_string(),
710 system,
711 }))
712 .await
713 .map_err(KenAuthError::from_status)?
714 .into_inner()
715 .user
716 .ok_or(KenAuthError::NotFound)
717 }
718
719 pub async fn ensure_bot_member(
720 &self,
721 organization_id: &str,
722 user_id: i64,
723 role_keys: Vec<String>,
724 role_ids: Vec<String>,
725 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
726 let mut client = self.organization();
727 client
728 .ensure_bot_member(self.write_request(proto::v1::EnsureBotMemberRequest {
729 organization_id: organization_id.to_string(),
730 user_id,
731 role_keys,
732 role_ids,
733 }))
734 .await
735 .map_err(KenAuthError::from_status)?
736 .into_inner()
737 .member
738 .ok_or(KenAuthError::NotFound)
739 }
740
741 pub async fn get_organization(
742 &self,
743 actor_user_id: i64,
744 organization_id: &str,
745 slug: &str,
746 ) -> Result<proto::v1::GetOrganizationResponse, KenAuthError> {
747 let mut client = self.organization();
748 client
749 .get_organization(self.read_request(proto::v1::GetOrganizationRequest {
750 actor_user_id,
751 organization_id: organization_id.to_string(),
752 slug: slug.to_string(),
753 }))
754 .await
755 .map_err(KenAuthError::from_status)
756 .map(|response| response.into_inner())
757 }
758
759 pub async fn get_member(
760 &self,
761 actor_user_id: i64,
762 organization_id: &str,
763 user_id: i64,
764 ) -> Result<Option<proto::v1::OrganizationMemberInfo>, KenAuthError> {
765 let mut client = self.organization();
766 match client
767 .get_member(self.read_request(proto::v1::GetMemberRequest {
768 actor_user_id,
769 organization_id: organization_id.to_string(),
770 member_id: String::new(),
771 user_id,
772 }))
773 .await
774 {
775 Ok(response) => Ok(response.into_inner().member),
776 Err(status) if status.code() == tonic::Code::NotFound => Ok(None),
777 Err(status) => Err(KenAuthError::from_status(status)),
778 }
779 }
780
781 pub async fn list_members(
782 &self,
783 actor_user_id: i64,
784 organization_id: &str,
785 include_inactive: bool,
786 include_banned: bool,
787 page: proto::common::v1::PageRequest,
788 ) -> Result<proto::v1::ListMembersResponse, KenAuthError> {
789 let mut client = self.organization();
790 client
791 .list_members(self.read_request(proto::v1::ListMembersRequest {
792 actor_user_id,
793 organization_id: organization_id.to_string(),
794 include_inactive,
795 include_banned,
796 page: Some(page),
797 }))
798 .await
799 .map_err(KenAuthError::from_status)
800 .map(|response| response.into_inner())
801 }
802
803 pub async fn list_organizations(
804 &self,
805 actor_user_id: i64,
806 user_id: i64,
807 include_archived: bool,
808 page: proto::common::v1::PageRequest,
809 ) -> Result<proto::v1::ListOrganizationsResponse, KenAuthError> {
810 let mut client = self.organization();
811 client
812 .list_organizations(self.read_request(proto::v1::ListOrganizationsRequest {
813 actor_user_id,
814 user_id,
815 include_archived,
816 page: Some(page),
817 }))
818 .await
819 .map_err(KenAuthError::from_status)
820 .map(|response| response.into_inner())
821 }
822
823 pub async fn list_public_organizations(
824 &self,
825 query: &str,
826 page: proto::common::v1::PageRequest,
827 ) -> Result<proto::v1::ListPublicOrganizationsResponse, KenAuthError> {
828 let mut client = self.organization();
829 client
830 .list_public_organizations(self.read_request(
831 proto::v1::ListPublicOrganizationsRequest {
832 query: query.to_string(),
833 page: Some(page),
834 },
835 ))
836 .await
837 .map_err(KenAuthError::from_status)
838 .map(|response| response.into_inner())
839 }
840
841 pub async fn check_permissions(
842 &self,
843 actor_user_id: i64,
844 organization_id: &str,
845 user_id: i64,
846 permissions: Vec<String>,
847 ) -> Result<proto::v1::CheckPermissionsResponse, KenAuthError> {
848 let mut client = self.organization();
849 client
850 .check_permissions(self.read_request(proto::v1::CheckPermissionsRequest {
851 actor_user_id,
852 organization_id: organization_id.to_string(),
853 user_id,
854 permissions,
855 }))
856 .await
857 .map_err(KenAuthError::from_status)
858 .map(|response| response.into_inner())
859 }
860
861 pub async fn create_organization(
862 &self,
863 actor_user_id: i64,
864 slug: &str,
865 name: &str,
866 description: &str,
867 avatar_url: &str,
868 join_policy: Option<i32>,
869 allow_join: Option<bool>,
870 require_email_verified: Option<bool>,
871 require_mfa: Option<bool>,
872 welcome_message: Option<String>,
873 member_must_enable_2fa: Option<bool>,
874 allow_invite: Option<bool>,
875 allow_join_level: Option<i32>,
876 ) -> Result<proto::v1::CreateOrganizationResponse, KenAuthError> {
877 let mut client = self.organization();
878 client
879 .create_organization(self.write_request(proto::v1::CreateOrganizationRequest {
880 actor_user_id,
881 slug: slug.to_string(),
882 name: name.to_string(),
883 description: description.to_string(),
884 avatar_url: avatar_url.to_string(),
885 join_policy,
886 allow_join,
887 require_email_verified,
888 require_mfa,
889 welcome_message,
890 member_must_enable_2fa,
891 allow_invite,
892 allow_join_level,
893 }))
894 .await
895 .map_err(KenAuthError::from_status)
896 .map(|response| response.into_inner())
897 }
898
899 #[allow(clippy::too_many_arguments)]
900 pub async fn update_organization(
901 &self,
902 actor_user_id: i64,
903 organization_id: &str,
904 name: Option<String>,
905 description: Option<String>,
906 avatar_url: Option<String>,
907 expected_version: i32,
908 join_policy: Option<i32>,
909 allow_join: Option<bool>,
910 require_email_verified: Option<bool>,
911 require_mfa: Option<bool>,
912 welcome_message: Option<String>,
913 member_must_enable_2fa: Option<bool>,
914 allow_invite: Option<bool>,
915 allow_join_level: Option<i32>,
916 ) -> Result<proto::v1::OrganizationInfo, KenAuthError> {
917 let mut client = self.organization();
918 client
919 .update_organization(self.write_request(proto::v1::UpdateOrganizationRequest {
920 actor_user_id,
921 organization_id: organization_id.to_string(),
922 name,
923 description,
924 avatar_url,
925 expected_version,
926 join_policy,
927 allow_join,
928 require_email_verified,
929 require_mfa,
930 welcome_message,
931 member_must_enable_2fa,
932 allow_invite,
933 allow_join_level,
934 }))
935 .await
936 .map_err(KenAuthError::from_status)?
937 .into_inner()
938 .organization
939 .ok_or(KenAuthError::NotFound)
940 }
941
942 pub async fn archive_organization(
943 &self,
944 actor_user_id: i64,
945 organization_id: &str,
946 reason: &str,
947 ) -> Result<(), KenAuthError> {
948 let mut client = self.organization();
949 client
950 .archive_organization(self.write_request(proto::v1::ArchiveOrganizationRequest {
951 actor_user_id,
952 organization_id: organization_id.to_string(),
953 reason: reason.to_string(),
954 }))
955 .await
956 .map_err(KenAuthError::from_status)?;
957 Ok(())
958 }
959
960 pub async fn restore_organization(
961 &self,
962 actor_user_id: i64,
963 organization_id: &str,
964 ) -> Result<(), KenAuthError> {
965 let mut client = self.organization();
966 client
967 .restore_organization(self.write_request(proto::v1::RestoreOrganizationRequest {
968 actor_user_id,
969 organization_id: organization_id.to_string(),
970 }))
971 .await
972 .map_err(KenAuthError::from_status)?;
973 Ok(())
974 }
975
976 pub async fn delete_organization(
977 &self,
978 actor_user_id: i64,
979 organization_id: &str,
980 force: bool,
981 reason: &str,
982 ) -> Result<(), KenAuthError> {
983 let mut client = self.organization();
984 client
985 .delete_organization(self.write_request(proto::v1::DeleteOrganizationRequest {
986 actor_user_id,
987 organization_id: organization_id.to_string(),
988 force,
989 reason: reason.to_string(),
990 }))
991 .await
992 .map_err(KenAuthError::from_status)?;
993 Ok(())
994 }
995 pub async fn add_member(
996 &self,
997 actor_user_id: i64,
998 organization_id: &str,
999 user_id: i64,
1000 role: i32,
1001 role_keys: Vec<String>,
1002 ) -> Result<(proto::v1::OrganizationMemberInfo, bool), KenAuthError> {
1003 let mut client = self.organization();
1004 let response = client
1005 .add_member(self.write_request(proto::v1::AddMemberRequest {
1006 actor_user_id,
1007 organization_id: organization_id.to_string(),
1008 user_id,
1009 role,
1010 role_keys,
1011 }))
1012 .await
1013 .map_err(KenAuthError::from_status)?
1014 .into_inner();
1015 let member = response.member.ok_or(KenAuthError::NotFound)?;
1016 Ok((member, response.created))
1017 }
1018
1019 pub async fn remove_member(
1020 &self,
1021 actor_user_id: i64,
1022 organization_id: &str,
1023 user_id: i64,
1024 reason: &str,
1025 ) -> Result<bool, KenAuthError> {
1026 let mut client = self.organization();
1027 client
1028 .remove_member(self.write_request(proto::v1::RemoveMemberRequest {
1029 actor_user_id,
1030 organization_id: organization_id.to_string(),
1031 member_id: String::new(),
1032 user_id,
1033 reason: reason.to_string(),
1034 }))
1035 .await
1036 .map_err(KenAuthError::from_status)
1037 .map(|response| response.into_inner().removed)
1038 }
1039
1040 pub async fn leave_organization(
1041 &self,
1042 actor_user_id: i64,
1043 organization_id: &str,
1044 ) -> Result<bool, KenAuthError> {
1045 let mut client = self.organization();
1046 client
1047 .leave_organization(self.write_request(proto::v1::LeaveOrganizationRequest {
1048 actor_user_id,
1049 organization_id: organization_id.to_string(),
1050 }))
1051 .await
1052 .map_err(KenAuthError::from_status)
1053 .map(|response| response.into_inner().left)
1054 }
1055
1056 #[allow(clippy::too_many_arguments)]
1057 pub async fn update_member(
1058 &self,
1059 actor_user_id: i64,
1060 organization_id: &str,
1061 user_id: i64,
1062 alias_name: Option<Option<String>>,
1063 alias_avatar_url: Option<Option<String>>,
1064 message_notifications: Option<String>,
1065 muted: Option<bool>,
1066 mute_until: Option<Option<prost_types::Timestamp>>,
1067 mobile_push: Option<bool>,
1068 suppress_everyone: Option<bool>,
1069 suppress_roles: Option<bool>,
1070 hide_muted_channels: Option<bool>,
1071 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1072 let (clear_mute_until, mute_until) = match mute_until {
1073 Some(None) => (Some(true), None),
1074 Some(Some(value)) => (None, Some(value)),
1075 None => (None, None),
1076 };
1077 let mut client = self.organization();
1078 client
1079 .update_member(self.write_request(proto::v1::UpdateMemberRequest {
1080 actor_user_id,
1081 organization_id: organization_id.to_string(),
1082 member_id: String::new(),
1083 alias_name: alias_name.map(|value| value.unwrap_or_default()),
1084 alias_avatar_url: alias_avatar_url.map(|value| value.unwrap_or_default()),
1085 message_notifications,
1086 muted,
1087 clear_mute_until,
1088 mute_until,
1089 mobile_push,
1090 suppress_everyone,
1091 suppress_roles,
1092 hide_muted_channels,
1093 expected_version: 0,
1094 user_id,
1095 }))
1096 .await
1097 .map_err(KenAuthError::from_status)?
1098 .into_inner()
1099 .member
1100 .ok_or(KenAuthError::NotFound)
1101 }
1102
1103 pub async fn ban_member(
1104 &self,
1105 actor_user_id: i64,
1106 organization_id: &str,
1107 user_id: i64,
1108 reason: &str,
1109 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1110 let mut client = self.organization();
1111 client
1112 .ban_member(self.write_request(proto::v1::BanMemberRequest {
1113 actor_user_id,
1114 organization_id: organization_id.to_string(),
1115 member_id: String::new(),
1116 reason: reason.to_string(),
1117 user_id,
1118 }))
1119 .await
1120 .map_err(KenAuthError::from_status)?
1121 .into_inner()
1122 .member
1123 .ok_or(KenAuthError::NotFound)
1124 }
1125
1126 pub async fn unban_member(
1127 &self,
1128 actor_user_id: i64,
1129 organization_id: &str,
1130 user_id: i64,
1131 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1132 let mut client = self.organization();
1133 client
1134 .unban_member(self.write_request(proto::v1::UnbanMemberRequest {
1135 actor_user_id,
1136 organization_id: organization_id.to_string(),
1137 member_id: String::new(),
1138 user_id,
1139 }))
1140 .await
1141 .map_err(KenAuthError::from_status)?
1142 .into_inner()
1143 .member
1144 .ok_or(KenAuthError::NotFound)
1145 }
1146
1147 #[allow(clippy::too_many_arguments)]
1148 pub async fn update_ban(
1149 &self,
1150 actor_user_id: i64,
1151 organization_id: &str,
1152 user_id: i64,
1153 reason: Option<Option<String>>,
1154 expires_at: Option<Option<prost_types::Timestamp>>,
1155 allow_speak: Option<bool>,
1156 allow_push_repo: Option<bool>,
1157 allow_comment_any: Option<bool>,
1158 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1159 let (clear_expires_at, expires_at) = match expires_at {
1160 Some(None) => (Some(true), None),
1161 Some(Some(value)) => (None, Some(value)),
1162 None => (None, None),
1163 };
1164 let mut client = self.organization();
1165 client
1166 .update_ban(self.write_request(proto::v1::UpdateBanRequest {
1167 actor_user_id,
1168 organization_id: organization_id.to_string(),
1169 user_id,
1170 reason: reason.map(|value| value.unwrap_or_default()),
1171 clear_expires_at,
1172 expires_at,
1173 allow_agent_join: None,
1174 allow_speak,
1175 allow_push_repo,
1176 allow_comment_any,
1177 }))
1178 .await
1179 .map_err(KenAuthError::from_status)?
1180 .into_inner()
1181 .ban
1182 .ok_or(KenAuthError::NotFound)
1183 }
1184
1185 #[allow(clippy::too_many_arguments)]
1186 pub async fn create_role(
1187 &self,
1188 actor_user_id: i64,
1189 organization_id: &str,
1190 key: &str,
1191 name: &str,
1192 description: &str,
1193 rank: i32,
1194 self_assignable: bool,
1195 permissions: Vec<String>,
1196 ) -> Result<proto::v1::OrganizationRoleInfo, KenAuthError> {
1197 let mut client = self.organization();
1198 client
1199 .create_role(self.write_request(proto::v1::CreateRoleRequest {
1200 actor_user_id,
1201 organization_id: organization_id.to_string(),
1202 key: key.to_string(),
1203 name: name.to_string(),
1204 description: description.to_string(),
1205 rank,
1206 default_role: false,
1207 permissions: permissions.into_iter().map(allow_grant).collect(),
1208 self_assignable,
1209 }))
1210 .await
1211 .map_err(KenAuthError::from_status)?
1212 .into_inner()
1213 .role
1214 .ok_or(KenAuthError::NotFound)
1215 }
1216
1217 #[allow(clippy::too_many_arguments)]
1218 pub async fn update_role(
1219 &self,
1220 actor_user_id: i64,
1221 organization_id: &str,
1222 role_id: &str,
1223 name: Option<String>,
1224 description: Option<String>,
1225 rank: Option<i32>,
1226 self_assignable: Option<bool>,
1227 expected_version: i32,
1228 ) -> Result<proto::v1::OrganizationRoleInfo, KenAuthError> {
1229 let mut client = self.organization();
1230 client
1231 .update_role(self.write_request(proto::v1::UpdateRoleRequest {
1232 actor_user_id,
1233 organization_id: organization_id.to_string(),
1234 role_id: role_id.to_string(),
1235 name,
1236 description,
1237 rank,
1238 default_role: None,
1239 expected_version,
1240 self_assignable,
1241 }))
1242 .await
1243 .map_err(KenAuthError::from_status)?
1244 .into_inner()
1245 .role
1246 .ok_or(KenAuthError::NotFound)
1247 }
1248
1249 pub async fn set_role_permissions(
1250 &self,
1251 actor_user_id: i64,
1252 organization_id: &str,
1253 role_id: &str,
1254 permissions: Vec<String>,
1255 ) -> Result<proto::v1::OrganizationRoleInfo, KenAuthError> {
1256 let mut client = self.organization();
1257 client
1258 .set_role_permissions(self.write_request(proto::v1::SetRolePermissionsRequest {
1259 actor_user_id,
1260 organization_id: organization_id.to_string(),
1261 role_id: role_id.to_string(),
1262 permissions: permissions.into_iter().map(allow_grant).collect(),
1263 }))
1264 .await
1265 .map_err(KenAuthError::from_status)?
1266 .into_inner()
1267 .role
1268 .ok_or(KenAuthError::NotFound)
1269 }
1270
1271 pub async fn delete_role(
1272 &self,
1273 actor_user_id: i64,
1274 organization_id: &str,
1275 role_id: &str,
1276 ) -> Result<bool, KenAuthError> {
1277 let mut client = self.organization();
1278 client
1279 .delete_role(self.write_request(proto::v1::DeleteRoleRequest {
1280 actor_user_id,
1281 organization_id: organization_id.to_string(),
1282 role_id: role_id.to_string(),
1283 }))
1284 .await
1285 .map_err(KenAuthError::from_status)
1286 .map(|response| response.into_inner().deleted)
1287 }
1288
1289 pub async fn assign_role(
1290 &self,
1291 actor_user_id: i64,
1292 organization_id: &str,
1293 user_id: i64,
1294 role_id: &str,
1295 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1296 let mut client = self.organization();
1297 client
1298 .assign_role(self.write_request(proto::v1::AssignRoleRequest {
1299 actor_user_id,
1300 organization_id: organization_id.to_string(),
1301 member_id: String::new(),
1302 role_id: role_id.to_string(),
1303 user_id,
1304 }))
1305 .await
1306 .map_err(KenAuthError::from_status)?
1307 .into_inner()
1308 .member
1309 .ok_or(KenAuthError::NotFound)
1310 }
1311
1312 pub async fn unassign_role(
1313 &self,
1314 actor_user_id: i64,
1315 organization_id: &str,
1316 user_id: i64,
1317 role_id: &str,
1318 ) -> Result<proto::v1::OrganizationMemberInfo, KenAuthError> {
1319 let mut client = self.organization();
1320 client
1321 .unassign_role(self.write_request(proto::v1::UnassignRoleRequest {
1322 actor_user_id,
1323 organization_id: organization_id.to_string(),
1324 member_id: String::new(),
1325 role_id: role_id.to_string(),
1326 user_id,
1327 }))
1328 .await
1329 .map_err(KenAuthError::from_status)?
1330 .into_inner()
1331 .member
1332 .ok_or(KenAuthError::NotFound)
1333 }
1334
1335 #[allow(clippy::too_many_arguments)]
1336 pub async fn create_invite(
1337 &self,
1338 actor_user_id: i64,
1339 organization_id: &str,
1340 method: i32,
1341 max_uses: i32,
1342 expires_at: Option<prost_types::Timestamp>,
1343 role_ids: Vec<String>,
1344 target_user_id: i64,
1345 email: &str,
1346 ) -> Result<(proto::v1::OrganizationInviteInfo, String), KenAuthError> {
1347 let mut client = self.organization();
1348 let response = client
1349 .create_invite(self.write_request(proto::v1::CreateInviteRequest {
1350 actor_user_id,
1351 organization_id: organization_id.to_string(),
1352 method,
1353 max_uses,
1354 expires_at,
1355 role_id: role_ids.first().cloned().unwrap_or_default(),
1356 target_user_id,
1357 email: email.to_string(),
1358 role_ids,
1359 }))
1360 .await
1361 .map_err(KenAuthError::from_status)?
1362 .into_inner();
1363 let invite = response.invite.ok_or(KenAuthError::NotFound)?;
1364 Ok((invite, response.token))
1365 }
1366
1367 pub async fn revoke_invite(
1368 &self,
1369 actor_user_id: i64,
1370 organization_id: &str,
1371 invite_id: &str,
1372 ) -> Result<bool, KenAuthError> {
1373 let mut client = self.organization();
1374 client
1375 .revoke_invite(self.write_request(proto::v1::RevokeInviteRequest {
1376 actor_user_id,
1377 organization_id: organization_id.to_string(),
1378 invite_id: invite_id.to_string(),
1379 }))
1380 .await
1381 .map_err(KenAuthError::from_status)
1382 .map(|response| response.into_inner().revoked)
1383 }
1384
1385 pub async fn redeem_invite(
1386 &self,
1387 actor_user_id: i64,
1388 token: &str,
1389 ) -> Result<proto::v1::RedeemInviteResponse, KenAuthError> {
1390 let mut client = self.organization();
1391 client
1392 .redeem_invite(self.write_request(proto::v1::RedeemInviteRequest {
1393 actor_user_id,
1394 token: token.to_string(),
1395 }))
1396 .await
1397 .map_err(KenAuthError::from_status)
1398 .map(|response| response.into_inner())
1399 }
1400
1401 pub async fn create_join_rule(
1402 &self,
1403 actor_user_id: i64,
1404 organization_id: &str,
1405 role_id: &str,
1406 trigger: &str,
1407 matcher: &str,
1408 enabled: bool,
1409 ) -> Result<proto::v1::JoinRuleInfo, KenAuthError> {
1410 let mut client = self.organization();
1411 client
1412 .create_join_rule(self.write_request(proto::v1::CreateJoinRuleRequest {
1413 actor_user_id,
1414 organization_id: organization_id.to_string(),
1415 role_id: role_id.to_string(),
1416 trigger: trigger.to_string(),
1417 matcher: matcher.to_string(),
1418 enabled,
1419 }))
1420 .await
1421 .map_err(KenAuthError::from_status)?
1422 .into_inner()
1423 .rule
1424 .ok_or(KenAuthError::NotFound)
1425 }
1426
1427 #[allow(clippy::too_many_arguments)]
1428 pub async fn update_join_rule(
1429 &self,
1430 actor_user_id: i64,
1431 organization_id: &str,
1432 rule_id: &str,
1433 role_id: Option<String>,
1434 trigger: Option<String>,
1435 matcher: Option<String>,
1436 enabled: Option<bool>,
1437 ) -> Result<proto::v1::JoinRuleInfo, KenAuthError> {
1438 let mut client = self.organization();
1439 client
1440 .update_join_rule(self.write_request(proto::v1::UpdateJoinRuleRequest {
1441 actor_user_id,
1442 organization_id: organization_id.to_string(),
1443 rule_id: rule_id.to_string(),
1444 role_id,
1445 trigger,
1446 matcher,
1447 enabled,
1448 }))
1449 .await
1450 .map_err(KenAuthError::from_status)?
1451 .into_inner()
1452 .rule
1453 .ok_or(KenAuthError::NotFound)
1454 }
1455
1456 pub async fn delete_join_rule(
1457 &self,
1458 actor_user_id: i64,
1459 organization_id: &str,
1460 rule_id: &str,
1461 ) -> Result<bool, KenAuthError> {
1462 let mut client = self.organization();
1463 client
1464 .delete_join_rule(self.write_request(proto::v1::DeleteJoinRuleRequest {
1465 actor_user_id,
1466 organization_id: organization_id.to_string(),
1467 rule_id: rule_id.to_string(),
1468 }))
1469 .await
1470 .map_err(KenAuthError::from_status)
1471 .map(|response| response.into_inner().deleted)
1472 }
1473
1474 pub async fn create_join_request(
1475 &self,
1476 actor_user_id: i64,
1477 organization_id: &str,
1478 note: &str,
1479 ) -> Result<proto::v1::JoinRequestInfo, KenAuthError> {
1480 let mut client = self.organization();
1481 client
1482 .create_join_request(self.write_request(proto::v1::CreateJoinRequestRequest {
1483 actor_user_id,
1484 organization_id: organization_id.to_string(),
1485 note: note.to_string(),
1486 }))
1487 .await
1488 .map_err(KenAuthError::from_status)?
1489 .into_inner()
1490 .request
1491 .ok_or(KenAuthError::NotFound)
1492 }
1493
1494 pub async fn withdraw_join_request(
1495 &self,
1496 actor_user_id: i64,
1497 organization_id: &str,
1498 request_id: &str,
1499 ) -> Result<proto::v1::JoinRequestInfo, KenAuthError> {
1500 let mut client = self.organization();
1501 client
1502 .withdraw_join_request(self.write_request(proto::v1::WithdrawJoinRequestRequest {
1503 actor_user_id,
1504 organization_id: organization_id.to_string(),
1505 request_id: request_id.to_string(),
1506 }))
1507 .await
1508 .map_err(KenAuthError::from_status)?
1509 .into_inner()
1510 .request
1511 .ok_or(KenAuthError::NotFound)
1512 }
1513
1514 pub async fn approve_join_request(
1515 &self,
1516 actor_user_id: i64,
1517 organization_id: &str,
1518 request_id: &str,
1519 ) -> Result<
1520 (
1521 proto::v1::JoinRequestInfo,
1522 Option<proto::v1::OrganizationMemberInfo>,
1523 ),
1524 KenAuthError,
1525 > {
1526 let mut client = self.organization();
1527 let response = client
1528 .approve_join_request(self.write_request(proto::v1::ApproveJoinRequestRequest {
1529 actor_user_id,
1530 organization_id: organization_id.to_string(),
1531 request_id: request_id.to_string(),
1532 }))
1533 .await
1534 .map_err(KenAuthError::from_status)?
1535 .into_inner();
1536 let request = response.request.ok_or(KenAuthError::NotFound)?;
1537 Ok((request, response.member))
1538 }
1539
1540 pub async fn reject_join_request(
1541 &self,
1542 actor_user_id: i64,
1543 organization_id: &str,
1544 request_id: &str,
1545 note: &str,
1546 ) -> Result<proto::v1::JoinRequestInfo, KenAuthError> {
1547 let mut client = self.organization();
1548 client
1549 .reject_join_request(self.write_request(proto::v1::RejectJoinRequestRequest {
1550 actor_user_id,
1551 organization_id: organization_id.to_string(),
1552 request_id: request_id.to_string(),
1553 note: note.to_string(),
1554 }))
1555 .await
1556 .map_err(KenAuthError::from_status)?
1557 .into_inner()
1558 .request
1559 .ok_or(KenAuthError::NotFound)
1560 }
1561}
1562
1563fn allow_grant(permission: String) -> proto::v1::OrganizationPermissionGrant {
1564 proto::v1::OrganizationPermissionGrant {
1565 permission,
1566 effect: proto::v1::PermissionEffect::Allow as i32,
1567 }
1568}
5pub use client::KenAuthClient;
Renamed lib/auth/src/oauth/assets.rs → lib/auth/src/runtime/assets.rs lib/auth/src/runtime/assets.rs +0 −0 View lib/auth/src/runtime/assets.rs
No content changes.
Renamed lib/auth/src/oauth/mod.rs → lib/auth/src/runtime/mod.rs lib/auth/src/runtime/mod.rs +1 −1 View lib/auth/src/runtime/mod.rs
@@ -160,7 +160,7 @@
160160 .wrap(cors.clone())
161161 .app_data(web::Data::new(state.service.clone()))
162162 .app_data(web::Data::new(web.clone()))
163 .configure(crate::server::router::configure)
163 .configure(crate::server::http::router::configure)
164164 .default_service(web::to(assets::serve))
165165 })
166166 .disable_signals()
Renamed lib/auth/src/server/access_token/handler.rs → lib/auth/src/server/http/access_token/handler.rs lib/auth/src/server/http/access_token/handler.rs +2 −2 View lib/auth/src/server/http/access_token/handler.rs
@@ -4,10 +4,10 @@
44
55use crate::envelope::{Envelope, NoData};
66use crate::server::AuthSvc;
7use crate::server::access_token::types::{
7use crate::server::errors::AuthError;
8use crate::server::http::access_token::types::{
89 AccessTokenCreateRequest, AccessTokenCreateResponse, AccessTokenSummary,
910};
10use crate::server::errors::AuthError;
1111use crate::server::share::types::ListQuery;
1212
1313#[utoipa::path(
Renamed lib/auth/src/server/access_token/mod.rs → lib/auth/src/server/http/access_token/mod.rs lib/auth/src/server/http/access_token/mod.rs +0 −0 View lib/auth/src/server/http/access_token/mod.rs
No content changes.
Renamed lib/auth/src/server/access_token/service.rs → lib/auth/src/server/http/access_token/service.rs lib/auth/src/server/http/access_token/service.rs +2 −2 View lib/auth/src/server/http/access_token/service.rs
@@ -13,14 +13,14 @@
1313
1414use crate::jwt::{AppClaims, JwtError};
1515use crate::server::AuthSvc;
16use crate::server::access_token::types::{
16use crate::server::errors::{AuthError, AuthResult};
17use crate::server::http::access_token::types::{
1718 ALLOWED_APP_SCOPES, AccessTokenAuthRequest, AccessTokenAuthResponse, AccessTokenCreateRequest,
1819 AccessTokenCreateResponse, AccessTokenSummary, LAST_USED_THROTTLE_SECS,
1920 MAX_ACCESS_KEY_DESCRIPTION_LEN, MAX_ACCESS_KEY_EXPIRES_SECS, MAX_ACCESS_KEY_NAME_LEN,
2021 MAX_ACCESS_KEY_SCOPE_ENTRIES, MAX_ACTIVE_ACCESS_KEYS, MIN_ACCESS_KEY_EXPIRES_SECS, TOKEN_BYTES,
2122 TOKEN_FINGERPRINT_LEN, TOKEN_HASH_KEY_ID,
2223};
23use crate::server::errors::{AuthError, AuthResult};
2424use crate::server::share::crypto::{random_b64url, sha256_hex};
2525use crate::server::share::types::ListQuery;
2626
Renamed lib/auth/src/server/access_token/types.rs → lib/auth/src/server/http/access_token/types.rs lib/auth/src/server/http/access_token/types.rs +0 −0 View lib/auth/src/server/http/access_token/types.rs
No content changes.
Renamed lib/auth/src/server/app_token/handler.rs → lib/auth/src/server/http/app_token/handler.rs lib/auth/src/server/http/app_token/handler.rs +1 −1 View lib/auth/src/server/http/app_token/handler.rs
@@ -3,8 +3,8 @@
33
44use crate::envelope::{Envelope, NoData};
55use crate::server::AuthSvc;
6use crate::server::app_token::types::{AppTokenRequest, AppTokenResponse};
76use crate::server::errors::AuthError;
7use crate::server::http::app_token::types::{AppTokenRequest, AppTokenResponse};
88
99#[utoipa::path(
1010 post,
Renamed lib/auth/src/server/app_token/mod.rs → lib/auth/src/server/http/app_token/mod.rs lib/auth/src/server/http/app_token/mod.rs +0 −0 View lib/auth/src/server/http/app_token/mod.rs
No content changes.
Renamed lib/auth/src/server/app_token/service.rs → lib/auth/src/server/http/app_token/service.rs lib/auth/src/server/http/app_token/service.rs +2 −2 View lib/auth/src/server/http/app_token/service.rs
@@ -1,10 +1,10 @@
11use crate::events::{AuthEvent, Labels, RestOperate, RuntimeEvent};
22
33use crate::server::AuthSvc;
4use crate::server::app_token::types::{
4use crate::server::errors::{AuthError, AuthResult};
5use crate::server::http::app_token::types::{
56 AppTokenRequest, AppTokenResponse, DEFAULT_TTL_SECS, MAX_TTL_SECS,
67};
7use crate::server::errors::{AuthError, AuthResult};
88use crate::server::share::issue;
99
1010impl AuthSvc {
Renamed lib/auth/src/server/app_token/types.rs → lib/auth/src/server/http/app_token/types.rs lib/auth/src/server/http/app_token/types.rs +0 −0 View lib/auth/src/server/http/app_token/types.rs
No content changes.
Renamed lib/auth/src/server/challenge/handler.rs → lib/auth/src/server/http/challenge/handler.rs lib/auth/src/server/http/challenge/handler.rs +1 −1 View lib/auth/src/server/http/challenge/handler.rs
@@ -3,8 +3,8 @@
33
44use crate::envelope::{Envelope, NoData};
55use crate::server::AuthSvc;
6use crate::server::challenge::types::ChallengeResponse;
76use crate::server::errors::AuthError;
7use crate::server::http::challenge::types::ChallengeResponse;
88
99#[utoipa::path(
1010 post,
Renamed lib/auth/src/server/challenge/mod.rs → lib/auth/src/server/http/challenge/mod.rs lib/auth/src/server/http/challenge/mod.rs +0 −0 View lib/auth/src/server/http/challenge/mod.rs
No content changes.
Renamed lib/auth/src/server/challenge/service.rs → lib/auth/src/server/http/challenge/service.rs lib/auth/src/server/http/challenge/service.rs +1 −1 View lib/auth/src/server/http/challenge/service.rs
@@ -2,8 +2,8 @@
22use crate::session::Session;
33
44use crate::server::AuthSvc;
5use crate::server::challenge::types::{ChallengeResponse, PowProofRequest};
65use crate::server::errors::AuthResult;
6use crate::server::http::challenge::types::{ChallengeResponse, PowProofRequest};
77
88impl AuthSvc {
99 #[tracing::instrument(skip_all, fields(request_id = %request_id, client_ip = ?session.client_ip().ok().flatten()))]
Renamed lib/auth/src/server/challenge/types.rs → lib/auth/src/server/http/challenge/types.rs lib/auth/src/server/http/challenge/types.rs +0 −0 View lib/auth/src/server/http/challenge/types.rs
No content changes.
Renamed lib/auth/src/server/login/handler.rs → lib/auth/src/server/http/login/handler.rs lib/auth/src/server/http/login/handler.rs +1 −1 View lib/auth/src/server/http/login/handler.rs
@@ -5,7 +5,7 @@
55use crate::server::AuthSvc;
66use crate::server::errors::AuthError;
77
8use crate::server::login::types::{
8use crate::server::http::login::types::{
99 LoginCodeRequest, LoginCodeResponse, LoginCodeVerifyRequest, LoginVerifyRequest,
1010 UserLoginRequest, UserLoginResponse,
1111};
Renamed lib/auth/src/server/login/mod.rs → lib/auth/src/server/http/login/mod.rs lib/auth/src/server/http/login/mod.rs +0 −0 View lib/auth/src/server/http/login/mod.rs
No content changes.
Renamed lib/auth/src/server/login/service.rs → lib/auth/src/server/http/login/service.rs lib/auth/src/server/http/login/service.rs +2 −2 View lib/auth/src/server/http/login/service.rs
@@ -8,7 +8,7 @@
88
99use crate::server::AuthSvc;
1010use crate::server::errors::{AuthError, AuthResult};
11use crate::server::login::types::{
11use crate::server::http::login::types::{
1212 LOGIN_ATTEMPTS_MAX, LOGIN_ATTEMPTS_WINDOW_SECS, LoginCodeRequest, LoginCodeResponse,
1313 LoginCodeVerifyRequest, LoginMfaChallenge, LoginVerifyRequest, MFA_CHALLENGE_TTL_SECS,
1414 SESSION_LOGIN_MFA, UserLoginRequest, UserLoginResponse,
@@ -404,7 +404,7 @@
404404 .exec(self.db().write())
405405 .await?;
406406
407 crate::server::me::service::invalidate_me_cache(self.cache(), user.id).await;
407 crate::server::http::me::service::invalidate_me_cache(self.cache(), user.id).await;
408408 self.audit(
409409 session,
410410 user.id,
Renamed lib/auth/src/server/login/types.rs → lib/auth/src/server/http/login/types.rs lib/auth/src/server/http/login/types.rs +1 −1 View lib/auth/src/server/http/login/types.rs
@@ -1,7 +1,7 @@
11use serde::{Deserialize, Serialize};
22use utoipa::ToSchema;
33
4use crate::server::challenge::types::PowProofRequest;
4use crate::server::http::challenge::types::PowProofRequest;
55
66pub const SESSION_LOGIN_MFA: &str = "login_mfa";
77pub const HASH_KEY_SHA256_V1: &str = "sha256-v1";
Renamed lib/auth/src/server/logout/handler.rs → lib/auth/src/server/http/logout/handler.rs lib/auth/src/server/http/logout/handler.rs +1 −1 View lib/auth/src/server/http/logout/handler.rs
@@ -4,7 +4,7 @@
44use crate::envelope::{Envelope, NoData};
55use crate::server::AuthSvc;
66use crate::server::errors::AuthError;
7use crate::server::logout::types::LogoutResponse;
7use crate::server::http::logout::types::LogoutResponse;
88
99#[utoipa::path(
1010 post,
Renamed lib/auth/src/server/logout/mod.rs → lib/auth/src/server/http/logout/mod.rs lib/auth/src/server/http/logout/mod.rs +0 −0 View lib/auth/src/server/http/logout/mod.rs
No content changes.
Renamed lib/auth/src/server/logout/service.rs → lib/auth/src/server/http/logout/service.rs lib/auth/src/server/http/logout/service.rs +2 −2 View lib/auth/src/server/http/logout/service.rs
@@ -5,7 +5,7 @@
55
66use crate::server::AuthSvc;
77use crate::server::errors::AuthResult;
8use crate::server::logout::types::LogoutResponse;
8use crate::server::http::logout::types::LogoutResponse;
99
1010impl AuthSvc {
1111 #[tracing::instrument(skip_all, fields(request_id = %request_id, client_ip = ?session.client_ip().ok().flatten()))]
@@ -53,7 +53,7 @@
5353 }
5454
5555 if let Some(uid) = user_id {
56 crate::server::me::service::invalidate_me_cache(self.cache(), uid).await;
56 crate::server::http::me::service::invalidate_me_cache(self.cache(), uid).await;
5757 if let Err(error) = crate::server::share::audit::entry(
5858 self.db(),
5959 uid,
Renamed lib/auth/src/server/logout/types.rs → lib/auth/src/server/http/logout/types.rs lib/auth/src/server/http/logout/types.rs +0 −0 View lib/auth/src/server/http/logout/types.rs
No content changes.
Renamed lib/auth/src/server/me/handler.rs → lib/auth/src/server/http/me/handler.rs lib/auth/src/server/http/me/handler.rs +1 −1 View lib/auth/src/server/http/me/handler.rs
@@ -4,7 +4,7 @@
44use crate::envelope::{Envelope, NoData};
55use crate::server::AuthSvc;
66use crate::server::errors::AuthError;
7use crate::server::me::types::MeResponse;
7use crate::server::http::me::types::MeResponse;
88
99/// 鉴权失败一律映射成 401/503:`JwtError::Config`/`Internal` 是服务端/配置故障,
1010/// 直接报 401 会让运维把可用性故障当成用户凭证问题。
Renamed lib/auth/src/server/me/mod.rs → lib/auth/src/server/http/me/mod.rs lib/auth/src/server/http/me/mod.rs +0 −0 View lib/auth/src/server/http/me/mod.rs
No content changes.
Renamed lib/auth/src/server/me/service.rs → lib/auth/src/server/http/me/service.rs lib/auth/src/server/http/me/service.rs +1 −1 View lib/auth/src/server/http/me/service.rs
@@ -7,7 +7,7 @@
77
88use crate::server::AuthSvc;
99use crate::server::errors::{AuthError, AuthResult};
10use crate::server::me::types::MeResponse;
10use crate::server::http::me::types::MeResponse;
1111
1212pub const ME_CACHE_TTL_SECS: u64 = 300;
1313const ME_COUNT_TTL_SECS: u64 = 600;
Renamed lib/auth/src/server/me/types.rs → lib/auth/src/server/http/me/types.rs lib/auth/src/server/http/me/types.rs +0 −0 View lib/auth/src/server/http/me/types.rs
No content changes.
Renamed lib/auth/src/server/organization/error.rs → lib/auth/src/server/http/organization/error.rs lib/auth/src/server/http/organization/error.rs +0 −0 View lib/auth/src/server/http/organization/error.rs
No content changes.
Renamed lib/auth/src/server/organization/handler.rs → lib/auth/src/server/http/organization/handler.rs lib/auth/src/server/http/organization/handler.rs +1 −1 View lib/auth/src/server/http/organization/handler.rs
@@ -4,7 +4,7 @@
44use crate::envelope::{Envelope, NoData};
55use crate::server::AuthSvc;
66use crate::server::errors::AuthError;
7use crate::server::organization::types::{
7use crate::server::http::organization::types::{
88 AddMemberBody, BanMemberBody, CheckPermissionBody, CreateOrganizationBody, CreateRoleBody,
99 InviteSummary, MemberSummary, OrganizationSummary, PermissionCheck, PermissionGrant,
1010 RoleSummary, SetMemberRoleBody, SetRolePermissionsBody, UpdateBanBody, UpdateMemberBody,
Renamed lib/auth/src/server/organization/invite.rs → lib/auth/src/server/http/organization/invite.rs lib/auth/src/server/http/organization/invite.rs +11 −6 View lib/auth/src/server/http/organization/invite.rs
@@ -14,9 +14,9 @@
1414};
1515use crate::server::AuthSvc;
1616use crate::server::errors::{AuthError, AuthResult};
17use crate::server::organization::member;
18use crate::server::organization::service::{bump_version, normalize_reason};
19use crate::server::organization::types::{
17use crate::server::http::organization::member;
18use crate::server::http::organization::service::{bump_version, normalize_reason};
19use crate::server::http::organization::types::{
2020 DEFAULT_INVITE_TTL_SECS, InviteSummary, SYSTEM_ROLE_MEMBER, SYSTEM_ROLE_OWNER,
2121};
2222use crate::server::share::crypto;
@@ -354,8 +354,13 @@
354354 if let Some(role) = role
355355 && role.key != SYSTEM_ROLE_OWNER
356356 {
357 crate::server::organization::role::bind_role(&txn, row.id, role.id, invite.created_by)
358 .await?;
357 crate::server::http::organization::role::bind_role(
358 &txn,
359 row.id,
360 role.id,
361 invite.created_by,
362 )
363 .await?;
359364 }
360365 if let Some(extra) = invite.extra_role_ids.as_deref() {
361366 for raw in extra.split(',') {
@@ -372,7 +377,7 @@
372377 if role.key == SYSTEM_ROLE_OWNER || role.key == SYSTEM_ROLE_MEMBER {
373378 continue;
374379 }
375 crate::server::organization::role::bind_role(
380 crate::server::http::organization::role::bind_role(
376381 &txn,
377382 row.id,
378383 role.id,
Renamed lib/auth/src/server/organization/join.rs → lib/auth/src/server/http/organization/join.rs lib/auth/src/server/http/organization/join.rs +6 −3 View lib/auth/src/server/http/organization/join.rs
@@ -11,10 +11,10 @@
1111 organization_join_rules, organization_members, organization_roles, organizations,
1212};
1313use crate::models::users::users;
14use crate::server::organization::types::{
14use crate::server::http::organization::types::{
1515 AddMemberBody, JoinRequestSummary, JoinRuleSummary, SYSTEM_ROLE_MEMBER, SYSTEM_ROLE_OWNER,
1616};
17use crate::server::organization::{member, service};
17use crate::server::http::organization::{member, service};
1818use crate::server::{AuthError, AuthResult, AuthSvc};
1919
2020fn rule_summary(row: &organization_join_rules::Model) -> JoinRuleSummary {
@@ -400,7 +400,10 @@
400400 role_keys: Vec<String>,
401401 role_ids: Vec<String>,
402402 request_id: Option<&str>,
403 ) -> AuthResult<(crate::server::organization::types::MemberSummary, bool)> {
403 ) -> AuthResult<(
404 crate::server::http::organization::types::MemberSummary,
405 bool,
406 )> {
404407 let txn = self.db().write().begin().await?;
405408 // 机器人成员的角色上限:OWNER 只能由人类走成员面转移,不能通过内部接口直接塞入。
406409 let user = crate::models::users::users::Entity::find_by_id(user_id)
Renamed lib/auth/src/server/organization/member.rs → lib/auth/src/server/http/organization/member.rs lib/auth/src/server/http/organization/member.rs +3 −3 View lib/auth/src/server/http/organization/member.rs
@@ -14,9 +14,9 @@
1414use crate::models::users::users;
1515use crate::server::AuthSvc;
1616use crate::server::errors::{AuthError, AuthResult};
17use crate::server::organization::role;
18use crate::server::organization::service::{bump_version, normalize_reason};
19use crate::server::organization::types::{
17use crate::server::http::organization::role;
18use crate::server::http::organization::service::{bump_version, normalize_reason};
19use crate::server::http::organization::types::{
2020 AddMemberBody, MAX_ALIAS_AVATAR_URL_LEN, MAX_ALIAS_NAME_LEN, MAX_REASON_LEN, MemberSummary,
2121 SetMemberRoleBody, UpdateBanBody, UpdateMemberBody, normalize_alias,
2222};
Renamed lib/auth/src/server/organization/mod.rs → lib/auth/src/server/http/organization/mod.rs lib/auth/src/server/http/organization/mod.rs +0 −0 View lib/auth/src/server/http/organization/mod.rs
No content changes.
Renamed lib/auth/src/server/organization/permission.rs → lib/auth/src/server/http/organization/permission.rs lib/auth/src/server/http/organization/permission.rs +2 −2 View lib/auth/src/server/http/organization/permission.rs
@@ -10,11 +10,11 @@
1010};
1111use crate::server::AuthSvc;
1212use crate::server::errors::{AuthError, AuthResult};
13use crate::server::organization::types::{
13use crate::server::http::organization::types::{
1414 PERMISSION_CACHE_TTL_SECS, PERMISSIONS, PermissionCheck, Resolution, SYSTEM_ROLE_ADMIN,
1515 SYSTEM_ROLE_OWNER, is_admin_permission, is_known_permission,
1616};
17use crate::server::organization::{member, role, service};
17use crate::server::http::organization::{member, role, service};
1818
1919/// 缓存进 Redis 的判定核心。版本号相同的组织共享同一份核心,
2020/// 任何写操作推进 `organizations.version` 都会让整份核心失效。
Renamed lib/auth/src/server/organization/role.rs → lib/auth/src/server/http/organization/role.rs lib/auth/src/server/http/organization/role.rs +8 −6 View lib/auth/src/server/http/organization/role.rs
@@ -12,13 +12,15 @@
1212};
1313use crate::server::AuthSvc;
1414use crate::server::errors::{AuthError, AuthResult};
15use crate::server::organization::service::{bump_version, normalize_role_key, normalize_role_name};
16use crate::server::organization::types::{
15use crate::server::http::organization::service::{
16 bump_version, normalize_role_key, normalize_role_name,
17};
18use crate::server::http::organization::types::{
1719 CreateRoleBody, MemberSummary, PermissionGrant, PermissionGrant as Grant, RoleSummary,
1820 SYSTEM_ROLE_ADMIN, SYSTEM_ROLE_MEMBER, SYSTEM_ROLE_OWNER, SetRolePermissionsBody,
1921 is_known_permission,
2022};
21use crate::server::organization::{error, member};
23use crate::server::http::organization::{error, member};
2224
2325/// 内置角色的固有授权。OWNER 不需要显式授权(解析链直接短路),
2426/// ADMIN 的固有集写在 permissions.rs 的白名单里,这里只落 MEMBER 的默认值。
@@ -536,7 +538,7 @@
536538 role_key: &str,
537539 request_id: Option<&str>,
538540 ) -> AuthResult<Vec<String>> {
539 let member = crate::server::organization::member::load_by_id(
541 let member = crate::server::http::organization::member::load_by_id(
540542 self.db().read(),
541543 organization_id,
542544 member_id,
@@ -605,7 +607,7 @@
605607 if role.key == SYSTEM_ROLE_OWNER {
606608 return Err(AuthError::OrganizationRoleSystem);
607609 }
608 let member = crate::server::organization::member::load_by_id(
610 let member = crate::server::http::organization::member::load_by_id(
609611 self.db().read(),
610612 organization_id,
611613 member_id,
@@ -667,7 +669,7 @@
667669 request_id,
668670 )
669671 .await?;
670 let member = crate::server::organization::member::load_by_id(
672 let member = crate::server::http::organization::member::load_by_id(
671673 self.db().read(),
672674 organization_id,
673675 member_id,
Renamed lib/auth/src/server/organization/service.rs → lib/auth/src/server/http/organization/service.rs lib/auth/src/server/http/organization/service.rs +2 −2 View lib/auth/src/server/http/organization/service.rs
@@ -16,13 +16,13 @@
1616use crate::models::users::users;
1717use crate::server::AuthSvc;
1818use crate::server::errors::{AuthError, AuthResult};
19use crate::server::organization::types::{
19use crate::server::http::organization::types::{
2020 CreateOrganizationBody, MAX_ORG_DESCRIPTION_LEN, MAX_ORG_NAME_LEN, MAX_PERMISSION_LEN,
2121 MAX_ROLE_KEY_LEN, MAX_ROLE_NAME_LEN, MAX_SLUG_LEN, MemberSummary, OrganizationSummary,
2222 PermissionGrant, RoleSummary, SYSTEM_ROLE_ADMIN, SYSTEM_ROLE_OWNER, UpdateOrganizationBody,
2323 is_known_permission,
2424};
25use crate::server::organization::{error, member, permission, role};
25use crate::server::http::organization::{error, member, permission, role};
2626
2727pub(crate) fn perm_cache_prefix(organization_id: Uuid, user_id: i64) -> String {
2828 format!("auth:org:perm:{organization_id}:{user_id}")
Renamed lib/auth/src/server/organization/types.rs → lib/auth/src/server/http/organization/types.rs lib/auth/src/server/http/organization/types.rs +0 −0 View lib/auth/src/server/http/organization/types.rs
No content changes.
Renamed lib/auth/src/server/password_reset/handler.rs → lib/auth/src/server/http/password_reset/handler.rs lib/auth/src/server/http/password_reset/handler.rs +1 −1 View lib/auth/src/server/http/password_reset/handler.rs
@@ -5,7 +5,7 @@
55use crate::server::AuthSvc;
66use crate::server::errors::AuthError;
77
8use crate::server::password_reset::types::{
8use crate::server::http::password_reset::types::{
99 PasswordResetConfirmRequest, PasswordResetConfirmResponse, PasswordResetRequest,
1010 PasswordResetResponse,
1111};
Renamed lib/auth/src/server/password_reset/mod.rs → lib/auth/src/server/http/password_reset/mod.rs lib/auth/src/server/http/password_reset/mod.rs +0 −0 View lib/auth/src/server/http/password_reset/mod.rs
No content changes.
Renamed lib/auth/src/server/password_reset/service.rs → lib/auth/src/server/http/password_reset/service.rs lib/auth/src/server/http/password_reset/service.rs +1 −1 View lib/auth/src/server/http/password_reset/service.rs
@@ -10,7 +10,7 @@
1010use crate::models::users::users;
1111use crate::server::AuthSvc;
1212use crate::server::errors::{AuthError, AuthResult};
13use crate::server::password_reset::types::{
13use crate::server::http::password_reset::types::{
1414 PasswordResetConfirmRequest, PasswordResetConfirmResponse, PasswordResetRequest,
1515 PasswordResetResponse,
1616};
Renamed lib/auth/src/server/password_reset/types.rs → lib/auth/src/server/http/password_reset/types.rs lib/auth/src/server/http/password_reset/types.rs +1 −1 View lib/auth/src/server/http/password_reset/types.rs
@@ -1,7 +1,7 @@
11use serde::{Deserialize, Serialize};
22use utoipa::ToSchema;
33
4use crate::server::challenge::types::PowProofRequest;
4use crate::server::http::challenge::types::PowProofRequest;
55
66#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
77pub struct PasswordResetRequest {
Renamed lib/auth/src/server/register/age.rs → lib/auth/src/server/http/register/age.rs lib/auth/src/server/http/register/age.rs +0 −0 View lib/auth/src/server/http/register/age.rs
No content changes.
Renamed lib/auth/src/server/register/handler.rs → lib/auth/src/server/http/register/handler.rs lib/auth/src/server/http/register/handler.rs +1 −1 View lib/auth/src/server/http/register/handler.rs
@@ -5,7 +5,7 @@
55use crate::server::AuthSvc;
66use crate::server::errors::AuthError;
77
8use crate::server::register::types::{
8use crate::server::http::register::types::{
99 RegisterCodeRequest, RegisterCodeResponse, UserRegisterRequest, UserRegisterResponse,
1010};
1111
Renamed lib/auth/src/server/register/mod.rs → lib/auth/src/server/http/register/mod.rs lib/auth/src/server/http/register/mod.rs +0 −0 View lib/auth/src/server/http/register/mod.rs
No content changes.
Renamed lib/auth/src/server/register/service.rs → lib/auth/src/server/http/register/service.rs lib/auth/src/server/http/register/service.rs +2 −2 View lib/auth/src/server/http/register/service.rs
@@ -10,8 +10,8 @@
1010use crate::models::users::users;
1111use crate::server::AuthSvc;
1212use crate::server::errors::{AuthError, AuthResult};
13use crate::server::register::age;
14use crate::server::register::types::{
13use crate::server::http::register::age;
14use crate::server::http::register::types::{
1515 RegisterCodeRequest, RegisterCodeResponse, UserRegisterRequest, UserRegisterResponse,
1616};
1717use crate::server::share::codes::{consume_email_code, store_email_code};
Renamed lib/auth/src/server/register/types.rs → lib/auth/src/server/http/register/types.rs lib/auth/src/server/http/register/types.rs +1 −1 View lib/auth/src/server/http/register/types.rs
@@ -1,7 +1,7 @@
11use serde::{Deserialize, Serialize};
22use utoipa::ToSchema;
33
4use crate::server::challenge::types::PowProofRequest;
4use crate::server::http::challenge::types::PowProofRequest;
55
66#[derive(Clone, Debug, Deserialize, Serialize, ToSchema)]
77pub struct RegisterCodeRequest {
Renamed lib/auth/src/server/ssh_key/handler.rs → lib/auth/src/server/http/ssh_key/handler.rs lib/auth/src/server/http/ssh_key/handler.rs +1 −1 View lib/auth/src/server/http/ssh_key/handler.rs
@@ -5,8 +5,8 @@
55use crate::envelope::{Envelope, NoData};
66use crate::server::AuthSvc;
77use crate::server::errors::AuthError;
8use crate::server::http::ssh_key::types::{SshKeyAddRequest, SshKeySummary};
89use crate::server::share::types::ListQuery;
9use crate::server::ssh_key::types::{SshKeyAddRequest, SshKeySummary};
1010
1111#[utoipa::path(
1212 get,
Renamed lib/auth/src/server/ssh_key/mod.rs → lib/auth/src/server/http/ssh_key/mod.rs lib/auth/src/server/http/ssh_key/mod.rs +0 −0 View lib/auth/src/server/http/ssh_key/mod.rs
No content changes.
Renamed lib/auth/src/server/ssh_key/service.rs → lib/auth/src/server/http/ssh_key/service.rs lib/auth/src/server/http/ssh_key/service.rs +3 −3 View lib/auth/src/server/http/ssh_key/service.rs
@@ -16,12 +16,12 @@
1616
1717use crate::server::AuthSvc;
1818use crate::server::errors::{AuthError, AuthResult};
19use crate::server::share::crypto;
20use crate::server::share::types::ListQuery;
21use crate::server::ssh_key::types::{
19use crate::server::http::ssh_key::types::{
2220 MAX_SSH_KEY_DESCRIPTION_LEN, MAX_SSH_KEY_NAME_LEN, MAX_SSH_PUBLIC_KEY_LEN,
2321 MIN_SSH_PUBLIC_KEY_LEN, SshKeyAddRequest, SshKeyAlgorithm, SshKeySummary,
2422};
23use crate::server::share::crypto;
24use crate::server::share::types::ListQuery;
2525
2626pub(crate) fn parse_public_key(raw: &str) -> AuthResult<(PublicKeyType, String)> {
2727 let key_line = raw.trim();
Renamed lib/auth/src/server/ssh_key/types.rs → lib/auth/src/server/http/ssh_key/types.rs lib/auth/src/server/http/ssh_key/types.rs +0 −0 View lib/auth/src/server/http/ssh_key/types.rs
No content changes.
Renamed lib/auth/src/server/token/handler.rs → lib/auth/src/server/http/token/handler.rs lib/auth/src/server/http/token/handler.rs +1 −1 View lib/auth/src/server/http/token/handler.rs
@@ -4,7 +4,7 @@
44
55use crate::server::AuthSvc;
66use crate::server::errors::AuthError;
7use crate::server::token::types::{TokenRequest, TokenResponse};
7use crate::server::http::token::types::{TokenRequest, TokenResponse};
88
99#[utoipa::path(
1010 post,
Renamed lib/auth/src/server/token/mod.rs → lib/auth/src/server/http/token/mod.rs lib/auth/src/server/http/token/mod.rs +0 −0 View lib/auth/src/server/http/token/mod.rs
No content changes.
Renamed lib/auth/src/server/token/service.rs → lib/auth/src/server/http/token/service.rs lib/auth/src/server/http/token/service.rs +2 −2 View lib/auth/src/server/http/token/service.rs
@@ -2,10 +2,10 @@
22
33use crate::server::AuthSvc;
44use crate::server::errors::AuthResult;
5use crate::server::share::issue;
6use crate::server::token::types::{
5use crate::server::http::token::types::{
76 DEFAULT_TTL_SECS, MAX_TTL_SECS, TOKEN_TYPE, TokenRequest, TokenResponse,
87};
8use crate::server::share::issue;
99
1010impl AuthSvc {
1111 #[tracing::instrument(skip_all, fields(user_id = user_id, request_id = %request_id.unwrap_or_default()))]
Renamed lib/auth/src/server/token/types.rs → lib/auth/src/server/http/token/types.rs lib/auth/src/server/http/token/types.rs +0 −0 View lib/auth/src/server/http/token/types.rs
No content changes.
Renamed lib/auth/src/server/health.rs → lib/auth/src/server/http/health.rs lib/auth/src/server/http/health.rs +0 −0 View lib/auth/src/server/http/health.rs
No content changes.
Added lib/auth/src/server/http/mod.rs lib/auth/src/server/http/mod.rs +15 −0 View lib/auth/src/server/http/mod.rs
@@ -0,0 +1,15 @@
1pub mod access_token;
2pub mod app_token;
3pub mod challenge;
4pub mod health;
5pub mod login;
6pub mod logout;
7pub mod me;
8pub mod openapi;
9pub mod organization;
10pub mod password_reset;
11pub mod register;
12pub mod router;
13pub mod socket_ticket;
14pub mod ssh_key;
15pub mod token;
Added lib/auth/src/server/http/openapi.rs lib/auth/src/server/http/openapi.rs +120 −0 View lib/auth/src/server/http/openapi.rs
@@ -0,0 +1,120 @@
1use utoipa::OpenApi;
2
3#[derive(OpenApi)]
4#[openapi(
5 info(
6 title = "auth",
7 description = "认证与账号服务:工作量证明、口令与验证码登录、二次验证、注册、口令重置、访问令牌与 SSH 公钥。",
8 version = env!("CARGO_PKG_VERSION")
9 ),
10 paths(
11 crate::server::http::challenge::handler::challenge,
12 crate::server::http::login::handler::login,
13 crate::server::http::login::handler::login_code,
14 crate::server::http::login::handler::login_code_verify,
15 crate::server::http::login::handler::login_verify,
16 crate::server::http::logout::handler::logout,
17 crate::server::http::me::handler::me,
18 crate::server::http::register::handler::register_code,
19 crate::server::http::register::handler::register,
20 crate::server::http::password_reset::handler::password_reset_request,
21 crate::server::http::password_reset::handler::password_reset,
22 crate::server::http::access_token::handler::access_token_list,
23 crate::server::http::access_token::handler::access_token_create,
24 crate::server::http::access_token::handler::access_token_revoke,
25 crate::server::http::app_token::handler::app_token_issue,
26 crate::server::http::token::handler::token_issue,
27 crate::server::http::ssh_key::handler::ssh_key_list,
28 crate::server::http::ssh_key::handler::ssh_key_add,
29 crate::server::http::ssh_key::handler::ssh_key_delete,
30 crate::server::oauth::protocol::authorize,
31 crate::server::oauth::protocol::token,
32 crate::server::oauth::protocol::revoke,
33 crate::server::oauth::protocol::metadata,
34 crate::server::oauth::protocol::openid_configuration,
35 crate::server::http::health::health,
36 crate::server::http::health::ready,
37 crate::server::oauth::userinfo::userinfo,
38 crate::server::oauth::logout::logout,
39 crate::server::oauth::consent::preview,
40 crate::server::oauth::consent::decide,
41 crate::server::http::organization::handler::create_organization,
42 crate::server::http::organization::handler::list_organizations,
43 crate::server::http::organization::handler::get_organization,
44 crate::server::http::organization::handler::update_organization,
45 crate::server::http::organization::handler::archive_organization,
46 crate::server::http::organization::handler::restore_organization,
47 crate::server::http::organization::handler::delete_organization,
48 crate::server::http::organization::handler::transfer_ownership,
49 crate::server::http::organization::handler::leave_organization,
50 crate::server::http::organization::handler::list_members,
51 crate::server::http::organization::handler::get_member,
52 crate::server::http::organization::handler::update_member,
53 crate::server::http::organization::handler::update_self_member,
54 crate::server::http::organization::handler::add_member,
55 crate::server::http::organization::handler::remove_member,
56 crate::server::http::organization::handler::set_member_role,
57 crate::server::http::organization::handler::ban_member,
58 crate::server::http::organization::handler::unban_member,
59 crate::server::http::organization::handler::set_member_permissions,
60 crate::server::http::organization::handler::list_bans,
61 crate::server::http::organization::handler::get_ban,
62 crate::server::http::organization::handler::update_ban,
63 crate::server::http::organization::handler::unban_by_user,
64 crate::server::http::organization::handler::list_roles,
65 crate::server::http::organization::handler::get_role,
66 crate::server::http::organization::handler::create_role,
67 crate::server::http::organization::handler::update_role,
68 crate::server::http::organization::handler::delete_role,
69 crate::server::http::organization::handler::set_role_permissions,
70 crate::server::http::organization::handler::assign_role,
71 crate::server::http::organization::handler::unassign_role,
72 crate::server::http::organization::handler::join_role,
73 crate::server::http::organization::handler::leave_role,
74 crate::server::http::organization::handler::check_permission,
75 crate::server::http::organization::handler::create_invite,
76 crate::server::http::organization::handler::list_invites,
77 crate::server::http::organization::handler::revoke_invite,
78 crate::server::http::organization::handler::redeem_invite,
79 ),
80 components(schemas(
81 crate::server::oauth::protocol::TokenRequest,
82 crate::server::oauth::protocol::RevokeRequest,
83 crate::server::http::health::HealthResponse,
84 crate::server::http::health::ReadinessResponse,
85 crate::server::http::health::ComponentCheck,
86 crate::server::oauth::consent::ConsentPreview,
87 crate::server::oauth::consent::ConsentDecision,
88 crate::server::oauth::consent::ConsentForm,
89 crate::server::http::organization::types::OrganizationSummary,
90 crate::server::http::organization::types::MemberSummary,
91 crate::server::http::organization::types::RoleSummary,
92 crate::server::http::organization::types::InviteSummary,
93 crate::server::http::organization::types::PermissionGrant,
94 crate::server::http::organization::types::PermissionCheck,
95 crate::server::http::organization::types::CreateOrganizationBody,
96 crate::server::http::organization::types::UpdateOrganizationBody,
97 crate::server::http::organization::types::AddMemberBody,
98 crate::server::http::organization::types::SetMemberRoleBody,
99 crate::server::http::organization::types::BanMemberBody,
100 crate::server::http::organization::types::CheckPermissionBody,
101 crate::server::http::organization::types::CreateRoleBody,
102 crate::server::http::organization::types::SetRolePermissionsBody,
103 crate::server::http::organization::handler::OrgPath,
104 crate::server::http::organization::handler::OrgMemberPath,
105 crate::server::http::organization::handler::OrgRolePath,
106 crate::server::http::organization::handler::OrgInvitePath,
107 crate::server::http::organization::handler::OrgListQuery,
108 crate::server::http::organization::handler::MemberListQuery,
109 crate::server::http::organization::handler::UpdateRoleBody,
110 crate::server::http::organization::handler::TransferBody,
111 crate::server::http::organization::handler::ReasonBody,
112 crate::server::http::organization::handler::DeleteOrgQuery,
113 crate::server::http::organization::handler::CreateInviteBody,
114 crate::server::http::organization::handler::RedeemInviteBody,
115 crate::server::http::organization::handler::CreateInviteResponse,
116 crate::server::http::organization::handler::RedeemInviteResponse,
117 crate::server::http::organization::handler::AssignRoleBody,
118 ))
119)]
120pub struct ApiDoc;
Added lib/auth/src/server/http/router.rs lib/auth/src/server/http/router.rs +310 −0 View lib/auth/src/server/http/router.rs
@@ -0,0 +1,310 @@
1use actix_web::web;
2
3pub fn configure(cfg: &mut web::ServiceConfig) {
4 cfg.route(
5 "/.well-known/openid-configuration",
6 web::get().to(crate::server::oauth::protocol::openid_configuration),
7 );
8 cfg.route(
9 "/.well-known/oauth-authorization-server",
10 web::get().to(crate::server::oauth::protocol::metadata),
11 );
12 cfg.route(
13 "/.well-known/jwks.json",
14 web::get().to(crate::server::keys::jwks),
15 );
16 cfg.route(
17 "/health",
18 web::get().to(crate::server::http::health::health),
19 );
20 cfg.route("/ready", web::get().to(crate::server::http::health::ready));
21 cfg.service(web::scope("/api/v1").configure(api));
22}
23
24fn api(cfg: &mut web::ServiceConfig) {
25 cfg.route(
26 "/oauth/authorize",
27 web::get().to(crate::server::oauth::protocol::authorize),
28 );
29 cfg.route(
30 "/oauth/token",
31 web::post().to(crate::server::oauth::protocol::token),
32 );
33 cfg.route(
34 "/oauth/revoke",
35 web::post().to(crate::server::oauth::protocol::revoke),
36 );
37 cfg.route(
38 "/oauth/userinfo",
39 web::get().to(crate::server::oauth::userinfo::userinfo),
40 );
41 cfg.route(
42 "/oauth/userinfo",
43 web::post().to(crate::server::oauth::userinfo::userinfo),
44 );
45 cfg.route(
46 "/oauth/logout",
47 web::get().to(crate::server::oauth::logout::logout),
48 );
49 cfg.route(
50 "/oauth/logout",
51 web::post().to(crate::server::oauth::logout::logout),
52 );
53 cfg.route(
54 "/oauth/consent",
55 web::get().to(crate::server::oauth::consent::preview),
56 );
57 cfg.route(
58 "/oauth/consent",
59 web::post().to(crate::server::oauth::consent::decide),
60 );
61 cfg.route(
62 "/oauth/socket-tickets",
63 web::post().to(crate::server::http::socket_ticket::issue),
64 );
65 cfg.route(
66 "/oauth/socket-tickets",
67 web::method(actix_web::http::Method::OPTIONS).to(crate::server::oauth::protocol::preflight),
68 );
69 cfg.route(
70 "/oauth/token",
71 web::method(actix_web::http::Method::OPTIONS).to(crate::server::oauth::protocol::preflight),
72 );
73 cfg.route(
74 "/oauth/revoke",
75 web::method(actix_web::http::Method::OPTIONS).to(crate::server::oauth::protocol::preflight),
76 );
77 cfg.route(
78 "/oauth/challenge",
79 web::post().to(crate::server::http::challenge::handler::challenge),
80 );
81 cfg.route(
82 "/oauth/login",
83 web::post().to(crate::server::http::login::handler::login),
84 );
85 cfg.route(
86 "/oauth/login/code",
87 web::post().to(crate::server::http::login::handler::login_code),
88 );
89 cfg.route(
90 "/oauth/login/code/verify",
91 web::post().to(crate::server::http::login::handler::login_code_verify),
92 );
93 cfg.route(
94 "/oauth/login/verify",
95 web::post().to(crate::server::http::login::handler::login_verify),
96 );
97 cfg.route(
98 "/oauth/session/logout",
99 web::post().to(crate::server::http::logout::handler::logout),
100 );
101 cfg.route(
102 "/oauth/me",
103 web::get().to(crate::server::http::me::handler::me),
104 );
105 cfg.route(
106 "/oauth/register/code",
107 web::post().to(crate::server::http::register::handler::register_code),
108 );
109 cfg.route(
110 "/oauth/register",
111 web::post().to(crate::server::http::register::handler::register),
112 );
113 cfg.route(
114 "/oauth/password/reset",
115 web::post().to(crate::server::http::password_reset::handler::password_reset_request),
116 );
117 cfg.route(
118 "/oauth/password/reset/confirm",
119 web::post().to(crate::server::http::password_reset::handler::password_reset),
120 );
121 cfg.route(
122 "/oauth/access-tokens",
123 web::get().to(crate::server::http::access_token::handler::access_token_list),
124 );
125 cfg.route(
126 "/oauth/access-tokens",
127 web::post().to(crate::server::http::access_token::handler::access_token_create),
128 );
129 cfg.route(
130 "/oauth/access-tokens/{token_id}",
131 web::delete().to(crate::server::http::access_token::handler::access_token_revoke),
132 );
133 cfg.route(
134 "/oauth/access-tokens/{token_id}/rotate",
135 web::post().to(crate::server::http::access_token::handler::access_token_rotate),
136 );
137 cfg.route(
138 "/oauth/app-tokens",
139 web::post().to(crate::server::http::app_token::handler::app_token_issue),
140 );
141 cfg.route(
142 "/oauth/session/token",
143 web::post().to(crate::server::http::token::handler::token_issue),
144 );
145 cfg.route("/oauth/jwks.json", web::get().to(crate::server::keys::jwks));
146 cfg.route(
147 "/oauth/ssh-keys",
148 web::get().to(crate::server::http::ssh_key::handler::ssh_key_list),
149 );
150 cfg.route(
151 "/oauth/ssh-keys",
152 web::post().to(crate::server::http::ssh_key::handler::ssh_key_add),
153 );
154 cfg.route(
155 "/oauth/ssh-keys/{key_id}",
156 web::delete().to(crate::server::http::ssh_key::handler::ssh_key_delete),
157 );
158 cfg.route(
159 "/organizations",
160 web::post().to(crate::server::http::organization::handler::create_organization),
161 );
162 cfg.route(
163 "/organizations",
164 web::get().to(crate::server::http::organization::handler::list_organizations),
165 );
166 cfg.route(
167 "/organizations/invites/redeem",
168 web::post().to(crate::server::http::organization::handler::redeem_invite),
169 );
170 cfg.route(
171 "/organizations/{organization_id}",
172 web::get().to(crate::server::http::organization::handler::get_organization),
173 );
174 cfg.route(
175 "/organizations/{organization_id}",
176 web::patch().to(crate::server::http::organization::handler::update_organization),
177 );
178 cfg.route(
179 "/organizations/{organization_id}",
180 web::delete().to(crate::server::http::organization::handler::delete_organization),
181 );
182 cfg.route(
183 "/organizations/{organization_id}/archive",
184 web::post().to(crate::server::http::organization::handler::archive_organization),
185 );
186 cfg.route(
187 "/organizations/{organization_id}/restore",
188 web::post().to(crate::server::http::organization::handler::restore_organization),
189 );
190 cfg.route(
191 "/organizations/{organization_id}/transfer",
192 web::post().to(crate::server::http::organization::handler::transfer_ownership),
193 );
194 cfg.route(
195 "/organizations/{organization_id}/leave",
196 web::post().to(crate::server::http::organization::handler::leave_organization),
197 );
198 cfg.route(
199 "/organizations/{organization_id}/members",
200 web::get().to(crate::server::http::organization::handler::list_members),
201 );
202 cfg.route(
203 "/organizations/{organization_id}/members",
204 web::post().to(crate::server::http::organization::handler::add_member),
205 );
206 cfg.route(
207 "/organizations/{organization_id}/members/@me",
208 web::patch().to(crate::server::http::organization::handler::update_self_member),
209 );
210 cfg.route(
211 "/organizations/{organization_id}/members/{member_id}",
212 web::get().to(crate::server::http::organization::handler::get_member),
213 );
214 cfg.route(
215 "/organizations/{organization_id}/members/{member_id}",
216 web::patch().to(crate::server::http::organization::handler::update_member),
217 );
218 cfg.route(
219 "/organizations/{organization_id}/members/{member_id}",
220 web::delete().to(crate::server::http::organization::handler::remove_member),
221 );
222 cfg.route(
223 "/organizations/{organization_id}/members/{member_id}/role",
224 web::patch().to(crate::server::http::organization::handler::set_member_role),
225 );
226 cfg.route(
227 "/organizations/{organization_id}/members/{member_id}/ban",
228 web::post().to(crate::server::http::organization::handler::ban_member),
229 );
230 cfg.route(
231 "/organizations/{organization_id}/members/{member_id}/unban",
232 web::post().to(crate::server::http::organization::handler::unban_member),
233 );
234 cfg.route(
235 "/organizations/{organization_id}/members/{member_id}/permissions",
236 web::put().to(crate::server::http::organization::handler::set_member_permissions),
237 );
238 cfg.route(
239 "/organizations/{organization_id}/bans",
240 web::get().to(crate::server::http::organization::handler::list_bans),
241 );
242 cfg.route(
243 "/organizations/{organization_id}/bans/{user_id}",
244 web::get().to(crate::server::http::organization::handler::get_ban),
245 );
246 cfg.route(
247 "/organizations/{organization_id}/bans/{user_id}",
248 web::patch().to(crate::server::http::organization::handler::update_ban),
249 );
250 cfg.route(
251 "/organizations/{organization_id}/bans/{user_id}",
252 web::delete().to(crate::server::http::organization::handler::unban_by_user),
253 );
254 cfg.route(
255 "/organizations/{organization_id}/roles",
256 web::get().to(crate::server::http::organization::handler::list_roles),
257 );
258 cfg.route(
259 "/organizations/{organization_id}/roles",
260 web::post().to(crate::server::http::organization::handler::create_role),
261 );
262 cfg.route(
263 "/organizations/{organization_id}/roles/assign",
264 web::post().to(crate::server::http::organization::handler::assign_role),
265 );
266 cfg.route(
267 "/organizations/{organization_id}/roles/unassign",
268 web::post().to(crate::server::http::organization::handler::unassign_role),
269 );
270 cfg.route(
271 "/organizations/{organization_id}/roles/{role_id}",
272 web::get().to(crate::server::http::organization::handler::get_role),
273 );
274 cfg.route(
275 "/organizations/{organization_id}/roles/{role_id}",
276 web::patch().to(crate::server::http::organization::handler::update_role),
277 );
278 cfg.route(
279 "/organizations/{organization_id}/roles/{role_id}/join",
280 web::post().to(crate::server::http::organization::handler::join_role),
281 );
282 cfg.route(
283 "/organizations/{organization_id}/roles/{role_id}/join",
284 web::delete().to(crate::server::http::organization::handler::leave_role),
285 );
286 cfg.route(
287 "/organizations/{organization_id}/roles/{role_id}",
288 web::delete().to(crate::server::http::organization::handler::delete_role),
289 );
290 cfg.route(
291 "/organizations/{organization_id}/roles/{role_id}/permissions",
292 web::put().to(crate::server::http::organization::handler::set_role_permissions),
293 );
294 cfg.route(
295 "/organizations/{organization_id}/permissions/check",
296 web::post().to(crate::server::http::organization::handler::check_permission),
297 );
298 cfg.route(
299 "/organizations/{organization_id}/invites",
300 web::post().to(crate::server::http::organization::handler::create_invite),
301 );
302 cfg.route(
303 "/organizations/{organization_id}/invites",
304 web::get().to(crate::server::http::organization::handler::list_invites),
305 );
306 cfg.route(
307 "/organizations/{organization_id}/invites/{invite_id}",
308 web::delete().to(crate::server::http::organization::handler::revoke_invite),
309 );
310}
Renamed lib/auth/src/server/socket_ticket.rs → lib/auth/src/server/http/socket_ticket.rs lib/auth/src/server/http/socket_ticket.rs +1 −1 View lib/auth/src/server/http/socket_ticket.rs
@@ -36,7 +36,7 @@
3636 let response = issue_inner(&svc, session, &req, &body, Some(request_id.as_str()))
3737 .await
3838 .unwrap_or_else(|error| error.error_response());
39 crate::server::protocol::cors(&svc, &web_cfg, &req, response)
39 crate::server::oauth::protocol::cors(&svc, &web_cfg, &req, response)
4040}
4141
4242#[tracing::instrument(skip_all, fields(request_id = %request_id.unwrap_or_default()))]
Renamed lib/auth/src/server/client/mod.rs → lib/auth/src/server/oauth/client/mod.rs lib/auth/src/server/oauth/client/mod.rs +0 −0 View lib/auth/src/server/oauth/client/mod.rs
No content changes.
Renamed lib/auth/src/server/client/registry.rs → lib/auth/src/server/oauth/client/registry.rs lib/auth/src/server/oauth/client/registry.rs +0 −0 View lib/auth/src/server/oauth/client/registry.rs
No content changes.
Renamed lib/auth/src/server/protocol.rs → lib/auth/src/server/oauth/protocol.rs lib/auth/src/server/oauth/protocol.rs +6 −6 View lib/auth/src/server/oauth/protocol.rs
@@ -20,7 +20,7 @@
2020use serde::{Deserialize, Serialize};
2121use sha2::{Digest, Sha256};
2222
23use crate::server::client::ClientRecord;
23use crate::server::oauth::client::ClientRecord;
2424use crate::server::share::crypto::{constant_time_eq, random_b64url, sha256_hex};
2525use crate::server::{AuthError, AuthResult, AuthSvc};
2626
@@ -62,7 +62,7 @@
6262 .iter()
6363 .any(|other| other.client_id == client.client_id);
6464 if duplicate
65 || crate::server::client::registry::validate_client_id(&client.client_id).is_err()
65 || crate::server::oauth::client::registry::validate_client_id(&client.client_id).is_err()
6666 // 仅跑 client_credentials 的机密客户端可以没有重定向地址。
6767 || (client.kind == crate::models::users::oauth_clients::ClientKind::Public
6868 && client.redirect_uris.is_empty())
@@ -74,7 +74,7 @@
7474 .redirect_uris
7575 .iter()
7676 .any(|uri| {
77 crate::server::client::registry::validate_uri(uri, config.allow_wildcard_redirect)
77 crate::server::oauth::client::registry::validate_uri(uri, config.allow_wildcard_redirect)
7878 .is_err()
7979 })
8080 || (client.kind == crate::models::users::oauth_clients::ClientKind::Confidential
@@ -83,7 +83,7 @@
8383 .as_deref()
8484 .is_none_or(
8585 |secret| {
86 secret.len() < crate::server::client::registry::MIN_SECRET_LEN
86 secret.len() < crate::server::oauth::client::registry::MIN_SECRET_LEN
8787 || is_placeholder(secret)
8888 },
8989 ))
@@ -104,7 +104,7 @@
104104}
105105
106106fn endpoint(raw: &str) -> Option<Url> {
107 crate::server::client::registry::endpoint(raw)
107 crate::server::oauth::client::registry::endpoint(raw)
108108}
109109
110110/// 一次授权请求里 `prompt` 解析结果。
@@ -1312,7 +1312,7 @@
13121312mod tests {
13131313 use super::*;
13141314 use crate::models::users::oauth_clients::{ClientKind, ClientSource};
1315 use crate::server::client::{ClientSpec, MIN_SECRET_LEN};
1315 use crate::server::oauth::client::{ClientSpec, MIN_SECRET_LEN};
13161316
13171317 fn make_record(kind: ClientKind, secret: Option<&str>, scopes: &[&str]) -> ClientRecord {
13181318 ClientRecord::from_spec(
Modified lib/auth/src/server/auth_svc.rs lib/auth/src/server/auth_svc.rs +4 −4 View lib/auth/src/server/auth_svc.rs
@@ -25,7 +25,7 @@
2525 apps: Arc<AppRegistry>,
2626 signing: Arc<crate::server::keys::SigningState>,
2727 jwt: crate::jwt::JwtState,
28 clients: Arc<crate::server::client::ClientRegistry>,
28 clients: Arc<crate::server::oauth::client::ClientRegistry>,
2929 session_max_age_secs: u64,
3030}
3131
@@ -42,13 +42,13 @@
4242 jwt_config: JwtConfig,
4343 session_max_age_secs: u64,
4444 ) -> AuthResult<Self> {
45 crate::server::protocol::validate_config(&auth.oauth, &jwt_config.issuer)?;
45 crate::server::oauth::protocol::validate_config(&auth.oauth, &jwt_config.issuer)?;
4646 let signing = crate::server::keys::SigningState::from_config(&jwt_config)?;
4747 let jwt_state = crate::jwt::JwtState::load(&jwt_config)
4848 .await
4949 .map_err(|error| AuthError::Unavailable(error.to_string()))?;
5050 // 客户端注册表:配置种子落库后加载,之后由管理接口维护。
51 let clients = crate::server::client::ClientRegistry::load(&db, &auth.oauth).await?;
51 let clients = crate::server::oauth::client::ClientRegistry::load(&db, &auth.oauth).await?;
5252 let svc = Self {
5353 db,
5454 cache,
@@ -103,7 +103,7 @@
103103 self.events.as_ref()
104104 }
105105
106 pub fn clients(&self) -> &crate::server::client::ClientRegistry {
106 pub fn clients(&self) -> &crate::server::oauth::client::ClientRegistry {
107107 &self.clients
108108 }
109109
Modified lib/auth/src/server/authority.rs lib/auth/src/server/authority.rs +1 −1 View lib/auth/src/server/authority.rs
@@ -268,7 +268,7 @@
268268 .map_err(invalid)?
269269 .pop()
270270 .ok_or(JwtError::Malformed)?;
271 crate::server::me::service::invalidate_me_cache(self.cache(), user_id).await;
271 crate::server::http::me::service::invalidate_me_cache(self.cache(), user_id).await;
272272 Ok(record(updated))
273273 }
274274}
Modified lib/auth/src/server/mod.rs lib/auth/src/server/mod.rs +7 −17 View lib/auth/src/server/mod.rs
@@ -1,32 +1,22 @@
1pub mod access_token;
21pub mod account_lifecycle;
3pub mod app_token;
42pub mod authority;
5pub mod challenge;
6pub mod client;
73pub mod errors;
84pub mod grpc;
9pub mod health;
5pub mod http;
106pub mod keys;
11pub mod login;
12pub mod logout;
13pub mod me;
147pub mod migrate;
158pub mod oauth;
16pub mod openapi;
17pub mod organization;
18pub mod password_reset;
199pub mod pow;
20pub mod protocol;
21pub mod register;
22pub mod router;
2310pub mod share;
24pub mod socket_ticket;
25pub mod ssh_key;
26pub mod token;
2711
2812pub use errors::{AuthError, AuthResult};
2913
3014mod auth_svc;
3115
3216pub use auth_svc::AuthSvc;
17
18pub use http::{
19 access_token, app_token, challenge, health, login, logout, me, openapi, organization,
20 password_reset, register, router, socket_ticket, ssh_key, token,
21};
22pub use oauth::{client, protocol};
Deleted lib/auth/src/server/openapi.rs lib/auth/src/server/openapi.rs +0 −120
@@ -1,120 +0,0 @@
1use utoipa::OpenApi;
2
3#[derive(OpenApi)]
4#[openapi(
5 info(
6 title = "auth",
7 description = "认证与账号服务:工作量证明、口令与验证码登录、二次验证、注册、口令重置、访问令牌与 SSH 公钥。",
8 version = env!("CARGO_PKG_VERSION")
9 ),
10 paths(
11 crate::server::challenge::handler::challenge,
12 crate::server::login::handler::login,
13 crate::server::login::handler::login_code,
14 crate::server::login::handler::login_code_verify,
15 crate::server::login::handler::login_verify,
16 crate::server::logout::handler::logout,
17 crate::server::me::handler::me,
18 crate::server::register::handler::register_code,
19 crate::server::register::handler::register,
20 crate::server::password_reset::handler::password_reset_request,
21 crate::server::password_reset::handler::password_reset,
22 crate::server::access_token::handler::access_token_list,
23 crate::server::access_token::handler::access_token_create,
24 crate::server::access_token::handler::access_token_revoke,
25 crate::server::app_token::handler::app_token_issue,
26 crate::server::token::handler::token_issue,
27 crate::server::ssh_key::handler::ssh_key_list,
28 crate::server::ssh_key::handler::ssh_key_add,
29 crate::server::ssh_key::handler::ssh_key_delete,
30 crate::server::protocol::authorize,
31 crate::server::protocol::token,
32 crate::server::protocol::revoke,
33 crate::server::protocol::metadata,
34 crate::server::protocol::openid_configuration,
35 crate::server::health::health,
36 crate::server::health::ready,
37 crate::server::oauth::userinfo::userinfo,
38 crate::server::oauth::logout::logout,
39 crate::server::oauth::consent::preview,
40 crate::server::oauth::consent::decide,
41 crate::server::organization::handler::create_organization,
42 crate::server::organization::handler::list_organizations,
43 crate::server::organization::handler::get_organization,
44 crate::server::organization::handler::update_organization,
45 crate::server::organization::handler::archive_organization,
46 crate::server::organization::handler::restore_organization,
47 crate::server::organization::handler::delete_organization,
48 crate::server::organization::handler::transfer_ownership,
49 crate::server::organization::handler::leave_organization,
50 crate::server::organization::handler::list_members,
51 crate::server::organization::handler::get_member,
52 crate::server::organization::handler::update_member,
53 crate::server::organization::handler::update_self_member,
54 crate::server::organization::handler::add_member,
55 crate::server::organization::handler::remove_member,
56 crate::server::organization::handler::set_member_role,
57 crate::server::organization::handler::ban_member,
58 crate::server::organization::handler::unban_member,
59 crate::server::organization::handler::set_member_permissions,
60 crate::server::organization::handler::list_bans,
61 crate::server::organization::handler::get_ban,
62 crate::server::organization::handler::update_ban,
63 crate::server::organization::handler::unban_by_user,
64 crate::server::organization::handler::list_roles,
65 crate::server::organization::handler::get_role,
66 crate::server::organization::handler::create_role,
67 crate::server::organization::handler::update_role,
68 crate::server::organization::handler::delete_role,
69 crate::server::organization::handler::set_role_permissions,
70 crate::server::organization::handler::assign_role,
71 crate::server::organization::handler::unassign_role,
72 crate::server::organization::handler::join_role,
73 crate::server::organization::handler::leave_role,
74 crate::server::organization::handler::check_permission,
75 crate::server::organization::handler::create_invite,
76 crate::server::organization::handler::list_invites,
77 crate::server::organization::handler::revoke_invite,
78 crate::server::organization::handler::redeem_invite,
79 ),
80 components(schemas(
81 crate::server::protocol::TokenRequest,
82 crate::server::protocol::RevokeRequest,
83 crate::server::health::HealthResponse,
84 crate::server::health::ReadinessResponse,
85 crate::server::health::ComponentCheck,
86 crate::server::oauth::consent::ConsentPreview,
87 crate::server::oauth::consent::ConsentDecision,
88 crate::server::oauth::consent::ConsentForm,
89 crate::server::organization::types::OrganizationSummary,
90 crate::server::organization::types::MemberSummary,
91 crate::server::organization::types::RoleSummary,
92 crate::server::organization::types::InviteSummary,
93 crate::server::organization::types::PermissionGrant,
94 crate::server::organization::types::PermissionCheck,
95 crate::server::organization::types::CreateOrganizationBody,
96 crate::server::organization::types::UpdateOrganizationBody,
97 crate::server::organization::types::AddMemberBody,
98 crate::server::organization::types::SetMemberRoleBody,
99 crate::server::organization::types::BanMemberBody,
100 crate::server::organization::types::CheckPermissionBody,
101 crate::server::organization::types::CreateRoleBody,
102 crate::server::organization::types::SetRolePermissionsBody,
103 crate::server::organization::handler::OrgPath,
104 crate::server::organization::handler::OrgMemberPath,
105 crate::server::organization::handler::OrgRolePath,
106 crate::server::organization::handler::OrgInvitePath,
107 crate::server::organization::handler::OrgListQuery,
108 crate::server::organization::handler::MemberListQuery,
109 crate::server::organization::handler::UpdateRoleBody,
110 crate::server::organization::handler::TransferBody,
111 crate::server::organization::handler::ReasonBody,
112 crate::server::organization::handler::DeleteOrgQuery,
113 crate::server::organization::handler::CreateInviteBody,
114 crate::server::organization::handler::RedeemInviteBody,
115 crate::server::organization::handler::CreateInviteResponse,
116 crate::server::organization::handler::RedeemInviteResponse,
117 crate::server::organization::handler::AssignRoleBody,
118 ))
119)]
120pub struct ApiDoc;
Deleted lib/auth/src/server/router.rs lib/auth/src/server/router.rs +0 −304
@@ -1,304 +0,0 @@
1use actix_web::web;
2
3pub fn configure(cfg: &mut web::ServiceConfig) {
4 cfg.route(
5 "/.well-known/openid-configuration",
6 web::get().to(crate::server::protocol::openid_configuration),
7 );
8 cfg.route(
9 "/.well-known/oauth-authorization-server",
10 web::get().to(crate::server::protocol::metadata),
11 );
12 cfg.route(
13 "/.well-known/jwks.json",
14 web::get().to(crate::server::keys::jwks),
15 );
16 cfg.route("/health", web::get().to(crate::server::health::health));
17 cfg.route("/ready", web::get().to(crate::server::health::ready));
18 cfg.service(web::scope("/api/v1").configure(api));
19}
20
21fn api(cfg: &mut web::ServiceConfig) {
22 cfg.route(
23 "/oauth/authorize",
24 web::get().to(crate::server::protocol::authorize),
25 );
26 cfg.route(
27 "/oauth/token",
28 web::post().to(crate::server::protocol::token),
29 );
30 cfg.route(
31 "/oauth/revoke",
32 web::post().to(crate::server::protocol::revoke),
33 );
34 cfg.route(
35 "/oauth/userinfo",
36 web::get().to(crate::server::oauth::userinfo::userinfo),
37 );
38 cfg.route(
39 "/oauth/userinfo",
40 web::post().to(crate::server::oauth::userinfo::userinfo),
41 );
42 cfg.route(
43 "/oauth/logout",
44 web::get().to(crate::server::oauth::logout::logout),
45 );
46 cfg.route(
47 "/oauth/logout",
48 web::post().to(crate::server::oauth::logout::logout),
49 );
50 cfg.route(
51 "/oauth/consent",
52 web::get().to(crate::server::oauth::consent::preview),
53 );
54 cfg.route(
55 "/oauth/consent",
56 web::post().to(crate::server::oauth::consent::decide),
57 );
58 cfg.route(
59 "/oauth/socket-tickets",
60 web::post().to(crate::server::socket_ticket::issue),
61 );
62 cfg.route(
63 "/oauth/socket-tickets",
64 web::method(actix_web::http::Method::OPTIONS).to(crate::server::protocol::preflight),
65 );
66 cfg.route(
67 "/oauth/token",
68 web::method(actix_web::http::Method::OPTIONS).to(crate::server::protocol::preflight),
69 );
70 cfg.route(
71 "/oauth/revoke",
72 web::method(actix_web::http::Method::OPTIONS).to(crate::server::protocol::preflight),
73 );
74 cfg.route(
75 "/oauth/challenge",
76 web::post().to(crate::server::challenge::handler::challenge),
77 );
78 cfg.route(
79 "/oauth/login",
80 web::post().to(crate::server::login::handler::login),
81 );
82 cfg.route(
83 "/oauth/login/code",
84 web::post().to(crate::server::login::handler::login_code),
85 );
86 cfg.route(
87 "/oauth/login/code/verify",
88 web::post().to(crate::server::login::handler::login_code_verify),
89 );
90 cfg.route(
91 "/oauth/login/verify",
92 web::post().to(crate::server::login::handler::login_verify),
93 );
94 cfg.route(
95 "/oauth/session/logout",
96 web::post().to(crate::server::logout::handler::logout),
97 );
98 cfg.route("/oauth/me", web::get().to(crate::server::me::handler::me));
99 cfg.route(
100 "/oauth/register/code",
101 web::post().to(crate::server::register::handler::register_code),
102 );
103 cfg.route(
104 "/oauth/register",
105 web::post().to(crate::server::register::handler::register),
106 );
107 cfg.route(
108 "/oauth/password/reset",
109 web::post().to(crate::server::password_reset::handler::password_reset_request),
110 );
111 cfg.route(
112 "/oauth/password/reset/confirm",
113 web::post().to(crate::server::password_reset::handler::password_reset),
114 );
115 cfg.route(
116 "/oauth/access-tokens",
117 web::get().to(crate::server::access_token::handler::access_token_list),
118 );
119 cfg.route(
120 "/oauth/access-tokens",
121 web::post().to(crate::server::access_token::handler::access_token_create),
122 );
123 cfg.route(
124 "/oauth/access-tokens/{token_id}",
125 web::delete().to(crate::server::access_token::handler::access_token_revoke),
126 );
127 cfg.route(
128 "/oauth/access-tokens/{token_id}/rotate",
129 web::post().to(crate::server::access_token::handler::access_token_rotate),
130 );
131 cfg.route(
132 "/oauth/app-tokens",
133 web::post().to(crate::server::app_token::handler::app_token_issue),
134 );
135 cfg.route(
136 "/oauth/session/token",
137 web::post().to(crate::server::token::handler::token_issue),
138 );
139 cfg.route("/oauth/jwks.json", web::get().to(crate::server::keys::jwks));
140 cfg.route(
141 "/oauth/ssh-keys",
142 web::get().to(crate::server::ssh_key::handler::ssh_key_list),
143 );
144 cfg.route(
145 "/oauth/ssh-keys",
146 web::post().to(crate::server::ssh_key::handler::ssh_key_add),
147 );
148 cfg.route(
149 "/oauth/ssh-keys/{key_id}",
150 web::delete().to(crate::server::ssh_key::handler::ssh_key_delete),
151 );
152 cfg.route(
153 "/organizations",
154 web::post().to(crate::server::organization::handler::create_organization),
155 );
156 cfg.route(
157 "/organizations",
158 web::get().to(crate::server::organization::handler::list_organizations),
159 );
160 cfg.route(
161 "/organizations/invites/redeem",
162 web::post().to(crate::server::organization::handler::redeem_invite),
163 );
164 cfg.route(
165 "/organizations/{organization_id}",
166 web::get().to(crate::server::organization::handler::get_organization),
167 );
168 cfg.route(
169 "/organizations/{organization_id}",
170 web::patch().to(crate::server::organization::handler::update_organization),
171 );
172 cfg.route(
173 "/organizations/{organization_id}",
174 web::delete().to(crate::server::organization::handler::delete_organization),
175 );
176 cfg.route(
177 "/organizations/{organization_id}/archive",
178 web::post().to(crate::server::organization::handler::archive_organization),
179 );
180 cfg.route(
181 "/organizations/{organization_id}/restore",
182 web::post().to(crate::server::organization::handler::restore_organization),
183 );
184 cfg.route(
185 "/organizations/{organization_id}/transfer",
186 web::post().to(crate::server::organization::handler::transfer_ownership),
187 );
188 cfg.route(
189 "/organizations/{organization_id}/leave",
190 web::post().to(crate::server::organization::handler::leave_organization),
191 );
192 cfg.route(
193 "/organizations/{organization_id}/members",
194 web::get().to(crate::server::organization::handler::list_members),
195 );
196 cfg.route(
197 "/organizations/{organization_id}/members",
198 web::post().to(crate::server::organization::handler::add_member),
199 );
200 cfg.route(
201 "/organizations/{organization_id}/members/@me",
202 web::patch().to(crate::server::organization::handler::update_self_member),
203 );
204 cfg.route(
205 "/organizations/{organization_id}/members/{member_id}",
206 web::get().to(crate::server::organization::handler::get_member),
207 );
208 cfg.route(
209 "/organizations/{organization_id}/members/{member_id}",
210 web::patch().to(crate::server::organization::handler::update_member),
211 );
212 cfg.route(
213 "/organizations/{organization_id}/members/{member_id}",
214 web::delete().to(crate::server::organization::handler::remove_member),
215 );
216 cfg.route(
217 "/organizations/{organization_id}/members/{member_id}/role",
218 web::patch().to(crate::server::organization::handler::set_member_role),
219 );
220 cfg.route(
221 "/organizations/{organization_id}/members/{member_id}/ban",
222 web::post().to(crate::server::organization::handler::ban_member),
223 );
224 cfg.route(
225 "/organizations/{organization_id}/members/{member_id}/unban",
226 web::post().to(crate::server::organization::handler::unban_member),
227 );
228 cfg.route(
229 "/organizations/{organization_id}/members/{member_id}/permissions",
230 web::put().to(crate::server::organization::handler::set_member_permissions),
231 );
232 cfg.route(
233 "/organizations/{organization_id}/bans",
234 web::get().to(crate::server::organization::handler::list_bans),
235 );
236 cfg.route(
237 "/organizations/{organization_id}/bans/{user_id}",
238 web::get().to(crate::server::organization::handler::get_ban),
239 );
240 cfg.route(
241 "/organizations/{organization_id}/bans/{user_id}",
242 web::patch().to(crate::server::organization::handler::update_ban),
243 );
244 cfg.route(
245 "/organizations/{organization_id}/bans/{user_id}",
246 web::delete().to(crate::server::organization::handler::unban_by_user),
247 );
248 cfg.route(
249 "/organizations/{organization_id}/roles",
250 web::get().to(crate::server::organization::handler::list_roles),
251 );
252 cfg.route(
253 "/organizations/{organization_id}/roles",
254 web::post().to(crate::server::organization::handler::create_role),
255 );
256 cfg.route(
257 "/organizations/{organization_id}/roles/assign",
258 web::post().to(crate::server::organization::handler::assign_role),
259 );
260 cfg.route(
261 "/organizations/{organization_id}/roles/unassign",
262 web::post().to(crate::server::organization::handler::unassign_role),
263 );
264 cfg.route(
265 "/organizations/{organization_id}/roles/{role_id}",
266 web::get().to(crate::server::organization::handler::get_role),
267 );
268 cfg.route(
269 "/organizations/{organization_id}/roles/{role_id}",
270 web::patch().to(crate::server::organization::handler::update_role),
271 );
272 cfg.route(
273 "/organizations/{organization_id}/roles/{role_id}/join",
274 web::post().to(crate::server::organization::handler::join_role),
275 );
276 cfg.route(
277 "/organizations/{organization_id}/roles/{role_id}/join",
278 web::delete().to(crate::server::organization::handler::leave_role),
279 );
280 cfg.route(
281 "/organizations/{organization_id}/roles/{role_id}",
282 web::delete().to(crate::server::organization::handler::delete_role),
283 );
284 cfg.route(
285 "/organizations/{organization_id}/roles/{role_id}/permissions",
286 web::put().to(crate::server::organization::handler::set_role_permissions),
287 );
288 cfg.route(
289 "/organizations/{organization_id}/permissions/check",
290 web::post().to(crate::server::organization::handler::check_permission),
291 );
292 cfg.route(
293 "/organizations/{organization_id}/invites",
294 web::post().to(crate::server::organization::handler::create_invite),
295 );
296 cfg.route(
297 "/organizations/{organization_id}/invites",
298 web::get().to(crate::server::organization::handler::list_invites),
299 );
300 cfg.route(
301 "/organizations/{organization_id}/invites/{invite_id}",
302 web::delete().to(crate::server::organization::handler::revoke_invite),
303 );
304}
Modified lib/auth/src/lib.rs lib/auth/src/lib.rs +4 −2 View lib/auth/src/lib.rs
@@ -1,15 +1,17 @@
11//! 认证中心:账号、会话、令牌、组织与 SSH 公钥的唯一入口。
22//!
3//! 服务端逻辑在 `server` / `oauth`,进程内 gRPC 客户端在 `client`;
3//! 服务端逻辑在 `server`,进程启动与关闭在 `runtime`,进程内 gRPC 客户端在 `client`;
44//! 其余基础设施(config、db、email、envelope、events、cache、models、
55//! oltp、protos、queue、session、shutdown、crypt)按原模块名重新导出。
66
77#![recursion_limit = "512"]
88
99pub mod client;
10pub mod oauth;
10pub mod runtime;
1111pub mod server;
1212
13pub use runtime as oauth;
14
1315pub use cache;
1416pub use config::identity as config;
1517pub use crypt;