Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
a1fred committed Apr 18, 2022
1 parent 90f7c7e commit 178985c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
7 changes: 7 additions & 0 deletions carnival/contrib/steps/docker_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ class PullServices(RestartServices):
subcommand = "pull"


class Rm(Ps):
"""
docker-compose stop
"""
subcommand = "rm"


class Stop(Ps):
"""
docker-compose stop
Expand Down
16 changes: 9 additions & 7 deletions carnival/contrib/steps/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ class AddAuthorizedKey(Step):
Добавить ssh ключ в `authorized_keys` если его там нет
"""

def __init__(self, ssh_key: str) -> None:
def __init__(self, ssh_key: str, use_sudo: bool = False) -> None:
"""
:param ssh_key: ключ
:param keys_file: пусть до файла `authorized_keys`
:return: `True` если ключ был добавлен, `False` если ключ уже был в файле
"""
self.ssh_key = ssh_key.strip()
self.keys_file: str = "~/.ssh/authorized_keys"
self.use_sudo = use_sudo

def run(self, c: Connection) -> None:
c.run("mkdir -p ~/.ssh", use_sudo=False)
c.run("chmod 700 ~/.ssh", use_sudo=False)
c.run(f"touch {self.keys_file}", use_sudo=False)
c.run("mkdir -p ~/.ssh", use_sudo=self.use_sudo)
c.run("chmod 700 ~/.ssh", use_sudo=self.use_sudo)
c.run(f"touch {self.keys_file}", use_sudo=self.use_sudo)

if not shortcuts.is_file_contains(c, self.keys_file, self.ssh_key, escape=True):
shortcuts.append_string_to_file(c, file=self.keys_file, string=self.ssh_key, use_sudo=False)
shortcuts.append_string_to_file(c, file=self.keys_file, string=self.ssh_key, use_sudo=self.use_sudo)
self.log_action("ssh key", "added")


Expand All @@ -33,14 +34,15 @@ class CopyId(Step):
Добавить публичный ssh-ключ текущего пользователя в авторизованные
"""

def __init__(self, pubkey_file: str = "~/.ssh/id_rsa.pub") -> None:
def __init__(self, pubkey_file: str = "~/.ssh/id_rsa.pub", use_sudo: bool = False) -> None:
"""
:param pubkey_file: путь до файла с публичным ключем
:return: `True` если ключ был добавлен, `False` если ключ уже был в файле
"""
self.pubkey_file = pubkey_file
self.use_sudo = use_sudo

def run(self, c: Connection) -> None:
with open(os.path.expanduser(self.pubkey_file)) as fp:
key = fp.read().strip()
AddAuthorizedKey(key).run(c=c)
AddAuthorizedKey(key, use_sudo=self.use_sudo).run(c=c)

0 comments on commit 178985c

Please sign in to comment.