Beispiel #1
0
    def _set_aws_auth(self):
        """
        _set_aws_auth gets key, secret, token and expiration either from a
        file or from a temporary instance and sets them
        """

        cred_tuple = get_aws_creds(self.run_local)
        self._aws_key = cred_tuple.access_key_id
        self._aws_secret = cred_tuple.secret_access_key
        self._aws_token = cred_tuple.token
        self._aws_token_expiry = parsedate(cred_tuple.expiration)
Beispiel #2
0
    def _set_aws_auth(self):
        """
        _set_aws_auth gets key, secret, token and expiration either from a
        file or from a temporary instance and sets them
        """

        cred_tuple = get_aws_creds(self.run_local)
        self._aws_key = cred_tuple.access_key_id
        self._aws_secret = cred_tuple.secret_access_key
        self._aws_token = cred_tuple.token
        self._aws_token_expiry = parsedate(cred_tuple.expiration)
Beispiel #3
0
def test_get_temp_creds_from_instance_profile(generate_mock_creds):
    config = {'use_instance_profile': True}
    with staticconf.testing.MockConfiguration(config):
        with mock.patch('sherlock.common.aws.fetch_creds',
                        autospec=True) as mock_creds:
            mock_creds.return_value = MOCK_CREDS
            temp_cred = aws.get_aws_creds(False, check_if_valid=False)
            assert temp_cred.last_updated == MOCK_CREDS['LastUpdated']
            assert temp_cred.access_key_id == MOCK_CREDS['AccessKeyId']
            assert temp_cred.secret_access_key == MOCK_CREDS['SecretAccessKey']
            assert temp_cred.token == MOCK_CREDS['Token']
            assert temp_cred.expiration == MOCK_CREDS['Expiration']
Beispiel #4
0
def test_get_temp_creds_from_instance_profile(generate_mock_creds):
    config = {
        'use_instance_profile': True
    }
    with staticconf.testing.MockConfiguration(config):
        with mock.patch('sherlock.common.aws.fetch_creds',
                        autospec=True) as mock_creds:
            mock_creds.return_value = MOCK_CREDS
            temp_cred = aws.get_aws_creds(False, check_if_valid=False)
            assert temp_cred.last_updated == MOCK_CREDS['LastUpdated']
            assert temp_cred.access_key_id == MOCK_CREDS['AccessKeyId']
            assert temp_cred.secret_access_key == MOCK_CREDS['SecretAccessKey']
            assert temp_cred.token == MOCK_CREDS['Token']
            assert temp_cred.expiration == MOCK_CREDS['Expiration']
Beispiel #5
0
        help="file with Redshift access credentials"
    )
    set_parser_config_option(parser)
    parser.set_defaults(func=rs_check_schema)


def get_cmd_line_args():
    parser = argparse.ArgumentParser(
        prog='PROG',
        description="""Redshift cluster management""",
    )
    subparsers = parser.add_subparsers()
    set_cluster_restore_parser(subparsers)
    set_cluster_delete_parser(subparsers)
    set_show_clusters_parser(subparsers)
    set_check_schema_parser(subparsers)
    return parser.parse_args()


if __name__ == "__main__":
    args = get_cmd_line_args()
    merge_configs(args.config)
    creds = get_aws_creds(from_local_file=True)
    rs_mgmt = RedshiftClusterMgmt(
        host=read_string('redshift_region_uri'),
        aws_access_key_id=creds.access_key_id,
        aws_secret_access_key=creds.secret_access_key,
        security_token=creds.token,
    )
    args.func(rs_mgmt, args)