Closes #21: Region should be configurable.

This commit is contained in:
Marina Samuel 2018-03-07 12:05:16 -05:00
Родитель 2b5a20fc53
Коммит 6e7176cc96
5 изменённых файлов: 14 добавлений и 9 удалений

Просмотреть файл

@ -25,7 +25,7 @@ class StatisticalDashboard(ExperimentDashboard):
def __init__(
self, api_key, aws_access_key, aws_secret_key,
self, api_key, aws_access_key, aws_secret_key, s3_region,
s3_bucket_id, project_name, dash_name, exp_id,
start_date=None, end_date=None
):
@ -39,7 +39,8 @@ class StatisticalDashboard(ExperimentDashboard):
self._ttables = {}
self._s3_bucket = s3_bucket_id
self._transfer = create_boto_transfer(aws_access_key, aws_secret_key)
self._transfer = create_boto_transfer(
aws_access_key, aws_secret_key, s3_region)
def _copy_ttable_tempalte(self):
template_copy = self.TTABLE_TEMPLATE.copy()

Просмотреть файл

@ -188,6 +188,7 @@ if __name__ == '__main__':
api_key = os.environ["REDASH_API_KEY"]
aws_access_key = os.environ['AWS_ACCESS_KEY']
aws_secret_key = os.environ['AWS_SECRET_KEY']
s3_region = os.environ['S3_REGION']
s3_bucket_id_stats = os.environ['S3_BUCKET_ID_STATS']
# T-Table Names
@ -205,12 +206,12 @@ if __name__ == '__main__':
api_key,
aws_access_key,
aws_secret_key,
s3_region,
s3_bucket_id_stats,
"Pocket Experiment",
"Sponsored Stories",
"pref-flip-activity-stream-59-beta-pocket-sponsored-stories-bug-1432989",
start_date="2018-01-29",
end_date="2018-02-13"
"Release Sponsored Stories",
"pref-flip-activity-stream-59-release-pocket-sponsored-stories-bug-1435822",
start_date="2018-02-12"
)
dash.add_graph_templates(POPULATION_TEMPLATE)

Просмотреть файл

@ -18,6 +18,7 @@ class TestStatisticalDashboard(AppTest):
EXPERIMENT_ID = "exp-014-screenshotsasync"
AWS_ACCESS_KEY = "access"
AWS_SECRET_KEY = "secret"
AWS_REGION = "us-west-2"
AWS_BUCKET_ID = "bucket"
def get_dashboard(self, api_key):
@ -32,6 +33,7 @@ class TestStatisticalDashboard(AppTest):
self.API_KEY,
self.AWS_ACCESS_KEY,
self.AWS_SECRET_KEY,
self.AWS_REGION,
self.AWS_BUCKET_ID,
self.DASH_PROJECT,
self.DASH_NAME,

Просмотреть файл

@ -18,6 +18,7 @@ class TestUtils(AppTest):
FILENAME = "test_file_name"
ACCESS_KEY = "key"
SECRET_KEY = "secret"
REGION = "us-west-2"
BUCKET_ID = "bucket"
DATA = {"columns": TTableSchema, "rows": []}
@ -27,7 +28,7 @@ class TestUtils(AppTest):
mock_boto_transfer_patcher = mock.patch("stmoab.utils.S3Transfer")
mock_boto_transfer_patcher.start()
transfer = create_boto_transfer(ACCESS_KEY, SECRET_KEY)
transfer = create_boto_transfer(ACCESS_KEY, SECRET_KEY, REGION)
query_string = upload_as_json(DIRECTORY_NAME, FILENAME, transfer, BUCKET_ID, DATA)
self.assertEqual(query_string, EXPECTED_BASE_URL + EXPECTED_S3_KEY)

Просмотреть файл

@ -8,10 +8,10 @@ from datetime import datetime, timedelta
s3 = boto3.client("s3")
def create_boto_transfer(access_key, secret_key):
def create_boto_transfer(access_key, secret_key, region):
client = boto3.client(
"s3",
region_name="us-west-2",
region_name=region,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key)
transfer = S3Transfer(client)