__init__.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:auth-tool 作者: luciddg 项目源码 文件源码
def sshkey(self, sshpubkey=None):
        http_method = cherrypy.request.method.upper()

        if cherrypy.session.get('auth', False):
            user = cherrypy.session['user']
            if http_method == 'POST':
                try:
                    newkey = SSHKey(sshpubkey)
                    user.add_key(newkey.key)
                    return {
                        'ok': True,
                        'fingerprint': newkey.fingerprint,
                        'comment': newkey.comment
                    }
                except UserModelException:
                    return {'ok': False}
                except InvalidKey:
                    return {
                        'ok': False,
                        'error': 'Not a valid SSH Public Key!'
                    }
                else:
                    return {'ok': False}

            if http_method == 'DELETE':
                try:
                    user.delete_key(sshpubkey)
                    return {'ok': True}
                except UserModelException:
                    return {'ok': False}

            if http_method == 'GET':
                return user.sshPublicKey
        else:
            raise cherrypy.HTTPError(403)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号