Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zaycev committed Jan 27, 2024
1 parent 2cc4c50 commit 067a112
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
8 changes: 4 additions & 4 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
rustflags = ["-Zlocation-detail=none"]
rustflags = []
[target.x86_64-apple-darwin]
rustflags = ["-Zlocation-detail=none"]
rustflags = []
[target.aarch64-apple-darwin]
rustflags = ["-Zlocation-detail=none"]
rustflags = []
[target.x86_64-linux-unknown]
rustflags = ["-Zlocation-detail=none"]
rustflags = []
35 changes: 20 additions & 15 deletions src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use anyhow::Context;

use crate::types::{BundleUploadLocation, Repo};
use crate::types::{BundleUploadLocation, CreateBundleUploadRequest, Repo};

pub const TRUNK_API_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30);
pub const TRUNK_API_TOKEN_HEADER: &str = "x-api-token";
Expand All @@ -13,32 +13,37 @@ pub async fn get_bundle_upload_location(
org_slug: &str,
repo: &Repo,
) -> anyhow::Result<BundleUploadLocation> {
let req_body = serde_json::json!({
"repo": {
"host": repo.host.clone(),
"owner": repo.owner.clone(),
"name": repo.name.clone(),
},
"orgUrlSlug": org_slug.to_string(),
});

let client = reqwest::Client::new();
let resp = match client
.post(api_address)
.timeout(TRUNK_API_TIMEOUT)
.header(reqwest::header::CONTENT_TYPE, "application/json")
.header(TRUNK_API_TOKEN_HEADER, api_token)
.json(&req_body)
.json(&CreateBundleUploadRequest {
org_url_slug: org_slug.to_owned(),
repo: repo.clone(),
})
.send()
.await
{
Ok(resp) => resp,
Err(e) => {
log::error!("Failed to create bundle upload. Status: {:?}", e.status());
if e.status() == Some(reqwest::StatusCode::UNAUTHORIZED) {
log::error!("Your Trunk token may be incorrect - find it on the Trunk app (Settings -> Manage Organization -> Organization API Token -> View).");
} else if e.status() == Some(reqwest::StatusCode::NOT_FOUND) {
log::error!("Your Trunk organization URL slug may be incorrect - find it on the Trunk app (Settings -> Manage Organization -> Organization Slug).");
match e.status() {
Some(reqwest::StatusCode::UNAUTHORIZED) => log::error!(
"Your Trunk token may be incorrect - \
find it on the Trunk app (Settings -> \
Manage Organization -> Organization \
API Token -> View)."
),
Some(reqwest::StatusCode::NOT_FOUND) => log::error!(
"Your Trunk organization URL \
slug may be incorrect - find \
it on the Trunk app (Settings \
-> Manage Organization -> \
Organization Slug)."
),
_ => {}
}
return Err(anyhow::anyhow!(e).context("Failed to create bundle upload"));
}
Expand Down
9 changes: 8 additions & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ use serde::{Deserialize, Serialize};

use crate::scanner::{BundleRepo, FileSet};

#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct CreateBundleUploadRequest {
pub repo: Repo,
#[serde(rename = "orgUrlSlug")]
pub org_url_slug: String,
}

#[derive(Debug, Serialize, Clone, Deserialize)]
pub struct BundleUploadLocation {
pub url: String,
pub key: String,
}

#[derive(Debug, Serialize, Clone, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct Repo {
pub host: String,
pub owner: String,
Expand Down

0 comments on commit 067a112

Please sign in to comment.