コード例 #1
0
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)}
コード例 #2
0
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)
    }
コード例 #3
0
    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')
コード例 #4
0
ファイル: test_auth.py プロジェクト: guardian/alerta
    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"}
コード例 #5
0
    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')
コード例 #6
0
ファイル: views.py プロジェクト: yekeqiang/alerta
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)}
コード例 #7
0
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'])
    }
コード例 #8
0
ファイル: views.py プロジェクト: xiaochengxiang/alerta-1
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)}
コード例 #9
0
ファイル: test_auth.py プロジェクト: xiaochengxiang/alerta-1
    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'
        }
コード例 #10
0
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)
    }
コード例 #11
0
    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'
        }
コード例 #12
0
ファイル: views.py プロジェクト: brynmathias/alerta
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)}
コード例 #13
0
ファイル: views.py プロジェクト: SkylePT/alerta
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)}
コード例 #14
0
ファイル: test_auth.py プロジェクト: shredder12/alerta
    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'
        }
コード例 #15
0
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)
    }
コード例 #16
0
ファイル: key.py プロジェクト: raddessi/alerta
 def create(self) -> 'ApiKey':
     """
     Create a new API key.
     """
     return ApiKey.from_db(db.create_key(self))
コード例 #17
0
ファイル: key.py プロジェクト: 3IWOH/alerta
 def create(self):
     """
     Create a new API key.
     """
     return ApiKey.from_db(db.create_key(self))