-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Global API Key (X-Auth-Key) support to Wrangler (#1351)
* Added Global API Key (X-Auth-Key) support to Wrangler * rename to CLOUDFLARE_API_KEY / CLOUDFLARE_EMAIL * fix a test's name Co-authored-by: Glen Maddern <[email protected]> Co-authored-by: Sunil Pai <[email protected]>
- Loading branch information
1 parent
8d68226
commit c770167
Showing
7 changed files
with
160 additions
and
56 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,7 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
feat: add support for CLOUDFLARE_API_KEY + CLOUDFLARE_EMAIL to authorise | ||
|
||
This adds support for using the CLOUDFLARE_API_KEY + CLOUDFLARE_EMAIL env vars for authorising a user. This also adds support for CF_API_KEY + CF_EMAIL from wrangler 1, with a deprecation warning. |
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 |
---|---|---|
|
@@ -51,7 +51,7 @@ describe("getUserInfo()", () => { | |
|
||
const userInfo = await getUserInfo(); | ||
expect(userInfo).toEqual({ | ||
authType: "API", | ||
authType: "API Token", | ||
apiToken: "123456789", | ||
email: "[email protected]", | ||
accounts: [ | ||
|
@@ -62,6 +62,67 @@ describe("getUserInfo()", () => { | |
}); | ||
}); | ||
|
||
it("should say it's using a Global API Key when one is set", async () => { | ||
process.env = { | ||
CLOUDFLARE_API_KEY: "123456789", | ||
CLOUDFLARE_EMAIL: "[email protected]", | ||
}; | ||
setMockResponse("/accounts", () => { | ||
return [ | ||
{ name: "Account One", id: "account-1" }, | ||
{ name: "Account Two", id: "account-2" }, | ||
{ name: "Account Three", id: "account-3" }, | ||
]; | ||
}); | ||
|
||
const userInfo = await getUserInfo(); | ||
expect(userInfo).toEqual({ | ||
authType: "Global API Key", | ||
apiToken: "123456789", | ||
email: "[email protected]", | ||
accounts: [ | ||
{ name: "Account One", id: "account-1" }, | ||
{ name: "Account Two", id: "account-2" }, | ||
{ name: "Account Three", id: "account-3" }, | ||
], | ||
}); | ||
}); | ||
|
||
it("should use a Global API Key in preference to an API token", async () => { | ||
process.env = { | ||
CLOUDFLARE_API_KEY: "123456789", | ||
CLOUDFLARE_EMAIL: "[email protected]", | ||
CLOUDFLARE_API_TOKEN: "123456789", | ||
}; | ||
setMockResponse("/accounts", () => { | ||
return [ | ||
{ name: "Account One", id: "account-1" }, | ||
{ name: "Account Two", id: "account-2" }, | ||
{ name: "Account Three", id: "account-3" }, | ||
]; | ||
}); | ||
|
||
const userInfo = await getUserInfo(); | ||
expect(userInfo).toEqual({ | ||
authType: "Global API Key", | ||
apiToken: "123456789", | ||
email: "[email protected]", | ||
accounts: [ | ||
{ name: "Account One", id: "account-1" }, | ||
{ name: "Account Two", id: "account-2" }, | ||
{ name: "Account Three", id: "account-3" }, | ||
], | ||
}); | ||
}); | ||
|
||
it("should return undefined only a Global API Key, but not Email, is set", async () => { | ||
process.env = { | ||
CLOUDFLARE_API_KEY: "123456789", | ||
}; | ||
const userInfo = await getUserInfo(); | ||
expect(userInfo).toEqual(undefined); | ||
}); | ||
|
||
it("should return the user's email and accounts if authenticated via config token", async () => { | ||
writeAuthConfigFile({ oauth_token: "some-oauth-token" }); | ||
|
||
|
@@ -79,7 +140,7 @@ describe("getUserInfo()", () => { | |
const userInfo = await getUserInfo(); | ||
|
||
expect(userInfo).toEqual({ | ||
authType: "OAuth", | ||
authType: "OAuth Token", | ||
apiToken: "some-oauth-token", | ||
email: "[email protected]", | ||
accounts: [ | ||
|
@@ -116,7 +177,7 @@ describe("WhoAmI component", () => { | |
|
||
it("should display the user's email and accounts", async () => { | ||
const user: UserInfo = { | ||
authType: "OAuth", | ||
authType: "OAuth Token", | ||
apiToken: "some-oauth-token", | ||
email: "[email protected]", | ||
accounts: [ | ||
|
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