Skip to content

Commit

Permalink
feat: resources endpoint (#740)
Browse files Browse the repository at this point in the history
  • Loading branch information
chesedo authored Mar 22, 2023
1 parent 6843874 commit abd17fe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ use serde_json::Value;

use crate::{database, DatabaseReadyInfo};

/// Common type to hold all the information we need for a generic resource
#[derive(Clone, Deserialize, Serialize)]
pub struct Response {
/// The type of this resource.
pub r#type: Type,

/// The data associated with this resource. Use the [Self::r#type] to know how to parse this data.
pub data: Value,
}

Expand Down
23 changes: 23 additions & 0 deletions deployer/src/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ pub async fn make_router(
"/projects/:project_name/services/:service_name/summary",
get(get_service_summary).layer(ScopedLayer::new(vec![Scope::Service])),
)
.route(
"/projects/:project_name/services/:service_name/resources",
get(get_service_resources).layer(ScopedLayer::new(vec![Scope::Resources])),
)
.route(
"/projects/:project_name/deployments/:deployment_id",
get(get_deployment.layer(ScopedLayer::new(vec![Scope::Deployment])))
Expand Down Expand Up @@ -192,6 +196,25 @@ async fn get_service_summary(
}
}

#[instrument(skip_all, fields(%project_name, %service_name))]
async fn get_service_resources(
Extension(persistence): Extension<Persistence>,
Path((project_name, service_name)): Path<(String, String)>,
) -> Result<Json<Vec<shuttle_common::resource::Response>>> {
if let Some(service) = persistence.get_service_by_name(&service_name).await? {
let resources = persistence
.get_resources(&service.id)
.await?
.into_iter()
.map(Into::into)
.collect();

Ok(Json(resources))
} else {
Err(Error::NotFound)
}
}

#[instrument(skip_all, fields(%project_name, %service_name))]
async fn post_service(
Extension(persistence): Extension<Persistence>,
Expand Down

0 comments on commit abd17fe

Please sign in to comment.