Skip to content

Commit

Permalink
fix: print deployment info
Browse files Browse the repository at this point in the history
  • Loading branch information
bittermandel committed Dec 12, 2024
1 parent 2e134db commit bfc511c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
17 changes: 9 additions & 8 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ impl APIClient {
) -> anyhow::Result<ListServicesResponse> {
let url = format!("{}/orgs/{}/envs/{}/svcs", self.base_url, org_name, env_name);
let response: String = self.get(&url, token)?.error_for_status()?.text()?;
println!("{}", response.clone());
serde_json::from_str(response.as_str()).with_context(|| "Failed to deserialize response")
}

Expand Down Expand Up @@ -119,7 +118,6 @@ impl APIClient {
match response.status() {
StatusCode::OK => {
let text = &response.text()?;
println!("{}", text);
Ok(serde_json::from_str(text)
.with_context(|| "Failed to deserialize environments")?)
}
Expand Down Expand Up @@ -191,16 +189,19 @@ impl APIClient {
let url = format!("{}/orgs/{}/envs/{}/svcs", self.base_url, org_name, env_name);
let body = serde_json::to_string(&service)?;
let response = self.post_str(&url, token, body)?;
match response.status() {
StatusCode::CREATED => Ok(serde_json::from_str(&response.text()?)
.with_context(|| "Failed to deserialize service")?),
let status = response.status();
let text = response.text()?;
match status {
StatusCode::CREATED => {
Ok(serde_json::from_str(&text).with_context(|| "Failed to deserialize service")?)
}
StatusCode::UNAUTHORIZED => Err(anyhow!("Unauthorized, please login first")),
StatusCode::NOT_FOUND => Err(anyhow!("Org or environment not found")),
StatusCode::BAD_REQUEST => Err(anyhow!("Bad request: {}", response.text()?)),
StatusCode::BAD_REQUEST => Err(anyhow!("Bad request: {}", text)),
_ => Err(anyhow!(
"Failed to deploy service. API returned {} - {}",
response.status(),
response.text()?
status,
text
)),
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/commands/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ impl Create {
.get_token()
.ok_or_else(|| anyhow!("No token found. Please login first."))?;

let response = base
.api_client()
.create_environment(token, &self.name, &org_name, self.copy_from.as_deref())?;
let response = base.api_client().create_environment(
token,
&self.name,
&org_name,
self.copy_from.as_deref(),
)?;

let table = Table::new([response]).to_string();
println!("{}", table);
Expand All @@ -83,7 +86,8 @@ impl List {

let response = base.api_client().get_environments(token, &org_name)?;

println!("{:?}", response);
let table = Table::new(response.environments).to_string();
println!("{}", table);

Ok(())
}
Expand All @@ -109,7 +113,6 @@ impl Delete {
println!("Delete cancelled");
return Ok(());
}


base.api_client()
.delete_environment(token, &org_name, &self.name)?;
Expand Down
5 changes: 3 additions & 2 deletions src/commands/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,14 @@ impl Deploy {
}
}

let _result = base.api_client().deploy_service(
let result = base.api_client().deploy_service(
token,
&org_name,
&manifest.environment,
manifest.service,
)?;
println!("Service deployed.");

println!("{:?}", result);
Ok(())
}

Expand Down

0 comments on commit bfc511c

Please sign in to comment.