예제 #1
0
def _send_install_report():
    import platform
    data = {
        'hostname': platform.node(),
        'python_version': platform.python_version(),
        'python_implementation': platform.python_implementation(),
        'platform': platform.platform(),
        'architecture': platform.machine(),
        'processor': platform.processor(),
        'pyexe_build': platform.architecture()[0]
    }
    try:
        client.request('post', '/v1/reports/install', data)
    except:
        pass
예제 #2
0
    def get(self, request, *args, **kwargs):
        auth = None

        if APP_ID and APP_SECRET:
            if self.CACHE_KEY:
                auth = cache.get(self.CACHE_KEY)

            if auth is None:
                # OAuth2 requests are not json-encoded
                headers = {'Content-Type': 'application/x-www-form-urlencoded'}
                res = client.request('POST',
                                     '/v1/oauth2/token',
                                     params={
                                         'grant_type': 'client_credentials',
                                         'client_id': APP_ID,
                                         'client_secret': APP_SECRET,
                                         'scope': self.SCOPE
                                     },
                                     auth_class=None,
                                     timeout=10,
                                     headers=headers)
                auth = json.dumps(res)

                if self.CACHE_KEY:
                    cache.set(self.CACHE_KEY, auth, timeout=self.CACHE_TIMEOUT)

        return HttpResponse(auth, content_type='application/json')
예제 #3
0
    def _handle_query(self, params, **kwargs):
        try:
            dataset = SolveBio.get_dataset(kwargs.get('dataset').rstrip('/'))
            # get a raw response to avoid decoding and re-encoding json
            response = client.request('post',
                                      dataset._data_url(),
                                      params=params,
                                      raw=True)
        except SolveError as e:
            return HttpResponseBadRequest(json.dumps({'detail': str(e)}),
                                          content_type='application/json')

        return HttpResponse(response.content, content_type='application/json')
예제 #4
0
def login(args):
    """
    Prompt user for login information (email/password).
    Email and password are used to get the user's auth_token key.
    """
    delete_credentials()

    email, password = _ask_for_credentials()
    data = {
        'email': email,
        'password': password
    }
    try:
        response = client.request('post', '/v1/auth/token', data)
    except SolveError as e:
        print 'Login failed: %s' % e.message
    else:
        save_credentials(email.lower(), response['token'])
        # reset the default client's auth token
        solvebio.api_key = response['token']
        _send_install_report()
        print 'You are now logged-in.'