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

deprecate kv bucket attribute #1355

Merged
merged 1 commit into from
Jun 2, 2020
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
2 changes: 0 additions & 2 deletions src/commands/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,10 @@ mod tests {
KvNamespace {
id: "fake".to_string(),
binding: "KV".to_string(),
bucket: None,
},
KvNamespace {
id: "fake".to_string(),
binding: "KV".to_string(),
bucket: None,
},
]),
name: "test-target".to_string(),
Expand Down
55 changes: 2 additions & 53 deletions src/commands/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::kv::bulk::delete;
use crate::settings::global_user::GlobalUser;
use crate::settings::toml::{DeployConfig, Target};
use crate::sites;
use crate::terminal::{emoji, message, styles};
use crate::terminal::{emoji, message};
use crate::upload;

pub fn publish(
Expand Down Expand Up @@ -54,18 +54,7 @@ pub fn publish(
delete(target, user, &site_namespace.id, to_delete)?;
}
} else {
let uses_kv_bucket = sync_non_site_buckets(target, user, verbose)?;

let upload_client = if uses_kv_bucket {
let wrangler_toml = styles::highlight("`wrangler.toml`");
let issue_link = styles::url("https://github.com/cloudflare/wrangler/issues/1136");
let msg = format!("As of 1.10.0, you will no longer be able to specify a bucket for a kv namespace in your {}.\nIf your application depends on this feature, please file an issue with your use case here:\n{}", wrangler_toml, issue_link);
message::deprecation_warning(&msg);

http::featured_legacy_auth_client(user, Feature::Bucket)
} else {
http::legacy_auth_client(user)
};
let upload_client = http::legacy_auth_client(user);

upload::script(&upload_client, &target, None)?;

Expand Down Expand Up @@ -124,46 +113,6 @@ pub fn validate_bucket_location(bucket: &PathBuf) -> Result<(), failure::Error>
Ok(())
}

// This is broken into a separate step because the intended design does not
// necessarily intend for bucket support outside of the [site] usage, especially
// since assets are still hashed. In a subsequent release, we will either
// deprecate this step, or we will integrate it more closely and adapt to user
// feedback.
//
// In order to track usage of this "feature", this function returns a bool that
// indicates whether any non-site kv namespaces were specified / uploaded.
pub fn sync_non_site_buckets(
target: &Target,
user: &GlobalUser,
verbose: bool,
) -> Result<bool, failure::Error> {
let mut is_using_non_site_bucket = false;

for namespace in target.kv_namespaces() {
if let Some(path) = &namespace.bucket {
is_using_non_site_bucket = true;
validate_bucket_location(path)?;
let (to_upload, to_delete, _) = sites::sync(target, user, &namespace.id, path)?;
// First, upload all existing files in bucket directory
if verbose {
message::info("Preparing to upload updated files...");
}
sites::upload_files(target, user, &namespace.id, to_upload)?;

// Finally, remove any stale files
if !to_delete.is_empty() {
if verbose {
message::info("Deleting stale files...");
}

delete(target, user, &namespace.id, to_delete)?;
}
}
}

Ok(is_using_non_site_bucket)
}

fn validate_target_required_fields_present(target: &Target) -> Result<(), failure::Error> {
let mut missing_fields = Vec::new();

Expand Down
2 changes: 0 additions & 2 deletions src/settings/toml/kv_namespace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::fmt;
use std::path::PathBuf;

use serde::{Deserialize, Serialize};

Expand All @@ -9,7 +8,6 @@ use crate::settings::binding::Binding;
pub struct KvNamespace {
pub id: String,
pub binding: String,
pub bucket: Option<PathBuf>,
}

impl fmt::Display for KvNamespace {
Expand Down
4 changes: 0 additions & 4 deletions src/settings/toml/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ fn it_builds_from_environments_config_with_kv() {
let kv_1 = KvNamespace {
id: "somecrazylongidentifierstring".to_string(),
binding: "prodKV-1".to_string(),
bucket: None,
};
let kv_2 = KvNamespace {
id: "anotherwaytoolongidstring".to_string(),
binding: "prodKV-2".to_string(),
bucket: None,
};

match target.kv_namespaces {
Expand All @@ -65,12 +63,10 @@ fn it_builds_from_environments_config_with_kv() {
let kv_1 = KvNamespace {
id: "somecrazylongidentifierstring".to_string(),
binding: "stagingKV-1".to_string(),
bucket: None,
};
let kv_2 = KvNamespace {
id: "anotherwaytoolongidstring".to_string(),
binding: "stagingKV-2".to_string(),
bucket: None,
};
match target.kv_namespaces {
Some(kv_namespaces) => {
Expand Down
10 changes: 0 additions & 10 deletions src/sites/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,9 @@ pub fn add_namespace(
}
};

// Check if namespace already is in namespace list
for namespace in target.kv_namespaces() {
if namespace.id == site_namespace.id {
return Ok(namespace); // Sites binding already exists; ignore
} else if namespace.bucket.is_some() {
failure::bail!("your wrangler.toml includes a `bucket` as part of a kv_namespace but also has a `[site]` specifed; did you mean to put this under `[site]`?");
}
}

let site_namespace = KvNamespace {
binding: "__STATIC_CONTENT".to_string(),
id: site_namespace.id,
bucket: Some(target.site.clone().unwrap().bucket),
};

target.add_kv_namespace(site_namespace.clone());
Expand Down