Esempio n. 1
0
    def auth(self, user=None, password=None):
        """
        Authenticate user to the API. If user and password params are left blank, function will use the
        credentials instance was started with

        :param user: User ID for a valid EASE user in your organization’s EASE account
        :param password: User’s password
        :return: Boolean
        """
        if user:
            self.username = user
        if password:
            self.password = password

        # Python auth
        payload = json.dumps({'user_id': self.username, 'password': self.password})
        url = '%s/users/authenticate/' % self.region['Python Web Services']
        if self.verbose:
            logging.debug('Sending auth via {}'.format(url))
        r = self.py_session.post(url, data=payload)

        resp = response_check(r)

        if resp['status'] == 200:
            self.token = resp['result']['token']
            self.user_data = resp['result']
            self.py_session.headers.update({'X-TOKEN': self.token})
            self.php_payload["params"] = {"token": self.token}
            Ease.connectors(self)
            return resp['result']['token']
        else:
            if self.verbose:
                logging.debug('Auth failed\n{}'.format(r.text))
            return False
Esempio n. 2
0
 def org_delete(self, psk):
     """
     :param psk: psk of the organization to be deleted
     :return: returns "ok", "auth", or the error message
     """
     url = '%s/organizations/%s' % (self.region['Python Web Services'], psk)
     r = self.py_session.delete(url)
     result = response_check(r, 'deleted_organization')
     return result