Skip to content

Commit

Permalink
feat: support secrets on beta platform (#1748)
Browse files Browse the repository at this point in the history
Co-authored-by: jonaro00 <[email protected]>
  • Loading branch information
oddgrd and jonaro00 authored Apr 23, 2024
1 parent fe9f49c commit b84ea8f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
31 changes: 28 additions & 3 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1724,9 +1724,34 @@ impl Shuttle {

if self.beta {
let manifest_path = working_directory.join("Cargo.toml");
if !manifest_path.exists() {
bail!("Cargo manifest file not found: {}", manifest_path.display());
}

// Look for a secrets file, first in the command args, and if it isn't there look
// in the root of the crate or workspace.
let secrets_file = args.secret_args.secrets.clone().or_else(|| {
let secrets_file = manifest_path.parent().unwrap().join("Secrets.toml");

if secrets_file.exists() && secrets_file.is_file() {
Some(secrets_file)
} else {
None
}
});

if let Some(secrets_file) = secrets_file {
trace!("Loading secrets from {}", secrets_file.display());
if let Ok(secrets_str) = read_to_string(&secrets_file) {
let secrets = toml::from_str::<HashMap<String, String>>(&secrets_str)?;

trace!(keys = ?secrets.keys(), "available secrets");

deployment_req.secrets = Some(secrets);
} else {
trace!("No secrets were loaded");
}
} else {
trace!("No secrets file was found");
};

let metadata = async_cargo_metadata(manifest_path.as_path()).await?;
let packages = find_shuttle_packages(&metadata)?;
let package_name = packages
Expand Down
4 changes: 3 additions & 1 deletion common/src/models/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use comfy_table::{
};
use crossterm::style::Stylize;
use serde::{Deserialize, Serialize};
use std::{fmt::Display, str::FromStr};
use std::{collections::HashMap, fmt::Display, str::FromStr};
use uuid::Uuid;

use crate::deployment::{EcsState, State};
Expand Down Expand Up @@ -412,6 +412,8 @@ pub struct DeploymentRequest {
pub data: Vec<u8>,
/// The cargo package name to compile and run. Required on beta.
pub package_name: Option<String>,
/// Secrets to add before this deployment. Ignored on alpha.
pub secrets: Option<HashMap<String, String>>,
/// Ignored on beta.
pub no_test: bool,
pub git_commit_id: Option<String>,
Expand Down

0 comments on commit b84ea8f

Please sign in to comment.