Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Docker OAuth block support (via #4987)
* add `onFound` callback to schemas * add warning to method docs (for #4957) * implement Docker OAuth2 init block support * update docs * add OAUTH_SCOPE_SEPARATOR * drop OAuth env from Dockerfile and run script * don't indent the first oauth block line * drop unused `dedent` import * touch up warning message * add more test cases * return an empty block if no OAuth content is generated * fix broken doc line
- Loading branch information
Showing
10 changed files
with
286 additions
and
163 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
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,13 @@ | ||
module.exports.indent = function indent(str, len, fromLine = 0) { | ||
|
||
return str | ||
.split("\n") | ||
.map((line, i) => { | ||
if (i + 1 >= fromLine) { | ||
return `${Array(len + 1).join(" ")}${line}` | ||
} else { | ||
return line | ||
} | ||
}) | ||
.join("\n") | ||
} |
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,43 @@ | ||
const translator = require("./translator") | ||
const indent = require("./helpers").indent | ||
|
||
const oauthBlockSchema = { | ||
OAUTH_CLIENT_ID: { | ||
type: "string", | ||
name: "clientId" | ||
}, | ||
OAUTH_CLIENT_SECRET: { | ||
type: "string", | ||
name: "clientSecret", | ||
onFound: () => console.warn("Swagger UI warning: don't use `OAUTH_CLIENT_SECRET` in production!") | ||
}, | ||
OAUTH_REALM: { | ||
type: "string", | ||
name: "realm" | ||
}, | ||
OAUTH_APP_NAME: { | ||
type: "string", | ||
name: "appName" | ||
}, | ||
OAUTH_SCOPE_SEPARATOR: { | ||
type: "string", | ||
name: "scopeSeparator" | ||
}, | ||
OAUTH_ADDITIONAL_PARAMS: { | ||
type: "object", | ||
name: "additionalQueryStringParams" | ||
} | ||
} | ||
|
||
module.exports = function oauthBlockBuilder(env) { | ||
const translatorResult = translator(env, { schema: oauthBlockSchema }) | ||
|
||
if(translatorResult) { | ||
return ( | ||
`ui.initOAuth({ | ||
${indent(translatorResult, 2)} | ||
})`) | ||
} | ||
|
||
return `` | ||
} |
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,58 @@ | ||
const expect = require("expect") | ||
const oauthBlockBuilder = require("../../docker/configurator/oauth") | ||
const dedent = require("dedent") | ||
|
||
describe("docker: env translator - oauth block", function() { | ||
it("should omit the block if there are no valid keys", function () { | ||
const input = {} | ||
|
||
expect(oauthBlockBuilder(input)).toEqual(``) | ||
}) | ||
it("should omit the block if there are no valid keys", function () { | ||
const input = { | ||
NOT_A_VALID_KEY: "asdf1234" | ||
} | ||
|
||
expect(oauthBlockBuilder(input)).toEqual(``) | ||
}) | ||
it("should generate a block from empty values", function() { | ||
const input = { | ||
OAUTH_CLIENT_ID: ``, | ||
OAUTH_CLIENT_SECRET: ``, | ||
OAUTH_REALM: ``, | ||
OAUTH_APP_NAME: ``, | ||
OAUTH_SCOPE_SEPARATOR: "", | ||
OAUTH_ADDITIONAL_PARAMS: ``, | ||
} | ||
|
||
expect(oauthBlockBuilder(input)).toEqual(dedent(` | ||
ui.initOAuth({ | ||
clientId: "", | ||
clientSecret: "", | ||
realm: "", | ||
appName: "", | ||
scopeSeparator: "", | ||
additionalQueryStringParams: undefined, | ||
})`)) | ||
}) | ||
it("should generate a full block", function() { | ||
const input = { | ||
OAUTH_CLIENT_ID: `myId`, | ||
OAUTH_CLIENT_SECRET: `mySecret`, | ||
OAUTH_REALM: `myRealm`, | ||
OAUTH_APP_NAME: `myAppName`, | ||
OAUTH_SCOPE_SEPARATOR: "%21", | ||
OAUTH_ADDITIONAL_PARAMS: `{ "a": 1234, "b": "stuff" }`, | ||
} | ||
|
||
expect(oauthBlockBuilder(input)).toEqual(dedent(` | ||
ui.initOAuth({ | ||
clientId: "myId", | ||
clientSecret: "mySecret", | ||
realm: "myRealm", | ||
appName: "myAppName", | ||
scopeSeparator: "%21", | ||
additionalQueryStringParams: { "a": 1234, "b": "stuff" }, | ||
})`)) | ||
}) | ||
}) |
Oops, something went wrong.