Esempio n. 1
0
    def save_service(self, name, url, *args, **kwargs):
        """
        Stores an OWS service in database (insert or update).

        :param name: A service name string.
        :parm url: A URL string.
        """
        try:
            query = self.request.dbsession.query(models.Service)
            one = query.filter(models.Service.name == name).first()
            if one:
                # update
                one.url = baseurl(url)
                one.type = kwargs.get('type', 'WPS')
                one.purl = kwargs.get('purl', '')
                one._verify = int(kwargs.get('verify', 1))
                one.auth = kwargs.get('auth', 'token')
                self.request.dbsession.merge(one)
            else:
                # insert
                one = models.Service(name=name,
                                     url=baseurl(url),
                                     type=kwargs.get('type', 'WPS'),
                                     purl=kwargs.get('purl', ''),
                                     _verify=int(kwargs.get('verify', 1)),
                                     auth=kwargs.get('auth', 'token'))
                self.request.dbsession.add(one)
        except DBAPIError:
            raise DatabaseError
        if not one:
            raise ServiceNotFound
        return one
Esempio n. 2
0
def test_baseurl():
    assert utils.baseurl('http://localhost:8094/wps') == 'http://localhost:8094/wps'
    assert utils.baseurl('http://localhost:8094/wps?service=wps&request=getcapabilities') == 'http://localhost:8094/wps'
    assert utils.baseurl('https://localhost:8094/wps?service=wps&request=getcapabilities') ==\
        'https://localhost:8094/wps'
    with pytest.raises(ValueError) as e_info:
        utils.baseurl('ftp://localhost:8094/wps')
Esempio n. 3
0
def test_baseurl():
    assert utils.baseurl('http://localhost:8094/wps') == 'http://localhost:8094/wps'
    assert utils.baseurl('http://localhost:8094/wps?service=wps&request=getcapabilities') == 'http://localhost:8094/wps'
    assert utils.baseurl('https://localhost:8094/wps?service=wps&request=getcapabilities') ==\
        'https://localhost:8094/wps'
    with pytest.raises(ValueError):
        utils.baseurl('ftp://localhost:8094/wps')
Esempio n. 4
0
    def register_service(self, url, name=None, service_type='wps', public=False, c4i=False, overwrite=True):
        """
        Adds OWS service with given name to registry database.
        """

        service_url = baseurl(url)
        # check if service is already registered
        if self.collection.count({'url': service_url}) > 0:
            if overwrite:
                self.collection.delete_one({'url': service_url})
            else:
                raise RegistrationException("service url already registered.")

        name = namesgenerator.get_sane_name(name)
        if not name:
            name = namesgenerator.get_random_name()
            if self.collection.count({'name': name}) > 0:
                name = namesgenerator.get_random_name(retry=True)
        if self.collection.count({'name': name}) > 0:
            if overwrite:
                self.collection.delete_one({'name': name})
            else:
                raise Exception("service name already registered.")
        service = dict(url=service_url, name=name, type=service_type, public=public, c4i=c4i)
        self.collection.insert_one(service)
        return service
Esempio n. 5
0
 def get_service_by_url(self, url):
     """
     Get service for given ``url`` from registry database.
     """
     service = self.collection.find_one({'url': baseurl(url)})
     if not service:
         raise ValueError('service not found')
     return doc2dict(service)
Esempio n. 6
0
 def save_service(self, service, overwrite=True):
     """
     Store an OWS service in database.
     """
     name = namesgenerator.get_sane_name(service.name)
     if not name:
         name = namesgenerator.get_random_name()
         if name in self.name_index:
             name = namesgenerator.get_random_name(retry=True)
     # check if service is already registered
     if name in self.name_index:
         if overwrite:
             self._delete(name=name)
         else:
             raise Exception("service name already registered.")
     self._insert(
         Service(name=name,
                 url=baseurl(service.url),
                 type=service.type,
                 purl=service.purl,
                 public=service.public,
                 auth=service.auth,
                 verify=service.verify))
     return self.fetch_by_name(name=name)
Esempio n. 7
0
 def save_service(self, service, overwrite=True):
     """
     Stores an OWS service in mongodb.
     """
     name = namesgenerator.get_sane_name(service.name)
     if not name:
         name = namesgenerator.get_random_name()
         if self.collection.count_documents({'name': name}) > 0:
             name = namesgenerator.get_random_name(retry=True)
     # check if service is already registered
     if self.collection.count_documents({'name': name}) > 0:
         if overwrite:
             self.collection.delete_one({'name': name})
         else:
             raise Exception("service name already registered.")
     self.collection.insert_one(
         Service(name=name,
                 url=baseurl(service.url),
                 type=service.type,
                 purl=service.purl,
                 public=service.public,
                 auth=service.auth,
                 verify=service.verify))
     return self.fetch_by_name(name=name)