def _get_conf(self): res = open_auklet_url( build_url(self.client.base_url, "private/devices/config/"), self.client.apikey) loaded = json.loads(u(res.read())) self._write_conf(loaded) self._read_from_conf(loaded)
def _get_config(self): res = open_auklet_url( build_url(self.base_url, "private/devices/{}/app_config/".format(self.app_id)), self.apikey) if res is not None: return json.loads(u(res.read()))['config']
def produce(self, data, data_type="monitoring"): if data_type == "monitoring": return post_auklet_url( build_url(self.client.base_url, "private/sampledstacktraces/store/"), self.client.apikey, data) elif data_type == "event": self.producer.publish().channel( self.producer_types[data_type]).message(data).sync() return True
def check_device(self, device_id): try: opened = open_auklet_url( build_url(self.base_url, "private/devices/{}/".format(device_id)), self.apikey) res = json.loads(u(opened.read())) created = False except HTTPError: res = self.create_device() created = True return res, created
def _get_certs(self): url = Request(build_url(self.client.base_url, "private/devices/certificates/"), headers={"Authorization": "JWT %s" % self.client.apikey}) try: try: res = urlopen(url) except HTTPError as e: # Allow for accessing redirect w/o including the # Authorization token. res = urlopen(e.geturl()) except URLError: return False filename = ".auklet/ca.pem" create_file(filename) f = open(filename, "wb") f.write(res.read()) return True
def _get_certs(self): certs_filename = "{}/pubnub.json".format(self.client.auklet_dir) if not os.path.isfile(certs_filename): url = Request( build_url(self.client.base_url, "private/devices/certificates/?cert_format=json"), headers={"Authorization": "JWT %s" % self.client.apikey}) try: try: res = urlopen(url) except HTTPError as e: # Allow for accessing redirect w/o including the # Authorization token. res = urlopen(e.geturl()) except URLError as e: return False create_file(certs_filename) f = open(certs_filename, "wb") f.write(res.read()) with open(certs_filename) as f: keys = json.loads(f.read()) self.publish_key = keys['publish_key'] self.subscribe_key = keys['subscribe_key'] return True
def create_device(self): return post_auklet_url(build_url(self.base_url, "private/devices/"), self.apikey, { "mac_address_hash": self.mac_hash, "application": self.app_id })