ssh/wip
Some checks failed
/ job (push) Failing after 8s

This commit is contained in:
Marc Beninca 2024-05-31 00:29:12 +02:00
parent 887ef88ba9
commit 70a8fd3e93
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
4 changed files with 27 additions and 22 deletions

View file

@ -2,6 +2,7 @@ import os
from cd.project import Project
from cd.projects import Projects
from rwx import fs
from rwx import ps
COMMANDS_PREFIX = 'cd-'
@ -50,7 +51,7 @@ def cd_clone_branch():
def cd_list_environment():
for variable, value in sorted(os.environ.items()):
for variable, value in sorted(projects.environment.items()):
print(variable, '=', value)
@ -64,3 +65,25 @@ def install_commands(path):
]:
print(command)
os.symlink(path, os.path.join(user, f'{COMMANDS_PREFIX}{command}'))
def set_ssh():
ssh_hosts = projects.environment.get('CD_SSH_HOSTS', None)
ssh_key = projects.environment.get('CD', None)
ssh_type = projects.environment.get('CD_SSH_TYPE', 'ed25519')
#
home = os.path.expanduser('~')
#
ssh = os.path.join(home, '.ssh')
os.makedirs(ssh, exist_ok=True)
os.chmod(ssh, 0o700)
#
key = os.path.join(ssh, f'id_{ssh_type}')
if ssh_key:
fs.write(key, ssh_key)
os.chmod(key, 0o400)
#
known = os.path.join(ssh, 'known_hosts')
if ssh_hosts:
fs.write(known, ssh_hosts)
os.chmod(known, 0o400)

View file

@ -10,6 +10,7 @@ if __name__ == '__main__':
command, *arguments = sys.argv
command = os.path.basename(command)
if command == '__main__.py':
cd.set_ssh()
cd.install_commands(__file__)
else:
command = command.replace('-', '_')