diff --git a/capsulflask/console.py b/capsulflask/console.py index ef2f42a..644c66c 100644 --- a/capsulflask/console.py +++ b/capsulflask/console.py @@ -159,7 +159,7 @@ def create(): elif os not in operating_systems: errors.append(f"Invalid os {os}") - posted_keys_count = int(request.form["ssh_public_key_count"]) + posted_keys_count = int(request.form["ssh_authorized_key_count"]) posted_keys = list() if posted_keys_count > 1000: @@ -226,8 +226,8 @@ def create(): csrf_token = session["csrf-token"], capacity_avaliable=capacity_avaliable, account_balance=format(account_balance, '.2f'), - ssh_public_keys=public_keys_for_account, - ssh_public_key_count=len(public_keys_for_account), + ssh_authorized_keys=public_keys_for_account, + ssh_authorized_key_count=len(public_keys_for_account), no_ssh_public_keys=len(public_keys_for_account) == 0, operating_systems=operating_systems, cant_afford=len(affordable_vm_sizes) == 0, diff --git a/capsulflask/hub_model.py b/capsulflask/hub_model.py index ca4bc51..a77c4a9 100644 --- a/capsulflask/hub_model.py +++ b/capsulflask/hub_model.py @@ -37,7 +37,7 @@ class MockHub(VirtualizationInterface): def list_ids(self) -> list: return get_model().all_non_deleted_vm_ids() - def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory_mb: int, ssh_public_keys: list): + def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory_mb: int, ssh_authorized_keys: list): validate_capsul_id(id) current_app.logger.info(f"mock create: {id} for {email}") sleep(1) @@ -177,7 +177,7 @@ class CapsulFlaskHub(VirtualizationInterface): return to_return - def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory_mb: int, ssh_public_keys: list): + def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory_mb: int, ssh_authorized_keys: list): validate_capsul_id(id) online_hosts = get_model().get_online_hosts() payload = json.dumps(dict( @@ -187,7 +187,7 @@ class CapsulFlaskHub(VirtualizationInterface): template_image_file_name=template_image_file_name, vcpus=vcpus, memory_mb=memory_mb, - ssh_public_keys=ssh_public_keys, + ssh_authorized_keys=ssh_authorized_keys, )) op = self.asynchronous_operation(online_hosts, payload) operation_id = op[0] diff --git a/capsulflask/shared.py b/capsulflask/shared.py index 92f9046..00c6805 100644 --- a/capsulflask/shared.py +++ b/capsulflask/shared.py @@ -33,7 +33,7 @@ class VirtualizationInterface: def list_ids(self) -> list: pass - def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory: int, ssh_public_keys: list): + def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory: int, ssh_authorized_keys: list): pass def destroy(self, email: str, id: str): diff --git a/capsulflask/spoke_api.py b/capsulflask/spoke_api.py index b73f2f7..9fcf502 100644 --- a/capsulflask/spoke_api.py +++ b/capsulflask/spoke_api.py @@ -101,7 +101,7 @@ def handle_create(operation_id, request_body): current_app.logger.error(f"/hosts/operation returned 400: operation_id is required for create ") return abort(400, f"bad request; operation_id is required. try POST /spoke/operation/") - parameters = ["email", "id", "template_image_file_name", "vcpus", "memory_mb", "ssh_public_keys"] + parameters = ["email", "id", "template_image_file_name", "vcpus", "memory_mb", "ssh_authorized_keys"] error_message = "" for parameter in parameters: if parameter not in request_body: @@ -134,13 +134,13 @@ def handle_create(operation_id, request_body): template_image_file_name=request_body['template_image_file_name'], vcpus=request_body['vcpus'], memory_mb=request_body['memory_mb'], - ssh_public_keys=request_body['ssh_public_keys'], + ssh_authorized_keys=request_body['ssh_authorized_keys'], ) except: error_message = my_exec_info_message(sys.exc_info()) params = f"email='{request_body['email']}', id='{request_body['id']}', " params = f"{params}, template_image_file_name='{request_body['template_image_file_name']}', vcpus='{request_body['vcpus']}'" - params = f"{params}, memory_mb='{request_body['memory_mb']}', ssh_public_keys='{request_body['ssh_public_keys']}'" + params = f"{params}, memory_mb='{request_body['memory_mb']}', ssh_authorized_keys='{request_body['ssh_authorized_keys']}'" current_app.logger.error(f"spoke_model.create({params}) failed: {error_message}") return jsonify(dict(assignment_status=assignment_status, error_message=error_message)) diff --git a/capsulflask/spoke_model.py b/capsulflask/spoke_model.py index 2f3f1b0..13cd3a8 100644 --- a/capsulflask/spoke_model.py +++ b/capsulflask/spoke_model.py @@ -33,7 +33,7 @@ class MockSpoke(VirtualizationInterface): def list_ids(self) -> list: return get_model().all_non_deleted_vm_ids() - def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory_mb: int, ssh_public_keys: list): + def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory_mb: int, ssh_authorized_keys: list): validate_capsul_id(id) current_app.logger.info(f"mock create: {id} for {email}") sleep(1) @@ -107,15 +107,15 @@ class ShellScriptSpoke(VirtualizationInterface): self.validate_completed_process(completedProcess) return list(map(lambda x: x.decode("utf-8"), completedProcess.stdout.splitlines() )) - def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory_mb: int, ssh_public_keys: list): + def create(self, email: str, id: str, template_image_file_name: str, vcpus: int, memory_mb: int, ssh_authorized_keys: list): validate_capsul_id(id) if not re.match(r"^[a-zA-Z0-9/_.-]+$", template_image_file_name): raise ValueError(f"template_image_file_name \"{template_image_file_name}\" must match \"^[a-zA-Z0-9/_.-]+$\"") - for ssh_public_key in ssh_public_keys: - if not re.match(r"^(ssh|ecdsa)-[0-9A-Za-z+/_=@. -]+$", ssh_public_key): - raise ValueError(f"ssh_public_key \"{ssh_public_key}\" must match \"^(ssh|ecdsa)-[0-9A-Za-z+/_=@. -]+$\"") + for ssh_authorized_key in ssh_authorized_keys: + if not re.match(r"^(ssh|ecdsa)-[0-9A-Za-z+/_=@. -]+$", ssh_authorized_key): + raise ValueError(f"ssh_authorized_key \"{ssh_authorized_key}\" must match \"^(ssh|ecdsa)-[0-9A-Za-z+/_=@. -]+$\"") if vcpus < 1 or vcpus > 8: raise ValueError(f"vcpus \"{vcpus}\" must match 1 <= vcpus <= 8") @@ -123,7 +123,7 @@ class ShellScriptSpoke(VirtualizationInterface): if memory_mb < 512 or memory_mb > 16384: raise ValueError(f"memory_mb \"{memory_mb}\" must match 512 <= memory_mb <= 16384") - ssh_keys_string = "\n".join(ssh_public_keys) + ssh_keys_string = "\n".join(ssh_authorized_keys) completedProcess = run([ join(current_app.root_path, 'shell_scripts/create.sh'), @@ -143,7 +143,7 @@ class ShellScriptSpoke(VirtualizationInterface): template_image_file_name={template_image_file_name} vcpus={str(vcpus)} memory={str(memory_mb)} - ssh_public_keys={ssh_keys_string} + ssh_authorized_keys={ssh_keys_string} """ if not status == "success": diff --git a/capsulflask/templates/create-capsul.html b/capsulflask/templates/create-capsul.html index 92d4e73..25f6654 100644 --- a/capsulflask/templates/create-capsul.html +++ b/capsulflask/templates/create-capsul.html @@ -53,10 +53,10 @@
- +
- {% for key in ssh_public_keys %} + {% for key in ssh_authorized_keys %}