Esempio n. 1
0
 def __init__(self,
              scheme=None,
              host=None,
              prefix=None,
              alternative_namespace=None,
              token=None):
     self.version = None
     self.namespace = alternative_namespace if alternative_namespace is not None else "{}://{}".format(
         scheme, host)
     self.env = None
     self.config = NexusConfig(scheme, host, prefix, alternative_namespace)
     self._http_client = HttpClient(self.config.NEXUS_ENDPOINT,
                                    self.config.NEXUS_PREFIX,
                                    token=token)
     self.domains = DomainRepository(self._http_client)
     self.contexts = ContextRepository(self._http_client)
     self.organizations = OrganizationRepository(self._http_client)
     self.instances = InstanceRepository(self._http_client)
     self.schemas = SchemaRepository(self._http_client)
Esempio n. 2
0
class NexusClient(object):
    SUPPORTED_VERSIONS = ['0.8.14']

    def __init__(self,
                 scheme=None,
                 host=None,
                 prefix=None,
                 alternative_namespace=None,
                 token=None):
        self.version = None
        self.namespace = alternative_namespace if alternative_namespace is not None else "{}://{}".format(
            scheme, host)
        self.env = None
        self.config = NexusConfig(scheme, host, prefix, alternative_namespace)
        self._http_client = HttpClient(self.config.NEXUS_ENDPOINT,
                                       self.config.NEXUS_PREFIX,
                                       token=token)
        self.domains = DomainRepository(self._http_client)
        self.contexts = ContextRepository(self._http_client)
        self.organizations = OrganizationRepository(self._http_client)
        self.instances = InstanceRepository(self._http_client)
        self.schemas = SchemaRepository(self._http_client)

    def version_check(self, supported_versions=SUPPORTED_VERSIONS):
        server_metadata_url = '{}/'.format(self.config.NEXUS_ENDPOINT)

        response = self._http_client.get(server_metadata_url)

        if response is not None:
            service_name = response.get('name')
            self.version = response.get('version')
            self.env = response.get('env')
            if service_name == 'kg' and self.version in supported_versions:
                LOGGER.info('Version supported : %s\nenv: %s', self.version,
                            self.env)
                return True
            else:
                LOGGER.error('**Version unsupported**: %s\nenv: %s',
                             self.version, self.env)
                return True
        else:
            raise NexusException(response.reason)

    def get_fullpath_for_entity(self, entity):
        return "{}{}".format(self.config.NEXUS_NAMESPACE, entity.path)
Esempio n. 3
0
 def test__transform_url_to_defined_endpoint(self):
     client = HttpClient("http://foo", "v0")
     result = client.transform_url_to_defined_endpoint(
         "https://nexus-dev.humanbrainproject.org/v0/data/something")
     print result
     assert result == "http://foo/v0/data/something"
Esempio n. 4
0
# 1. Connection to KG instance via http client object.
#
# Host details and http client
#
import os

#
# NEXUS_URL
# URL of nexus instance
#
host_url = os.environ['NEXUS_URL']

nar_host = {'host': host_url, 'prefix': 'v0', 'scheme': 'http'}
from pyxus.utils.http_client import HttpClient

nar_client = HttpClient(nar_host)

#
# 2. Create an organisation in KG and list it
#
# Local organization object
#  name, description
#  name should be at most 5 characters
#  host_url/v0/organizations/
#
from pyxus.resources.entity import Organization
from pyxus.resources.repository import OrganizationRepository

naro = Organization.create_new(organisation_name,
                               "HBP Neural Activity Resource")
# create organization on KG