def test_crypt_file_ok(self): crypt = Crypt() crypt.generate_key("mypassword", True) arguments = ["encrypt", "prueba"] cmd = Command(arguments=arguments, autorun=False) cmd.run() crypt.delete_key()
def test_crypt_file_ok(self): crypt = CryptFernet() crypt.generate_key("mypassword", True) message = "My crypt message" encrypt_message = crypt.encrypt(message) assert message == crypt.decrypt(str(encrypt_message, encoding="utf-8")) crypt.delete_key()
def run(self): crypt = Crypt() if self.create_key: path = crypt._loader.get_path_from_env() # pylint: disable=protected-access pwd = self.get_input('Type a password to generate the key file: ') generate_file = self.get_input('Do you want to generate a file in {}? [Y/n]'.format(path)) generate_file = generate_file.lower() != "n" key = crypt.generate_key(pwd, generate_file) if generate_file: self.print_ok("File {} generated OK".format(path)) else: self.print_ok("Key generated: {}".format(key)) if self.encrypt: encrypted = crypt.encrypt(self.encrypt) self.print_ok("Encrypted OK: {}".format(encrypted)) if self.startproject: check_package_exists("cookiecutter") cookiecutter = import_from("cookiecutter.main", "cookiecutter") cookiecutter('gh:python-microservices/cookiecutter-pyms', checkout=self.branch) self.print_ok("Created project OK") if self.merge_swagger: try: merge_swagger_file(main_file=self.file) self.print_ok("Swagger file generated [swagger-complete.yaml]") except FileNotFoundError as ex: self.print_error(ex.__str__()) return False return True
def run(self): crypt = Crypt() if self.create_key: path = crypt._loader.get_path_from_env() # pylint: disable=protected-access pwd = self.get_input("Type a password to generate the key file: ") # Should use yes_no_input insted of get input below # the result should be validated for Yes (Y|y) rather allowing anything other than 'n' generate_file = self.get_input( "Do you want to generate a file in {}? [Y/n]".format(path)) generate_file = generate_file.lower() != "n" key = crypt.generate_key(pwd, generate_file) if generate_file: self.print_ok("File {} generated OK".format(path)) else: self.print_ok("Key generated: {}".format(key)) if self.encrypt: # Spoted Unhandle exceptions - The encrypt function throws FileDoesNotExistException, ValueError # which are not currently handled encrypted = crypt.encrypt(self.encrypt) self.print_ok("Encrypted OK: {}".format(encrypted)) if self.startproject: check_package_exists("cookiecutter") cookiecutter = import_from("cookiecutter.main", "cookiecutter") cookiecutter("gh:python-microservices/cookiecutter-pyms", checkout=self.branch) self.print_ok("Created project OK") if self.merge_swagger: try: merge_swagger_file(main_file=self.file) self.print_ok("Swagger file generated [swagger-complete.yaml]") except FileNotFoundError as ex: self.print_error(ex.__str__()) return False if self.create_config: use_requests = self.yes_no_input("Do you want to use request") use_swagger = self.yes_no_input("Do you want to use swagger") try: conf_file_path = create_conf_file(use_requests, use_swagger) self.print_ok(f'Config file "{conf_file_path}" created') return True except Exception as ex: self.print_error(ex.__str__()) return False return True
def run(self): crypt = Crypt() if self.create_key: path = crypt._loader.get_path_from_env() # pylint: disable=protected-access pwd = self.get_input('Type a password to generate the key file: ') generate_file = self.get_input('Do you want to generate a file in {}? [Y/n]'.format(path)) generate_file = generate_file.lower() != "n" key = crypt.generate_key(pwd, generate_file) if generate_file: self.print_ok("File {} generated OK".format(path)) else: self.print_ok("Key generated: {}".format(key)) if self.encrypt: encrypted = crypt.encrypt(self.encrypt) self.print_ok("Encrypted OK: {}".format(encrypted)) if self.startproject: check_package_exists("cookiecutter") cookiecutter = import_from("cookiecutter.main", "cookiecutter") cookiecutter('gh:python-microservices/cookiecutter-pyms', checkout=self.branch) self.print_ok("Created project OK") return True