예제 #1
0
파일: resources.py 프로젝트: jfwood/keep
    def on_post(self, req, resp):
        body = load_body(req)
        username = body['username']
        logging.debug('Username is {0}'.format(username))

        tenant = find_tenant(self.db, username=username)

        if tenant:
            abort(falcon.HTTP_400, 'Tenant with username {0} '
                                   'already exists'.format(username))

        new_tenant = Tenant(username)
        self.db.add(new_tenant)
        self.db.commit()

        resp.status = falcon.HTTP_201
        resp.set_header('Location', '/v1/{0}'.format(new_tenant.id))
예제 #2
0
파일: resources.py 프로젝트: jfwood/keep
    def on_put(self, req, resp, tenant_id, secret_id):
        #verify the tenant exists
        tenant = find_tenant(self.db, tenant_id=tenant_id,
                             when_not_found=_tenant_not_found)

        #verify the secret exists
        secret = find_secret(self.db, id=secret_id,
                             when_not_found=_secret_not_found)

        #verify the secret belongs to the tenant
        if not secret in tenant.secrets:
            _secret_not_found()

        #load the message
        body = load_body(req)

        #if attributes are present in message, update the secret
        if 'name' in body.keys():
            secret.name = body['name']

        self.db.commit()
        resp.status = falcon.HTTP_200
예제 #3
0
파일: resources.py 프로젝트: jfwood/keep
    def on_post(self, req, resp, tenant_id):
        tenant = find_tenant(self.db, id=tenant_id,
                             when_not_found=_tenant_not_found)

        body = load_body(req)
        secret_name = body['name']

        # Check if the tenant already has a secret with this name
        for secret in tenant.secrets:
            if secret.name == secret_name:
                abort(falcon.HTTP_400, 'Secret with name {0} already exists.'
                .format(secret.name, secret.id))

        # Create the new secret
        new_secret = Secret(tenant.id, secret_name)
        tenant.secrets.append(new_secret)

        self.db.add(new_secret)
        self.db.commit()

        resp.status = falcon.HTTP_201
        resp.set_header('Location',
                        '/v1/{0}/secrets/{1}'
                        .format(tenant_id, new_secret.id))