-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: refactor wrangler login/logout/whoami
to use defineCommand
#7150
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ecd7932
move whoami.ts into user/
emily-shen f7b01fa
move wranger `login/logout/whoami` and use defineCommand
emily-shen 4176abb
Update packages/wrangler/src/index.ts
edmundhung c30d150
make args optional
edmundhung 6226a59
disable warning for invalid config
edmundhung 54d2163
add changeset
edmundhung ec6d4cd
allow disabling readConfig warning with defineCommand
edmundhung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
refactor: improve login/logout/whoami setup with the new internal registration utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { defineCommand } from "../core/define-command"; | ||
import { CommandLineArgsError } from "../errors"; | ||
import * as metrics from "../metrics"; | ||
import { listScopes, login, logout, validateScopeKeys } from "./user"; | ||
import { whoami } from "./whoami"; | ||
|
||
defineCommand({ | ||
command: "wrangler login", | ||
metadata: { | ||
description: "🔓 Login to Cloudflare", | ||
owner: "Workers: Authoring and Testing", | ||
status: "stable", | ||
}, | ||
behaviour: { | ||
printConfigWarnings: false, | ||
}, | ||
args: { | ||
"scopes-list": { | ||
describe: "List all the available OAuth scopes with descriptions", | ||
}, | ||
browser: { | ||
default: true, | ||
type: "boolean", | ||
describe: "Automatically open the OAuth link in a browser", | ||
}, | ||
scopes: { | ||
describe: "Pick the set of applicable OAuth scopes when logging in", | ||
array: true, | ||
type: "string", | ||
requiresArg: true, | ||
}, | ||
}, | ||
async handler(args, { config }) { | ||
if (args.scopesList) { | ||
listScopes(); | ||
return; | ||
} | ||
if (args.scopes) { | ||
if (args.scopes.length === 0) { | ||
// don't allow no scopes to be passed, that would be weird | ||
listScopes(); | ||
return; | ||
} | ||
if (!validateScopeKeys(args.scopes)) { | ||
throw new CommandLineArgsError( | ||
`One of ${args.scopes} is not a valid authentication scope. Run "wrangler login --scopes-list" to see the valid scopes.` | ||
); | ||
} | ||
await login({ scopes: args.scopes, browser: args.browser }); | ||
return; | ||
} | ||
await login({ browser: args.browser }); | ||
await metrics.sendMetricsEvent("login user", { | ||
sendMetrics: config.send_metrics, | ||
}); | ||
|
||
// TODO: would be nice if it optionally saved login | ||
// credentials inside node_modules/.cache or something | ||
// this way you could have multiple users on a single machine | ||
}, | ||
}); | ||
|
||
defineCommand({ | ||
command: "wrangler logout", | ||
metadata: { | ||
description: "🚪 Logout from Cloudflare", | ||
owner: "Workers: Authoring and Testing", | ||
status: "stable", | ||
}, | ||
behaviour: { | ||
printConfigWarnings: false, | ||
}, | ||
async handler(_, { config }) { | ||
await logout(); | ||
await metrics.sendMetricsEvent("logout user", { | ||
sendMetrics: config.send_metrics, | ||
}); | ||
}, | ||
}); | ||
|
||
defineCommand({ | ||
command: "wrangler whoami", | ||
metadata: { | ||
description: "🕵️ Retrieve your user information", | ||
owner: "Workers: Authoring and Testing", | ||
status: "stable", | ||
}, | ||
behaviour: { | ||
printConfigWarnings: false, | ||
}, | ||
args: { | ||
account: { | ||
type: "string", | ||
describe: | ||
"Show membership information for the given account (id or name).", | ||
}, | ||
}, | ||
async handler(args, { config }) { | ||
await whoami(args.account); | ||
await metrics.sendMetricsEvent("view accounts", { | ||
sendMetrics: config.send_metrics, | ||
}); | ||
}, | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was rebasing the changes on #6756 over to this PR and notice the same changes doesn't work here. The reason was that
defineCommand
will read the config for you and there was no way to disable the warning. You can find the full changes that enable this option in ec6d4cdcc: @penalosa @emily-shen