-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathendpoint.rs
More file actions
64 lines (54 loc) · 1.39 KB
/
endpoint.rs
File metadata and controls
64 lines (54 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use anyhow::*;
use clap::Parser;
use toolchain::{
rivet_api::{apis, models},
ToolchainCtx,
};
/// Get information about a route endpoint
#[derive(Parser, Clone)]
pub struct Opts {
/// Name of the route to retrieve information about
function_name: String,
/// Specify the environment to get the route from (will prompt if not specified)
#[clap(long, alias = "env", short = 'e')]
environment: Option<String>,
}
impl Opts {
pub async fn execute(&self) -> Result<()> {
let ctx = crate::util::login::load_or_login().await?;
let env = crate::util::env::get_or_select(&ctx, self.environment.as_ref()).await?;
// Get route information
let route = get_route(&ctx, &env, &self.function_name).await?;
match route {
Some(route) => {
println!("https://{}{}", route.hostname, route.path);
Ok(())
}
None => Err(anyhow!(
"Route '{}' not found in environment '{}'",
self.function_name,
env
)),
}
}
}
// Helper function to get route if it exists
async fn get_route(
ctx: &ToolchainCtx,
env: &str,
route_id: &str,
) -> Result<Option<models::RoutesRoute>> {
let routes_response = apis::routes_api::routes_list(
&ctx.openapi_config_cloud,
Some(&ctx.project.name_id.to_string()),
Some(env),
)
.await?;
// Find route that matches the ID
let matching_route = routes_response
.routes
.iter()
.find(|route| route.id == *route_id)
.cloned();
Ok(matching_route)
}