Beispiel #1
0
def status():

    endpoint_dict = parse_section()
    unauthorized_endpoint_dict = copy.copy(endpoint_dict)

    query = u"""
        SELECT COUNT(*)
        FROM <http://semantica.globo.com/person>
        WHERE {?s a owl:Class}
    """

    info = {
        "type": u"authenticated [%s:%s]" % (endpoint_dict["auth_username"],
                                            endpoint_dict["auth_password"]),
        "endpoint": endpoint_dict["url"]
    }

    auth_msg = _run_status_request(query, endpoint_dict, info)

    unauthorized_endpoint_dict.pop("auth_mode", None)

    info.update({
        "type": u"not-authenticated",
    })

    non_auth_msg = _run_status_request(query, unauthorized_endpoint_dict, info)

    msg = u"{0}<br>{1}".format(auth_msg, non_auth_msg)

    return msg
Beispiel #2
0
def status():
    endpoint_dict = parse_section()
    unauthorized_endpoint_dict = copy.copy(endpoint_dict)

    query = u"""
        SELECT COUNT(*)
        FROM <http://semantica.globo.com/person>
        WHERE {?s a owl:Class}
    """

    info = {
        "type":
        u"authenticated [%s:%s]" %
        (endpoint_dict["auth_username"], endpoint_dict["auth_password"]),
        "endpoint":
        endpoint_dict["url"]
    }

    auth_msg = _run_status_request(query, endpoint_dict, info)

    unauthorized_endpoint_dict.pop("auth_mode", None)

    info.update({
        "type": u"not-authenticated",
    })

    non_auth_msg = _run_status_request(query, unauthorized_endpoint_dict, info)

    msg = u"{0}<br>{1}".format(auth_msg, non_auth_msg)

    return msg
Beispiel #3
0
 def query(self, query_string, graph=None):
     endpoint_dict = parse_section()
     self.process_inference_options()
     response = triplestore.query_sparql(query_string,
                                         endpoint_dict,
                                         async=False)
     return response
Beispiel #4
0
 def _set_triplestore_config(self, request):
     auth_client_id = request.headers.get(CLIENT_ID_HEADER, 'default')
     try:
         self.triplestore_config = parse_section(section=auth_client_id)
     except ConfigParserNoSectionError:
         raise HTTPError(
             404,
             _(u"Client-Id provided at '{0}' ({1}) is not known").format(
                 CLIENT_ID_HEADER, auth_client_id))
 def test_parse_default_config_file_and_default_section(self):
     response = parse_section()
     expected_response = {
         'url': 'http://localhost:8890/sparql-auth',
         'app_name': 'Brainiak',
         'auth_mode': 'digest',
         'auth_username': '******',
         'auth_password': '******'
     }
     self.assertEqual(response, expected_response)
Beispiel #6
0
 def test_parse_default_config_file_and_default_section(self):
     response = parse_section()
     expected_response = {
         'url': 'http://localhost:8890/sparql-auth',
         'app_name': 'Brainiak',
         'auth_mode': 'digest',
         'auth_username': '******',
         'auth_password': '******'
     }
     self.assertEqual(response, expected_response)
Beispiel #7
0
def find_graph_from_class(class_uri):
    query = QUERY_FIND_GRAPH_FROM_CLASS % {'class_uri': class_uri}
    result_dict = query_sparql(query,
                               config_parser.parse_section(),
                               async=False)
    graphs = filter_values(result_dict, 'graph')
    try:
        return graphs[0] if (len(graphs) == 1) else None
    except IndexError:
        return None
Beispiel #8
0
def find_graph_from_class(class_uri):
    query = QUERY_FIND_GRAPH_FROM_CLASS % {'class_uri': class_uri}
    result_dict = query_sparql(query,
                               config_parser.parse_section(),
                               async=False)
    graphs = filter_values(result_dict, 'graph')
    try:
        return graphs[0] if (len(graphs) == 1) else None
    except IndexError:
        return None
Beispiel #9
0
def get_subproperties(super_property):
    params = {
        "ruleset": "http://semantica.globo.com/ruleset",
        "property": super_property
    }
    query = QUERY_SUBPROPERTIES % params
    result_dict = query_sparql(query,
                               config_parser.parse_section(),
                               async=False)
    subproperties = filter_values(result_dict, "property")
    return subproperties
Beispiel #10
0
def get_subproperties(super_property):
    params = {
        "ruleset": "http://semantica.globo.com/ruleset",
        "property": super_property
    }
    query = QUERY_SUBPROPERTIES % params
    result_dict = query_sparql(query,
                               config_parser.parse_section(),
                               async=False)
    subproperties = filter_values(result_dict, "property")
    return subproperties
Beispiel #11
0
 def test_parse_config_file_and_other_section(self):
     local_ini = "src/brainiak/triplestore.ini"
     response = parse_section(local_ini, "other")
     expected_response = {
         'url': 'http://localhost:8890/sparql-auth',
         'app_name': 'Other',
         'auth_mode': 'digest',
         'auth_username': '******',
         'auth_password': '******'
     }
     self.assertEqual(response, expected_response)
 def test_parse_config_file_and_other_section(self):
     local_ini = "src/brainiak/triplestore.ini"
     response = parse_section(local_ini, "other")
     expected_response = {
         'url': 'http://localhost:8890/sparql-auth',
         'app_name': 'Other',
         'auth_mode': 'digest',
         'auth_username': '******',
         'auth_password': '******'
     }
     self.assertEqual(response, expected_response)
Beispiel #13
0
def find_graph_and_class_from_instance(instance_uri):
    query = QUERY_FIND_GRAPH_AND_CLASS_FROM_INSTANCE % {'instance_uri': instance_uri}
    result_dict = query_sparql(query,
                               config_parser.parse_section(),
                               async=False)
    graphs = filter_values(result_dict, 'graph')
    classes = filter_values(result_dict, 'class')
    try:
        graph_uri = graphs[0] if (len(graphs) == 1) else None
    except IndexError:
        graph_uri = None

    try:
        class_uri = classes[0] if (len(classes) == 1) else None
    except IndexError:
        class_uri = None

    return graph_uri, class_uri
 def test_sync_query_authenticated_fails(self):
     triplestore_config = config_parser.parse_section()
     triplestore_config["auth_password"] = "******"
     self.assertRaises(HTTPError, triplestore.query_sparql, SIMPLE_QUERY, triplestore_config, async=False)
 def test_sync_query_authenticated_works(self):
     triplestore_config = config_parser.parse_section()
     response = triplestore.query_sparql(SIMPLE_QUERY, triplestore_config, async=False)
     self.assertTrue(response["boolean"])
 def test_sync_query_not_authenticated_works(self):
     triplestore_config = config_parser.parse_section()
     triplestore_config["url"] = "http://localhost:8890/sparql"
     response = triplestore.query_sparql(SIMPLE_QUERY, triplestore_config, async=False)
     self.assertTrue(response['boolean'])
Beispiel #17
0
 def _set_triplestore_config(self, request):
     auth_client_id = request.headers.get(CLIENT_ID_HEADER, 'default')
     try:
         self.triplestore_config = parse_section(section=auth_client_id)
     except ConfigParserNoSectionError:
         raise HTTPError(404, _(u"Client-Id provided at '{0}' ({1}) is not known").format(CLIENT_ID_HEADER, auth_client_id))
Beispiel #18
0
 def query(self, query_string, graph=None):
     endpoint_dict = parse_section()
     self.process_inference_options()
     response = triplestore.query_sparql(query_string, endpoint_dict, async=False)
     return response