예제 #1
0
 def __call__(self, location: Location, system_context: SystemContext,
              *args: typing.Any, **kwargs: typing.Any) -> None:
     """Execute command."""
     # FIXME: Implement this!
     # self._validate_key_directory(location, key_directory)
     if not isdir(system_context, '/etc/ssh'):
         raise GenerateError('"{}": No /etc/ssh directory found in system.'
                             .format(self.name), location=location)
예제 #2
0
 def _check_or_create_directory(self, location: Location,
                                system_context: SystemContext,
                                directory: str,
                                **kwargs: typing.Any) -> None:
     if not exists(system_context, directory):
         makedirs(system_context, directory, **kwargs)
         return
     if not isdir(system_context, directory):
         raise GenerateError(
             '"{}" needs directory "{}", but that exists and is not a directory.'
             .format(self.name, directory),
             location=location)
예제 #3
0
 def _check_or_create_directory(
     self,
     location: Location,
     system_context: SystemContext,
     directory: str,
     **kwargs: typing.Any,
 ) -> None:
     if not exists(system_context, directory):
         self._execute(location.next_line(), system_context, "mkdir",
                       directory, **kwargs)
         return
     if not isdir(system_context, directory):
         raise GenerateError(
             f'"{self.name}" needs directory "{directory}", but that exists and is not a directory.',
             location=location,
         )
예제 #4
0
    def __call__(self, location: Location, system_context: SystemContext,
                 *args: typing.Any, **kwargs: typing.Any) -> None:
        """Execute command."""
        key_directory = args[0]
        self._validate_key_directory(location, key_directory)
        if not isdir(system_context, '/etc/ssh'):
            raise GenerateError(
                '"{}": No /etc/ssh directory found in system.'.format(
                    self.name),
                location=location)

        self._execute(location,
                      system_context,
                      'copy',
                      _key_files(key_directory),
                      '/etc/ssh',
                      from_outside=True)
        chown(system_context, 'root', 'root', _key_files('/etc/ssh'))
        chmod(system_context, 0o600, '/etc/ssh/ssh_host_*_key')
        chmod(system_context, 0o644, '/etc/ssh/ssh_host_*_key.pub')
예제 #5
0
    def __call__(
        self,
        location: Location,
        system_context: SystemContext,
        *args: typing.Any,
        **kwargs: typing.Any,
    ) -> None:
        """Execute command."""
        key_directory = args[0]
        self._validate_key_directory(location, key_directory)
        if not isdir(system_context, "/etc/ssh"):
            os.makedirs(system_context.file_name("/etc/ssh"))

        self._execute(
            location,
            system_context,
            "copy",
            _key_files(key_directory),
            "/etc/ssh",
            from_outside=True,
        )
        chown(system_context, "root", "root", _key_files("/etc/ssh"))
        chmod(system_context, 0o600, "/etc/ssh/ssh_host_*_key")
        chmod(system_context, 0o644, "/etc/ssh/ssh_host_*_key.pub")