Skip to content

Commit

Permalink
Merge pull request #1753 from shuttle-hq/feat/shuttle-ecs-common
Browse files Browse the repository at this point in the history
chore: merge shuttle-ecs-common to main
  • Loading branch information
oddgrd authored Apr 25, 2024
2 parents 61ec530 + 95c155b commit 3322112
Show file tree
Hide file tree
Showing 31 changed files with 1,589 additions and 731 deletions.
816 changes: 451 additions & 365 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ once_cell = "1.16.0"
opentelemetry = "0.21.0"
opentelemetry_sdk = { version = "0.21.0", features = ["rt-tokio", "logs"] }
opentelemetry-http = "0.10.0"
opentelemetry-otlp = { version = "0.14.0", features = ["logs", "grpc-tonic"] }
opentelemetry-otlp = { version = "0.14.0", features = ["logs", "grpc-tonic", "http-proto"] }
opentelemetry-proto = "0.4.0"
opentelemetry-contrib = { version = "0.4.0", features = ["datadog"] }
opentelemetry-appender-tracing = "0.2.0"
Expand All @@ -94,6 +94,7 @@ test-context = "0.3.0"
thiserror = "1.0.37"
tokio = "1.22.0"
tokio-stream = "0.1.11"
tokio-util = "0.7.10"
toml = "0.8.2"
toml_edit = "0.20.2"
tonic = "0.10.2"
Expand Down
7 changes: 7 additions & 0 deletions backends/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ impl ServicesApiClient {
}
}

pub fn new_with_default_headers(base: Uri, headers: HeaderMap) -> Self {
Self {
client: Self::builder().default_headers(headers).build().unwrap(),
base,
}
}

pub async fn get<T: DeserializeOwned>(
&self,
path: &str,
Expand Down
65 changes: 65 additions & 0 deletions backends/src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,71 @@ 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 to ensure requests originate from the control service.
pub static X_SHUTTLE_CTL_SECRET: HeaderName = HeaderName::from_static("x-shuttle-ctl-secret");

pub struct XShuttleCtlSecret(pub String);

impl Header for XShuttleCtlSecret {
fn name() -> &'static HeaderName {
&X_SHUTTLE_CTL_SECRET
}

fn decode<'i, I>(values: &mut I) -> Result<Self, headers::Error>
where
Self: Sized,
I: Iterator<Item = &'i 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<HeaderValue>>(&self, values: &mut E) {
if let Ok(value) = HeaderValue::from_str(self.0.as_str()) {
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
16 changes: 16 additions & 0 deletions backends/src/resource.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use serde::{Deserialize, Serialize};

/// Used by the runner service to send requests to control plane, where the requested resources
/// will be provisioned.
#[derive(Serialize, Deserialize)]
pub struct ResourceRequest {
/// The resource input returned from the runtime::load call.
pub resources: Vec<Vec<u8>>,
}

/// Used to request the provisioning or deletion of a shared DB from the provisioner service.
#[derive(Deserialize, Serialize)]
pub struct SharedDbRequest {
pub db_name: String,
pub role_name: String,
}
4 changes: 2 additions & 2 deletions backends/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
.tracing()
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.http()
.with_endpoint(otlp_address.clone()),
)
.with_trace_config(trace::config().with_resource(Resource::new(resources.clone())))
Expand All @@ -57,7 +57,7 @@ where
.with_log_config(Config::default().with_resource(Resource::new(resources.clone())))
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.http()
.with_endpoint(otlp_address),
)
.install_batch(Tokio)
Expand Down
7 changes: 4 additions & 3 deletions cargo-shuttle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.44.0"
edition.workspace = true
license.workspace = true
repository.workspace = true
description = "A cargo command for the shuttle platform (https://www.shuttle.rs/)"
description = "A cargo command for the Shuttle platform (https://www.shuttle.rs/)"
homepage = "https://www.shuttle.rs"

[dependencies]
Expand Down Expand Up @@ -32,10 +32,10 @@ gix = { version = "0.62.0", default-features = false, features = [
"worktree-mutation",
] }
globset = "0.4.13"
home = { workspace = true }
headers = { workspace = true }
indicatif = "0.17.3"
home = { workspace = true }
ignore = "0.4.20"
indicatif = "0.17.3"
indoc = "2.0.1"
percent-encoding = { workspace = true }
portpicker = { workspace = true }
Expand Down Expand Up @@ -65,6 +65,7 @@ url = { workspace = true }
uuid = { workspace = true, features = ["v4"] }
walkdir = "2.3.3"
webbrowser = "0.8.2"
zip = "0.6.6"

[dev-dependencies]
assert_cmd = "2.0.6"
Expand Down
11 changes: 7 additions & 4 deletions cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub struct ShuttleArgs {
/// Turn on tracing output for cargo-shuttle and shuttle libraries.
#[arg(long, env = "SHUTTLE_DEBUG")]
pub debug: bool,
/// Target Shuttle's development environment
#[arg(long, env = "SHUTTLE_BETA", hide = true)]
pub beta: bool,

#[command(subcommand)]
pub cmd: Command,
Expand Down Expand Up @@ -158,13 +161,13 @@ pub enum DeploymentCommand {
limit: u32,

#[arg(long, default_value_t = false)]
/// Output table in `raw` format
/// Output table without borders
raw: bool,
},
/// View status of a deployment
Status {
/// ID of deployment to get status for
id: Uuid,
id: String,
},
}

Expand All @@ -173,7 +176,7 @@ pub enum ResourceCommand {
/// List all the resources for a project
List {
#[arg(long, default_value_t = false)]
/// Output table in `raw` format
/// Output table without borders
raw: bool,

#[arg(
Expand Down Expand Up @@ -219,7 +222,7 @@ pub enum ProjectCommand {
limit: u32,

#[arg(long, default_value_t = false)]
/// Output table in `raw` format
/// Output table without borders
raw: bool,
},
/// Delete a project and all linked data
Expand Down
Loading

0 comments on commit 3322112

Please sign in to comment.