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

Commit

Permalink
Remove unneeded validate function
Browse files Browse the repository at this point in the history
It no longer does anything now that the account ID is loaded on demand.
  • Loading branch information
jyn514 committed Jun 28, 2021
1 parent d699809 commit c532063
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 57 deletions.
4 changes: 1 addition & 3 deletions src/commands/kv/bulk/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ use cloudflare::endpoints::workerskv::write_bulk::KeyValuePair;
use anyhow::Result;
use indicatif::{ProgressBar, ProgressStyle};

use crate::commands::kv;
use crate::kv::bulk::delete;
use crate::kv::bulk::BATCH_KEY_MAX;
use crate::settings::global_user::GlobalUser;
use crate::settings::toml::Target;
use crate::terminal::interactive;
use crate::terminal::message::{Message, StdOut};
pub fn run(target: &Target, user: &GlobalUser, namespace_id: &str, filename: &Path) -> Result<()> {
kv::validate_target(target)?;

pub fn run(target: &Target, user: &GlobalUser, namespace_id: &str, filename: &Path) -> Result<()> {
match interactive::confirm(&format!(
"Are you sure you want to delete all keys in {}?",
filename.display()
Expand Down
3 changes: 0 additions & 3 deletions src/commands/kv/bulk/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ use cloudflare::endpoints::workerskv::write_bulk::KeyValuePair;
use anyhow::{anyhow, Result};
use indicatif::{ProgressBar, ProgressStyle};

use crate::commands::kv::validate_target;
use crate::kv::bulk::put;
use crate::kv::bulk::BATCH_KEY_MAX;
use crate::settings::global_user::GlobalUser;
use crate::settings::toml::Target;
use crate::terminal::message::{Message, StdErr};
pub fn run(target: &Target, user: &GlobalUser, namespace_id: &str, filename: &Path) -> Result<()> {
validate_target(target)?;

let pairs: Vec<KeyValuePair> = match &metadata(filename) {
Ok(file_type) if file_type.is_file() => {
let data = fs::read_to_string(filename)?;
Expand Down
3 changes: 1 addition & 2 deletions src/commands/kv/key/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ use cloudflare::framework::apiclient::ApiClient;

use anyhow::Result;

use crate::commands::kv::{format_error, validate_target};
use crate::commands::kv::format_error;
use crate::http;
use crate::settings::global_user::GlobalUser;
use crate::settings::toml::Target;
use crate::terminal::interactive;
use crate::terminal::message::{Message, StdOut};
pub fn delete(target: &Target, user: &GlobalUser, id: &str, key: &str) -> Result<()> {
validate_target(target)?;
let client = http::cf_v4_client(user)?;

match interactive::confirm(&format!("Are you sure you want to delete key \"{}\"?", key)) {
Expand Down
1 change: 0 additions & 1 deletion src/commands/kv/key/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::settings::toml::Target;
use std::io::{self, Write};

pub fn get(target: &Target, user: &GlobalUser, id: &str, key: &str) -> Result<()> {
kv::validate_target(target)?;
let api_endpoint = format!(
"https://api.cloudflare.com/client/v4/accounts/{}/storage/kv/namespaces/{}/values/{}",
target.account_id.load()?,
Expand Down
1 change: 0 additions & 1 deletion src/commands/kv/key/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub fn list(
namespace_id: &str,
prefix: Option<&str>,
) -> Result<()> {
kv::validate_target(target)?;
let client = http::cf_v4_client(&user)?;
let key_list = KeyList::new(target, client, namespace_id, prefix)?;

Expand Down
2 changes: 0 additions & 2 deletions src/commands/kv/key/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ pub fn parse_metadata(arg: Option<&str>) -> Result<Option<serde_json::Value>> {
}

pub fn put(target: &Target, user: &GlobalUser, data: KVMetaData) -> Result<()> {
kv::validate_target(target)?;

let api_endpoint = format!(
"https://api.cloudflare.com/client/v4/accounts/{}/storage/kv/namespaces/{}/values/{}",
target.account_id.load()?,
Expand Down
17 changes: 0 additions & 17 deletions src/commands/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,6 @@ fn kv_help(error_code: u16) -> &'static str {
}
}

pub fn validate_target(target: &Target) -> Result<()> {
// let mut missing_fields = Vec::new();

// if target.account_id.is_empty() {
// missing_fields.push("account_id")
// };

// if !missing_fields.is_empty() {
// anyhow::bail!(
// "Your configuration file is missing the following field(s): {:?}",
// missing_fields
// )
// } else {
Ok(())
// }
}

fn check_duplicate_namespaces(target: &Target) -> bool {
// HashSet for detecting duplicate namespace bindings
let mut binding_names: HashSet<String> = HashSet::new();
Expand Down
1 change: 0 additions & 1 deletion src/commands/kv/namespace/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::terminal::message::{Message, StdOut};
use anyhow::Result;

pub fn run(target: &Target, user: &GlobalUser, id: &str) -> Result<()> {
kv::validate_target(target)?;
let client = http::cf_v4_client(user)?;

match interactive::confirm(&format!(
Expand Down
3 changes: 0 additions & 3 deletions src/commands/kv/namespace/list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::commands::kv;
use crate::http;
use crate::kv::namespace::list;
use crate::settings::global_user::GlobalUser;
Expand All @@ -7,8 +6,6 @@ use crate::settings::toml::Target;
use anyhow::Result;

pub fn run(target: &Target, user: &GlobalUser) -> Result<()> {
kv::validate_target(target)?;

let client = http::cf_v4_client(user)?;
let result = list(&client, target);
match result {
Expand Down
23 changes: 0 additions & 23 deletions src/commands/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,6 @@ fn format_error(e: ApiFailure) -> String {
http::format_error(e, Some(&secret_errors))
}

fn validate_target(target: &Target) -> Result<()> {
// let mut missing_fields = Vec::new();

// if target.account_id.is_empty() {
// missing_fields.push("account_id")
// };

// if !missing_fields.is_empty() {
// anyhow::bail!(
// "{} Your configuration file is missing the following field(s): {:?}",
// emoji::WARN,
// missing_fields
// )
// } else {
Ok(())
// }
}

// secret_errors() provides more detailed explanations of API error codes.
fn secret_errors(error_code: u16) -> &'static str {
match error_code {
Expand Down Expand Up @@ -71,8 +53,6 @@ pub fn upload_draft_worker(
}

pub fn create_secret(name: &str, user: &GlobalUser, target: &Target) -> Result<()> {
validate_target(target)?;

let secret_value = interactive::get_user_input_multi_line(&format!(
"Enter the secret text you'd like assigned to the variable {} on the script named {}:",
name, target.name
Expand Down Expand Up @@ -127,8 +107,6 @@ pub fn create_secret(name: &str, user: &GlobalUser, target: &Target) -> Result<(
}

pub fn delete_secret(name: &str, user: &GlobalUser, target: &Target) -> Result<()> {
validate_target(target)?;

match interactive::confirm(&format!(
"Are you sure you want to permanently delete the variable {} on the script named {}?",
name, target.name
Expand Down Expand Up @@ -163,7 +141,6 @@ pub fn delete_secret(name: &str, user: &GlobalUser, target: &Target) -> Result<(
}

pub fn list_secrets(user: &GlobalUser, target: &Target) -> Result<()> {
validate_target(target)?;
let client = http::cf_v4_client(user)?;

let response = client.request(&ListSecrets {
Expand Down
1 change: 0 additions & 1 deletion src/sites/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn sync(
namespace_id: &str,
path: &Path,
) -> Result<(Vec<KeyValuePair>, Vec<String>, AssetManifest)> {
kv::validate_target(target)?;
// First, find all changed files in given local directory (aka files that are now stale
// in Workers KV).

Expand Down

0 comments on commit c532063

Please sign in to comment.