def credential_put(name, type, body=None): if body is None: body = bottle.request.body.read() gpg = GPG(config['gpg_home_dir']) signees = gpg.get_cipher_signees(body) credential = signees.next() signee = signees.next() old_credential = store.get(name, type) if old_credential is None: old_recipients = [] else: old_recipients = list(gpg.get_cipher_recipients(gpg.get_cipher_signees(old_credential).next())) new_recipients = list(gpg.get_cipher_recipients(credential)) #print('Old:', map(str, old_recipients)) #print('New:', map(str, new_recipients)) if len(old_recipients) > 0 and signee not in old_recipients: raise bottle.HTTPResponse(status=401, output='No access') elif signee not in new_recipients: raise bottle.HTTPResponse(status=400, output='Idiot...') store.set(name, type, body)
def credential_delete(name, type, body=None): if body is None: body = bottle.request.body.read() gpg = GPG(config['gpg_home_dir']) signees = gpg.get_cipher_signees(body) signees.next() signees = list(signees) old_signees = gpg.get_cipher_signees(store.get(name, type)) old_recipients = list(gpg.get_cipher_recipients(old_signees.next())) for signee in signees: if len(old_recipients) > 0: if signee in old_recipients: store.delete(name, type) return else: raise bottle.HTTPResponse(status=401) else: raise bottle.HTTPResponse(status=404)