Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from hanswesterbeek/add-iam-auth-support
Add iam auth support
- Loading branch information
Showing
10 changed files
with
230 additions
and
2 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 |
---|---|---|
|
@@ -36,3 +36,6 @@ jspm_packages | |
# Optional REPL history | ||
.node_repl_history | ||
*.zip | ||
|
||
# IntelliJ files | ||
.idea/ |
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,14 @@ | ||
const AWS = require('aws-sdk') | ||
|
||
function decorateWithIamToken(baseConfig) { | ||
const rdsSigner = new AWS.RDS.Signer() | ||
const token = rdsSigner.getAuthToken({ | ||
hostname: baseConfig.PGHOST, | ||
port: baseConfig.PGPORT != null ? baseConfig.PGPORT : 5432, | ||
region: baseConfig.S3_REGION, | ||
username: baseConfig.PGUSER | ||
}) | ||
return { ...baseConfig, PGPASSWORD: token } | ||
} | ||
|
||
module.exports = decorateWithIamToken |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,5 +4,8 @@ | |
"globals": { | ||
"describe": true, | ||
"it": true | ||
}, | ||
"env": { | ||
"mocha": true | ||
} | ||
} |
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,41 @@ | ||
/* eslint no-underscore-dangle: 0 */ | ||
const { expect } = require('chai') | ||
const rewire = require('rewire') | ||
const chai = require('chai') | ||
const chaiAsPromised = require('chai-as-promised') | ||
const AWSMOCK = require('aws-sdk-mock') | ||
const AWS = require('aws-sdk') | ||
|
||
chai.should() | ||
chai.use(chaiAsPromised) | ||
|
||
AWSMOCK.setSDKInstance(AWS) | ||
|
||
|
||
const decorateWithIamToken = rewire('../lib/iam') | ||
|
||
describe('iam-based auth', () => { | ||
it('should set the postgres default if no PGPORT is set', async () => { | ||
const mockEvent = { USE_IAM_AUTH: true } | ||
const token = 'foo' | ||
AWSMOCK.mock('RDS.Signer', 'getAuthToken', (options) => { | ||
expect(options.port).to.equal(5432) | ||
return token | ||
}) | ||
decorateWithIamToken(mockEvent) | ||
}) | ||
|
||
it('should apply PGPORT to the auth-token request', async () => { | ||
const mockEvent = { USE_IAM_AUTH: true, PGPORT: 2345 } | ||
const token = 'foo' | ||
AWSMOCK.mock('RDS.Signer', 'getAuthToken', (options) => { | ||
expect(options.port).to.equal(mockEvent.PGPORT) | ||
return token | ||
}) | ||
decorateWithIamToken(mockEvent) | ||
}) | ||
|
||
afterEach(() => { | ||
AWSMOCK.restore('RDS.Signer') | ||
}) | ||
}) |