Create an L{SSHFactory} which allows access to Mantissa accounts.
9147
def getFactory(self):
        
        privateKey = Key.fromString(data=self.hostKey)
        public = privateKey.public()
        factory = SSHFactory()
        factory.publicKeys = {'ssh-rsa': public}
        factory.privateKeys = {'ssh-rsa': privateKey}
        factory.portal = Portal(
            IRealm(self.store), [ICredentialsChecker(self.store)])
        return factory
481448
private ServerConnector createSSLConnector() {
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePath(m_keystore);
        sslContextFactory.setKeyStorePassword(m_keystorepassword);
        sslContextFactory.setTrustStorePath(m_truststore);
        sslContextFactory.setTrustStorePassword(m_truststorepassword);
        sslContextFactory.setNeedClientAuth(m_clientauthentication);
        sslContextFactory.setIncludeCipherSuites(m_tls_cipher_suites);

        HttpConfiguration http_config = new HttpConfiguration();
        http_config.setSecureScheme("https");
        HttpConfiguration https_config = new HttpConfiguration(http_config);
        https_config.addCustomizer(new SecureRequestCustomizer());
        SslConnectionFactory sslConnFactory = new SslConnectionFactory(sslContextFactory, "http/1.1");
        HttpConnectionFactory httpConnFactory = new HttpConnectionFactory(https_config);
        ServerConnector sslConnector = new ServerConnector(m_jettyServer, sslConnFactory, httpConnFactory);
        return sslConnector;
    }
1337158
def cli(env, identifier):
    """"""

    mgr = SoftLayer.UserManager(env.client)
    user_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'username')
    object_mask = "mask[id, permissions, isMasterUserFlag, roles]"

    user = mgr.get_user(user_id, object_mask)
    all_permissions = mgr.get_all_permissions()
    user_permissions = perms_to_dict(user['permissions'])

    if user['isMasterUserFlag']:
        click.secho('This account is the Master User and has all permissions enabled', fg='green')

    env.fout(roles_table(user))
    env.fout(permission_table(user_permissions, all_permissions))
1096514
def create(self, name, ssh_key, params=None):
        ''' 
        '''
        params = update_params(params, {
            'name': name,
            'ssh_key': ssh_key
        })
        return self.request('/v1/sshkey/create', params, 'POST')
446065
def _build_credentials_tuple(mech, source, user, passwd, extra):
    
    user = _unicode(user) if user is not None else None
    password = passwd if passwd is None else _unicode(passwd)
    if mech == 'GSSAPI':
        properties = extra.get('authmechanismproperties', {})
        service_name = properties.get('SERVICE_NAME', 'mongodb')
        canonicalize = properties.get('CANONICALIZE_HOST_NAME', False)
        service_realm = properties.get('SERVICE_REALM')
        props = GSSAPIProperties(service_name=service_name,
                                 canonicalize_host_name=canonicalize,
                                 service_realm=service_realm)
        # Source is always $external.
        return MongoCredential(mech, '$external', user, password, props)
    elif mech == 'MONGODB-X509':
        # user can be None.
        return MongoCredential(mech, '$external', user, None, None)
    else:
        if passwd is None:
            raise ConfigurationError("A password is required.")
        return MongoCredential(mech, source, user, password, None)
504892
def ssh(self, enable=True, comment=None):
        
        self.make_request(
            NodeCommandFailed,
            method='update',
            resource='ssh',
            params={'enable': enable, 'comment': comment})
760267
def from_passwd(uid_min=None, uid_max=None):
        """"""
        import pwd
        users = Users(oktypes=User)
        passwd_list = pwd.getpwall()
        if not uid_min:
            uid_min = UID_MIN
        if not uid_max:
            uid_max = UID_MAX
        sudoers_entries = read_sudoers()
        for pwd_entry in passwd_list:
            if uid_min <= pwd_entry.pw_uid <= uid_max:
                user = User(name=text_type(pwd_entry.pw_name),
                            passwd=text_type(pwd_entry.pw_passwd),
                            uid=pwd_entry.pw_uid,
                            gid=pwd_entry.pw_gid,
                            gecos=text_type(pwd_entry.pw_gecos),
                            home_dir=text_type(pwd_entry.pw_dir),
                            shell=text_type(pwd_entry.pw_shell),
                            public_keys=read_authorized_keys(username=pwd_entry.pw_name),
                            sudoers_entry=get_sudoers_entry(username=pwd_entry.pw_name,
                                                            sudoers_entries=sudoers_entries))
                users.append(user)
        return users
493028
def create(cls, datacenter, memory, cores, ip_version, bandwidth,
               login, password, hostname, image, run, background, sshkey,
               size, vlan, ip, script, script_args, ssh):
        """"""
        from gandi.cli.modules.network import Ip, Iface
        if not background and not cls.intty():
            background = True

        datacenter_id_ = int(Datacenter.usable_id(datacenter))

        if not hostname:
            hostname = randomstring('vm')
            disk_name = 'sys_%s' % hostname[2:]
        else:
            disk_name = 'sys_%s' % hostname.replace('.', '')

        vm_params = {
            'hostname': hostname,
            'datacenter_id': datacenter_id_,
            'memory': memory,
            'cores': cores,
        }

        if login:
            vm_params['login'] = login

        if run:
            vm_params['run'] = run

        if password:
            vm_params['password'] = password

        if ip_version:
            vm_params['ip_version'] = ip_version
            vm_params['bandwidth'] = bandwidth

        if script:
            with open(script) as fd:
                vm_params['script'] = fd.read()
            if script_args:
                vm_params['script_args'] = script_args

        vm_params.update(cls.convert_sshkey(sshkey))

        # XXX: name of disk is limited to 15 chars in ext2fs, ext3fs
        # but api allow 255, so we limit to 15 for now
        disk_params = {'datacenter_id': vm_params['datacenter_id'],
                       'name': disk_name[:15]}

        if size:
            if isinstance(size, tuple):
                prefix, size = size
            disk_params['size'] = size

        sys_disk_id_ = int(Image.usable_id(image, datacenter_id_))

        ip_summary = []
        if ip_version == 4:
            ip_summary = ['v4', 'v6']
        elif ip_version == 6:
            ip_summary = ['v6']

        if vlan:
            ip_ = None
            ip_summary.append('private')
            if ip:
                try:
                    ip_ = Ip.info(ip)
                except Exception:
                    pass
                else:
                    if not Ip._check_and_detach(ip_, None):
                        return
            if ip_:
                iface_id = ip_['iface_id']
            else:
                ip_create = Ip.create(4,
                                      vm_params['datacenter_id'],
                                      bandwidth,
                                      None,
                                      vlan,
                                      ip)

                iface_id = ip_create['iface_id']

            # if there is a public ip, will attach this one later, else give
            # the iface to vm.create
            if not ip_version:
                vm_params['iface_id'] = iface_id

        result = cls.call('hosting.vm.create_from', vm_params, disk_params,
                          sys_disk_id_)

        cls.echo('* Configuration used: %d cores, %dMb memory, ip %s, '
                 'image %s, hostname: %s, datacenter: %s' %
                 (cores, memory, '+'.join(ip_summary), image, hostname,
                  datacenter))

        # background mode, bail out now (skip interactive part)
        if background and (not vlan or not ip_version):
            return result

        # interactive mode, run a progress bar
        cls.echo('Creating your Virtual Machine %s.' % hostname)
        cls.display_progress(result)
        cls.echo('Your Virtual Machine %s has been created.' % hostname)

        vm_id = None
        for oper in result:
            if oper.get('vm_id'):
                vm_id = oper.get('vm_id')
                break

        if vlan and ip_version:
            attach = Iface._attach(iface_id, vm_id)
            if background:
                return attach

        if 'ssh_key' not in vm_params and 'keys' not in vm_params:
            return

        if vm_id and ip_version:
            cls.wait_for_sshd(vm_id)
            if ssh:
                cls.ssh_keyscan(vm_id)
                cls.ssh(vm_id, 'root', None)
732392
def add_ssh_options(self, parser):
        """"""
        parser.add_argument(
            "--username", metavar='USER', help=(
                "Username for the SSH connection."))
        parser.add_argument(
            "--boot-only", action="store_true", help=(
                "Only use the IP addresses on the machine's boot interface."))
1063496
def ssh(gandi, resource, login, identity, wipe_key, wait, args):
    
    if '@' in resource:
        (login, resource) = resource.split('@', 1)
    if wipe_key:
        gandi.iaas.ssh_keyscan(resource)
    if wait:
        gandi.iaas.wait_for_sshd(resource)
    gandi.iaas.ssh(resource, login, identity, args)
537062
def connect(host, port, username, password):
        """"""
        # Instantiate ftplib client
        session = ftplib.FTP()

        # Connect to host without auth
        session.connect(host, port)

        # Authenticate connection
        session.login(username, password)
        return session
200608
def connect_ssh_with_cb(ssh_cb, user, host, auth_cb, allow_new=True, 
                        verbosity=0):
    

    with connect_ssh(user, host, auth_cb, allow_new=True, verbosity=0) as ssh:
        ssh_cb(ssh)
690322
def samdb_connect():
    
    with root():
        lp = samba.param.LoadParm()
    lp.load("/etc/samba/smb.conf")
    creds = Credentials()
    creds.guess(lp)
    session = system_session()
    samdb = SamDB("/var/lib/samba/private/sam.ldb",
                  session_info=session,
                  credentials=creds,
                  lp=lp)
    return samdb
608870
def create_system(self):
        """"""
        return System(
            self.networkapi_url,
            self.user,
            self.password,
            self.user_ldap)
1270317
def mount(self):
        """"""
        if self.mounted:
            return

        self._mount_point_local_create()

        if len(self.system.mount_opts) == 0:
            sshfs_opts = ""
        else:
            sshfs_opts = " -o %s" % " -o ".join(self.system.mount_opts)

        if self.system.auth_method == self.system.AUTH_METHOD_PUBLIC_KEY:
            ssh_opts = '-o PreferredAuthentications=publickey -i %s' % self.system.ssh_key
        elif self.system.auth_method:
            ssh_opts = '-o PreferredAuthentications=%s' % self.system.auth_method
        else:
            ssh_opts = '-o PreferredAuthentications=password'

        cmd = ("{cmd_before_mount} &&"
               " sshfs -o ssh_command="
               "'ssh -o ConnectTimeout={timeout} -p {port} {ssh_opts}'"
               " {sshfs_opts} {user}@{host}:{remote_path} {local_path}")
        cmd = cmd.format(
            cmd_before_mount = self.system.cmd_before_mount,
            timeout = self.SSH_CONNECT_TIMEOUT,
            port = self.system.port,
            ssh_opts = ssh_opts,
            sshfs_opts = sshfs_opts,
            host = self.system.host,
            user = self.system.user,
            remote_path = self.mount_point_remote,
            local_path = self.mount_point_local,
        )

        output = shell_exec(cmd).strip()

        if not self.mounted:
            # Clean up the directory tree
            self._mount_point_local_delete()
            if output == '':
                output = 'Mounting failed for a reason unknown to sftpman.'
            raise SftpMountException(cmd, output)
1184418
def create(self, environment, target_name):
        
        remote_server_command(
            ["ssh", environment.deploy_target, "create", target_name],
            environment, self,
            clean_up=True,
            )
849385
def main():
    """"""
    authenticator = prawcore.TrustedAuthenticator(
        prawcore.Requestor("prawcore_script_auth_example"),
        os.environ["PRAWCORE_CLIENT_ID"],
        os.environ["PRAWCORE_CLIENT_SECRET"],
    )
    authorizer = prawcore.ScriptAuthorizer(
        authenticator,
        os.environ["PRAWCORE_USERNAME"],
        os.environ["PRAWCORE_PASSWORD"],
    )
    authorizer.refresh()

    with prawcore.session(authorizer) as session:
        data = session.request("GET", "/api/v1/me/friends")

    for friend in data["data"]["children"]:
        print(friend["name"])

    return 0