How to use import_key_material method in localstack

Best Python code snippet using localstack_python

external_key.py

Source:external_key.py Github

copy

Full Screen

...36 encrypted_key_material = self.encryptor.encrypt_key_material(37 key_material=kms_external_key.key_material,38 wrapping_key=wrapping_key,39 )40 return self.kms_client.import_key_material(41 KeyId=kms_external_key.key_id,42 ImportToken=token,43 EncryptedKeyMaterial=encrypted_key_material,44 ExpirationModel='KEY_MATERIAL_DOES_NOT_EXPIRE',...

Full Screen

Full Screen

test_external_key.py

Source:test_external_key.py Github

copy

Full Screen

1import os2import boto33import pytest4from unittest import mock5from moto import mock_kms6from dataclasses import FrozenInstanceError7from import_key_material.external_key import (8 KMSExternalKey, KMSExternalKeyImporter9)10@pytest.fixture()11def key_material():12 yield os.urandom(32)13@pytest.fixture()14def kms_client():15 with mock_kms():16 yield boto3.client(17 "kms",18 region_name="us-east-1"19 )20@mock_kms21def test_get_parameters_for_import(key_material):22 with mock.patch("import_key_material.external_key.KMSExternalKey") \23 as external_key:24 external_key.get_parameters_for_import()25 external_key.get_parameters_for_import.assert_called()26@mock_kms27def test_adding_attributes_to_external_key(key_material):28 with pytest.raises(FrozenInstanceError):29 external_key = KMSExternalKey(30 key_id="123456789",31 key_material=key_material32 )33 external_key.test_attribute = "Test"34@mock_kms35def test_import_key_material_to_kms_with_wrong_argument():36 wrong_agrument = "Test_string"37 kms_key_importer = KMSExternalKeyImporter()38 with pytest.raises(TypeError):39 kms_key_importer.import_external_key_to_kms(40 wrong_agrument41 )42@mock_kms43def test_import_external_key_to_kms(key_material):44 with mock.patch("import_key_material.external_key.KMSExternalKeyImporter") \45 as importer:46 external_key = KMSExternalKey(47 key_id="123456789",48 key_material=key_material49 )50 importer.import_external_key_to_kms(external_key)51 importer.import_external_key_to_kms.assert_called_once_with(52 external_key...

Full Screen

Full Screen

__main__.py

Source:__main__.py Github

copy

Full Screen

1import argparse2from Crypto.Random import get_random_bytes3from import_key_material.external_key import (4 KMSExternalKey, KMSExternalKeyImporter5)6def generate_aes256_key():7 return get_random_bytes(32)8def parse_arguments(description):9 parser = argparse.ArgumentParser(description=description)10 parser.add_argument(11 "-id", "--key_id", metavar="", help="KMS key identification"12 )13 parser.add_argument(14 "-alg", "--algorithm", metavar="", help="Encryption algorithm"15 )16 return parser.parse_args()17def main():18 args = parse_arguments("Import key material into KMS")19 key_material = generate_aes256_key()20 external_key = KMSExternalKey(21 args.key_id,22 key_material,23 args.algorithm24 )25 importer = KMSExternalKeyImporter()26 response = importer.import_external_key_to_kms(27 kms_external_key=external_key28 )29 print(f"Imported key material: Key_id => {args.key_id}: {response}")30if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful