Skip to content

Commit

Permalink
chore: refine doc in auth
Browse files Browse the repository at this point in the history
Signed-off-by: bsbds <[email protected]>
  • Loading branch information
bsbds committed Aug 3, 2023
1 parent 3e3dbf3 commit 1bd9bb1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 41 deletions.
62 changes: 24 additions & 38 deletions xline-client/src/types/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ pub struct AuthenticateRequest {

impl AuthenticateRequest {
/// Creates a new `AuthenticateRequest`.
///
/// `name` is the name of the user to authenticate,
/// `password` is the password of the user.
#[inline]
pub fn new(name: impl Into<String>, password: impl Into<String>) -> Self {
pub fn new(user_name: impl Into<String>, user_password: impl Into<String>) -> Self {
Self {
inner: xlineapi::AuthenticateRequest {
name: name.into(),
password: password.into(),
name: user_name.into(),
password: user_password.into(),
},
}
}
Expand All @@ -40,13 +37,12 @@ pub struct AuthUserAddRequest {

impl AuthUserAddRequest {
/// Creates a new `AuthUserAddRequest`.
///
/// `name` is the name of the user to add.
#[inline]
pub fn new(name: impl Into<String>) -> Self {
pub fn new(user_name: impl Into<String>) -> Self {
Self {
inner: xlineapi::AuthUserAddRequest {
name: name.into(),
name: user_name.into(),
options: Some(xlineapi::UserAddOptions { no_password: true }),
..Default::default()
},
}
Expand All @@ -57,14 +53,7 @@ impl AuthUserAddRequest {
#[must_use]
pub fn with_pwd(mut self, password: impl Into<String>) -> Self {
self.inner.password = password.into();
self
}

/// If set, Xline will add the user without password, password set with `with_pwd` will be ignored.
#[inline]
#[must_use]
pub const fn with_no_pwd(mut self) -> Self {
self.inner.options = Some(xlineapi::UserAddOptions { no_password: true });
self.inner.options = Some(xlineapi::UserAddOptions { no_password: false });
self
}
}
Expand All @@ -85,12 +74,12 @@ pub struct AuthUserGetRequest {

impl AuthUserGetRequest {
/// Creates a new `AuthUserGetRequest`.
///
/// `name` is the name of the user to get
#[inline]
pub fn new(name: impl Into<String>) -> Self {
pub fn new(user_name: impl Into<String>) -> Self {
Self {
inner: xlineapi::AuthUserGetRequest { name: name.into() },
inner: xlineapi::AuthUserGetRequest {
name: user_name.into(),
},
}
}
}
Expand All @@ -111,12 +100,12 @@ pub struct AuthUserDeleteRequest {

impl AuthUserDeleteRequest {
/// Creates a new `AuthUserDeleteRequest`.
///
/// `name` is the name of the user to delete.
#[inline]
pub fn new(name: impl Into<String>) -> Self {
pub fn new(user_name: impl Into<String>) -> Self {
Self {
inner: xlineapi::AuthUserDeleteRequest { name: name.into() },
inner: xlineapi::AuthUserDeleteRequest {
name: user_name.into(),
},
}
}
}
Expand All @@ -137,15 +126,12 @@ pub struct AuthUserChangePasswordRequest {

impl AuthUserChangePasswordRequest {
/// Creates a new `AuthUserChangePasswordRequest`.
///
/// `name` is the name of the user to change password,
/// `password` is the new password of the user.
#[inline]
pub fn new(name: impl Into<String>, password: impl Into<String>) -> Self {
pub fn new(user_name: impl Into<String>, new_password: impl Into<String>) -> Self {
Self {
inner: xlineapi::AuthUserChangePasswordRequest {
name: name.into(),
password: password.into(),
name: user_name.into(),
password: new_password.into(),
hashed_password: String::new(),
},
}
Expand All @@ -169,13 +155,13 @@ pub struct AuthUserGrantRoleRequest {
impl AuthUserGrantRoleRequest {
/// Creates a new `AuthUserGrantRoleRequest`
///
/// `name` is the name of the user to grant role,
/// `user_name` is the name of the user to grant role,
/// `role` is the role name to grant.
#[inline]
pub fn new(name: impl Into<String>, role: impl Into<String>) -> Self {
pub fn new(user_name: impl Into<String>, role: impl Into<String>) -> Self {
Self {
inner: xlineapi::AuthUserGrantRoleRequest {
user: name.into(),
user: user_name.into(),
role: role.into(),
},
}
Expand All @@ -199,13 +185,13 @@ pub struct AuthUserRevokeRoleRequest {
impl AuthUserRevokeRoleRequest {
/// Creates a new `AuthUserRevokeRoleRequest`
///
/// `name` is the name of the user to revoke role,
/// `user_name` is the name of the user to revoke role,
/// `role` is the role name to revoke.
#[inline]
pub fn new(name: impl Into<String>, role: impl Into<String>) -> Self {
pub fn new(user_name: impl Into<String>, role: impl Into<String>) -> Self {
Self {
inner: xlineapi::AuthUserRevokeRoleRequest {
name: name.into(),
name: user_name.into(),
role: role.into(),
},
}
Expand Down
4 changes: 1 addition & 3 deletions xline-client/tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ async fn user_role_operations_should_success_in_normal_path() -> Result<()> {
let role1 = "role1";
let role2 = "role2";

client
.user_add(AuthUserAddRequest::new(name1).with_no_pwd())
.await?;
client.user_add(AuthUserAddRequest::new(name1)).await?;
client.role_add(AuthRoleAddRequest::new(role1)).await?;
client.role_add(AuthRoleAddRequest::new(role2)).await?;

Expand Down

0 comments on commit 1bd9bb1

Please sign in to comment.