Skip to content

Commit 396346d

Browse files
added untested public keys
1 parent ce3c3fe commit 396346d

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

bibigrid/core/actions/create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, *, providers, configurations, config_path, log, debug=False,
5050
self.cluster_id = cluster_id or id_generation.generate_safe_cluster_id(providers)
5151
self.ssh_user = configurations[0].get("sshUser") or "ubuntu"
5252
self.ssh_add_public_key_commands = ssh_handler.get_add_ssh_public_key_commands(
53-
configurations[0].get("sshPublicKeyFiles"))
53+
configurations[0].get("sshPublicKeyFiles"), configurations[0].get("sshPublicKeys")) # TODO: Document
5454
self.ssh_timeout = configurations[0].get("sshTimeout", 5)
5555
self.config_path = config_path
5656
self.master_ip = None

bibigrid/core/rest/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class MasterConfig(BaseModel):
117117
network: Optional[str] = Field(default=None)
118118
cloud_identifier: Optional[str] = None
119119
sshPublicKeyFiles: Optional[List[str]] = Field(default=[])
120+
sshPublicKeys: Optional[str] = Field(default=None)
120121
sshTimeout: Optional[int] = 5
121122
cloudScheduling: Optional[CloudScheduling] = None
122123
nfsShares: Optional[List[str]] = Field(default=[])

bibigrid/core/utility/handler/ssh_handler.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,23 @@ def get_ac_command(providers, name):
5050
"Copy application credentials.")
5151

5252

53-
def get_add_ssh_public_key_commands(ssh_public_key_files):
53+
def get_add_ssh_public_key_commands(ssh_public_key_files=None, ssh_public_keys=None):
5454
"""
5555
Builds and returns the necessary commands to add given public keys to remote for additional access.
56-
@param ssh_public_key_files: public keys to add
56+
@param ssh_public_keys: public keys to add
57+
@param ssh_public_key_files: public keys to add from file
5758
@return: list of public key add commands
5859
"""
5960
commands = []
6061
if ssh_public_key_files:
6162
for ssh_public_key_file in ssh_public_key_files:
62-
with open(ssh_public_key_file, mode="r", encoding="UTF-8") as ssh_public_key:
63-
commands.append((f"echo {ssh_public_key.readline().strip()} >> .ssh/authorized_keys",
63+
with open(ssh_public_key_file, mode="r", encoding="UTF-8") as ssh_public_key_stream:
64+
commands.append((f"echo {ssh_public_key_stream.readline().strip()} >> .ssh/authorized_keys",
6465
f"Add SSH Key {ssh_public_key_file}."))
66+
if ssh_public_keys:
67+
for i, ssh_public_key in enumerate(ssh_public_keys):
68+
commands.append((f"echo {ssh_public_key} >> .ssh/authorized_keys",
69+
f"Add SSH Key {i}."))
6570
return commands
6671

6772

0 commit comments

Comments
 (0)