rabbitmq_http_client/blocking_api/
limits.rs1use crate::{
16 commons::{UserLimitTarget, VirtualHostLimitTarget},
17 path,
18 requests::EnforcedLimitParams,
19 responses,
20};
21use reqwest::StatusCode;
22use serde_json::json;
23
24use super::client::{Client, Result};
25use std::fmt::Display;
26
27impl<E, U, P> Client<E, U, P>
28where
29 E: Display,
30 U: Display,
31 P: Display,
32{
33 pub fn set_user_limit(
35 &self,
36 username: &str,
37 limit: EnforcedLimitParams<UserLimitTarget>,
38 ) -> Result<()> {
39 let body = json!({"value": limit.value});
40 let _response = self.http_put(
41 path!("user-limits", username, limit.kind),
42 &body,
43 None,
44 None,
45 )?;
46 Ok(())
47 }
48
49 pub fn clear_user_limit(&self, username: &str, kind: UserLimitTarget) -> Result<()> {
51 let _response = self.http_delete(path!("user-limits", username, kind), None, None)?;
52 Ok(())
53 }
54
55 pub fn list_all_user_limits(&self) -> Result<Vec<responses::UserLimits>> {
57 let response = self.http_get("user-limits", None, None)?;
58 let response = response.json()?;
59 Ok(response)
60 }
61
62 pub fn list_user_limits(&self, username: &str) -> Result<Vec<responses::UserLimits>> {
64 let response = self.http_get(path!("user-limits", username), None, None)?;
65 let response = response.json()?;
66 Ok(response)
67 }
68
69 pub fn set_vhost_limit(
73 &self,
74 vhost: &str,
75 limit: EnforcedLimitParams<VirtualHostLimitTarget>,
76 ) -> Result<()> {
77 let body = json!({"value": limit.value});
78 let _response =
79 self.http_put(path!("vhost-limits", vhost, limit.kind), &body, None, None)?;
80 Ok(())
81 }
82
83 pub fn clear_vhost_limit(&self, vhost: &str, kind: VirtualHostLimitTarget) -> Result<()> {
87 let _response = self.http_delete(
88 path!("vhost-limits", vhost, kind),
89 Some(StatusCode::NOT_FOUND),
90 None,
91 )?;
92 Ok(())
93 }
94
95 pub fn list_all_vhost_limits(&self) -> Result<Vec<responses::VirtualHostLimits>> {
99 let response = self.http_get("vhost-limits", None, None)?;
100 let response = response.json()?;
101 Ok(response)
102 }
103
104 pub fn list_vhost_limits(&self, vhost: &str) -> Result<Vec<responses::VirtualHostLimits>> {
108 let response = self.http_get(path!("vhost-limits", vhost), None, None)?;
109 let response = response.json()?;
110 Ok(response)
111 }
112}