List SSH public key(s) from LDAP.
968258
def list(config):  # pragma: no cover
        """"""
        client = Client()
        client.prepare_connection()
        key_api = API(client)
        for key, values in key_api.get_keys_from_ldap().items():
            print("{}: ".format(key))
            for value in [v.decode() for v in values]:
                print("\t - {}".format(value))
578379
async def get_ssh_key(self, raw_ssh=False):
        
        key_facade = client.KeyManagerFacade.from_connection(self.connection())
        entity = {'tag': tag.model(self.info.uuid)}
        entities = client.Entities([entity])
        return await key_facade.ListKeys(entities, raw_ssh)
423016
def match_keys(inp, p=False):
    """"""
    _keys = []
    ssh_keys = DO.get_ssh_keys()
    for k in inp.split(","):
        done = False
        if k.isdigit():
            for _ in [s for s in ssh_keys if s["id"] == int(k)]:
                done = True
                _keys.append(_["fingerprint"])
        else:
            for _ in [s for s in ssh_keys if s["fingerprint"] == k]:
                done = True
                _keys.append(_["fingerprint"])
        if p and not done:
            print("Could not find a match for '{}', skipping".format(k), file=sys.stderr)
    return _keys
349804
def getCredentialValues(self, new=False):
        """"""

        credentials_base = "credentials."
        return tuple([self.getValue(credentials_base + p) for p in [
            "username", "password", "private_key"]])
665830
def _get_public_key_count(self):
        """"""
        index = len(self._public_keys)
        for authentication in self._authentications:
            if authentication.is_public_key():
                index += 1
        return index
758902
def list_passwords(kwargs=None, call=None):
    '''
    
    '''
    response = _query('support', 'password/list')

    ret = {}
    for item in response['list']:
        if 'server' in item:
            server = item['server']['name']
            if server not in ret:
                ret[server] = []
            ret[server].append(item)

    return ret
906495
def get_asns(self, privaddr=0):
        """"""
        ips = {}
        if privaddr:
            for k, v in self._ips.items():
                if not is_private_addr(k):
                    ips[k] = v
        else:
            ips = self._ips
        #
        # Special case for the loopback IP Address: 127.0.0.1 - Do not ASN resolve...
        if '127.0.0.1' in ips:
            del ips['127.0.0.1']
        #
        # ASN Lookup...
        asnquerylist = dict.fromkeys(map(lambda x: x.rsplit(" ", 1)[0], ips)).keys()
        if self._asres is None:
            asnlist = []
        else:
            try:
                asnlist = self._asres.resolve(*asnquerylist)
            except:
                pass
        for ip, asn, desc, in asnlist:
            if asn is None:
                continue
            iplist = self._asns.get(asn, [])  # Get previous ASN value
            iplist.append(ip)			# Append IP Address to previous ASN

            #
            # If ASN is a string Convert to a number: (i.e., 'AS3257' => 3257)
            if type(asn) == str:
                asn = asn.upper()
                asn = asn.replace('AS', '')
                try:
                    asn = int(asn)
                    self._asns[asn] = iplist
                    self._asds[asn] = desc
                except:
                    continue
            else:
                self._asns[asn] = iplist
                self._asds[asn] = desc
198759
def __ldap_attr(self, fname, lname, type, group,
                    group_api):  # pragma: no cover
        """"""
        return {
            'uid':
            str(self.username).encode(),
            'cn':
            ' '.join([fname, lname]).encode(),
            'sn':
            str(lname).encode(),
            'givenname':
            str(fname).encode(),
            'homedirectory':
            os.path.join(os.path.sep, 'home', self.username).encode(),
            'loginshell':
            os.path.join(os.path.sep, 'bin', 'bash').encode(),
            'mail':
            '@'.join([self.username, self.client.mail_domain]).encode(),
            'uidnumber':
            self.__uidnumber(type),
            'gidnumber':
            API.__gidnumber(group, group_api),
            'userpassword':
            str('{SSHA}' + API.__create_password().decode()).encode(),
        }
937830
def show_rsa(minion_id, dns_name):
    '''
    
    '''
    cache = salt.cache.Cache(__opts__, syspaths.CACHE_DIR)
    bank = 'digicert/domains'
    data = cache.fetch(
        bank, dns_name
    )
    return data['private_key']
558316
def get_ldict_keys(ldict, flatten_keys=False, **kwargs):
    
    result = []
    for ddict in ldict:
        if isinstance(ddict, dict):

            if flatten_keys:
                ddict = flatten(ddict, **kwargs)

            result.extend(ddict.keys())
    return list(set(result))
1062999
def keys_list(gandi, fqdn):
    """"""
    keys = gandi.dns.keys(fqdn)
    output_keys = ['uuid', 'algorithm', 'algorithm_name', 'ds', 'flags',
                   'status']
    for num, key in enumerate(keys):
        if num:
            gandi.separator_line()
        output_generic(gandi, key, output_keys, justify=15)
    return keys
24548
def ssh_keys(self):
        
        params = {}
        json = self.request('/ssh_keys', method='GET', params=params)
        status = json.get('status')
        if status == 'OK':
            ssh_keys_json = json.get('ssh_keys', [])
            keys = [SSHKey.from_json(ssh_key) for ssh_key in ssh_keys_json]
            return keys
        else:
            message = json.get('message')
            raise DOPException('[%s]: %s' % (status, message))
1329652
def install(self):  # pragma: no cover
        """"""
        keys = self.get_keys_from_ldap()
        for user, ssh_keys in keys.items():
            user_dir = API.__authorized_keys_path(user)
            if not os.path.isdir(user_dir):
                os.makedirs(user_dir)
            authorized_keys_file = os.path.join(user_dir, 'authorized_keys')
            with open(authorized_keys_file, 'w') as FILE:
                print("\n".join([k.decode() for k in ssh_keys]), file=FILE)
75812
def output_sshkey(gandi, sshkey, output_keys, justify=12):
    
    output_generic(gandi, sshkey, output_keys, justify)
130324
def key_pair_paths(key_name):
    """"""
    public_key_path = os.path.expanduser("~/.ssh/{}.pub".format(key_name))
    private_key_path = os.path.expanduser("~/.ssh/{}.pem".format(key_name))
    return public_key_path, private_key_path
664545
def get_ldap_groups(self):
        """"""
        if (not self.conf_LDAP_SYNC_GROUP):
            return (None, None)
        uri_groups_server, groups = self.ldap_search(self.conf_LDAP_SYNC_GROUP_FILTER, self.conf_LDAP_SYNC_GROUP_ATTRIBUTES.keys(), self.conf_LDAP_SYNC_GROUP_INCREMENTAL, self.conf_LDAP_SYNC_GROUP_FILTER_INCREMENTAL)
        logger.debug("Retrieved %d groups from %s LDAP server" % (len(groups), uri_groups_server))
        return (uri_groups_server, groups)
537293
def list_vpnservices(self, retrieve_all=True, **_params):
        """"""
        return self.list('vpnservices', self.vpnservices_path, retrieve_all,
                         **_params)