How to use store_cert_key_files method in localstack

Best Python code snippet using localstack_python

crypto.py

Source:crypto.py Github

copy

Full Screen

...26 # (Our test Lambdas are importing this file but don't have the module installed)27 from OpenSSL import crypto28 def all_exist(*files):29 return all(os.path.exists(f) for f in files)30 def store_cert_key_files(base_filename):31 key_file_name = "%s.key" % base_filename32 cert_file_name = "%s.crt" % base_filename33 # TODO: Cleaner code to load the cert dynamically34 # extract key and cert from target_file and store into separate files35 content = load_file(target_file)36 key_start = re.search(PEM_KEY_START_REGEX, content)37 key_start = key_start.group(0)38 key_end = re.search(PEM_KEY_END_REGEX, content)39 key_end = key_end.group(0)40 key_content = content[content.index(key_start) : content.index(key_end) + len(key_end)]41 cert_content = content[42 content.index(PEM_CERT_START) : content.rindex(PEM_CERT_END) + len(PEM_CERT_END)43 ]44 save_file(key_file_name, key_content)45 save_file(cert_file_name, cert_content)46 return cert_file_name, key_file_name47 if target_file and not overwrite and os.path.exists(target_file):48 try:49 cert_file_name, key_file_name = store_cert_key_files(target_file)50 except Exception as e:51 # fall back to temporary files if we cannot store/overwrite the files above52 LOG.info(53 "Error storing key/cert SSL files (falling back to random tmp file names): %s", e54 )55 target_file_tmp = new_tmp_file()56 cert_file_name, key_file_name = store_cert_key_files(target_file_tmp)57 if all_exist(cert_file_name, key_file_name):58 return target_file, cert_file_name, key_file_name59 if random and target_file:60 if "." in target_file:61 target_file = target_file.replace(".", ".%s." % short_uid(), 1)62 else:63 target_file = "%s.%s" % (target_file, short_uid())64 # create a key pair65 k = crypto.PKey()66 k.generate_key(crypto.TYPE_RSA, 2048)67 # create a self-signed cert68 cert = crypto.X509()69 subj = cert.get_subject()70 subj.C = "AU"...

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