コード例 #1
0
 def _inject_aws_credentials(self):
     if TRANSFER_SPEC in self.body and AWS_S3_DATA_SOURCE in self.body[
             TRANSFER_SPEC]:
         aws_hook = AwsHook(self.aws_conn_id)
         aws_credentials = aws_hook.get_credentials()
         aws_access_key_id = aws_credentials.access_key
         aws_secret_access_key = aws_credentials.secret_key
         self.body[TRANSFER_SPEC][AWS_S3_DATA_SOURCE][AWS_ACCESS_KEY] = {
             ACCESS_KEY_ID: aws_access_key_id,
             SECRET_ACCESS_KEY: aws_secret_access_key,
         }
コード例 #2
0
 def test_get_credentials_from_extra_without_token(self,
                                                   mock_get_connection):
     mock_connection = Connection(
         extra='{"aws_access_key_id": "aws_access_key_id",'
         '"aws_secret_access_key": "aws_secret_access_key"}')
     mock_get_connection.return_value = mock_connection
     hook = AwsHook()
     credentials_from_hook = hook.get_credentials()
     self.assertEqual(credentials_from_hook.access_key, 'aws_access_key_id')
     self.assertEqual(credentials_from_hook.secret_key,
                      'aws_secret_access_key')
     self.assertIsNone(credentials_from_hook.token)
コード例 #3
0
 def test_get_credentials_from_login_with_token(self, mock_get_connection):
     mock_connection = Connection(
         login='******',
         password='******',
         extra='{"aws_session_token": "test_token"}')
     mock_get_connection.return_value = mock_connection
     hook = AwsHook()
     credentials_from_hook = hook.get_credentials()
     self.assertEqual(credentials_from_hook.access_key, 'aws_access_key_id')
     self.assertEqual(credentials_from_hook.secret_key,
                      'aws_secret_access_key')
     self.assertEqual(credentials_from_hook.token, 'test_token')
コード例 #4
0
    def test_get_credentials_from_role_arn(self, mock_get_connection):
        mock_connection = Connection(
            extra='{"role_arn":"arn:aws:iam::123456:role/role_arn"}')
        mock_get_connection.return_value = mock_connection
        hook = AwsHook()
        credentials_from_hook = hook.get_credentials()
        self.assertIn("ASIA", credentials_from_hook.access_key)

        # We assert the length instead of actual values as the values are random:
        # Details: https://github.com/spulec/moto/commit/ab0d23a0ba2506e6338ae20b3fde70da049f7b03
        self.assertEqual(20, len(credentials_from_hook.access_key))
        self.assertEqual(40, len(credentials_from_hook.secret_key))
        self.assertEqual(356, len(credentials_from_hook.token))
コード例 #5
0
    def test_get_credentials_from_login_without_token(self,
                                                      mock_get_connection):
        mock_connection = Connection(
            login='******',
            password='******',
        )

        mock_get_connection.return_value = mock_connection
        hook = AwsHook()
        credentials_from_hook = hook.get_credentials()
        self.assertEqual(credentials_from_hook.access_key, 'aws_access_key_id')
        self.assertEqual(credentials_from_hook.secret_key,
                         'aws_secret_access_key')
        self.assertIsNone(credentials_from_hook.token)