Skip to content

Commit

Permalink
feat: add resource request struct to backends (#1718)
Browse files Browse the repository at this point in the history
  • Loading branch information
oddgrd authored and iulianbarbu committed Apr 11, 2024
1 parent 197a344 commit 553ad8a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
33 changes: 33 additions & 0 deletions backends/src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,39 @@ impl Header for XShuttleAdminSecret {
}
}

pub static X_SHUTTLE_PROJECT_SECRET: HeaderName =
HeaderName::from_static("x-shuttle-project-secret");

/// Typed header for sending admin secrets to Shuttle components
pub struct XShuttleProjectSecret(pub String);

impl Header for XShuttleProjectSecret {
fn name() -> &'static HeaderName {
&X_SHUTTLE_PROJECT_SECRET
}

fn decode<'i, I>(values: &mut I) -> Result<Self, headers::Error>
where
Self: Sized,
I: Iterator<Item = &'i http::HeaderValue>,
{
let value = values
.next()
.ok_or_else(headers::Error::invalid)?
.to_str()
.map_err(|_| headers::Error::invalid())?
.to_string();

Ok(Self(value))
}

fn encode<E: Extend<http::HeaderValue>>(&self, values: &mut E) {
if let Ok(value) = HeaderValue::from_str(&self.0) {
values.extend(std::iter::once(value));
}
}
}

/// Used by deployers <=0.38.0. Can be removed when those are no longer supported
pub static X_SHUTTLE_PROJECT: HeaderName = HeaderName::from_static("x-shuttle-project");

Expand Down
1 change: 1 addition & 0 deletions backends/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub mod headers;
pub mod metrics;
mod otlp_tracing_bridge;
pub mod project_name;
pub mod resource;
pub mod trace;

#[cfg(any(test, feature = "test-utils"))]
Expand Down
4 changes: 4 additions & 0 deletions backends/src/resource.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[derive(serde::Serialize, serde::Deserialize)]
pub struct ResourceRequest {
pub resources: Vec<Vec<u8>>,
}

0 comments on commit 553ad8a

Please sign in to comment.