Example #1
0
def authorize(program, project, roles):
    resource = "/programs/{}/projects/{}".format(program, project)
    jwt = get_jwt_from_header()
    authz = flask.current_app.auth.auth_request(jwt=jwt,
                                                service="sheepdog",
                                                methods=roles,
                                                resources=[resource])
    if not authz:
        raise AuthZError("user is unauthorized")
Example #2
0
 def authorize_and_call(program, project, *args, **kwargs):
     resource = "/programs/{}/projects/{}".format(program, project)
     jwt = get_jwt_from_header()
     authz = flask.current_app.auth.auth_request(jwt=jwt,
                                                 service="sheepdog",
                                                 methods=required_roles,
                                                 resources=[resource])
     if not authz:
         raise AuthZError("user is unauthorized")
     return func(program, project, *args, **kwargs)
Example #3
0
 def authorize_and_call(*args, **kwargs):
     jwt = get_jwt_from_header()
     authz = flask.current_app.auth.auth_request(
         jwt=jwt,
         service="sheepdog",
         methods="*",
         resources=["/services/sheepdog/submission/project"],
     )
     if not authz:
         raise AuthZError(
             "Unauthorized: User must be Sheepdog project admin")
     return func(*args, **kwargs)
Example #4
0
        def make_mock_response(*args, **kwargs):
            if not authorized:
                raise AuthZError('Mocked Arborist says no')
            mocked_response = MagicMock(requests.Response)
            mocked_response.status_code = 200

            def mocked_get(*args, **kwargs):
                return None

            mocked_response.get = mocked_get

            return mocked_response
Example #5
0
def authorize(program, project, roles, resource_list=None):
    resource = "/programs/{}/projects/{}".format(program, project)

    resources = []
    if resource_list:
        for res in resource_list:
            resources.append(resource + res)
    else:
        resources = [resource]

    jwt = get_jwt_from_header()
    authz = flask.current_app.auth.auth_request(jwt=jwt,
                                                service="sheepdog",
                                                methods=roles,
                                                resources=resources)

    if not authz:
        raise AuthZError("user is unauthorized")