Esempio n. 1
0
    def _put(self, data, files=None, extra_paths=[]):
        if self.api_version == 'v1':
            if len(extra_paths) == 0:
                url = '%s%s/%s' % (self.target_endpoint, self.instance_id,
                                   self.entity_uri)
            else:
                url = '%s%s/%s/%s' % (self.target_endpoint, self.instance_id,
                                      self.entity_uri, '/'.join(extra_paths))
        elif self.api_version == 'v2':
            url = utils.urljoin(self.target_endpoint,
                                'instances',
                                self.instance_id,
                                self.entity_uri,
                                extra_paths=extra_paths)

        if not files:
            response = utils._check_response(
                requests.put(url,
                             params=dict(auth_code=self.auth_code),
                             data=data,
                             verify=False))
        else:
            response = utils._check_response(
                requests.put(url,
                             params=dict(auth_code=self.auth_code),
                             files=files,
                             data=data,
                             verify=False))
        _logger.debug('PUT - %s - %s', url, response.text)
        return response
Esempio n. 2
0
    def _create(self, data, files=None, extra_paths=[], form="json"):
        url = utils.urljoin(
            self.target_endpoint,
            "instances",
            self.instance_id,
            self.entity_uri,
            extra_paths=extra_paths,
        )

        if not files:
            if form == "json":
                response = utils._check_response(
                    self.session.post(
                        url,
                        params=dict(auth_code=self.auth_code),
                        json=data,
                        verify=False,
                    ))
            elif form == "data":
                response = utils._check_response(
                    self.session.post(
                        url,
                        params=dict(auth_code=self.auth_code),
                        data=data,
                        verify=False,
                    ))
        else:
            if form == "json":
                response = utils._check_response(
                    self.session.post(
                        url,
                        params=dict(auth_code=self.auth_code),
                        json=data,
                        files=files,
                        verify=False,
                    ))
            elif form == "data":
                response = utils._check_response(
                    self.session.post(
                        url,
                        params=dict(auth_code=self.auth_code),
                        data=data,
                        files=files,
                        verify=False,
                    ))

        return response
Esempio n. 3
0
 def _put(self, data, extra_paths=[]):
     url = utils.urljoin(
         self.target_endpoint,
         "instances",
         self.instance_id,
         self.entity_uri,
         extra_paths=extra_paths,
     )
     get_params = {}
     get_params.update(dict(auth_code=self.auth_code))
     response = utils._check_response(
         self.session.put(url, params=get_params, json=data, verify=False))
     return response
Esempio n. 4
0
 def _create(self, data, files=None, extra_paths=[]):
     if len(extra_paths) == 0:
         url = '%s%s/%s' % (self.target_endpoint, self.instance_id,
                            self.entity_uri)
     else:
         url = '%s%s/%s/%s' % (self.target_endpoint, self.instance_id,
                               self.entity_uri, '/'.join(extra_paths))
     if not files:
         response = utils._check_response(
             requests.post(url,
                           params=dict(auth_code=self.auth_code),
                           json=data,
                           verify=False))
     else:
         response = utils._check_response(
             requests.post(url,
                           params=dict(auth_code=self.auth_code),
                           json=data,
                           files=files,
                           verify=False))
     _logger.debug('POST - %s - %s', url, response.text)
     return response
Esempio n. 5
0
 def _get(self, params={}, extra_paths=[]):
     if len(extra_paths) == 0:
         url = '%s%s/%s' % (self.target_endpoint, self.instance_id,
                            self.entity_uri)
     else:
         url = '%s%s/%s/%s' % (self.target_endpoint, self.instance_id,
                               self.entity_uri, '/'.join(extra_paths))
     get_params = {}
     get_params.update(dict(auth_code=self.auth_code))
     get_params.update(params)
     response = utils._check_response(
         requests.get(url, params=get_params, verify=False))
     _logger.debug('GET - %s - %s', url, response.text)
     return response
Esempio n. 6
0
    def _del(self, params={}, extra_paths=[]):
        url = utils.urljoin(self.target_endpoint,
                            'instances',
                            self.instance_id,
                            self.entity_uri,
                            extra_paths=extra_paths)

        get_params = {}
        get_params.update(dict(auth_code=self.auth_code))
        get_params.update(params)
        response = utils._check_response(
            requests.delete(url, params=get_params, verify=False))
        _logger.debug('DELETE - %s - %s', url, response.text)
        return response
Esempio n. 7
0
    def _get_api_version(self):
        # Fetch api-afs root info 
        url = utils.urljoin(self.target_endpoint, extra_paths={})
        response = utils._check_response(self.session.get(url, verify=False))

        # Check AFS version
        afs_version = response.json().get("AFS_version", None)

        # Check API version
        api_version = response.json().get("API_version", None)
        if not api_version:
            raise ValueError("No API_version from api-afs.")

        if response.json().get("AFS_version", None):
            return api_version, afs_version
        else:
            raise ConnectionError("Cannot fetch AFS server from {}.".format(url))
Esempio n. 8
0
    def _get_api_version(self):
        if self.version <= '2.0.1':
            url = utils.urljoin(self.target_endpoint, 'info', extra_paths={})
        else:
            url = utils.urljoin(self.target_endpoint, extra_paths={})
        response = utils._check_response(requests.get(url, verify=False))
        _logger.debug('GET - %s - %s', url, response.text)

        afs_portal_version = response.json().get('AFS_version', None)
        if afs_portal_version != self.__version__:
            warnings.warn(
                'SDK version is {0}, and AFS portal version is {1}. It will cause some compatibility issues. Readthedocs: https://afs-docs.readthedocs.io/en/latest/index.html'
                .format(self.__version__, afs_portal_version))

        if response.json().get('AFS_version', None):
            return response.json()['API_version'], afs_portal_version
        else:
            raise ConnectionError('Cannot fetch AFS server info')