-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 #818 from fishtown-analytics/feature/redshift-iam-…
…auth Feature/redshift iam auth
- Loading branch information
Showing
6 changed files
with
236 additions
and
8 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
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 |
---|---|---|
|
@@ -13,3 +13,4 @@ google-cloud-bigquery==0.29.0 | |
requests>=2.18.0 | ||
agate>=1.6,<2 | ||
jsonschema==2.6.0 | ||
boto3>=1.6.23 |
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 |
---|---|---|
|
@@ -52,5 +52,6 @@ def read(fname): | |
'google-cloud-bigquery==0.29.0', | ||
'agate>=1.6,<2', | ||
'jsonschema==2.6.0', | ||
'boto3>=1.6.23' | ||
] | ||
) |
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,98 @@ | ||
import unittest | ||
import mock | ||
|
||
import dbt.flags as flags | ||
import dbt.utils | ||
|
||
from dbt.adapters.redshift import RedshiftAdapter | ||
from dbt.exceptions import ValidationException, FailedToConnectException | ||
from dbt.logger import GLOBAL_LOGGER as logger # noqa | ||
|
||
@classmethod | ||
def fetch_cluster_credentials(*args, **kwargs): | ||
return { | ||
'DbUser': 'root', | ||
'DbPassword': 'tmp_password' | ||
} | ||
|
||
class TestRedshiftAdapter(unittest.TestCase): | ||
|
||
def setUp(self): | ||
flags.STRICT_MODE = True | ||
|
||
def test_implicit_database_conn(self): | ||
implicit_database_profile = { | ||
'dbname': 'redshift', | ||
'user': 'root', | ||
'host': 'database', | ||
'pass': 'password', | ||
'port': 5439, | ||
'schema': 'public' | ||
} | ||
|
||
creds = RedshiftAdapter.get_credentials(implicit_database_profile) | ||
self.assertEquals(creds, implicit_database_profile) | ||
|
||
def test_explicit_database_conn(self): | ||
explicit_database_profile = { | ||
'method': 'database', | ||
'dbname': 'redshift', | ||
'user': 'root', | ||
'host': 'database', | ||
'pass': 'password', | ||
'port': 5439, | ||
'schema': 'public' | ||
} | ||
|
||
creds = RedshiftAdapter.get_credentials(explicit_database_profile) | ||
self.assertEquals(creds, explicit_database_profile) | ||
|
||
def test_explicit_iam_conn(self): | ||
explicit_iam_profile = { | ||
'method': 'iam', | ||
'cluster_id': 'my_redshift', | ||
'iam_duration_s': 1200, | ||
'dbname': 'redshift', | ||
'user': 'root', | ||
'host': 'database', | ||
'port': 5439, | ||
'schema': 'public', | ||
} | ||
|
||
with mock.patch.object(RedshiftAdapter, 'fetch_cluster_credentials', new=fetch_cluster_credentials): | ||
creds = RedshiftAdapter.get_credentials(explicit_iam_profile) | ||
|
||
expected_creds = dbt.utils.merge(explicit_iam_profile, {'pass': 'tmp_password'}) | ||
self.assertEquals(creds, expected_creds) | ||
|
||
def test_invalid_auth_method(self): | ||
invalid_profile = { | ||
'method': 'badmethod', | ||
'dbname': 'redshift', | ||
'user': 'root', | ||
'host': 'database', | ||
'pass': 'password', | ||
'port': 5439, | ||
'schema': 'public' | ||
} | ||
|
||
with self.assertRaises(dbt.exceptions.FailedToConnectException) as context: | ||
with mock.patch.object(RedshiftAdapter, 'fetch_cluster_credentials', new=fetch_cluster_credentials): | ||
RedshiftAdapter.get_credentials(invalid_profile) | ||
|
||
self.assertTrue('badmethod' in context.exception.msg) | ||
|
||
def test_invalid_iam_no_cluster_id(self): | ||
invalid_profile = { | ||
'method': 'iam', | ||
'dbname': 'redshift', | ||
'user': 'root', | ||
'host': 'database', | ||
'port': 5439, | ||
'schema': 'public' | ||
} | ||
with self.assertRaises(dbt.exceptions.FailedToConnectException) as context: | ||
with mock.patch.object(RedshiftAdapter, 'fetch_cluster_credentials', new=fetch_cluster_credentials): | ||
RedshiftAdapter.get_credentials(invalid_profile) | ||
|
||
self.assertTrue("'cluster_id' must be provided" in context.exception.msg) |