-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor
wrangler login/logout/whoami
to use defineCommand (#…
…7150) * move whoami.ts into user/ * move wranger `login/logout/whoami` and use defineCommand * Update packages/wrangler/src/index.ts Co-authored-by: Somhairle MacLeòid <smacleod@cloudflare.com> * make args optional * disable warning for invalid config * add changeset * allow disabling readConfig warning with defineCommand --------- Co-authored-by: Edmund Hung <edmund@cloudflare.com> Co-authored-by: Somhairle MacLeòid <smacleod@cloudflare.com>
- Loading branch information
1 parent
edef523
commit 6380d86
Showing
8 changed files
with
158 additions
and
119 deletions.
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.