def handle_enterprises(): if request.method == 'GET': return jsonify(Enterprise.getAllSerialized()), 200 if request.method == 'POST': body = request.get_json() newEnterprise = Enterprise.newInstance(body) newEnterprise.addCommit() return toJson(newEnterprise), 201
def signup(username, password) -> Tuple[Enterprise, Signer_Impl]: try: signer = create_account(username, password) enterprise = Enterprise(username=username, password=password) contract_addr = deploy_contract("Enterprise", signer=signer) enterprise.contract_addr = contract_addr enterprise.account_addr = str(signer.keypair.address) enterprise.account_pub = str(signer.keypair.public_key) enterprise.account_priv = str(signer.keypair.private_key) privkey, pubkey = gen_rsakey() enterprise.envelope_pub = pubkey enterprise.envelope_priv = privkey managementAddr = db.session.query(Contracts).filter( Contracts.name == "Management").first().addr call_contract(managementAddr, "Management", "addEnterprise", args=[ username, to_checksum_address(enterprise.account_addr), to_checksum_address(enterprise.contract_addr), enterprise.envelope_pub, "" ]) db.session.add(enterprise) db.session.commit() except Exception: traceback.print_exc() db.session.rollback() return None, None return enterprise, signer
def handle_new_enterprise(): enterprise = Enterprise() new_enterprise = request.get_json() validation = validation_global_cooker(new_enterprise) check_new_username = request.json.get('nickname',None) check_new_password = request.json.get('password',None) if not check_new_username: return 'Missing username', 400 if not check_new_password: return 'Missing password', 400 if validation == True: enterprise.add_enterprise(new_enterprise) return "Success email",200 else: return "Error syntaxis",406
def setUp(self): self.set_application(tst_app) self.setup_testbed() self.init_datastore_stub() self.init_memcache_stub() self.init_taskqueue_stub() self.init_app_identity_stub() self.init_mail_stub() self.register_search_api_stub() self.init_urlfetch_stub() self.init_blobstore_stub() self.init_modules_stub() cloudstorage.set_default_retry_params(None) # Create enterprise, sensortype and sensor self.e = Enterprise.Create() self.e.Update(name="Test Ent", timezone="Africa/Nairobi") self.e.put() self.owner = User.Create(self.e, phone=OWNER_NUM, notify=False) self.owner.Update(name=OWNER_NAME, currency="KES") self.owner.put() self.spedometer = SensorType.Create(self.e) schema = {'speed': {'unit': 'kph'}, 'narrative': {'type': 'string'}} self.spedometer.Update(name="Spedometer", schema=json.dumps(schema)) self.spedometer.put() self.vehicle_1 = Sensor.Create(self.e, TEST_SENSOR_ID, self.spedometer.key().id()) self.vehicle_1.Update(sensortype_id=self.spedometer.key().id(), name="Vehicle Sensor 1") self.vehicle_1.put()
def setUp(self): self.set_application(tst_app) self.setup_testbed() self.init_datastore_stub() self.init_memcache_stub() self.init_taskqueue_stub() self.register_search_api_stub() self.init_modules_stub() # Create enterprise, sensortype and sensor self.e = Enterprise.Create() self.e.Update(name="Test Ent", alias=E_ALIAS.upper()) self.e.put() self.u = User.Create(self.e, phone=TEST_NUM, email=TEST_EMAIL) self.u.Update(password=PW, level=USER.ACCOUNT_ADMIN) self.u.put() self.st = SensorType.Create(self.e) self.st.Update(alias="geo", schema=json.dumps({'location': { 'type': 'location' }})) self.st.put()
def login(): if not request.is_json: return jsonify({"msg": "Missing JSON in request"}), 400 email = request.json.get('email', None) password = request.json.get('password', None) if not email: return jsonify({"msg": "Missing email parameter"}), 400 if not password: return jsonify({"msg": "Missing password parameter"}), 400 enterprise = Enterprise.get_enterprise_with_login_credentials( email, password) if enterprise == None: return jsonify({"msg": "Bad email or password"}), 400 access_token = create_access_token(identity=enterprise.email) ret = { 'access_token': access_token, 'refresh_token': create_refresh_token(identity=enterprise.email), 'is_admin': enterprise.is_admin() } return jsonify(ret), 200
def handle_enterprise(id): enterprise = Enterprise.getById(id) if request.method == 'GET': return toJson(enterprise), 200 if request.method == 'PUT': body = request.get_json() enterprise.updateModel(body) enterprise.store() return json.dumps({"Message": "Correctly scheduled"}), 200
def setUp(self): self.set_application(tst_app) self.setup_testbed() self.init_datastore_stub() self.init_memcache_stub() self.init_taskqueue_stub() self.init_mail_stub() self.register_search_api_stub() self.init_urlfetch_stub() self.init_modules_stub() # Create enterprise, sensortype and sensor self.e = Enterprise.Create() self.e.Update(name="Test Ent", timezone="Africa/Nairobi") self.e.put() self.owner = User.Create(self.e, phone=OWNER_NUM, notify=False) self.owner.Update(name=OWNER_NAME, currency="KES") self.owner.put() self.spedometer = SensorType.Create(self.e) schema = { 'speed': { 'unit': 'kph' }, 'bearing': { 'unit': 'deg' }, 'location': { 'unit': 'degrees' }, 'hard_braking': { 'unit': 'boolean' } } self.spedometer.Update(name="Geo Sensor", schema=json.dumps(schema)) self.spedometer.put() self.vehicle_1 = Sensor.Create(self.e, TEST_SENSOR_ID, self.spedometer.key().id()) self.vehicle_1.Update(sensortype_id=self.spedometer.key().id(), name="Vehicle Sensor 1", contacts={"owner": self.owner.key().id()}) self.vehicle_1.put() # Create alarm self.speeding_alarm = Rule.Create(self.e) self.speeding_alarm.Update(name="Speeding", sensortype_id=self.spedometer.key().id(), column="speed", trigger=RULE.CEILING, value2=80.0, alert_contacts=["owner"], alert_message=SPEEDING_ALERT_MESSAGE, duration=0) self.speeding_alarm.put()
def setUp(self): self.set_application(tst_app) self.setup_testbed() self.init_datastore_stub() self.init_memcache_stub() self.init_taskqueue_stub() self.register_search_api_stub() # Create enterprise, sensortype and sensor self.e = Enterprise.Create() self.e.Update(name="Test Ent") self.e.put() self.geosensor = SensorType.Create(self.e) schema = { 'location': { 'unit': 'deg', 'label': "Location", 'role': [COLUMN.LOCATION] }, 'ax': {}, 'ay': { 'unit': 'm/s^2', 'type': 'number' }, 'az': { 'unit': 'm/s^2', 'type': 'number' }, 'accel_mag': { 'unit': 'm/2^2', 'label': "Acceleration Magnitude", 'calculation': "SQRT([ax]^2 + [ay]^2 + [az]^2)" } } self.geosensor.Update(name="Geo Sensor", schema=json.dumps(schema)) self.geosensor.put() self.geosensor1 = Sensor.Create(self.e, TEST_SENSOR_ID, self.geosensor.key().id()) self.geosensor1.Update(sensortype_id=self.geosensor.key().id(), name="Geo Sensor 1") self.geosensor1.put()
def setUp(self): self.set_application(tst_app) self.setup_testbed() self.init_datastore_stub() self.init_memcache_stub() self.init_taskqueue_stub() self.init_mail_stub() self.register_search_api_stub() self.init_urlfetch_stub() self.init_modules_stub() # Create enterprise, sensortype and sensor self.e = Enterprise.Create() self.e.Update(name="Test Ent", timezone="Africa/Nairobi") self.e.put() self.owner = User.Create(self.e, phone=OWNER_NUM, notify=False) self.owner.Update(name=OWNER_NAME, currency="KES") self.owner.put() self.tracker = SensorType.Create(self.e) schema = { 'bearing': { 'unit': 'deg' }, 'location': { 'unit': 'deg', 'label': "Location", 'role': [COLUMN.LOCATION], 'type': 'latlng' } } self.tracker.Update(name="Geo Sensor", schema=json.dumps(schema)) self.tracker.put() self.vehicle_1 = Sensor.Create(self.e, TEST_SENSOR_ID, self.tracker.key().id()) self.vehicle_1.Update(sensortype_id=self.tracker.key().id(), name="Vehicle Sensor 1", contacts={"owner": self.owner.key().id()}) self.vehicle_1.put()
def setUp(self): self.set_application(tst_app) self.setup_testbed() self.init_datastore_stub() self.init_memcache_stub() self.init_taskqueue_stub() self.init_mail_stub() self.register_search_api_stub() self.init_urlfetch_stub() self.init_modules_stub() # Create enterprise, sensortype and sensor self.e = Enterprise.Create() self.e.Update(name="Test Ent", timezone="Africa/Nairobi") self.e.put() self.tracker = SensorType.Create(self.e) schema = { 'speed': { 'unit': 'kph' }, 'ign_on': { 'unit': 'boolean' }, 'ign_off': { 'unit': 'boolean' } } self.tracker.Update(name="Tracker Sensor", schema=json.dumps(schema)) self.tracker.put() self.vehicle_1 = Sensor.Create(self.e, TEST_SENSOR_ID, self.tracker.key().id()) self.vehicle_1.Update( sensortype_id=self.tracker.key().id(), name="Vehicle Sensor 1" ) self.vehicle_1.put() # Create alarm self.ign_on_alarm = Rule.Create(self.e) self.ign_on_alarm.Update( name="Ignition On", sensortype_id=self.tracker.key().id(), column="ign_on", trigger=RULE.CEILING, value2=0, consecutive_limit=-1, duration=0) self.ign_on_alarm.put() self.ign_off_alarm = Rule.Create(self.e) self.ign_off_alarm.Update( name="Ignition Off", sensortype_id=self.tracker.key().id(), column="ign_off", trigger=RULE.CEILING, value2=0, consecutive_limit=-1, duration=0, spec=json.dumps({'processers': [ { 'analysis_key_pattern': ANALYSIS_KEY_PATTERN, 'expr': '. + SINCE(LAST_ALARM(%d)) / 1000' % self.ign_on_alarm.key().id(), 'column': 'on_secs' } ]})) self.ign_off_alarm.put()
def handle_enterprises(): return jsonify(Enterprise.get_enterprises())