pub struct AuthClient { /* private fields */ }Implementations§
Source§impl AuthClient
impl AuthClient
Sourcepub async fn health(&self) -> Result<Value>
pub async fn health(&self) -> Result<Value>
Examples found in repository?
examples/support/utils.rs (line 82)
60pub async fn create_client() -> Result<Client, Box<dyn Error>> {
61 let endpoint =
62 env::var("MUBIT_ENDPOINT").unwrap_or_else(|_| "http://127.0.0.1:3000".to_string());
63 let grpc_endpoint =
64 env::var("MUBIT_GRPC_ENDPOINT").unwrap_or_else(|_| "127.0.0.1:50051".to_string());
65 let timeout_ms = env::var("MUBIT_TIMEOUT_MS")
66 .ok()
67 .and_then(|raw| raw.parse::<u64>().ok())
68 .unwrap_or(30_000);
69
70 let api_key =
71 env::var("MUBIT_API_KEY").map_err(|_| boxed_error("MUBIT_API_KEY must be set"))?;
72
73 let mut cfg = ClientConfig::new(endpoint).transport("http");
74 cfg.grpc_endpoint = Some(grpc_endpoint);
75 cfg.timeout_ms = timeout_ms;
76 cfg.api_key = Some(api_key.clone());
77
78 let client = Client::new(cfg)?;
79 client.set_transport(TransportMode::Http);
80 client.set_api_key(Some(api_key));
81
82 let _ = client.auth.health().await?;
83
84 Ok(client)
85}More examples
examples/internal/auth_lifecycle.rs (line 20)
10async fn main() -> Result<(), Box<dyn Error>> {
11 let name = "internal_auth_lifecycle";
12 let started = Instant::now();
13 let client = create_client().await?;
14 let username = format!("sdk_example_{}", SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_millis());
15 let mut passed = true;
16 let mut detail = "validated raw auth lifecycle".to_string();
17 let mut metrics = json!({});
18
19 let scenario = async {
20 let health = client.auth.health().await?;
21 let created = client.auth.create_user(json!({"username": username, "role": "user"})).await?;
22 let listed = client.auth.list_users(json!({})).await?;
23 let rotated = client.auth.rotate_user_api_key(json!({"username": username})).await?;
24 let fetched = client.auth.get_user(json!({"username": username})).await?;
25 let revoked = client.auth.revoke_user_api_key(json!({"username": username})).await?;
26 let deleted = client.auth.delete_user(json!({"username": username})).await?;
27 let listed_users = listed
28 .as_array()
29 .cloned()
30 .or_else(|| listed.get("users").and_then(Value::as_array).cloned())
31 .unwrap_or_default();
32 let fetched_user = fetched.get("user").unwrap_or(&fetched);
33
34 require(!health.is_null(), format!("auth health failed: {health}"))?;
35 require(created.get("success").and_then(Value::as_bool).unwrap_or(true) || created.get("api_key").is_some(), format!("create_user failed: {created}"))?;
36 require(listed_users.iter().any(|item| item.get("username").and_then(Value::as_str) == Some(username.as_str())), format!("list_users missing created user: {listed}"))?;
37 require(rotated.get("success").and_then(Value::as_bool).unwrap_or(true) || rotated.get("api_key").is_some(), format!("rotate_user_api_key failed: {rotated}"))?;
38 require(fetched_user.get("username").and_then(Value::as_str) == Some(username.as_str()), format!("get_user failed: {fetched}"))?;
39 require(revoked.get("success").and_then(Value::as_bool).unwrap_or(true), format!("revoke_user_api_key failed: {revoked}"))?;
40 require(deleted.get("success").and_then(Value::as_bool).unwrap_or(true), format!("delete_user failed: {deleted}"))?;
41
42 metrics = json!({"username": username});
43 Ok::<(), Box<dyn Error>>(())
44 }.await;
45
46 if let Err(err) = scenario { passed = false; detail = err.to_string(); }
47 print_summary(name, passed, &detail, &metrics, started.elapsed().as_secs_f64(), true);
48 if passed { Ok(()) } else { Err(boxed_error(detail)) }
49}pub fn set_api_key(&self, api_key: Option<String>)
pub fn set_token(&self, token: Option<String>)
pub fn set_run_id(&self, run_id: Option<String>)
Source§impl AuthClient
impl AuthClient
Sourcepub async fn create_user<T: Serialize>(&self, payload: T) -> Result<Value>
pub async fn create_user<T: Serialize>(&self, payload: T) -> Result<Value>
Examples found in repository?
examples/internal/auth_lifecycle.rs (line 21)
10async fn main() -> Result<(), Box<dyn Error>> {
11 let name = "internal_auth_lifecycle";
12 let started = Instant::now();
13 let client = create_client().await?;
14 let username = format!("sdk_example_{}", SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_millis());
15 let mut passed = true;
16 let mut detail = "validated raw auth lifecycle".to_string();
17 let mut metrics = json!({});
18
19 let scenario = async {
20 let health = client.auth.health().await?;
21 let created = client.auth.create_user(json!({"username": username, "role": "user"})).await?;
22 let listed = client.auth.list_users(json!({})).await?;
23 let rotated = client.auth.rotate_user_api_key(json!({"username": username})).await?;
24 let fetched = client.auth.get_user(json!({"username": username})).await?;
25 let revoked = client.auth.revoke_user_api_key(json!({"username": username})).await?;
26 let deleted = client.auth.delete_user(json!({"username": username})).await?;
27 let listed_users = listed
28 .as_array()
29 .cloned()
30 .or_else(|| listed.get("users").and_then(Value::as_array).cloned())
31 .unwrap_or_default();
32 let fetched_user = fetched.get("user").unwrap_or(&fetched);
33
34 require(!health.is_null(), format!("auth health failed: {health}"))?;
35 require(created.get("success").and_then(Value::as_bool).unwrap_or(true) || created.get("api_key").is_some(), format!("create_user failed: {created}"))?;
36 require(listed_users.iter().any(|item| item.get("username").and_then(Value::as_str) == Some(username.as_str())), format!("list_users missing created user: {listed}"))?;
37 require(rotated.get("success").and_then(Value::as_bool).unwrap_or(true) || rotated.get("api_key").is_some(), format!("rotate_user_api_key failed: {rotated}"))?;
38 require(fetched_user.get("username").and_then(Value::as_str) == Some(username.as_str()), format!("get_user failed: {fetched}"))?;
39 require(revoked.get("success").and_then(Value::as_bool).unwrap_or(true), format!("revoke_user_api_key failed: {revoked}"))?;
40 require(deleted.get("success").and_then(Value::as_bool).unwrap_or(true), format!("delete_user failed: {deleted}"))?;
41
42 metrics = json!({"username": username});
43 Ok::<(), Box<dyn Error>>(())
44 }.await;
45
46 if let Err(err) = scenario { passed = false; detail = err.to_string(); }
47 print_summary(name, passed, &detail, &metrics, started.elapsed().as_secs_f64(), true);
48 if passed { Ok(()) } else { Err(boxed_error(detail)) }
49}Sourcepub async fn rotate_user_api_key<T: Serialize>(
&self,
payload: T,
) -> Result<Value>
pub async fn rotate_user_api_key<T: Serialize>( &self, payload: T, ) -> Result<Value>
Examples found in repository?
examples/internal/auth_lifecycle.rs (line 23)
10async fn main() -> Result<(), Box<dyn Error>> {
11 let name = "internal_auth_lifecycle";
12 let started = Instant::now();
13 let client = create_client().await?;
14 let username = format!("sdk_example_{}", SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_millis());
15 let mut passed = true;
16 let mut detail = "validated raw auth lifecycle".to_string();
17 let mut metrics = json!({});
18
19 let scenario = async {
20 let health = client.auth.health().await?;
21 let created = client.auth.create_user(json!({"username": username, "role": "user"})).await?;
22 let listed = client.auth.list_users(json!({})).await?;
23 let rotated = client.auth.rotate_user_api_key(json!({"username": username})).await?;
24 let fetched = client.auth.get_user(json!({"username": username})).await?;
25 let revoked = client.auth.revoke_user_api_key(json!({"username": username})).await?;
26 let deleted = client.auth.delete_user(json!({"username": username})).await?;
27 let listed_users = listed
28 .as_array()
29 .cloned()
30 .or_else(|| listed.get("users").and_then(Value::as_array).cloned())
31 .unwrap_or_default();
32 let fetched_user = fetched.get("user").unwrap_or(&fetched);
33
34 require(!health.is_null(), format!("auth health failed: {health}"))?;
35 require(created.get("success").and_then(Value::as_bool).unwrap_or(true) || created.get("api_key").is_some(), format!("create_user failed: {created}"))?;
36 require(listed_users.iter().any(|item| item.get("username").and_then(Value::as_str) == Some(username.as_str())), format!("list_users missing created user: {listed}"))?;
37 require(rotated.get("success").and_then(Value::as_bool).unwrap_or(true) || rotated.get("api_key").is_some(), format!("rotate_user_api_key failed: {rotated}"))?;
38 require(fetched_user.get("username").and_then(Value::as_str) == Some(username.as_str()), format!("get_user failed: {fetched}"))?;
39 require(revoked.get("success").and_then(Value::as_bool).unwrap_or(true), format!("revoke_user_api_key failed: {revoked}"))?;
40 require(deleted.get("success").and_then(Value::as_bool).unwrap_or(true), format!("delete_user failed: {deleted}"))?;
41
42 metrics = json!({"username": username});
43 Ok::<(), Box<dyn Error>>(())
44 }.await;
45
46 if let Err(err) = scenario { passed = false; detail = err.to_string(); }
47 print_summary(name, passed, &detail, &metrics, started.elapsed().as_secs_f64(), true);
48 if passed { Ok(()) } else { Err(boxed_error(detail)) }
49}Sourcepub async fn revoke_user_api_key<T: Serialize>(
&self,
payload: T,
) -> Result<Value>
pub async fn revoke_user_api_key<T: Serialize>( &self, payload: T, ) -> Result<Value>
Examples found in repository?
examples/internal/auth_lifecycle.rs (line 25)
10async fn main() -> Result<(), Box<dyn Error>> {
11 let name = "internal_auth_lifecycle";
12 let started = Instant::now();
13 let client = create_client().await?;
14 let username = format!("sdk_example_{}", SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_millis());
15 let mut passed = true;
16 let mut detail = "validated raw auth lifecycle".to_string();
17 let mut metrics = json!({});
18
19 let scenario = async {
20 let health = client.auth.health().await?;
21 let created = client.auth.create_user(json!({"username": username, "role": "user"})).await?;
22 let listed = client.auth.list_users(json!({})).await?;
23 let rotated = client.auth.rotate_user_api_key(json!({"username": username})).await?;
24 let fetched = client.auth.get_user(json!({"username": username})).await?;
25 let revoked = client.auth.revoke_user_api_key(json!({"username": username})).await?;
26 let deleted = client.auth.delete_user(json!({"username": username})).await?;
27 let listed_users = listed
28 .as_array()
29 .cloned()
30 .or_else(|| listed.get("users").and_then(Value::as_array).cloned())
31 .unwrap_or_default();
32 let fetched_user = fetched.get("user").unwrap_or(&fetched);
33
34 require(!health.is_null(), format!("auth health failed: {health}"))?;
35 require(created.get("success").and_then(Value::as_bool).unwrap_or(true) || created.get("api_key").is_some(), format!("create_user failed: {created}"))?;
36 require(listed_users.iter().any(|item| item.get("username").and_then(Value::as_str) == Some(username.as_str())), format!("list_users missing created user: {listed}"))?;
37 require(rotated.get("success").and_then(Value::as_bool).unwrap_or(true) || rotated.get("api_key").is_some(), format!("rotate_user_api_key failed: {rotated}"))?;
38 require(fetched_user.get("username").and_then(Value::as_str) == Some(username.as_str()), format!("get_user failed: {fetched}"))?;
39 require(revoked.get("success").and_then(Value::as_bool).unwrap_or(true), format!("revoke_user_api_key failed: {revoked}"))?;
40 require(deleted.get("success").and_then(Value::as_bool).unwrap_or(true), format!("delete_user failed: {deleted}"))?;
41
42 metrics = json!({"username": username});
43 Ok::<(), Box<dyn Error>>(())
44 }.await;
45
46 if let Err(err) = scenario { passed = false; detail = err.to_string(); }
47 print_summary(name, passed, &detail, &metrics, started.elapsed().as_secs_f64(), true);
48 if passed { Ok(()) } else { Err(boxed_error(detail)) }
49}Sourcepub async fn list_users<T: Serialize>(&self, payload: T) -> Result<Value>
pub async fn list_users<T: Serialize>(&self, payload: T) -> Result<Value>
Examples found in repository?
examples/internal/auth_lifecycle.rs (line 22)
10async fn main() -> Result<(), Box<dyn Error>> {
11 let name = "internal_auth_lifecycle";
12 let started = Instant::now();
13 let client = create_client().await?;
14 let username = format!("sdk_example_{}", SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_millis());
15 let mut passed = true;
16 let mut detail = "validated raw auth lifecycle".to_string();
17 let mut metrics = json!({});
18
19 let scenario = async {
20 let health = client.auth.health().await?;
21 let created = client.auth.create_user(json!({"username": username, "role": "user"})).await?;
22 let listed = client.auth.list_users(json!({})).await?;
23 let rotated = client.auth.rotate_user_api_key(json!({"username": username})).await?;
24 let fetched = client.auth.get_user(json!({"username": username})).await?;
25 let revoked = client.auth.revoke_user_api_key(json!({"username": username})).await?;
26 let deleted = client.auth.delete_user(json!({"username": username})).await?;
27 let listed_users = listed
28 .as_array()
29 .cloned()
30 .or_else(|| listed.get("users").and_then(Value::as_array).cloned())
31 .unwrap_or_default();
32 let fetched_user = fetched.get("user").unwrap_or(&fetched);
33
34 require(!health.is_null(), format!("auth health failed: {health}"))?;
35 require(created.get("success").and_then(Value::as_bool).unwrap_or(true) || created.get("api_key").is_some(), format!("create_user failed: {created}"))?;
36 require(listed_users.iter().any(|item| item.get("username").and_then(Value::as_str) == Some(username.as_str())), format!("list_users missing created user: {listed}"))?;
37 require(rotated.get("success").and_then(Value::as_bool).unwrap_or(true) || rotated.get("api_key").is_some(), format!("rotate_user_api_key failed: {rotated}"))?;
38 require(fetched_user.get("username").and_then(Value::as_str) == Some(username.as_str()), format!("get_user failed: {fetched}"))?;
39 require(revoked.get("success").and_then(Value::as_bool).unwrap_or(true), format!("revoke_user_api_key failed: {revoked}"))?;
40 require(deleted.get("success").and_then(Value::as_bool).unwrap_or(true), format!("delete_user failed: {deleted}"))?;
41
42 metrics = json!({"username": username});
43 Ok::<(), Box<dyn Error>>(())
44 }.await;
45
46 if let Err(err) = scenario { passed = false; detail = err.to_string(); }
47 print_summary(name, passed, &detail, &metrics, started.elapsed().as_secs_f64(), true);
48 if passed { Ok(()) } else { Err(boxed_error(detail)) }
49}Sourcepub async fn get_user<T: Serialize>(&self, payload: T) -> Result<Value>
pub async fn get_user<T: Serialize>(&self, payload: T) -> Result<Value>
Examples found in repository?
examples/internal/auth_lifecycle.rs (line 24)
10async fn main() -> Result<(), Box<dyn Error>> {
11 let name = "internal_auth_lifecycle";
12 let started = Instant::now();
13 let client = create_client().await?;
14 let username = format!("sdk_example_{}", SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_millis());
15 let mut passed = true;
16 let mut detail = "validated raw auth lifecycle".to_string();
17 let mut metrics = json!({});
18
19 let scenario = async {
20 let health = client.auth.health().await?;
21 let created = client.auth.create_user(json!({"username": username, "role": "user"})).await?;
22 let listed = client.auth.list_users(json!({})).await?;
23 let rotated = client.auth.rotate_user_api_key(json!({"username": username})).await?;
24 let fetched = client.auth.get_user(json!({"username": username})).await?;
25 let revoked = client.auth.revoke_user_api_key(json!({"username": username})).await?;
26 let deleted = client.auth.delete_user(json!({"username": username})).await?;
27 let listed_users = listed
28 .as_array()
29 .cloned()
30 .or_else(|| listed.get("users").and_then(Value::as_array).cloned())
31 .unwrap_or_default();
32 let fetched_user = fetched.get("user").unwrap_or(&fetched);
33
34 require(!health.is_null(), format!("auth health failed: {health}"))?;
35 require(created.get("success").and_then(Value::as_bool).unwrap_or(true) || created.get("api_key").is_some(), format!("create_user failed: {created}"))?;
36 require(listed_users.iter().any(|item| item.get("username").and_then(Value::as_str) == Some(username.as_str())), format!("list_users missing created user: {listed}"))?;
37 require(rotated.get("success").and_then(Value::as_bool).unwrap_or(true) || rotated.get("api_key").is_some(), format!("rotate_user_api_key failed: {rotated}"))?;
38 require(fetched_user.get("username").and_then(Value::as_str) == Some(username.as_str()), format!("get_user failed: {fetched}"))?;
39 require(revoked.get("success").and_then(Value::as_bool).unwrap_or(true), format!("revoke_user_api_key failed: {revoked}"))?;
40 require(deleted.get("success").and_then(Value::as_bool).unwrap_or(true), format!("delete_user failed: {deleted}"))?;
41
42 metrics = json!({"username": username});
43 Ok::<(), Box<dyn Error>>(())
44 }.await;
45
46 if let Err(err) = scenario { passed = false; detail = err.to_string(); }
47 print_summary(name, passed, &detail, &metrics, started.elapsed().as_secs_f64(), true);
48 if passed { Ok(()) } else { Err(boxed_error(detail)) }
49}Sourcepub async fn delete_user<T: Serialize>(&self, payload: T) -> Result<Value>
pub async fn delete_user<T: Serialize>(&self, payload: T) -> Result<Value>
Examples found in repository?
examples/internal/auth_lifecycle.rs (line 26)
10async fn main() -> Result<(), Box<dyn Error>> {
11 let name = "internal_auth_lifecycle";
12 let started = Instant::now();
13 let client = create_client().await?;
14 let username = format!("sdk_example_{}", SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_millis());
15 let mut passed = true;
16 let mut detail = "validated raw auth lifecycle".to_string();
17 let mut metrics = json!({});
18
19 let scenario = async {
20 let health = client.auth.health().await?;
21 let created = client.auth.create_user(json!({"username": username, "role": "user"})).await?;
22 let listed = client.auth.list_users(json!({})).await?;
23 let rotated = client.auth.rotate_user_api_key(json!({"username": username})).await?;
24 let fetched = client.auth.get_user(json!({"username": username})).await?;
25 let revoked = client.auth.revoke_user_api_key(json!({"username": username})).await?;
26 let deleted = client.auth.delete_user(json!({"username": username})).await?;
27 let listed_users = listed
28 .as_array()
29 .cloned()
30 .or_else(|| listed.get("users").and_then(Value::as_array).cloned())
31 .unwrap_or_default();
32 let fetched_user = fetched.get("user").unwrap_or(&fetched);
33
34 require(!health.is_null(), format!("auth health failed: {health}"))?;
35 require(created.get("success").and_then(Value::as_bool).unwrap_or(true) || created.get("api_key").is_some(), format!("create_user failed: {created}"))?;
36 require(listed_users.iter().any(|item| item.get("username").and_then(Value::as_str) == Some(username.as_str())), format!("list_users missing created user: {listed}"))?;
37 require(rotated.get("success").and_then(Value::as_bool).unwrap_or(true) || rotated.get("api_key").is_some(), format!("rotate_user_api_key failed: {rotated}"))?;
38 require(fetched_user.get("username").and_then(Value::as_str) == Some(username.as_str()), format!("get_user failed: {fetched}"))?;
39 require(revoked.get("success").and_then(Value::as_bool).unwrap_or(true), format!("revoke_user_api_key failed: {revoked}"))?;
40 require(deleted.get("success").and_then(Value::as_bool).unwrap_or(true), format!("delete_user failed: {deleted}"))?;
41
42 metrics = json!({"username": username});
43 Ok::<(), Box<dyn Error>>(())
44 }.await;
45
46 if let Err(err) = scenario { passed = false; detail = err.to_string(); }
47 print_summary(name, passed, &detail, &metrics, started.elapsed().as_secs_f64(), true);
48 if passed { Ok(()) } else { Err(boxed_error(detail)) }
49}Trait Implementations§
Source§impl Clone for AuthClient
impl Clone for AuthClient
Source§fn clone(&self) -> AuthClient
fn clone(&self) -> AuthClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for AuthClient
impl !RefUnwindSafe for AuthClient
impl Send for AuthClient
impl Sync for AuthClient
impl Unpin for AuthClient
impl UnsafeUnpin for AuthClient
impl !UnwindSafe for AuthClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request