Example #1
0
    def take_action(self, parsed_args):
        """Process CLI call."""
        provider = SSHPortingProvider(storage=self.storage, crendetial=None)
        provider.export_hosts()

        self.log.info(
            'Export hosts from local storage to ~/.termius/sshconfig')
def test_single_sshconfig(mockpath):
    mockpath.return_value.open.return_value.__enter__.return_value = StringIO(
        """
Host firstone
    HostName localhost
    User ubuntu
    ServerAliveInterval 100
    ServerAliveCountMax 3
    IdentitiesOnly yes
    StrictHostKeyChecking no
        """
    )
    service = SSHPortingProvider(None, '')
    ssh_hosts = service.provider_hosts()
    eq_(ssh_hosts, [
        Host(
            label='firstone',
            address='localhost',
            ssh_config=SshConfig(
                port=None,
                timeout=100,
                keep_alive_packages=3,
                use_ssh_key=True,
                strict_host_key_check=False,
                identity=Identity(
                    username='******',
                    ssh_key=None,
                    label='firstone',
                    is_visible=False
                )
            )
        )
    ])
def test_single_sshconfig_with_fnmatch(mockpath):
    mockpath.return_value.open.return_value.__enter__.return_value = StringIO(
        """
Host ?i*one
    Port 2022

Host firstone
    HostName localhost
    User ubuntu
        """
    )
    service = SSHPortingProvider(None, '')
    ssh_hosts = service.provider_hosts()
    eq_(ssh_hosts, [
        Host(
            label='firstone',
            address='localhost',
            ssh_config=SshConfig(
                port=2022,
                timeout=None,
                keep_alive_packages=None,
                use_ssh_key=None,
                strict_host_key_check=None,
                identity=Identity(
                    label='firstone',
                    is_visible=False,
                    username='******',
                    ssh_key=None
                )
            )
        )
    ])
Example #4
0
def test_single_sshconfig_with_keys(path_in_providers, path_in_adapters):
    sshconfig_content = """
Host firstone
    HostName localhost
    User ubuntu
    IdentityFile ~/.ssh/id_rsa
    IdentityFile ~/.ssh/id_dsa
    """
    private_key_content = 'private_key'
    fake_files = FakePathsObj(**{
        '~/.ssh/config': sshconfig_content,
        '~/.ssh/id_rsa': private_key_content
    })

    path_in_providers.side_effect = fake_files.generate_path_obj
    path_in_adapters.side_effect = fake_files.generate_path_obj

    service = SSHPortingProvider(None, '')
    ssh_hosts = service.provider_hosts()
    eq_(ssh_hosts, [
        Host(label='firstone',
             address='localhost',
             ssh_config=SshConfig(
                 port=None,
                 timeout=None,
                 keep_alive_packages=None,
                 use_ssh_key=None,
                 strict_host_key_check=None,
                 identity=Identity(username='******',
                                   ssh_key=SshKey(label='id_rsa',
                                                  private_key='private_key'))))
    ])
    def take_action(self, parsed_args):
        """Process CLI call."""
        provider = SSHPortingProvider(storage=self.storage, crendetial=None)
        provider.export_hosts()

        self.log.info(
            'Export hosts from local storage to ~/.termius/sshconfig'
        )
Example #6
0
    def take_action(self, parsed_args):
        """Process CLI call."""
        provider = SSHPortingProvider(storage=self.storage, crendetial=None)
        provider.import_hosts()

        if len(provider.skipped_hosts):
            for alias in provider.skipped_hosts:
                self.log.info('Host %s already exists, skip...' % alias)

            self.log.info('\nImport completed, part of the hosts was ignored')
        else:
            self.log.info('Import hosts from ~/.ssh/config to local storage')
    def take_action(self, parsed_args):
        """Process CLI call."""
        provider = SSHPortingProvider(storage=self.storage, crendetial=None)
        provider.import_hosts()

        if len(provider.skipped_hosts):
            for alias in provider.skipped_hosts:
                self.log.info(
                    'Host %s already exists, skip...' % alias
                )

            self.log.info(
                '\nImport completed, part of the hosts was ignored'
            )
        else:
            self.log.info(
                'Import hosts from ~/.ssh/config to local storage'
            )
def test_single_sshconfig_with_keys(path_in_providers, path_in_adapters):
    sshconfig_content = """
Host firstone
    HostName localhost
    User ubuntu
    IdentityFile ~/.ssh/id_rsa
    IdentityFile ~/.ssh/id_dsa
    """
    private_key_content = 'private_key'
    fake_files = FakePathsObj(**{
        '~/.ssh/config': sshconfig_content,
        '~/.ssh/id_rsa': private_key_content
    })

    path_in_providers.side_effect = fake_files.generate_path_obj
    path_in_adapters.side_effect = fake_files.generate_path_obj

    service = SSHPortingProvider(None, '')
    ssh_hosts = service.provider_hosts()
    eq_(ssh_hosts, [
        Host(
            label='firstone',
            address='localhost',
            ssh_config=SshConfig(
                port=None,
                timeout=None,
                keep_alive_packages=None,
                use_ssh_key=None,
                strict_host_key_check=None,
                identity=Identity(
                    label='firstone',
                    is_visible=False,
                    username='******',
                    ssh_key=SshKey(
                        label='id_rsa',
                        private_key='private_key'
                    )
                )
            )
        )
    ])
Example #9
0
def test_single_sshconfig_with_fnmatch(mockpath):
    mockpath.return_value.open.return_value.__enter__.return_value = StringIO(
        """
Host ?i*one
    Port 2022

Host firstone
    HostName localhost
    User ubuntu
        """)
    service = SSHPortingProvider(None, '')
    ssh_hosts = service.provider_hosts()
    eq_(ssh_hosts, [
        Host(label='firstone',
             address='localhost',
             ssh_config=SshConfig(port=2022,
                                  timeout=None,
                                  keep_alive_packages=None,
                                  use_ssh_key=None,
                                  strict_host_key_check=None,
                                  identity=Identity(username='******',
                                                    ssh_key=None)))
    ])
Example #10
0
def test_single_sshconfig(mockpath):
    mockpath.return_value.open.return_value.__enter__.return_value = StringIO(
        """
Host firstone
    HostName localhost
    User ubuntu
    ServerAliveInterval 100
    ServerAliveCountMax 3
    IdentitiesOnly yes
    StrictHostKeyChecking no
        """)
    service = SSHPortingProvider(None, '')
    ssh_hosts = service.provider_hosts()
    eq_(ssh_hosts, [
        Host(label='firstone',
             address='localhost',
             ssh_config=SshConfig(port=None,
                                  timeout=100,
                                  keep_alive_packages=3,
                                  use_ssh_key=True,
                                  strict_host_key_check=False,
                                  identity=Identity(username='******',
                                                    ssh_key=None)))
    ])
def test_empty_sshconfig(mockpath):
    mockpath.return_value.open.return_value.__enter__.return_value = StringIO()
    service = SSHPortingProvider(None, '')
    ssh_hosts = service.provider_hosts()
    eq_(ssh_hosts, [])
Example #12
0
def test_empty_sshconfig(mockpath):
    mockpath.return_value.open.return_value.__enter__.return_value = StringIO()
    service = SSHPortingProvider(None, '')
    ssh_hosts = service.provider_hosts()
    eq_(ssh_hosts, [])