Skip to content
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

Add support for a credential provider process #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions connection.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"title": "Connect using",
"type": "string",
"minLength": 1,
"enum": ["Profile", "Session Credentials"],
"enum": ["Profile", "Session Credentials", "Profile Credential Process"],
"default": "Profile"
},
"outputLocation": {
Expand All @@ -30,7 +30,7 @@
{
"properties": {
"connectionMethod": {
"enum": ["Profile"]
"enum": ["Profile", "Profile Credential Process"]
},
"profile": {
"title": "AWS Profile",
Expand Down
26 changes: 17 additions & 9 deletions src/ls/driver.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import AWS from 'aws-sdk';
import AbstractDriver from '@sqltools/base-driver';
import { IConnectionDriver, MConnectionExplorer, NSDatabase, Arg0, ContextValue } from '@sqltools/types';
import queries from './queries';
import { v4 as generateId } from 'uuid';
import { Athena, AWSError, Credentials, SharedIniFileCredentials } from 'aws-sdk';
import { Athena, AWSError, Credentials, SharedIniFileCredentials, ProcessCredentials } from 'aws-sdk';
import { PromiseResult } from 'aws-sdk/lib/request';
import { GetQueryResultsInput, GetQueryResultsOutput } from 'aws-sdk/clients/athena';

Expand Down Expand Up @@ -33,19 +34,26 @@ export default class AthenaDriver extends AbstractDriver<Athena, Athena.Types.Cl
return this.connection;
}

if (this.credentials.connectionMethod !== 'Profile')
var credentials = new Credentials({
let credentials;

if (this.credentials.connectionMethod === 'Profile') {
credentials = new SharedIniFileCredentials({ profile: this.credentials.profile });
} else if (this.credentials.connectionMethod === 'Profile Credential Process') {
credentials = new ProcessCredentials({ profile: this.credentials.profile });
} else {
credentials = new Credentials({
accessKeyId: this.credentials.accessKeyId,
secretAccessKey: this.credentials.secretAccessKey,
sessionToken: this.credentials.sessionToken,
});
else
var credentials = new SharedIniFileCredentials({ profile: this.credentials.profile });
}

this.connection = Promise.resolve(new Athena({
credentials: credentials,
region: this.credentials.region || 'us-east-1',
}));
this.connection = Promise.resolve(
new AWS.Athena({
credentials: credentials,
region: this.credentials.region || 'us-east-1',
})
);

return this.connection;
}
Expand Down