Skip to content
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
9 changes: 8 additions & 1 deletion src/commands/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,14 @@ fn move_history(scratch: &Path, hosted: &AppSource, repo: &str, rerun: &str) ->
let hosted_url = format!("https://github.com/{hosted_repo}.git");
let target_url = format!("https://github.com/{repo}.git");
let mirror = scratch.join("hosted.git");
let cloned = hosted_git(scratch, &hosted_url)
let mut clone = hosted_git(scratch, &hosted_url).map_err(|error| {
Stop(
format!("{} Nothing changed.", error.message),
"GIT_CLONE_FAILED",
rerun.to_string(),
)
})?;
let cloned = clone
.args(["clone", "--bare", "--quiet", "--"])
.arg(&hosted_url)
.arg(&mirror)
Expand Down
155 changes: 59 additions & 96 deletions src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const POLL_TIMEOUT: Duration = Duration::from_secs(1200);
struct EnvInjectionPlan {
mode: String,
services: Vec<ServiceEnvInjectionPlan>,
notes: Vec<String>,
}

#[derive(Debug, Serialize)]
Expand Down Expand Up @@ -738,34 +737,39 @@ fn run_preflight(
}

// --- Human output ---
display_preflight_human(
&app_name,
&resolved,
&services,
&per_service_detection,
&runtime_plan,
&env_injection_plan,
&validation_findings,
);
if !reports {
// `floo deploy` shows only what needs attention; the deploy prints its own progress.
print_warnings(&all_findings);
} else {
display_preflight_human(
&app_name,
&resolved,
&services,
&per_service_detection,
&runtime_plan,
&env_injection_plan,
&validation_findings,
);

if !managed_services.is_empty() {
eprintln!(" Managed services (declared):");
for ms in &managed_services {
let tier_label = ms.tier.as_deref().unwrap_or("basic");
eprintln!(" {} (tier {tier_label})", ms.env_handle());
if !managed_services.is_empty() {
eprintln!(" Managed services:");
for ms in &managed_services {
let tier_label = ms.tier.as_deref().unwrap_or("basic");
eprintln!(" {} ({tier_label})", ms.env_handle());
}
eprintln!();
}
eprintln!();
}

if let Some(ref plan) = remote_plan {
render_plan_human(plan, &app_name);
}
if app_not_created {
eprintln!(" {}", app_not_created_note(&app_name));
eprintln!();
}
if let Some(ref plan) = remote_plan {
render_plan_human(plan, &app_name);
}
if app_not_created {
eprintln!(" {}", app_not_created_note(&app_name));
eprintln!();
}

render_security_findings_human(&security_findings);
render_security_findings_human(&security_findings);
}

if !valid {
for f in all_findings.iter().filter(|f| f.is_error()) {
Expand All @@ -780,26 +784,23 @@ fn run_preflight(
process::exit(1);
}

match &deploy_plan {
Some(preview) => {
let warn_count = all_findings
.iter()
.filter(|f| f.severity == Severity::Warning)
.count();
eprintln!();
if warn_count > 0 {
output::success(
&format!("Config valid with {warn_count} warning(s); review them above."),
None,
);
} else {
output::success("Config valid.", None);
}
for line in preview.summary.lines() {
eprintln!(" {line}");
}
if let Some(preview) = &deploy_plan {
let warn_count = all_findings
.iter()
.filter(|f| f.severity == Severity::Warning)
.count();
eprintln!();
if warn_count > 0 {
output::success(
&format!("Config valid with {warn_count} warning(s); review them above."),
None,
);
} else {
output::success("Config valid.", None);
}
for line in preview.summary.lines() {
eprintln!(" {line}");
}
None => print_preflight_ready(&all_findings),
}
(resolved, services, primary_detection)
}
Expand Down Expand Up @@ -2033,14 +2034,9 @@ fn build_env_injection_plan(
.map(|ms| ms.env_handle())
.collect::<Vec<_>>();

let mut notes = Vec::new();
let mode = if explicit_managed {
"explicit".to_string()
} else if !declared_handles.is_empty() {
notes.push(
"No service declares env.managed, so managed service credentials use legacy implicit injection."
.to_string(),
);
"implicit_all".to_string()
} else {
"none".to_string()
Expand Down Expand Up @@ -2085,28 +2081,22 @@ fn build_env_injection_plan(
EnvInjectionPlan {
mode,
services: service_plans,
notes,
}
}

fn display_env_injection_plan(plan: &EnvInjectionPlan) {
eprintln!(" Env injection plan:");
match plan.mode.as_str() {
"explicit" => eprintln!(" mode: explicit per-service env.managed"),
"implicit_all" => eprintln!(" mode: legacy implicit managed env on every service"),
_ => eprintln!(" mode: no managed service credentials declared locally"),
}
for note in &plan.notes {
eprintln!(" note: {note}");
if plan
.services
.iter()
.all(|svc| svc.managed.is_empty() && svc.required.is_empty() && svc.optional.is_empty())
{
return;
}
eprintln!(" Env vars:");
for svc in &plan.services {
eprintln!(" {}", svc.service);
if svc.managed.is_empty() {
eprintln!(" managed: none");
} else {
for managed in &svc.managed {
eprintln!(" {} -> {}", managed.handle, managed.keys.join(", "));
}
for managed in &svc.managed {
eprintln!(" {}: {}", managed.handle, managed.keys.join(", "));
}
if !svc.required.is_empty() {
eprintln!(" required: {}", svc.required.join(", "));
Expand Down Expand Up @@ -2185,10 +2175,7 @@ fn display_preflight_human(
.as_deref()
.map(|f| format!(" ({f})"))
.unwrap_or_default();
eprintln!(
" runtime: {}{framework_label} \u{2014} {} confidence",
det.runtime, det.confidence
);
eprintln!(" runtime: {}{framework_label}", det.runtime);
if runtime.availability == "paused" {
eprintln!(" availability: paused, 0 running instances");
} else if runtime.availability == "fixed" {
Expand All @@ -2211,7 +2198,6 @@ fn display_preflight_human(
for note in &runtime.notes {
eprintln!(" note: {note}");
}
eprintln!(" note: plan limits are resolved by the server; verify with `floo services show --json`");
eprintln!();
}

Expand Down Expand Up @@ -2245,6 +2231,10 @@ fn display_preflight_human(
}
}

print_warnings(findings);
}

fn print_warnings(findings: &[PreflightFinding]) {
for f in findings.iter().filter(|f| f.severity == Severity::Warning) {
// The root service uses path "." — a "." : prefix there is just noise.
match f.path.as_deref() {
Expand All @@ -2268,33 +2258,6 @@ fn render_security_findings_human(findings: &[PreflightFinding]) {
eprintln!();
}

/// Print the auto-deploy contract and the final "ready" line. Only called when
/// the config has no errors; the warning count keeps a clean green honest.
fn print_preflight_ready(findings: &[PreflightFinding]) {
// Closes feedback c9b70eb5: "no obvious signal anywhere in the floo
// workflow that dev auto-deploys on GitHub push." The CLI is the surface
// the user is in front of right before pushing — surfacing the auto-deploy
// contract here means they don't have to leave for the docs.
eprintln!();
eprintln!(" Deploys: dev auto-deploys on every `git push` to your default branch.");
eprintln!(" See https://getfloo.com/docs/guides/golden-path.md for the full flow.");

let warn_count = findings
.iter()
.filter(|f| f.severity == Severity::Warning)
.count();
if warn_count > 0 {
output::success(
&format!(
"Config valid with {warn_count} warning(s) \u{2014} review the warnings above before deploying."
),
None,
);
} else {
output::success("Config valid \u{2014} ready to deploy.", None);
}
}

/// Stream deploy logs via SSE and return the final deploy state.
pub(crate) fn stream_deploy(
client: &FlooClient,
Expand Down
20 changes: 16 additions & 4 deletions src/commands/projects.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::env;
use std::io::{self, BufRead};
use std::path::Path;
use std::process::{self, Command, Stdio};
Expand All @@ -8,6 +9,10 @@ use crate::errors::{ErrorCode, FlooApiError};
use crate::output;
use crate::resolve::resolve_app;

/// The app and push token floo's own git commands pass to `floo git-credential`.
pub(crate) const GIT_TOKEN_APP_ENV: &str = "FLOO_GIT_APP_ID";
pub(crate) const GIT_TOKEN_ENV: &str = "FLOO_GIT_TOKEN";

fn fail(error: FlooApiError) -> ! {
let next = if error.status_code == 401 || error.code == "NOT_AUTHENTICATED" {
"next: floo auth login"
Expand Down Expand Up @@ -233,10 +238,17 @@ pub fn git_credential(operation: &str) {
))
});
let Some(app_id) = app_id else { return };
let credential = client()
.project_git_token(&app_id)
.unwrap_or_else(|error| fail(error));
output::git_credentials(&credential.token).unwrap_or_else(|_| {
// floo's own git commands fetch the token first and hand it over here.
let token = match (env::var(GIT_TOKEN_APP_ENV), env::var(GIT_TOKEN_ENV)) {
(Ok(for_app), Ok(token)) if for_app == app_id => token,
_ => {
client()
.project_git_token(&app_id)
.unwrap_or_else(|error| fail(error))
.token
}
};
output::git_credentials(&token).unwrap_or_else(|_| {
fail(FlooApiError::new(
0,
"INVALID_RESPONSE",
Expand Down
49 changes: 31 additions & 18 deletions src/commands/ship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use serde_json::{json, Value};

use crate::api_client::FlooClient;
use crate::api_types::{AppSource, DeployPlan};
use crate::errors::ErrorCode;
use crate::errors::{ErrorCode, FlooApiError};
use crate::output;
use crate::project_config::{self, AppAccessMode, AppFileConfig};

use super::projects::{managed_app_id, shell_quote};
use super::projects::{managed_app_id, shell_quote, GIT_TOKEN_APP_ENV, GIT_TOKEN_ENV};

/// The remote a hosted repo gets when `origin` already points elsewhere.
const HOSTED_REMOTE: &str = "floo";
Expand Down Expand Up @@ -737,7 +737,7 @@ fn dev_access_mode(config: &AppFileConfig, plan: &DeployPlan) -> Option<String>
}
}

/// Said when only the org can open the app, since a plain request then gets 401.
/// Said when only the org can open the app.
fn access_note(config: &AppFileConfig, plan: &DeployPlan) -> Option<String> {
if dev_access_mode(config, plan).as_deref() != Some("accounts") {
return None;
Expand All @@ -750,9 +750,7 @@ fn access_note(config: &AppFileConfig, plan: &DeployPlan) -> Option<String> {
your users can't reach it. Set {table} access_mode = \"public\" in floo.app.toml."
));
}
let mut note = format!(
"Only signed-in members of {org} can open it; a request without a floo sign-in gets 401."
);
let mut note = format!("Only signed-in members of {org} can open it.");
if config.dev_access_mode().is_none() {
note.push_str(" For a public site, set [app] access_mode = \"public\" in floo.app.toml.");
}
Expand Down Expand Up @@ -967,18 +965,21 @@ fn push_github(path: &Path, remote: &str, branch: &str, head: &str, quoted: &str
/// git with floo's short-lived token for a hosted repo, and no other credential
/// helper, so no keychain stores the token. Refuses any URL that isn't a
/// credential-free floo-hosted HTTPS URL, as `projects clone` does.
pub(crate) fn hosted_git(path: &Path, clone_url: &str) -> Command {
if clone_url
///
/// floo asks for the token before git runs, so a failure is floo's own error,
/// and git may never prompt: a prompt from inside a deploy looks like a hang.
pub(crate) fn hosted_git(path: &Path, clone_url: &str) -> Result<Command, FlooApiError> {
let Some(app_id) = clone_url
.strip_prefix("https://github.com/")
.and_then(managed_app_id)
.is_none()
{
stop(
"The app's hosted repository is not a floo-hosted repository.",
else {
return Err(FlooApiError::new(
0,
"INVALID_RESPONSE",
"Contact floo support with the app name.",
);
}
"The app's hosted repository is not a floo-hosted repository. Contact floo support with the app name.",
));
};
let token = super::init_client(None).project_git_token(&app_id)?.token;
let executable = std::env::current_exe()
.ok()
.and_then(|path| path.to_str().map(str::to_owned))
Expand All @@ -998,8 +999,13 @@ pub(crate) fn hosted_git(path: &Path, clone_url: &str) -> Command {
let mut command = git(path);
command
.args(["-c", "credential.helper=", "-c", &helper])
.args(["-c", "credential.useHttpPath=true"]);
command
.args(["-c", "credential.useHttpPath=true"])
.env(GIT_TOKEN_APP_ENV, &app_id)
.env(GIT_TOKEN_ENV, token)
.env("GIT_TERMINAL_PROMPT", "0")
// Set but empty, so git skips core.askPass and SSH_ASKPASS too.
.env("GIT_ASKPASS", "");
Ok(command)
}

/// Seconds to wait before each retry of a new hosted repo's first push.
Expand All @@ -1014,7 +1020,14 @@ fn push_hosted(path: &Path, clone_url: &str, branch: &str, quoted: &str, new_rep
let mut waits = waits.iter();
loop {
// Push to the validated URL, not a remote name that could carry another pushurl.
let output = hosted_git(path, clone_url)
let mut push = hosted_git(path, clone_url).unwrap_or_else(|error| {
stop(
&error.message,
&error.code,
&format!("floo deploy {quoted}"),
)
});
let output = push
.arg("push")
.args([clone_url, refspec.as_str()])
// Keep stdout for floo's JSON; read git's errors to spot GitHub's 403.
Expand Down
Loading
Loading