From 0789ec3885fab163d885ca205e33d54a86d51311 Mon Sep 17 00:00:00 2001 From: bsbds <69835502+bsbds@users.noreply.github.com> Date: Wed, 2 Aug 2023 14:09:12 +0800 Subject: [PATCH] refactor: move xlineapi export to types Signed-off-by: bsbds <69835502+bsbds@users.noreply.github.com> --- xline-client/src/lib.rs | 4 ---- xline-client/src/types/auth.rs | 10 +++++++++- xline-client/src/types/kv.rs | 6 +++++- xline-client/src/types/lease.rs | 5 +++++ xline-client/src/types/watch.rs | 2 ++ xline-client/tests/auth.rs | 13 ++++++------- xline-client/tests/kv.rs | 4 ++-- xline-client/tests/watch.rs | 7 +++++-- 8 files changed, 34 insertions(+), 17 deletions(-) diff --git a/xline-client/src/lib.rs b/xline-client/src/lib.rs index 3e248f79b..523511e75 100644 --- a/xline-client/src/lib.rs +++ b/xline-client/src/lib.rs @@ -175,10 +175,6 @@ pub mod error; mod lease_gen; /// Request type definitions. pub mod types; -/// Xline proto types API -pub mod api_types { - pub use xlineapi::*; -} /// Xline client #[derive(Clone, Debug)] diff --git a/xline-client/src/types/auth.rs b/xline-client/src/types/auth.rs index 508867137..c2b49b542 100644 --- a/xline-client/src/types/auth.rs +++ b/xline-client/src/types/auth.rs @@ -1,5 +1,13 @@ use xline::server::KeyRange; -use xlineapi::Type as PermissionType; + +pub use xlineapi::{ + AuthDisableResponse, AuthEnableResponse, AuthRoleAddResponse, AuthRoleDeleteResponse, + AuthRoleGetResponse, AuthRoleGrantPermissionResponse, AuthRoleListResponse, + AuthRoleRevokePermissionResponse, AuthStatusResponse, AuthUserAddResponse, + AuthUserChangePasswordResponse, AuthUserDeleteResponse, AuthUserGetResponse, + AuthUserGrantRoleResponse, AuthUserListResponse, AuthUserRevokeRoleResponse, + AuthenticateResponse, Type as PermissionType, +}; /// Request for `Authenticate` #[derive(Debug)] diff --git a/xline-client/src/types/kv.rs b/xline-client/src/types/kv.rs index 6adaeb47d..44ddd7000 100644 --- a/xline-client/src/types/kv.rs +++ b/xline-client/src/types/kv.rs @@ -1,5 +1,9 @@ use xline::server::KeyRange; -use xlineapi::{CompareResult, CompareTarget, SortOrder, SortTarget, TargetUnion}; + +pub use xlineapi::{ + CompareResult, CompareTarget, DeleteRangeResponse, PutResponse, RangeResponse, Response, + ResponseOp, SortOrder, SortTarget, TargetUnion, TxnResponse, +}; /// Request type for `Put` #[derive(Debug, PartialEq)] diff --git a/xline-client/src/types/lease.rs b/xline-client/src/types/lease.rs index a54b23ede..04e41ee98 100644 --- a/xline-client/src/types/lease.rs +++ b/xline-client/src/types/lease.rs @@ -1,6 +1,11 @@ use crate::error::{ClientError, Result}; use futures::channel::mpsc::Sender; +pub use xlineapi::{ + LeaseGrantResponse, LeaseKeepAliveResponse, LeaseLeasesResponse, LeaseRevokeResponse, + LeaseStatus, LeaseTimeToLiveResponse, +}; + /// The lease keep alive handle. #[derive(Debug)] pub struct LeaseKeeper { diff --git a/xline-client/src/types/watch.rs b/xline-client/src/types/watch.rs index 70ac49c60..e91c960c6 100644 --- a/xline-client/src/types/watch.rs +++ b/xline-client/src/types/watch.rs @@ -6,6 +6,8 @@ use xlineapi::{RequestUnion, WatchCancelRequest, WatchProgressRequest}; use crate::error::{ClientError, Result}; +pub use xlineapi::{Event, EventType, KeyValue, WatchResponse}; + /// The watching handle. #[derive(Debug)] pub struct Watcher { diff --git a/xline-client/tests/auth.rs b/xline-client/tests/auth.rs index 3f682d7eb..d39e3d122 100644 --- a/xline-client/tests/auth.rs +++ b/xline-client/tests/auth.rs @@ -6,10 +6,9 @@ use xline_client::{ AuthRoleAddRequest, AuthRoleDeleteRequest, AuthRoleGetRequest, AuthRoleGrantPermissionRequest, AuthRoleRevokePermissionRequest, AuthUserAddRequest, AuthUserChangePasswordRequest, AuthUserDeleteRequest, AuthUserGetRequest, - AuthUserGrantRoleRequest, AuthUserRevokeRoleRequest, Permission, + AuthUserGrantRoleRequest, AuthUserRevokeRoleRequest, Permission, PermissionType, }, }; -use xlineapi::Type; mod common; @@ -57,11 +56,11 @@ async fn permission_operations_should_success_in_normal_path() -> Result<()> { let client = client.auth_client(); let role1 = "role1"; - let perm1 = Permission::new(Type::Read, "123"); - let perm2 = Permission::new(Type::Write, "abc").with_from_key(); - let perm3 = Permission::new(Type::Readwrite, "hi").with_range_end("hjj"); - let perm4 = Permission::new(Type::Write, "pp").with_prefix(); - let perm5 = Permission::new(Type::Read, vec![0]).with_from_key(); + let perm1 = Permission::new(PermissionType::Read, "123"); + let perm2 = Permission::new(PermissionType::Write, "abc").with_from_key(); + let perm3 = Permission::new(PermissionType::Readwrite, "hi").with_range_end("hjj"); + let perm4 = Permission::new(PermissionType::Write, "pp").with_prefix(); + let perm5 = Permission::new(PermissionType::Read, vec![0]).with_from_key(); client.role_add(AuthRoleAddRequest::new(role1)).await?; diff --git a/xline-client/tests/kv.rs b/xline-client/tests/kv.rs index 9cbde81e6..8d86da4e1 100644 --- a/xline-client/tests/kv.rs +++ b/xline-client/tests/kv.rs @@ -4,10 +4,10 @@ use test_macros::abort_on_panic; use xline_client::{ error::Result, types::kv::{ - CompactionRequest, Compare, DeleteRangeRequest, PutRequest, RangeRequest, TxnOp, TxnRequest, + CompactionRequest, Compare, CompareResult, DeleteRangeRequest, PutRequest, RangeRequest, + TxnOp, TxnRequest, }, }; -use xlineapi::CompareResult; mod common; diff --git a/xline-client/tests/watch.rs b/xline-client/tests/watch.rs index 49b2ecf93..788c66fa0 100644 --- a/xline-client/tests/watch.rs +++ b/xline-client/tests/watch.rs @@ -1,7 +1,10 @@ //! The following tests are originally from `etcd-client` use crate::common::get_cluster_client; -use xline_client::{error::Result, types::kv::PutRequest, types::watch::WatchRequest}; -use xlineapi::EventType; +use xline_client::{ + error::Result, + types::kv::PutRequest, + types::watch::{EventType, WatchRequest}, +}; mod common;