Example #1
0
    def extract_payload(self, payload, signature):

        expected_sig = self.sign_string(payload)
        if signature != expected_sig:
            return None

        return json_load(base64_url_decode(payload))
Example #2
0
    def extract_payload(self, payload, signature):

        expected_sig = self.sign_string(payload)
        if signature != expected_sig:
            return None

        return json_load(base64_url_decode(payload))
Example #3
0
    def _check_token(self):
        if not self._token or not self._token_exp or time.time(
        ) >= self._token_exp:
            try:
                conn = httplib.HTTPConnection(self.credential_proxy_host,
                                              self.credential_proxy_port,
                                              timeout=1)
                conn.request("GET",
                             "/latest/meta-data/security-credentials",
                             headers={"Accept": "application/json"})
                response = conn.getresponse()
                # Reuse the connection
                if response.status == 200:
                    r = response.read()
                    if r:
                        # first reverse escape, then json_load
                        r = json_load(eval(r))
                        self._token = r.get('id_token')
                        self._token_exp = r.get('expiration')
                        self.iam_access_key = r.get('access_key')
                        self.iam_secret_key = r.get('secret_key')

                        self._auth_handler = QuerySignatureAuthHandler(
                            self.host, str(self.iam_access_key),
                            str(self.iam_secret_key))

                elif response.status == 404:
                    print("The current instance has no credentials")
                    pass
            except Exception as e:
                print("Failed to get credentials due to error: %s" % e)
                pass
Example #4
0
 def send_request(self, action, body, url = '/app/', verb = 'GET'):
     """ send request """
     request = body
     request['action'] = action
     request.setdefault('zone', self.zone)
     if self.expires:
         request['expires'] = self.expires
     resp = self.send(url, request, verb)
     if resp:
         return json_load(resp)
 def send_request(self, action, body, url = '/app/', verb = 'GET'):
     """ send request """
     request = body
     request['action'] = action
     request.setdefault('zone', self.zone)
     if self.expires:
         request['expires'] = self.expires
     resp = self.send(url, request, verb)
     if resp:
         return json_load(resp)
Example #6
0
 def test_json_load_invalid_string(self):
     string = '{"int":1,:null,"str":"string"}'
     expected = None
     self.assertEqual(json_load(string), expected)
Example #7
0
 def test_json_load_string(self):
     string = '{"int":1,"none":null,"str":"string"}'
     expected = {'int': 1, 'str': 'string', 'none': None}
     self.assertEqual(json_load(string), expected)