def test_loaded_data_is_checked(self, mock_check_account):
        directory = tempfile.mkdtemp()
        filename = "account.yaml"
        content = "account_one:\n  id: 1\n  email: [email protected]\n  owner: me"

        try:
            with open(os.path.join(directory, filename), "w") as test_file:
                test_file.write(content)

            ai.read_directory(directory)

            mock_check_account.assert_called_once_with(
                {'account_one': {
                    'id': '1', 'email': '*****@*****.**', 'owner': 'me'}})
        finally:
            shutil.rmtree(directory)
    def test_account_id_is_converted_to_string(self):
        directory = tempfile.mkdtemp()
        filename = "account.yaml"
        content = {
            "account_name": {
                "id": 42,
                "email": "*****@*****.**",
                "owner": "me"
            },
            "another": {
                "id": "43",
                "email": "*****@*****.**",
                "owner": "minime"
            }
        }

        try:
            with open(os.path.join(directory, filename), "w") as test_file:
                test_file.write(yaml.dump(content))

            result = ai.read_directory(directory)

            expected_content = content
            # Must have been converted from int 42 to string "42".
            expected_content['account_name']['id'] = '42'
            self.assertEqual(expected_content, result)
        finally:
            shutil.rmtree(directory)
    def test_loaded_data_is_checked(self, mock_check_account):
        directory = tempfile.mkdtemp()
        filename = "account.yaml"
        content = "account_one:\n  id: 1\n  email: [email protected]\n  owner: me"

        try:
            with open(os.path.join(directory, filename), "w") as test_file:
                test_file.write(content)

            ai.read_directory(directory)

            mock_check_account.assert_called_once_with({
                'account_one': {
                    'id': '1',
                    'email': '*****@*****.**',
                    'owner': 'me'
                }
            })
        finally:
            shutil.rmtree(directory)
    def test_loaded_data_is_returned_data(self):
        directory = tempfile.mkdtemp()
        filename = "account.yaml"
        content = {"account_name": {"id": "42", "email": "*****@*****.**", "owner": "me"}}

        try:
            with open(os.path.join(directory, filename), "w") as test_file:
                test_file.write(yaml.dump(content))

            result = ai.read_directory(directory)

            self.assertEqual(content, result)
        finally:
            shutil.rmtree(directory)
def upload(data_directory, destination_bucket_name, allowed_ips=None):
    allowed_ips = allowed_ips or []

    try:
        account_data = read_directory(data_directory)
    except Exception as e:
        raise Exception("Failed to read data directory '{0}': {1} ".format(data_directory, e))

    data_to_upload = get_converted_aws_accounts(account_data)

    our_account_ids = [account["id"] for account in account_data.values()]
    uploader = S3Uploader(destination_bucket_name, allowed_ips=allowed_ips, allowed_aws_account_ids=our_account_ids)

    uploader.setup_infrastructure()
    uploader.upload_to_S3(data_to_upload)
def upload(data_directory, destination_bucket_name, allowed_ips=None):
    allowed_ips = allowed_ips or []

    try:
        account_data = read_directory(data_directory)
    except Exception as e:
        raise Exception("Failed to read data directory '{0}': {1} ".format(
            data_directory, e))

    data_to_upload = get_converted_aws_accounts(account_data)

    our_account_ids = [account['id'] for account in account_data.values()]
    uploader = S3Uploader(destination_bucket_name,
                          allowed_ips=allowed_ips,
                          allowed_aws_account_ids=our_account_ids)

    uploader.setup_infrastructure()
    uploader.upload_to_S3(data_to_upload)
    def test_account_id_is_converted_to_string(self):
        directory = tempfile.mkdtemp()
        filename = "account.yaml"
        content = {
            "account_name": {"id": 42, "email": "*****@*****.**", "owner": "me"},
            "another": {"id": "43", "email": "*****@*****.**", "owner": "minime"}}

        try:
            with open(os.path.join(directory, filename), "w") as test_file:
                test_file.write(yaml.dump(content))

            result = ai.read_directory(directory)

            expected_content = content
            # Must have been converted from int 42 to string "42".
            expected_content['account_name']['id'] = '42'
            self.assertEqual(expected_content, result)
        finally:
            shutil.rmtree(directory)
    def test_loaded_data_is_returned_data(self):
        directory = tempfile.mkdtemp()
        filename = "account.yaml"
        content = {
            "account_name": {
                "id": "42",
                "email": "*****@*****.**",
                "owner": "me"
            }
        }

        try:
            with open(os.path.join(directory, filename), "w") as test_file:
                test_file.write(yaml.dump(content))

            result = ai.read_directory(directory)

            self.assertEqual(content, result)
        finally:
            shutil.rmtree(directory)