Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
refactor: pass client to upload::script
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleymichal committed Mar 6, 2020
1 parent 9ba8de3 commit 8746da4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::commands::kv;
use crate::commands::kv::bucket::{sync, upload_files};
use crate::commands::kv::bulk::delete::delete_bulk;
use crate::deploy;
use crate::http;
use crate::settings::global_user::GlobalUser;
use crate::settings::toml::{DeployConfig, KvNamespace, Target};
use crate::terminal::{emoji, message};
Expand Down Expand Up @@ -38,9 +39,10 @@ pub fn publish(
upload_files(target, user, &site_namespace.id, to_upload)?;

sync_other_buckets(target, user, verbose)?;
let upload_client = http::auth_client(Some("site"), user);

// Next, upload and deploy the worker with the updated asset_manifest
upload::script(&user, &target, Some(asset_manifest))?;
upload::script(&upload_client, &target, Some(asset_manifest))?;

deploy::worker(&user, &deploy_config)?;

Expand All @@ -55,7 +57,8 @@ pub fn publish(
} else {
sync_other_buckets(target, user, verbose)?;

upload::script(&user, &target, None)?;
let upload_client = http::auth_client(None, user);
upload::script(&upload_client, &target, None)?;

deploy::worker(&user, &deploy_config)?;
}
Expand Down
3 changes: 2 additions & 1 deletion src/commands/secret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ pub fn upload_draft_worker(
for error in &api_errors.errors {
if error.code == 10007 {
message::working(&format!("Worker {} doesn't exist in the API yet. Creating a draft Worker so we can create new secret.", target.name));
return Some(upload::script(user, target, None));
let upload_client = http::auth_client(None, user);
return Some(upload::script(&upload_client, target, None));
} else {
return None;
}
Expand Down
12 changes: 3 additions & 9 deletions src/upload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ pub mod package;

pub use package::Package;

use reqwest::blocking::Client;

use crate::commands::kv::bucket::AssetManifest;
use crate::http;
use crate::settings::global_user::GlobalUser;
use crate::settings::toml::Target;

pub fn script(
user: &GlobalUser,
client: &Client,
target: &Target,
asset_manifest: Option<AssetManifest>,
) -> Result<(), failure::Error> {
Expand All @@ -19,12 +19,6 @@ pub fn script(
target.account_id, target.name,
);

let client = if target.site.is_some() {
http::auth_client(Some("site"), user)
} else {
http::auth_client(None, user)
};

let script_upload_form = form::build(target, asset_manifest)?;

let res = client
Expand Down

0 comments on commit 8746da4

Please sign in to comment.