Create a new key for the authenticated user.

        :param str title: (required), key title
        :param key: (required), actual key contents, accepts path as a string
            or file-like object
        :returns: :class:`Key <github3.users.Key>`
486926
def create_key(self, title, key):
        
        created = None

        if title and key:
            url = self._build_url('user', 'keys')
            req = self._post(url, data={'title': title, 'key': key})
            json = self._json(req, 201)
            if json:
                created = Key(json, self)
        return created
843251
def get_user_api_key(self, username, create=True):
        
        retval = self._database.users.find_one({"username": username}, {"apikey": 1})
        if "apikey" not in retval and create:
            apikey = self.generate_api_key()
            self._database.users.update_one({"username": username}, {"$set": {"apikey": apikey}})
        elif "apikey" not in retval:
            apikey = None
        else:
            apikey = retval["apikey"]
        return apikey
93577
def create_key(key_name, save_path, region=None, key=None, keyid=None,
               profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    try:
        key = conn.create_key_pair(key_name)
        log.debug("the key to return is : %s", key)
        key.save(save_path)
        return key.material
    except boto.exception.BotoServerError as e:
        log.debug(e)
        return False
782577
def createFromAPIKey(self, apikey, maybeWriteDefault=False):
        
        self._data = {
            'default_key': 'default',
            'keys': {
                'default': {
                    'key': apikey,
                    'desc': 'imported API key'
                }
            }
        }
        self._keyID = 'default'
        self._doDefaults()
        if maybeWriteDefault:
            path = os.path.expanduser(self.DEFAULT_CONFIG_FILE)
            self.write(path)
161075
def keypair_add(name, pubfile=None, pubkey=None, profile=None, **kwargs):
    '''
    
    '''
    conn = _auth(profile, **kwargs)
    return conn.keypair_add(
        name,
        pubfile,
        pubkey
    )
123867
def short_title(self, key, value):
    
    short_title = value.get('a')
    title_variants = self.get('title_variants', [])

    if value.get('u'):
        short_title = value.get('u')
        title_variants.append(value.get('a'))

    self['title_variants'] = title_variants
    return short_title
362717
def keys_create(cls, fqdn, flag):
        """"""
        data = {
            "flags": flag,
        }
        meta = cls.get_fqdn_info(fqdn)
        url = meta['domain_keys_href']
        ret, headers = cls.json_post(url, data=json.dumps(data),
                                     return_header=True)
        return cls.json_get(headers['location'])
1118057
def key_from_req(req):
    """"""
    if hasattr(req, "key"):
        # from pkg_resources, such as installed dists for pip-sync
        key = req.key
    else:
        # from packaging, such as install requirements from requirements.txt
        key = req.name

    key = key.replace("_", "-").lower()
    return key
1181189
def CreateKey(self, prikey=None):
        
        account = super(UserWallet, self).CreateKey(private_key=prikey)
        self.OnCreateAccount(account)
        contract = WalletContract.CreateSignatureContract(account.PublicKey)
        self.AddContract(contract)
        return account
383175
def load_key(self, path):
        
        with open(path, 'r') as f:
            self.key = f.readline().strip()
            self.secret = f.readline().strip()
30416
def add_key(self, key, label, notes=None):
        
        order = {
            'key': key,
            'label': label,
            'notes': notes,
        }

        return self.sshkey.createObject(order)
903448
def create_user(username, rsa_pub_key, rsa_pub_key_name)
      key_name = "#{username}@#{rsa_pub_key_name}"
      key_path = @configuration.user_key_path(key_name)

      if users_public_keys().include?(key_path)
        raise ::Gitolite::Duplicate, "Public key (#{rsa_pub_key_name}) already exists for user (#{username}) on gitolite server"
      end

      add_commit_file(key_path,rsa_pub_key, "Added public key (#{rsa_pub_key_name}) for user (#{username}) ")

      key_path
    end
785291
def create_ssh_key(kwargs=None, call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The create_ssh_key function must be called with '
            '-f or --function'
        )

    conn = get_conn()

    # Assemble the composite SshKey object.
    ssh_key = _get_ssh_key(kwargs)

    data = conn.create_ssh_key(ssh_key=ssh_key)

    return {'SshKey': data}
1142698
def gen_keys_signature(self, priv, pub, signature_path, auto_create=False, keysize=None):
        '''
        
        '''
        # check given pub-key
        if pub:
            if not os.path.isfile(pub):
                return 'Public-key {0} does not exist'.format(pub)
        # default to master.pub
        else:
            mpub = self.opts['pki_dir'] + '/' + 'master.pub'
            if os.path.isfile(mpub):
                pub = mpub

        # check given priv-key
        if priv:
            if not os.path.isfile(priv):
                return 'Private-key {0} does not exist'.format(priv)
        # default to master_sign.pem
        else:
            mpriv = self.opts['pki_dir'] + '/' + 'master_sign.pem'
            if os.path.isfile(mpriv):
                priv = mpriv

        if not priv:
            if auto_create:
                log.debug(
                    'Generating new signing key-pair .%s.* in %s',
                    self.opts['master_sign_key_name'], self.opts['pki_dir']
                )
                salt.crypt.gen_keys(self.opts['pki_dir'],
                                    self.opts['master_sign_key_name'],
                                    keysize or self.opts['keysize'],
                                    self.opts.get('user'),
                                    self.passphrase)

                priv = self.opts['pki_dir'] + '/' + self.opts['master_sign_key_name'] + '.pem'
            else:
                return 'No usable private-key found'

        if not pub:
            return 'No usable public-key found'

        log.debug('Using public-key %s', pub)
        log.debug('Using private-key %s', priv)

        if signature_path:
            if not os.path.isdir(signature_path):
                log.debug('target directory %s does not exist', signature_path)
        else:
            signature_path = self.opts['pki_dir']

        sign_path = signature_path + '/' + self.opts['master_pubkey_signature']

        skey = get_key(self.opts)
        return skey.gen_signature(priv, pub, sign_path)
1334064
def upload_GitHub_deploy_key(deploy_repo, ssh_key, *, read_only=False,
    title="Doctr deploy key for pushing to gh-pages from Travis", **login_kwargs):
    
    DEPLOY_KEY_URL = "https://api.github.com/repos/{deploy_repo}/keys".format(deploy_repo=deploy_repo)

    data = {
        "title": title,
        "key": ssh_key,
        "read_only": read_only,
    }
    return GitHub_post(data, DEPLOY_KEY_URL, **login_kwargs)
394766
def create(self, key=None, label=None):
        
        key = '%s' % key
        url = self.bitbucket.url('SET_SSH_KEY')
        return self.bitbucket.dispatch('POST', url, auth=self.bitbucket.auth, key=key, label=label)
178217
def authenticate_key(api_key):
    
    user_model = Query()
    user = db.search(user_model.api_key == api_key)[0]
    if user:
        return user['username']
    return False