Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add resource request struct to backends #1718

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>>,
}