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

Add API token support #471

Merged
merged 26 commits into from
Nov 2, 2019
Merged

Add API token support #471

merged 26 commits into from
Nov 2, 2019

Conversation

gabbifish
Copy link
Contributor

@gabbifish gabbifish commented Aug 26, 2019

This closes #354.

API tokens can now be added to wrangler config with the following workflow:

$ wrangler config
Looking to use a Global API Key and email instead? Run "wrangler config --api-key". (Not Recommended)
Enter your API token:
none_of_your_beeswax_this_is_my_token
Success  

$ wrangler config --api-key
We don't recommend using your Global API Key! Please consider using an API Token instead. https://support.cloudflare.com/hc/en-us/articles/200167836-Managing-API-Tokens-and-Keys
Enter your email:
[email protected]
Enter your API key:
none_of_your_beeswax
Success

Currently, a user is expected to enter an email/API key pair or API token.

@gabbifish
Copy link
Contributor Author

This PR is blocked until we have support for tokens in the workers UI and workers.dev.

src/main.rs Outdated Show resolved Hide resolved
@gabbifish gabbifish added regression Something is broken, but works in previous releases status - needs review and removed blocked labels Oct 24, 2019
@gabbifish gabbifish added this to the 1.5.0 milestone Oct 24, 2019
src/main.rs Outdated Show resolved Hide resolved
Comment on lines 36 to 50
} else {
message::warn("We don't recommend using your Global API Key! Please consider using an API Token instead. https://support.cloudflare.com/hc/en-us/articles/200167836-Managing-API-Tokens-and-Keys");
println!("Enter email: ");
let mut email_str: String = read!("{}\n");
email_str.truncate(email_str.trim_end().len());
if !email_str.is_empty() {
user.email = Some(email_str);
}

println!("Enter global API key: ");
let mut api_key_str: String = read!("{}\n");
api_key_str.truncate(api_key_str.trim_end().len());
if !api_key_str.is_empty() {
user.api_key = Some(api_key_str);
}
Copy link
Contributor

@EverlastingBugstopper EverlastingBugstopper Nov 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this else be moved to the level of if !api_key {} else {, not if the API token string is empty? If the API token string is empty, I'd expect an error to be thrown (might as well check for length as well), but I wouldn't expect it to just continue to entering email and key

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, so our baseline was that an empty string would not be serialized and would trigger the default API authentication failure message. This is preserving the preexisting behavior, but we can revisit this and think about adding additional error messages. We can do this after the RC is cut.

src/http.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@ashleymichal ashleymichal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the design is good, and apart from changes that have already been discussed, my only problem with this PR is shunting interactivity into a module function; as a rule, I think that should be kept as close to main as possible.

README.md Show resolved Hide resolved
README.md Show resolved Hide resolved
src/commands/config/mod.rs Outdated Show resolved Hide resolved
src/commands/config/mod.rs Outdated Show resolved Hide resolved
src/commands/config/mod.rs Outdated Show resolved Hide resolved
src/commands/kv/mod.rs Show resolved Hide resolved
src/commands/preview/upload.rs Outdated Show resolved Hide resolved
src/commands/whoami/mod.rs Outdated Show resolved Hide resolved
src/main.rs Show resolved Hide resolved
Copy link
Contributor

@EverlastingBugstopper EverlastingBugstopper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
regression Something is broken, but works in previous releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Support for API Tokens
6 participants