Skip to content

Commit

Permalink
chore: use shorter name for management API
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Mar 14, 2024
1 parent 9b2e39c commit a115a15
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 69 deletions.
18 changes: 5 additions & 13 deletions src/query/management/src/network_policy/network_policy_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,13 @@ use databend_common_meta_types::SeqV;

#[async_trait::async_trait]
pub trait NetworkPolicyApi: Sync + Send {
async fn add_network_policy(
&self,
network_policy: NetworkPolicy,
create_option: &CreateOption,
) -> Result<()>;
async fn add(&self, network_policy: NetworkPolicy, create_option: &CreateOption) -> Result<()>;

async fn update_network_policy(
&self,
network_policy: NetworkPolicy,
seq: MatchSeq,
) -> Result<u64>;
async fn update(&self, network_policy: NetworkPolicy, seq: MatchSeq) -> Result<u64>;

async fn drop_network_policy(&self, name: &str, seq: MatchSeq) -> Result<()>;
async fn drop(&self, name: &str, seq: MatchSeq) -> Result<()>;

async fn get_network_policy(&self, name: &str, seq: MatchSeq) -> Result<SeqV<NetworkPolicy>>;
async fn get(&self, name: &str, seq: MatchSeq) -> Result<SeqV<NetworkPolicy>>;

async fn get_network_policies(&self) -> Result<Vec<NetworkPolicy>>;
async fn list(&self) -> Result<Vec<NetworkPolicy>>;
}
18 changes: 5 additions & 13 deletions src/query/management/src/network_policy/network_policy_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ impl NetworkPolicyMgr {
impl NetworkPolicyApi for NetworkPolicyMgr {
#[async_backtrace::framed]
#[minitrace::trace]
async fn add_network_policy(
&self,
network_policy: NetworkPolicy,
create_option: &CreateOption,
) -> Result<()> {
async fn add(&self, network_policy: NetworkPolicy, create_option: &CreateOption) -> Result<()> {
let ident = self.ident(network_policy.name.as_str());

let seq = MatchSeq::from(*create_option);
Expand All @@ -85,11 +81,7 @@ impl NetworkPolicyApi for NetworkPolicyMgr {

#[async_backtrace::framed]
#[minitrace::trace]
async fn update_network_policy(
&self,
network_policy: NetworkPolicy,
match_seq: MatchSeq,
) -> Result<u64> {
async fn update(&self, network_policy: NetworkPolicy, match_seq: MatchSeq) -> Result<u64> {
let ident = self.ident(network_policy.name.as_str());
let upsert = UpsertPB::update(ident, network_policy.clone()).with(match_seq);

Expand All @@ -106,7 +98,7 @@ impl NetworkPolicyApi for NetworkPolicyMgr {

#[async_backtrace::framed]
#[minitrace::trace]
async fn drop_network_policy(&self, name: &str, seq: MatchSeq) -> Result<()> {
async fn drop(&self, name: &str, seq: MatchSeq) -> Result<()> {
let ident = self.ident(name);

let upsert = UpsertPB::delete(ident).with(seq);
Expand All @@ -124,7 +116,7 @@ impl NetworkPolicyApi for NetworkPolicyMgr {

#[async_backtrace::framed]
#[minitrace::trace]
async fn get_network_policy(&self, name: &str, seq: MatchSeq) -> Result<SeqV<NetworkPolicy>> {
async fn get(&self, name: &str, seq: MatchSeq) -> Result<SeqV<NetworkPolicy>> {
let ident = self.ident(name);

let res = self.kv_api.get_pb(&ident).await?;
Expand All @@ -144,7 +136,7 @@ impl NetworkPolicyApi for NetworkPolicyMgr {

#[async_backtrace::framed]
#[minitrace::trace]
async fn get_network_policies(&self) -> Result<Vec<NetworkPolicy>> {
async fn list(&self) -> Result<Vec<NetworkPolicy>> {
let dir_name = DirName::new(self.ident("dummy"));

let values = self.kv_api.list_pb_values(&dir_name).await?;
Expand Down
14 changes: 5 additions & 9 deletions src/query/management/src/password_policy/password_policy_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@ use databend_common_meta_types::SeqV;

#[async_trait::async_trait]
pub trait PasswordPolicyApi: Sync + Send {
async fn add_password_policy(
async fn add(
&self,
password_policy: PasswordPolicy,
create_option: &CreateOption,
) -> Result<()>;

async fn update_password_policy(
&self,
password_policy: PasswordPolicy,
seq: MatchSeq,
) -> Result<u64>;
async fn update(&self, password_policy: PasswordPolicy, seq: MatchSeq) -> Result<u64>;

async fn drop_password_policy(&self, name: &str, seq: MatchSeq) -> Result<()>;
async fn drop(&self, name: &str, seq: MatchSeq) -> Result<()>;

async fn get_password_policy(&self, name: &str, seq: MatchSeq) -> Result<SeqV<PasswordPolicy>>;
async fn get(&self, name: &str, seq: MatchSeq) -> Result<SeqV<PasswordPolicy>>;

async fn get_password_policies(&self) -> Result<Vec<PasswordPolicy>>;
async fn list(&self) -> Result<Vec<PasswordPolicy>>;
}
14 changes: 5 additions & 9 deletions src/query/management/src/password_policy/password_policy_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl PasswordPolicyMgr {
impl PasswordPolicyApi for PasswordPolicyMgr {
#[async_backtrace::framed]
#[minitrace::trace]
async fn add_password_policy(
async fn add(
&self,
password_policy: PasswordPolicy,
create_option: &CreateOption,
Expand All @@ -85,11 +85,7 @@ impl PasswordPolicyApi for PasswordPolicyMgr {

#[async_backtrace::framed]
#[minitrace::trace]
async fn update_password_policy(
&self,
password_policy: PasswordPolicy,
match_seq: MatchSeq,
) -> Result<u64> {
async fn update(&self, password_policy: PasswordPolicy, match_seq: MatchSeq) -> Result<u64> {
let ident = self.ident(&password_policy.name);

let upsert = UpsertPB::update(ident, password_policy.clone()).with(match_seq);
Expand All @@ -107,7 +103,7 @@ impl PasswordPolicyApi for PasswordPolicyMgr {

#[async_backtrace::framed]
#[minitrace::trace]
async fn drop_password_policy(&self, name: &str, seq: MatchSeq) -> Result<()> {
async fn drop(&self, name: &str, seq: MatchSeq) -> Result<()> {
let ident = self.ident(name);

let upsert = UpsertPB::delete(ident).with(seq);
Expand All @@ -125,7 +121,7 @@ impl PasswordPolicyApi for PasswordPolicyMgr {

#[async_backtrace::framed]
#[minitrace::trace]
async fn get_password_policy(&self, name: &str, seq: MatchSeq) -> Result<SeqV<PasswordPolicy>> {
async fn get(&self, name: &str, seq: MatchSeq) -> Result<SeqV<PasswordPolicy>> {
let ident = self.ident(name);

let seqv = self.kv_api.get_pb(&ident).await?;
Expand All @@ -146,7 +142,7 @@ impl PasswordPolicyApi for PasswordPolicyMgr {

#[async_backtrace::framed]
#[minitrace::trace]
async fn get_password_policies(&self) -> Result<Vec<PasswordPolicy>> {
async fn list(&self) -> Result<Vec<PasswordPolicy>> {
let dir_name = DirName::new(self.ident("dummy"));

let values = self.kv_api.list_pb_values(&dir_name).await?;
Expand Down
17 changes: 6 additions & 11 deletions src/query/users/src/network_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ impl UserApiProvider {
create_option: &CreateOption,
) -> Result<()> {
let client = self.network_policy_api(tenant);
client
.add_network_policy(network_policy, create_option)
.await
client.add(network_policy, create_option).await
}

// Update network policy.
Expand All @@ -50,7 +48,7 @@ impl UserApiProvider {
if_exists: bool,
) -> Result<Option<u64>> {
let client = self.network_policy_api(tenant);
let seq_network_policy = match client.get_network_policy(name, MatchSeq::GE(0)).await {
let seq_network_policy = match client.get(name, MatchSeq::GE(0)).await {
Ok(seq_network_policy) => seq_network_policy,
Err(e) => {
if if_exists && e.code() == ErrorCode::UNKNOWN_NETWORK_POLICY {
Expand All @@ -74,10 +72,7 @@ impl UserApiProvider {
}
network_policy.update_on = Some(Utc::now());

match client
.update_network_policy(network_policy, MatchSeq::Exact(seq))
.await
{
match client.update(network_policy, MatchSeq::Exact(seq)).await {
Ok(res) => Ok(Some(res)),
Err(e) => Err(e.add_message_back(" (while alter network policy).")),
}
Expand All @@ -104,7 +99,7 @@ impl UserApiProvider {
}

let client = self.network_policy_api(tenant);
match client.drop_network_policy(name, MatchSeq::GE(1)).await {
match client.drop(name, MatchSeq::GE(1)).await {
Ok(res) => Ok(res),
Err(e) => {
if if_exists && e.code() == ErrorCode::UNKNOWN_NETWORK_POLICY {
Expand Down Expand Up @@ -139,7 +134,7 @@ impl UserApiProvider {
name: &str,
) -> Result<NetworkPolicy> {
let client = self.network_policy_api(tenant);
let network_policy = client.get_network_policy(name, MatchSeq::GE(0)).await?.data;
let network_policy = client.get(name, MatchSeq::GE(0)).await?.data;
Ok(network_policy)
}

Expand All @@ -151,7 +146,7 @@ impl UserApiProvider {
) -> Result<Vec<NetworkPolicy>> {
let client = self.network_policy_api(tenant);
let network_policies = client
.get_network_policies()
.list()
.await
.map_err(|e| e.add_message_back(" (while get network policies)."))?;
Ok(network_policies)
Expand Down
20 changes: 6 additions & 14 deletions src/query/users/src/password_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ impl UserApiProvider {
check_password_policy(&password_policy)?;

let client = self.password_policy_api(tenant);
client
.add_password_policy(password_policy, create_option)
.await
client.add(password_policy, create_option).await
}

// Update password policy.
Expand All @@ -99,7 +97,7 @@ impl UserApiProvider {
if_exists: bool,
) -> Result<Option<u64>> {
let client = self.password_policy_api(tenant);
let seq_password_policy = match client.get_password_policy(name, MatchSeq::GE(0)).await {
let seq_password_policy = match client.get(name, MatchSeq::GE(0)).await {
Ok(seq_password_policy) => seq_password_policy,
Err(e) => {
if if_exists && e.code() == ErrorCode::UNKNOWN_PASSWORD_POLICY {
Expand Down Expand Up @@ -152,10 +150,7 @@ impl UserApiProvider {

password_policy.update_on = Some(Utc::now());

match client
.update_password_policy(password_policy, MatchSeq::Exact(seq))
.await
{
match client.update(password_policy, MatchSeq::Exact(seq)).await {
Ok(res) => Ok(Some(res)),
Err(e) => Err(e.add_message_back(" (while alter password policy).")),
}
Expand All @@ -182,7 +177,7 @@ impl UserApiProvider {
}

let client = self.password_policy_api(tenant);
match client.drop_password_policy(name, MatchSeq::GE(1)).await {
match client.drop(name, MatchSeq::GE(1)).await {
Ok(res) => Ok(res),
Err(e) => {
if if_exists && e.code() == ErrorCode::UNKNOWN_PASSWORD_POLICY {
Expand Down Expand Up @@ -221,10 +216,7 @@ impl UserApiProvider {
name: &str,
) -> Result<PasswordPolicy> {
let client = self.password_policy_api(tenant);
let password_policy = client
.get_password_policy(name, MatchSeq::GE(0))
.await?
.data;
let password_policy = client.get(name, MatchSeq::GE(0)).await?.data;
Ok(password_policy)
}

Expand All @@ -236,7 +228,7 @@ impl UserApiProvider {
) -> Result<Vec<PasswordPolicy>> {
let client = self.password_policy_api(tenant);
let password_policies = client
.get_password_policies()
.list()
.await
.map_err(|e| e.add_message_back(" (while get password policies)."))?;
Ok(password_policies)
Expand Down

0 comments on commit a115a15

Please sign in to comment.