Skip to content

Commit 081e550

Browse files
committed
add auth, fix url
1 parent e5bd2d7 commit 081e550

4 files changed

Lines changed: 29 additions & 7 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ secrecy = "0.8.0"
8080
lru = "0.16.0"
8181
backon = { version = "1.5.2", features = ["std", "std-blocking-sleep"] }
8282
tokio = { version = "1.47", features = ["rt"] }
83+
http = "1.4.0"
8384

8485
[dev-dependencies]
8586
assert_cmd = "2.0.11"

src/commands/build/snapshots.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ use std::path::Path;
44
use anyhow::{Context as _, Result};
55
use clap::{Arg, ArgMatches, Command};
66
use console::style;
7+
use http::header::AUTHORIZATION;
78
use log::{debug, info};
8-
use objectstore_client::{Client, Usecase};
9+
use objectstore_client::{Client, ClientBuilder, Usecase};
10+
use secrecy::ExposeSecret as _;
911
use sha2::{Digest as _, Sha256};
1012
use walkdir::WalkDir;
1113

1214
use crate::api::Api;
13-
use crate::config::Config;
15+
use crate::config::{Auth, Config};
1416
use crate::utils::api::get_org_project_id;
1517
use crate::utils::args::ArgExt as _;
1618
use crate::utils::objectstore::get_objectstore_url;
19+
use http::{self, HeaderValue};
1720

1821
const EXPERIMENTAL_WARNING: &str =
1922
"[EXPERIMENTAL] The \"build snapshots\" command is experimental. \
@@ -135,8 +138,26 @@ fn upload_files(
135138
project: &str,
136139
snapshot_id: &str,
137140
) -> Result<()> {
141+
let config = Config::current();
142+
let auth = config
143+
.get_auth()
144+
.ok_or_else(|| anyhow::anyhow!("Authentication required"))?;
145+
let token = match auth {
146+
Auth::Token(token) => token.raw().expose_secret(),
147+
};
148+
138149
let url = get_objectstore_url(Api::current(), org)?;
139-
let client = Client::new(url)?;
150+
let client = ClientBuilder::new(url.clone())
151+
.configure_reqwest(move |r| {
152+
let mut headers = http::HeaderMap::new();
153+
headers.insert(
154+
AUTHORIZATION,
155+
HeaderValue::from_str(&format!("Bearer {token}"))
156+
.expect("always a valid header value"),
157+
);
158+
r.default_headers(headers)
159+
})
160+
.build()?;
140161

141162
let (org, project) = get_org_project_id(Api::current(), org, project)?;
142163
let session = Usecase::new("preprod")

src/utils/objectstore/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ use crate::api::Api;
77
pub fn get_objectstore_url(api: impl AsRef<Api>, org: &str) -> Result<String> {
88
let api = api.as_ref().authenticated()?;
99
let base = api.fetch_organization_details(org)?.links.region_url;
10-
Ok(format!("{base}/api/0/objectstore"))
10+
Ok(format!("{base}/api/0/organizations/{org}/objectstore"))
1111
}

0 commit comments

Comments
 (0)