def create_key(): if g.get('role', None) == 'admin': try: user = request.json.get('user', g.user) customer = request.json.get('customer', None) except AttributeError: return jsonify(status="error", message="Must supply 'user' as parameter"), 400 else: try: user = g.user customer = g.get('customer', None) except AttributeError: return jsonify(status="error", message="Must supply API Key or Bearer Token when creating new API key"), 400 type = request.json.get("type", "read-only") if type not in ['read-only', 'read-write']: return jsonify(status="error", message="API key 'type' must be 'read-only' or 'read-write'"), 400 text = request.json.get("text", "API Key for %s" % user) try: key = db.create_key(user, type, customer, text) except Exception as e: return jsonify(status="error", message=str(e)), 500 return jsonify(status="ok", key=key), 201, {'Location': absolute_url('/key/' + key)}
def create_key(): if g.get('role', None) == 'admin': try: user = request.json.get('user', g.user) customer = request.json.get('customer', None) except AttributeError: return jsonify(status="error", message="Must supply 'user' as parameter"), 400 else: try: user = g.user customer = g.get('customer', None) except AttributeError: return jsonify( status="error", message= "Must supply API Key or Bearer Token when creating new API key" ), 400 type = request.json.get("type", "read-only") if type not in ['read-only', 'read-write']: return jsonify( status="error", message="API key 'type' must be 'read-only' or 'read-write'"), 400 text = request.json.get("text", "API Key for %s" % user) try: key = db.create_key(user, type, customer, text) except Exception as e: return jsonify(status="error", message=str(e)), 500 return jsonify(status="ok", key=key), 201, { 'Location': absolute_url('/key/' + key) }
def setUp(self): app.config['TESTING'] = True app.config['AUTH_REQUIRED'] = True app.config['CUSTOMER_VIEWS'] = True self.app = app.test_client() self.alert = { 'event': 'node_marginal', 'resource': 'node404', 'environment': 'Production', 'service': ['Network'], 'severity': 'warning', 'correlate': ['node_down', 'node_marginal', 'node_up'] } self.admin_api_key = db.create_key('admin-api-key', type='read-write', text='demo-key') self.customer_api_key = db.create_key('customer-api-key', customer='Foo', type='read-write', text='demo-key')
def setUp(self): app.config["TESTING"] = True app.config["AUTH_REQUIRED"] = True app.config["CUSTOMER_VIEWS"] = True app.config["ALLOWED_EMAIL_DOMAINS"] = ["debeauharnais.fr"] self.app = app.test_client() self.alert = {"event": "Foo", "resource": "Bar", "environment": "Production", "service": ["Quux"]} self.api_key = db.create_key("demo-key", type="read-write", text="demo-key") self.headers = {"Authorization": "Key %s" % self.api_key, "Content-type": "application/json"}
def create_key(): if request.json and 'user' in request.json: user = request.json["user"] data = { "user": user, "text": request.json.get("text", "API Key for %s" % user) } try: key = db.create_key(data) except Exception as e: return jsonify(status="error", message=str(e)), 500 else: return jsonify(status="error", message="must supply 'user' as parameter"), 400 return jsonify(status="ok", key=key), 201, {'Location': '%s/%s' % (request.base_url, key)}
def create_key(): if 'admin' in g.scopes or 'admin:keys' in g.scopes: try: user = request.json.get('user', g.user) customer = request.json.get('customer', None) except AttributeError: return jsonify(status="error", message="Must supply 'user' as parameter"), 400 else: try: user = g.user customer = g.get('customer', None) except AttributeError: return jsonify( status="error", message= "Must supply API Key or Bearer Token when creating new API key" ), 400 scopes = request.json.get("scopes", []) for scope in scopes: if not is_in_scope(scope): return jsonify( status="error", message="Requested scope %s is beyond existing scopes: %s." % (scope, ','.join(g.scopes))), 403 type = request.json.get("type", None) if type and type not in ['read-only', 'read-write']: return jsonify( status="error", message="API key 'type' must be 'read-only' or 'read-write'"), 400 text = request.json.get("text", "API Key for %s" % user) try: key = db.create_key(user, scopes=scopes, type=type, customer=customer, text=text) except Exception as e: return jsonify(status="error", message=str(e)), 500 return jsonify(status="ok", key=key['key'], data=key), 201, { 'Location': absolute_url('/key/' + key['key']) }
def create_key(): if request.json and 'user' in request.json: user = request.json['user'] else: return jsonify(status="error", message="must supply 'user' as parameter"), 400 type = request.json.get("type", "read-only") if type not in ['read-only', 'read-write']: return jsonify(status="error", message="API key must be read-only or read-write"), 400 text = request.json.get("text", "API Key for %s" % user) try: key = db.create_key(user, type, text) except Exception as e: return jsonify(status="error", message=str(e)), 500 return jsonify(status="ok", key=key), 201, {'Location': '%s/%s' % (request.base_url, key)}
def setUp(self): app.config['TESTING'] = True app.config['AUTH_REQUIRED'] = True self.app = app.test_client() self.alert = { 'event': 'Foo', 'resource': 'Bar', 'environment': 'Production', 'service': ['Quux'] } self.api_key = db.create_key('demo-key', type='read-write', text='demo-key') self.headers = { 'Authorization': 'Key %s' % self.api_key, 'Content-type': 'application/json' }
def create_key(): if request.json and 'user' in request.json: user = request.json["user"] data = { "user": user, "text": request.json.get("text", "API Key for %s" % user) } try: key = db.create_key(data) except Exception as e: return jsonify(status="error", message=str(e)), 500 else: return jsonify(status="error", message="must supply 'user' as parameter"), 400 return jsonify(status="ok", key=key), 201, { 'Location': '%s/%s' % (request.base_url, key) }
def create_key(): if request.json and 'user' in request.json: user = request.json['user'] else: return jsonify(status="error", message="must supply 'user' as parameter"), 400 type = request.json.get("type", "read-only") if type not in ['read-only', 'read-write']: return jsonify(status="error", message="API key must be read-only or read-write"), 400 customer = g.get('customer', None) or request.json.get("customer", None) text = request.json.get("text", "API Key for %s" % user) try: key = db.create_key(user, type, customer, text) except Exception as e: return jsonify(status="error", message=str(e)), 500 return jsonify(status="ok", key=key), 201, {'Location': '%s/%s' % (request.base_url, key)}
def create_key(): if g.get('role', None) != 'admin': user = g.user customer = g.customer else: user = request.json.get('user', g.user) customer = request.json.get('customer', None) type = request.json.get("type", "read-only") if type not in ['read-only', 'read-write']: return jsonify(status="error", message="API key must be read-only or read-write"), 400 text = request.json.get("text", "API Key for %s" % user) try: key = db.create_key(user, type, customer, text) except Exception as e: return jsonify(status="error", message=str(e)), 500 return jsonify(status="ok", key=key), 201, {'Location': absolute_url('/key/' + key)}
def setUp(self): app.config['TESTING'] = True app.config['AUTH_REQUIRED'] = True app.config['CUSTOMER_VIEWS'] = True app.config['ALLOWED_EMAIL_DOMAINS'] = ['debeauharnais.fr'] self.app = app.test_client() self.alert = { 'event': 'Foo', 'resource': 'Bar', 'environment': 'Production', 'service': ['Quux'] } self.api_key = db.create_key('demo-key', type='read-write', text='demo-key')['key'] self.headers = { 'Authorization': 'Key %s' % self.api_key, 'Content-type': 'application/json' }
def create_key(): if g.get('role', None) != 'admin': user = g.user customer = g.customer else: user = request.json.get('user', g.user) customer = request.json.get('customer', None) type = request.json.get("type", "read-only") if type not in ['read-only', 'read-write']: return jsonify(status="error", message="API key must be read-only or read-write"), 400 text = request.json.get("text", "API Key for %s" % user) try: key = db.create_key(user, type, customer, text) except Exception as e: return jsonify(status="error", message=str(e)), 500 return jsonify(status="ok", key=key), 201, { 'Location': absolute_url('/key/' + key) }
def create(self) -> 'ApiKey': """ Create a new API key. """ return ApiKey.from_db(db.create_key(self))
def create(self): """ Create a new API key. """ return ApiKey.from_db(db.create_key(self))