Exemplo n.º 1
0
    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))
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
def _tenant_already_exists():
    abort(falcon.HTTP_400, 'Tenant already exists.')
Exemplo n.º 4
0
def _secret_not_found():
    abort(falcon.HTTP_400, 'Unable to locate secret profile.')
Exemplo n.º 5
0
def _tenant_not_found():
    abort(falcon.HTTP_404, 'Unable to locate tenant.')