From 182b29fad50f39a40354870511146d157f1d2fbe Mon Sep 17 00:00:00 2001 From: Shreyas Nagare Date: Tue, 2 Jun 2020 15:35:52 -0400 Subject: [PATCH 01/70] Update to Python3 - used 2to3 --- bd_oauth2.py | 46 +++++++++---------- buildingdepot/CentralReplica/demo.py | 4 +- buildingdepot/CentralReplica/main.py | 2 +- buildingdepot/CentralReplica/models.py | 2 +- .../CentralService/app/auth/access_control.py | 4 +- .../CentralService/app/central/utils.py | 2 +- .../CentralService/app/central/views.py | 12 ++--- .../CentralService/app/oauth_bd/views.py | 4 +- .../buildingtemplate_tagtypes.py | 2 +- .../app/rest_api/dataservices/dataservice.py | 2 +- .../CentralService/app/rest_api/helper.py | 18 ++++---- .../app/rest_api/sensorgroups/sg_tags.py | 8 ++-- .../app/rest_api/sensors/search.py | 2 +- .../app/rest_api/sensors/sensor.py | 2 +- .../CentralService/app/rest_api/views.py | 2 +- buildingdepot/CentralService/app/rpc/defs.py | 4 +- .../app/api_0_0/resources/subscription.py | 2 +- .../app/api_0_0/resources/utils.py | 16 +++---- .../app/api_0_0/resources/write.py | 10 ++-- .../app/rest_api/app_subscription.py | 6 +-- .../DataService/app/rest_api/apps.py | 23 +++++----- .../DataService/app/rest_api/helper.py | 2 +- .../DataService/app/rest_api/timeseries.py | 22 ++++----- .../DataService/app/rest_api/views.py | 12 ++--- .../DataService/app/service/utils.py | 2 +- .../DataService/app/service/views.py | 8 ++-- .../Documentation/source/source/conf.py | 18 ++++---- buildingdepot/Instrumentation/comment.py | 4 +- buildingdepot/Instrumentation/instrument.py | 2 +- .../Instrumentation/logSummarizer.py | 10 ++-- buildingdepot/Instrumentation/uncomment.py | 4 +- setup_bd.py | 16 +++---- testing/BD-Performance-Test/results/parse.py | 2 +- 33 files changed, 137 insertions(+), 138 deletions(-) diff --git a/bd_oauth2.py b/bd_oauth2.py index 58201e11..b1620694 100644 --- a/bd_oauth2.py +++ b/bd_oauth2.py @@ -66,7 +66,7 @@ from optparse import OptionParser import smtplib import sys -import urllib +import urllib.request, urllib.parse, urllib.error def SetupOptionParser(): @@ -138,12 +138,12 @@ def AccountsUrl(command): def UrlEscape(text): # See OAUTH 5.1 for a definition of which characters need to be escaped. - return urllib.quote(text, safe='~-._') + return urllib.parse.quote(text, safe='~-._') def UrlUnescape(text): # See OAUTH 5.1 for a definition of which characters need to be escaped. - return urllib.unquote(text) + return urllib.parse.unquote(text) def FormatUrlParams(params): @@ -156,7 +156,7 @@ def FormatUrlParams(params): A URL query string version of the given parameters. """ param_fragments = [] - for param in sorted(params.iteritems(), key=lambda x: x[0]): + for param in sorted(iter(params.items()), key=lambda x: x[0]): param_fragments.append('%s=%s' % (param[0], UrlEscape(param[1]))) return '&'.join(param_fragments) @@ -205,7 +205,7 @@ def AuthorizeTokens(client_id, client_secret, authorization_code): params['grant_type'] = 'authorization_code' request_url = AccountsUrl('o/oauth2/token') - response = urllib.urlopen(request_url, urllib.urlencode(params)).read() + response = urllib.request.urlopen(request_url, urllib.parse.urlencode(params)).read() return json.loads(response) @@ -229,7 +229,7 @@ def RefreshToken(client_id, client_secret, refresh_token): params['grant_type'] = 'refresh_token' request_url = AccountsUrl('o/oauth2/token') - response = urllib.urlopen(request_url, urllib.urlencode(params)).read() + response = urllib.request.urlopen(request_url, urllib.parse.urlencode(params)).read() return json.loads(response) @@ -262,7 +262,7 @@ def TestImapAuthentication(user, auth_string): auth_string: A valid OAuth2 string, as returned by GenerateOAuth2String. Must not be base64-encoded, since imaplib does its own base64-encoding. """ - print + print() imap_conn = imaplib.IMAP4_SSL('imap.gmail.com') imap_conn.debug = 4 imap_conn.authenticate('XOAUTH2', lambda x: auth_string) @@ -277,7 +277,7 @@ def TestSmtpAuthentication(user, auth_string): auth_string: A valid OAuth2 string, not base64-encoded, as returned by GenerateOAuth2String. """ - print + print() smtp_conn = smtplib.SMTP('smtp.gmail.com', 587) smtp_conn.set_debuglevel(True) smtp_conn.ehlo('test') @@ -288,7 +288,7 @@ def TestSmtpAuthentication(user, auth_string): def RequireOptions(options, *args): missing = [arg for arg in args if getattr(options, arg) is None] if missing: - print 'Missing options: %s' % ' '.join(missing) + print('Missing options: %s' % ' '.join(missing)) sys.exit(-1) @@ -299,22 +299,22 @@ def main(argv): RequireOptions(options, 'client_id', 'client_secret') response = RefreshToken(options.client_id, options.client_secret, options.refresh_token) - print 'Access Token: %s' % response['access_token'] - print 'Access Token Expiration Seconds: %s' % response['expires_in'] + print('Access Token: %s' % response['access_token']) + print('Access Token Expiration Seconds: %s' % response['expires_in']) elif options.generate_oauth2_string: RequireOptions(options, 'user', 'access_token') - print ('OAuth2 argument:\n' + - GenerateOAuth2String(options.user, options.access_token)) + print(('OAuth2 argument:\n' + + GenerateOAuth2String(options.user, options.access_token))) elif options.generate_oauth2_token: RequireOptions(options, 'client_id', 'client_secret') - print 'To authorize token, visit this url and follow the directions:' - print ' %s' % GeneratePermissionUrl(options.client_id, options.scope) - authorization_code = raw_input('Enter verification code: ') + print('To authorize token, visit this url and follow the directions:') + print(' %s' % GeneratePermissionUrl(options.client_id, options.scope)) + authorization_code = input('Enter verification code: ') response = AuthorizeTokens(options.client_id, options.client_secret, authorization_code) - print 'Refresh Token: %s' % response['refresh_token'] - print 'Access Token: %s' % response['access_token'] - print 'Access Token Expiration Seconds: %s' % response['expires_in'] + print('Refresh Token: %s' % response['refresh_token']) + print('Access Token: %s' % response['access_token']) + print('Access Token Expiration Seconds: %s' % response['expires_in']) elif options.test_imap_authentication: RequireOptions(options, 'user', 'access_token') TestImapAuthentication(options.user, @@ -327,7 +327,7 @@ def main(argv): base64_encode=False)) else: options_parser.print_help() - print 'Nothing to do, exiting.' + print('Nothing to do, exiting.') return def main_bd(): @@ -340,9 +340,9 @@ def main_bd(): d = json.load(fp) cid = d['client_id'] csec = d['client_secret'] - print 'To authorize token, visit this url and follow the directions:' - print ' %s' % GeneratePermissionUrl(cid) - authorization_code = raw_input('Enter verification code: ') + print('To authorize token, visit this url and follow the directions:') + print(' %s' % GeneratePermissionUrl(cid)) + authorization_code = input('Enter verification code: ') response = AuthorizeTokens(cid, csec, authorization_code) with open(cred_filename, 'r') as fp: d = json.load(fp) diff --git a/buildingdepot/CentralReplica/demo.py b/buildingdepot/CentralReplica/demo.py index 0e0ec987..714c5958 100755 --- a/buildingdepot/CentralReplica/demo.py +++ b/buildingdepot/CentralReplica/demo.py @@ -1,5 +1,5 @@ -from models import * +from .models import * connect('buildingdepot') -print Role.objects(name='default').first().permission +print(Role.objects(name='default').first().permission) diff --git a/buildingdepot/CentralReplica/main.py b/buildingdepot/CentralReplica/main.py index 55e3090f..bac13a25 100755 --- a/buildingdepot/CentralReplica/main.py +++ b/buildingdepot/CentralReplica/main.py @@ -14,7 +14,7 @@ from SocketServer import ThreadingMixIn from models import * from mongoengine import connect -from config import Config +from .config import Config connect(db=Config.MONGODB_DATABASE, host=Config.MONGODB_HOST, diff --git a/buildingdepot/CentralReplica/models.py b/buildingdepot/CentralReplica/models.py index cc046665..7f4e75fa 100755 --- a/buildingdepot/CentralReplica/models.py +++ b/buildingdepot/CentralReplica/models.py @@ -14,7 +14,7 @@ from mongoengine import * from itsdangerous import TimedJSONWebSignatureSerializer as Serializer from werkzeug.security import check_password_hash -from config import Config +from .config import Config from flask import current_app from flask_login import UserMixin from itsdangerous import TimedJSONWebSignatureSerializer as Serializer diff --git a/buildingdepot/CentralService/app/auth/access_control.py b/buildingdepot/CentralService/app/auth/access_control.py index a425d2a2..63cfad7d 100755 --- a/buildingdepot/CentralService/app/auth/access_control.py +++ b/buildingdepot/CentralService/app/auth/access_control.py @@ -132,7 +132,7 @@ def authorize_user(user_group, sensorgroup_name, email=None): args['tags__all'] = tag_list sensors = Sensor.objects(**args) for sensor in sensors: - print sensor['name'] + print(sensor['name']) if permission(sensor['name'], email) != 'r/w/p': return False return True @@ -144,7 +144,7 @@ def authorize_addition(usergroup_name, email): return True for user in user_group.users: - print type(user['manager']) + print(type(user['manager'])) if user['user_id'] == email and user['manager']: return True return False diff --git a/buildingdepot/CentralService/app/central/utils.py b/buildingdepot/CentralService/app/central/utils.py index 4b919a40..3c1b60cb 100755 --- a/buildingdepot/CentralService/app/central/utils.py +++ b/buildingdepot/CentralService/app/central/utils.py @@ -15,7 +15,7 @@ def get_choices(cls): """Given a class type retrieve all its instances from MongoDB""" names = [obj['name'] for obj in cls._get_collection().find({}, {'_id': 0, 'name': 1})] - return zip(names, names) + return list(zip(names, names)) graph = {tag_type.name: tag_type.children for tag_type in TagType.objects} diff --git a/buildingdepot/CentralService/app/central/views.py b/buildingdepot/CentralService/app/central/views.py index c7122fe5..9f8b5808 100755 --- a/buildingdepot/CentralService/app/central/views.py +++ b/buildingdepot/CentralService/app/central/views.py @@ -88,7 +88,7 @@ def buildingtemplate(): obj.can_delete = False else: obj.can_delete = True - obj.tag_types = map(str, obj.tag_types) + obj.tag_types = list(map(str, obj.tag_types)) form = BuildingTemplateForm() # Get list of tags that this building can use form.tag_types.choices = get_choices(TagType) @@ -167,7 +167,7 @@ def building_metadata(name): then update the metadata""" if request.method == 'GET': metadata = Building._get_collection().find({'name': name}, {'metadata': 1, '_id': 0})[0]['metadata'] - metadata = [{'name': key, 'value': val} for key, val in metadata.iteritems()] + metadata = [{'name': key, 'value': val} for key, val in metadata.items()] return jsonify({'data': metadata}) else: # Update the metadata @@ -230,7 +230,7 @@ def user_tags_owned(email): triples = [{'building': item.building, 'tags': [{'name': elem.name, 'value': elem.value} for elem in item.tags]} for item in user.tags_owned] - print triples, data + print(triples, data) return jsonify({'data': data, 'triples': triples}) else: tags_owned = request.get_json()['data'] @@ -400,7 +400,7 @@ def sensorgroup(): form = SensorGroupForm() # Get list of valid buildings for this DataService and create a sensorgroup form.building.choices = get_building_choices() - print "Got building choices" + print("Got building choices") if form.validate_on_submit(): SensorGroup(name=str(form.name.data), description=str(form.description.data), @@ -538,7 +538,7 @@ def permission_query(): def sensors_search(): data = json.loads(request.args.get('q')) args = {} - for key, values in data.iteritems(): + for key, values in data.items(): if key == 'Building': form_query('building',values,args,"$or") elif key == 'SourceName': @@ -553,7 +553,7 @@ def sensors_search(): form_query('tags',values,args,"$and") elif key == 'MetaData': form_query('metadata',values,args,"$and") - print args + print(args) # Show the user PAGE_SIZE number of sensors on each page page = request.args.get('page', 1, type=int) skip_size = (page - 1) * PAGE_SIZE diff --git a/buildingdepot/CentralService/app/oauth_bd/views.py b/buildingdepot/CentralService/app/oauth_bd/views.py index 9ac37db8..e01c8ee4 100755 --- a/buildingdepot/CentralService/app/oauth_bd/views.py +++ b/buildingdepot/CentralService/app/oauth_bd/views.py @@ -219,10 +219,10 @@ def get_access_token(client_id, client_secret): @oauth_bd.route('/generate', methods=['POST']) def generate_credentials(): cred = request.get_json()['data'] - print cred['email'], type(cred) + print(cred['email'], type(cred)) email = cred['email'] password = cred['password'] - print email, password + print(email, password) user = User.objects(email=email).first() if user is not None and user.first_login and user.verify_password(password): response = dict(responses.success_true) diff --git a/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate_tagtypes.py b/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate_tagtypes.py index 6956ca47..fa90db8a 100644 --- a/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate_tagtypes.py +++ b/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate_tagtypes.py @@ -65,6 +65,6 @@ def put(self, name): return jsonify(responses.invalid_template) data = request.get_json()['data'] tagtype_exists = lambda tagtype: TagType.objects(name=tagtype).first() - valid_tagtypes = filter(tagtype_exists, data['tagtypes']) + valid_tagtypes = list(filter(tagtype_exists, data['tagtypes'])) return jsonify({'success': 'True', 'invalid_tagtypes': list(set(data['tagtypes']) - set(valid_tagtypes))}) if buildingtemplate.update(set__tag_types=valid_tagtypes)\ else jsonify({'success': 'False'}) \ No newline at end of file diff --git a/buildingdepot/CentralService/app/rest_api/dataservices/dataservice.py b/buildingdepot/CentralService/app/rest_api/dataservices/dataservice.py index 5a601464..d42267f5 100755 --- a/buildingdepot/CentralService/app/rest_api/dataservices/dataservice.py +++ b/buildingdepot/CentralService/app/rest_api/dataservices/dataservice.py @@ -50,7 +50,7 @@ def post(self): @check_oauth def get(self, name): - print "Name :", name + print("Name :", name) if name == "list": all_dataservices=[] collection = DataService.objects diff --git a/buildingdepot/CentralService/app/rest_api/helper.py b/buildingdepot/CentralService/app/rest_api/helper.py index e6b0e654..f69a947a 100755 --- a/buildingdepot/CentralService/app/rest_api/helper.py +++ b/buildingdepot/CentralService/app/rest_api/helper.py @@ -55,7 +55,7 @@ def gen_update(params, data): in the params list """ result = {} - for key, value in data.iteritems(): + for key, value in data.items(): if key in params: result[key] = value return result @@ -71,7 +71,7 @@ def send_local_smtp(user_name, to_email, password): smtpObj = smtplib.SMTP('localhost') smtpObj.sendmail(sender, receivers, message) except smtplib.SMTPException: - print "Failed to send registration mail to %s" % (to_email) + print("Failed to send registration mail to %s" % (to_email)) def GenerateOAuth2String(username, access_token, base64_encode=True): @@ -103,17 +103,17 @@ def get_access_token(): access_token = r.json()['access_token'] return access_token except Exception as e: - print "Failed to obtain access token " + str(e) + print("Failed to obtain access token " + str(e)) def send_mail_gmail(user_name, to_email, password): - print "getting access_token" + print("getting access_token") access_token = get_access_token() if access_token is None: return sender = current_app.config['EMAIL_ID'] - print access_token - print sender + print(access_token) + print(sender) try: smtp_conn = smtplib.SMTP('smtp.gmail.com', 587) smtp_conn.ehlo('test') @@ -123,7 +123,7 @@ def send_mail_gmail(user_name, to_email, password): msg = responses.registration_email % (sender, user_name, to_email, to_email, password, '/'.join(request.base_url.split('/')[:3])) smtp_conn.sendmail(sender, to_email, msg) except Exception as e: - print "Failed to send registration email to " + to_email + " " + str(e) + print("Failed to send registration email to " + to_email + " " + str(e)) def get_email(): @@ -160,11 +160,11 @@ def get_building_choices(call_type=None): buildings_list = [] for dataservice in dataservices: for building in dataservice.buildings: - print building + print(building) if building not in buildings_list: buildings_list.append(building) if not call_type: - return zip(buildings_list, buildings_list) + return list(zip(buildings_list, buildings_list)) else: return buildings_list diff --git a/buildingdepot/CentralService/app/rest_api/sensorgroups/sg_tags.py b/buildingdepot/CentralService/app/rest_api/sensorgroups/sg_tags.py index eab88ff6..34032e11 100755 --- a/buildingdepot/CentralService/app/rest_api/sensorgroups/sg_tags.py +++ b/buildingdepot/CentralService/app/rest_api/sensorgroups/sg_tags.py @@ -99,14 +99,14 @@ def post(self,name): def check_tags(self,tags,building): building_tags = get_building_tags(building) - print building_tags - print tags + print(building_tags) + print(tags) for tag in tags: tagtype = building_tags.get(tag.get('name')) - print tagtype + print(tagtype) if tagtype is None: return jsonify(responses.invalid_tagtype) - print tag.get('value') + print(tag.get('value')) tag_values = tagtype.get('values') if tag.get('value') not in tag_values: return jsonify(responses.invalid_tag_value) diff --git a/buildingdepot/CentralService/app/rest_api/sensors/search.py b/buildingdepot/CentralService/app/rest_api/sensors/search.py index e83af42d..e4ee53ce 100755 --- a/buildingdepot/CentralService/app/rest_api/sensors/search.py +++ b/buildingdepot/CentralService/app/rest_api/sensors/search.py @@ -27,7 +27,7 @@ def post(self): return jsonify(responses.missing_data) args = {} - for key, values in data.iteritems(): + for key, values in data.items(): if key == 'Building': form_query('building', values, args, "$or") elif key == 'SourceName': diff --git a/buildingdepot/CentralService/app/rest_api/sensors/sensor.py b/buildingdepot/CentralService/app/rest_api/sensors/sensor.py index 09aee9d8..adba3ace 100755 --- a/buildingdepot/CentralService/app/rest_api/sensors/sensor.py +++ b/buildingdepot/CentralService/app/rest_api/sensors/sensor.py @@ -48,7 +48,7 @@ def get(self, name): return jsonify(responses.invalid_uuid) tags_owned = [{'name': tag.name, 'value': tag.value} for tag in sensor.tags] metadata = Sensor._get_collection().find({'name': name}, {'metadata': 1, '_id': 0})[0]['metadata'] - metadata = [{'name': key, 'value': val} for key, val in metadata.iteritems()] + metadata = [{'name': key, 'value': val} for key, val in metadata.items()] response = dict(responses.success_true) response.update({'building': str(sensor.building), 'name': str(sensor.name), diff --git a/buildingdepot/CentralService/app/rest_api/views.py b/buildingdepot/CentralService/app/rest_api/views.py index 8d5939cf..9281bde4 100755 --- a/buildingdepot/CentralService/app/rest_api/views.py +++ b/buildingdepot/CentralService/app/rest_api/views.py @@ -17,7 +17,7 @@ @api.route('/buildingtemplate//edit', methods=['POST']) def buildingtemplate_tag_edit(name): - data = map(str,request.get_json()['data']) + data = list(map(str,request.get_json()['data'])) buildingtemplate = BuildingTemplate.objects(name=name).first() if buildingtemplate.update(set__tag_types=data): return jsonify({'success': 'True'}) diff --git a/buildingdepot/CentralService/app/rpc/defs.py b/buildingdepot/CentralService/app/rpc/defs.py index ed3854f9..c37ee4c4 100755 --- a/buildingdepot/CentralService/app/rpc/defs.py +++ b/buildingdepot/CentralService/app/rpc/defs.py @@ -68,10 +68,10 @@ def delete_permission(user_group, sensor_group): def invalidate_permission(sensor_group): svr = get_remote(get_sg_ds(sensor_group)) try: - print "Invalidating permission" + print("Invalidating permission") svr.invalidate_permission(sensor_group) except Exception as e: - print e + print(e) return False return True diff --git a/buildingdepot/DataService/app/api_0_0/resources/subscription.py b/buildingdepot/DataService/app/api_0_0/resources/subscription.py index b03addb7..945dd2ee 100755 --- a/buildingdepot/DataService/app/api_0_0/resources/subscription.py +++ b/buildingdepot/DataService/app/api_0_0/resources/subscription.py @@ -7,7 +7,7 @@ def subscribed_sensors_validator(sensors): - if isinstance(sensors, (unicode, str)): + if isinstance(sensors, str): sensors = [sensors] if not isinstance(sensors, list): raise ValueError('Sensors field must be string or list') diff --git a/buildingdepot/DataService/app/api_0_0/resources/utils.py b/buildingdepot/DataService/app/api_0_0/resources/utils.py index 2d44dbb0..a61870e1 100755 --- a/buildingdepot/DataService/app/api_0_0/resources/utils.py +++ b/buildingdepot/DataService/app/api_0_0/resources/utils.py @@ -99,7 +99,7 @@ def permission(sensor_name, email=None): r.hset(sensor_name, email, 'r/w/p') return 'r/w/p' - print "Not owner or admin" + print("Not owner or admin") current_res = 'u/d' usergroups = r.smembers('user:{}'.format(email)) @@ -113,7 +113,7 @@ def permission(sensor_name, email=None): # This one chooses the most restrictive one by counting the number of tags res = r.hget('permission:{}:{}'.format(usergroup, sensorgroup), "permission") owner_email = r.hget('permission:{}:{}'.format(usergroup, sensorgroup), "owner") - print res + print(res) if res is not None and permission(sensor_name, owner_email) == 'r/w/p': if permissions_val[res] > permissions_val[current_res]: current_res = res @@ -153,8 +153,8 @@ def batch_permission_check(sensors_list, email=None): # check if the owner:sensor key is present => sensor exists redis_sensor_keys = [''.join(['owner:', sensor]) for sensor in sensors_list] - owners = dict(zip(redis_sensor_keys, r.mget(*redis_sensor_keys))) - for k, v in owners.items(): + owners = dict(list(zip(redis_sensor_keys, r.mget(*redis_sensor_keys)))) + for k, v in list(owners.items()): if not v: sensors_missing_from_cache.append(k[6:]) @@ -169,7 +169,7 @@ def batch_permission_check(sensors_list, email=None): owners[''.join(['owner:', sensor.name])] = sensor.owner # Invalid sensors - for k, v in owners.items(): + for k, v in list(owners.items()): if not v: del owners[k] permissions[k[6:]] = 'absent' @@ -177,7 +177,7 @@ def batch_permission_check(sensors_list, email=None): # If the user is sensor owner or admin, give complete access and add to cache p = r.pipeline() - for k, v in owners.items(): + for k, v in list(owners.items()): if check_if_super(email) or email == v: permissions[k[6:]] = 'r/w/p' r.hset(k[6:], email, 'r/w/p') @@ -251,7 +251,7 @@ def authorize_user(user_group, sensorgroup_name, email=None): args['tags__all'] = tag_list sensors = Sensor.objects(**args) for sensor in sensors: - print sensor['name'] + print(sensor['name']) if permission(sensor['name'], email) != 'r/w/p': return False return True @@ -263,7 +263,7 @@ def authorize_addition(usergroup_name, email): return True for user in user_group.users: - print type(user['manager']) + print(type(user['manager'])) if user['user_id'] == email and user['manager']: return True return False diff --git a/buildingdepot/DataService/app/api_0_0/resources/write.py b/buildingdepot/DataService/app/api_0_0/resources/write.py index 13961b5a..e2c50f02 100755 --- a/buildingdepot/DataService/app/api_0_0/resources/write.py +++ b/buildingdepot/DataService/app/api_0_0/resources/write.py @@ -42,7 +42,7 @@ def post(self, sensor_name): parser.add_argument('timeseries', type=timeseries_validator, required=True, location='json') args = parser.parse_args() - points = [[int(pair.keys()[0]), pair.values()[0]] for pair in args['timeseries']] + points = [[int(list(pair.keys())[0]), list(pair.values())[0]] for pair in args['timeseries']] max_point = max(points) # sub_s = time() @@ -59,15 +59,15 @@ def post(self, sensor_name): 'columns': ['time', 'value'], 'points': points }] - print 'I am here' - print data + print('I am here') + print(data) # series_s = time() try: influx.write_points(data) except Exception as e: - print 'wrong ', e + print('wrong ', e) # series_e = time() - print 'I am ther' + print('I am ther') # all_e = time() # print 'permission: ', permission_e - permission_s # print 'sub: ', sub_e - sub_s diff --git a/buildingdepot/DataService/app/rest_api/app_subscription.py b/buildingdepot/DataService/app/rest_api/app_subscription.py index 3376c75f..bbd132d9 100755 --- a/buildingdepot/DataService/app/rest_api/app_subscription.py +++ b/buildingdepot/DataService/app/rest_api/app_subscription.py @@ -48,8 +48,8 @@ def dispatch_request(self): channel.queue_unbind(exchange=exchange, queue=app['value'], routing_key=sensor) r.srem(''.join(['apps:', sensor]), app['value']) except Exception as e: - print "Failed to bind queue " + str(e) - print traceback.print_exc() + print("Failed to bind queue " + str(e)) + print(traceback.print_exc()) return jsonify({'success': 'False', 'error': 'Failed to bind queue'}) if pubsub: @@ -57,7 +57,7 @@ def dispatch_request(self): channel.close() pubsub.close() except Exception as e: - print "Failed to end RabbitMQ session" + str(e) + print("Failed to end RabbitMQ session" + str(e)) return jsonify({'success': 'True'}) diff --git a/buildingdepot/DataService/app/rest_api/apps.py b/buildingdepot/DataService/app/rest_api/apps.py index 1b15a259..32a8d2e8 100755 --- a/buildingdepot/DataService/app/rest_api/apps.py +++ b/buildingdepot/DataService/app/rest_api/apps.py @@ -78,8 +78,8 @@ def post(self): channel = pubsub.channel() result = channel.queue_declare(durable=True) except Exception as e: - print "Failed to create queue " + str(e) - print traceback.print_exc() + print("Failed to create queue " + str(e)) + print(traceback.print_exc()) if channel: channel.close() return jsonify(responses.queue_creation_failure) @@ -97,7 +97,7 @@ def post(self): channel.close() pubsub.close() except Exception as e: - print "Failed to end RabbitMQ session" + str(e) + print("Failed to end RabbitMQ session" + str(e)) return jsonify({'success': 'True', 'app_id': result.method.queue}) @@ -122,9 +122,9 @@ def delete(self): name = '' json_data = request.get_json() - if 'data' not in json_data.keys(): + if 'data' not in list(json_data.keys()): return jsonify(responses.missing_parameters) - elif 'name' not in json_data['data'].keys(): + elif 'name' not in list(json_data['data'].keys()): return jsonify(responses.missing_parameters) else: name = json_data['data']['name'] @@ -134,7 +134,7 @@ def delete(self): # check whether there is an application with the given name # case 1 - there is already an application instance for the given user if apps.count() > 0: - app_filter = filter(lambda x: x['name'] == name, apps[0]['apps']) + app_filter = [x for x in apps[0]['apps'] if x['name'] == name] if len(app_filter) > 0: app_to_be_deleted = app_filter[0] @@ -150,16 +150,15 @@ def delete(self): try: channel = pubsub.channel() - if 'value' in app_to_be_deleted.keys(): + if 'value' in list(app_to_be_deleted.keys()): result = channel.queue_delete(queue=app_to_be_deleted['value']) - new_app_list = list(filter(lambda x: x['name'] != name, - apps[0]['apps'])) + new_app_list = list([x for x in apps[0]['apps'] if x['name'] != name]) Application.objects(user=email).update(set__apps=new_app_list) except Exception as e: - print "Failed to delete queue " + str(e) - print traceback.print_exc() + print("Failed to delete queue " + str(e)) + print(traceback.print_exc()) if channel: channel.close() @@ -170,6 +169,6 @@ def delete(self): channel.close() pubsub.close() except Exception as e: - print "Failed to end RabbitMQ session" + str(e) + print("Failed to end RabbitMQ session" + str(e)) return jsonify(responses.success_true) diff --git a/buildingdepot/DataService/app/rest_api/helper.py b/buildingdepot/DataService/app/rest_api/helper.py index 2d08ff52..74acd21a 100755 --- a/buildingdepot/DataService/app/rest_api/helper.py +++ b/buildingdepot/DataService/app/rest_api/helper.py @@ -134,7 +134,7 @@ def connect_broker(): channel.close() return pubsub except Exception as e: - print "Failed to open connection to broker " + str(e) + print("Failed to open connection to broker " + str(e)) return None diff --git a/buildingdepot/DataService/app/rest_api/timeseries.py b/buildingdepot/DataService/app/rest_api/timeseries.py index 9f926fc8..cea2000a 100755 --- a/buildingdepot/DataService/app/rest_api/timeseries.py +++ b/buildingdepot/DataService/app/rest_api/timeseries.py @@ -153,14 +153,14 @@ def post(self): pipeline = r.pipeline() for sensor in sensors_list: pipeline.exists(''.join(['apps:', sensor])) - apps = dict(zip(sensors_list, pipeline.execute())) + apps = dict(list(zip(sensors_list, pipeline.execute()))) for sensor in json: # check a user has permission unauthorised_sensor = [] # If 'w' (write is in the permission), authorize if 'w' in permissions[sensor['sensor_id']]: for sample in sensor['samples']: - for key in sample.keys(): + for key in list(sample.keys()): if type(sample[key]) is list: length = len(sample[key]) for i in range(length): @@ -184,7 +184,7 @@ def post(self): if view_fields: fields = [field.strip() for field in view_fields.split(',')] view_dic = dict(dic) - view_fields = {k: v for k, v in dic['fields'].items() if k in fields } + view_fields = {k: v for k, v in list(dic['fields'].items()) if k in fields } view_dic.update({'fields': view_fields}) if apps[view]: if not pubsub: @@ -194,15 +194,15 @@ def post(self): try: channel = pubsub.channel() except Exception as e: - print "Failed to open channel" + " error" + str(e) + print("Failed to open channel" + " error" + str(e)) try: # print ('\n\n' + '{s:{c}^{n}}'.format(s=' view_dic ', n=100, c='#')) # print (view_dic) # print ('#' * 100 + '\n\n') channel.basic_publish(exchange=exchange, routing_key=view, body=str(view_dic)) except Exception as e: - print "except inside" - print "Failed to write to broker " + str(e) + print("except inside") + print("Failed to write to broker " + str(e)) if apps[sensor['sensor_id']]: if not pubsub: @@ -212,19 +212,19 @@ def post(self): try: channel = pubsub.channel() except Exception as e: - print "Failed to open channel" + " error" + str(e) + print("Failed to open channel" + " error" + str(e)) try: # print ('\n\n' + '{s:{c}^{n}}'.format(s=' dic ', n=100, c='#')) # print (dic) # print ('#' * 100 + '\n\n') channel.basic_publish(exchange=exchange, routing_key=sensor['sensor_id'], body=str(dic)) except Exception as e: - print "except inside" - print "Failed to write to broker " + str(e) + print("except inside") + print("Failed to write to broker " + str(e)) else: unauthorised_sensor.append(sensor['sensor_id']) except KeyError: - print json + print(json) abort(400) # # Log InfluxDB Query # # @@ -249,6 +249,6 @@ def post(self): channel.close() pubsub.close() except Exception as e: - print "Failed to end RabbitMQ session" + str(e) + print("Failed to end RabbitMQ session" + str(e)) return jsonify(response) diff --git a/buildingdepot/DataService/app/rest_api/views.py b/buildingdepot/DataService/app/rest_api/views.py index e17115db..912dc7c5 100755 --- a/buildingdepot/DataService/app/rest_api/views.py +++ b/buildingdepot/DataService/app/rest_api/views.py @@ -20,10 +20,10 @@ from uuid import uuid4 from .. import r, influx, oauth, exchange, permissions from werkzeug.security import gen_salt -import sys, time, influxdb, urllib, traceback, pika +import sys, time, influxdb, urllib.request, urllib.parse, urllib.error, traceback, pika sys.path.append('/srv/buildingdepot') -from utils import get_user_oauth +from .utils import get_user_oauth from ..api_0_0.resources.utils import * from ..api_0_0.resources.acl_cache import invalidate_user, invalidate_permission from .helper import check_oauth @@ -72,11 +72,11 @@ def get_sensors_metadata(): if (request_type is None) or (len(request.args) < 2): return jsonify(responses.missing_paramters) - for key, val in request.args.iteritems(): + for key, val in request.args.items(): if key != 'filter': - param = urllib.unquote(key).decode('utf8') - value = urllib.unquote(val).decode('utf8') - print param, value + param = urllib.parse.unquote(key).decode('utf8') + value = urllib.parse.unquote(val).decode('utf8') + print(param, value) if request_type == "params": list_sensors = Sensor._get_collection().find({param: value}) diff --git a/buildingdepot/DataService/app/service/utils.py b/buildingdepot/DataService/app/service/utils.py index 4bce2fd9..2a19c70b 100755 --- a/buildingdepot/DataService/app/service/utils.py +++ b/buildingdepot/DataService/app/service/utils.py @@ -29,5 +29,5 @@ def validate_email_password(email, password): def get_admins(): - print svr.get_admins(current_app.config['NAME']) + print(svr.get_admins(current_app.config['NAME'])) return svr.get_admins(current_app.config['NAME']) diff --git a/buildingdepot/DataService/app/service/views.py b/buildingdepot/DataService/app/service/views.py index b9dfddca..535c0c74 100755 --- a/buildingdepot/DataService/app/service/views.py +++ b/buildingdepot/DataService/app/service/views.py @@ -51,9 +51,9 @@ def sensor(): @service.route('/sensor/search', methods=['GET', 'POST']) def sensors_search(): data = json.loads(request.args.get('q')) - print data, type(data) + print(data, type(data)) args = {} - for key, values in data.iteritems(): + for key, values in data.items(): if key == 'Building': form_query('building', values, args, "$or") elif key == 'SourceName': @@ -66,7 +66,7 @@ def sensors_search(): form_query('tags', values, args, "$and") elif key == 'MetaData': form_query('metadata', values, args, "$and") - print args + print(args) # Show the user PAGE_SIZE number of sensors on each page page = request.args.get('page', 1, type=int) skip_size = (page - 1) * PAGE_SIZE @@ -105,7 +105,7 @@ def graph(name): temp = obj break metadata = Sensor._get_collection().find({'name': name}, {'metadata': 1, '_id': 0})[0]['metadata'] - metadata = [{'name': key, 'value': val} for key, val in metadata.iteritems()] + metadata = [{'name': key, 'value': val} for key, val in metadata.items()] obj = Sensor.objects(name=name).first() tags_owned = [{'name': tag.name, 'value': tag.value} for tag in obj.tags] return render_template('service/graph.html', name=name, obj=temp, metadata=metadata, tags=tags_owned) diff --git a/buildingdepot/Documentation/source/source/conf.py b/buildingdepot/Documentation/source/source/conf.py index fb193900..766b1226 100644 --- a/buildingdepot/Documentation/source/source/conf.py +++ b/buildingdepot/Documentation/source/source/conf.py @@ -19,14 +19,14 @@ # -- Project information ----------------------------------------------------- -project = u"BuildingDepot v3.2.9" -copyright = u"2020, Shreyas Nagare" -author = u"Shreyas Nagare" +project = "BuildingDepot v3.3.0" +copyright = "2020, SynergyLabs@CMU" +author = "Shreyas Nagare" # The short X.Y version -version = u"" +version = "" # The full version, including alpha/beta/rc tags -release = u"" +release = "" # -- General configuration --------------------------------------------------- @@ -127,8 +127,8 @@ ( master_doc, "BuildingDepotv329.tex", - u"BuildingDepot v3.2.9 Documentation", - u"Shreyas Nagare", + "BuildingDepot v3.2.9 Documentation", + "Shreyas Nagare", "manual", ), ] @@ -142,7 +142,7 @@ ( master_doc, "buildingdepotv329", - u"BuildingDepot v3.2.9 Documentation", + "BuildingDepot v3.2.9 Documentation", [author], 1, ) @@ -158,7 +158,7 @@ ( master_doc, "BuildingDepotv329", - u"BuildingDepot v3.2.9 Documentation", + "BuildingDepot v3.2.9 Documentation", author, "BuildingDepotv329", "One line description of project.", diff --git a/buildingdepot/Instrumentation/comment.py b/buildingdepot/Instrumentation/comment.py index 70a5640d..27842a45 100644 --- a/buildingdepot/Instrumentation/comment.py +++ b/buildingdepot/Instrumentation/comment.py @@ -11,6 +11,6 @@ for line in f: if line == '@instrument\n': - print "# " + line, + print("# " + line, end=' ') else: - print line, \ No newline at end of file + print(line, end=' ') \ No newline at end of file diff --git a/buildingdepot/Instrumentation/instrument.py b/buildingdepot/Instrumentation/instrument.py index e942d88c..ae4292cc 100644 --- a/buildingdepot/Instrumentation/instrument.py +++ b/buildingdepot/Instrumentation/instrument.py @@ -14,7 +14,7 @@ 185618305,1,write_timeseries_data,41105.2598953,41124.270916,19.0110206604 """ -import thread +import _thread import time from functools import wraps import traceback diff --git a/buildingdepot/Instrumentation/logSummarizer.py b/buildingdepot/Instrumentation/logSummarizer.py index 0e549e32..3544b246 100644 --- a/buildingdepot/Instrumentation/logSummarizer.py +++ b/buildingdepot/Instrumentation/logSummarizer.py @@ -22,17 +22,17 @@ reader = csv.reader(f) logs = list(reader) for log in logs: - if log[2] in averages.keys(): + if log[2] in list(averages.keys()): averages[log[2]][0] += float(log[5]) averages[log[2]][1] += 1 else: averages[log[2]] = [float(log[5]), 1] -print "\nAVERAGES FOR TIME TAKEN (Function wise): " -for key, value in averages.iteritems(): - print " " + key + "(): " + str(value[0]/value[1]) + "ms (" + str(value[1]) + " calls)" +print("\nAVERAGES FOR TIME TAKEN (Function wise): ") +for key, value in averages.items(): + print(" " + key + "(): " + str(value[0]/value[1]) + "ms (" + str(value[1]) + " calls)") -print +print() diff --git a/buildingdepot/Instrumentation/uncomment.py b/buildingdepot/Instrumentation/uncomment.py index 3f882005..349d0e89 100644 --- a/buildingdepot/Instrumentation/uncomment.py +++ b/buildingdepot/Instrumentation/uncomment.py @@ -11,6 +11,6 @@ for line in f: if line == '# @instrument\n': - print "@instrument\n", + print("@instrument\n", end=' ') else: - print line, \ No newline at end of file + print(line, end=' ') \ No newline at end of file diff --git a/setup_bd.py b/setup_bd.py index 83e4bb14..160b0c53 100644 --- a/setup_bd.py +++ b/setup_bd.py @@ -1,11 +1,11 @@ #!/srv/buildingdepot/venv/bin/python2.7 import json,sys -import StringIO,os,ConfigParser +import io,os,configparser import string,random from pymongo import MongoClient from werkzeug.security import generate_password_hash -print "Setting up BuildingDepot.. " +print("Setting up BuildingDepot.. ") option = sys.argv[1:][0] #get arguments @@ -14,11 +14,11 @@ # Get Username and Password for MongoDB if (option == "install"): - configBuffer = StringIO.StringIO() + configBuffer = io.StringIO() configBuffer.write('[dummysection]\n') configBuffer.write(open('/srv/buildingdepot/CentralService/cs_config').read()) configBuffer.seek(0, os.SEEK_SET) - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.readfp(configBuffer) user=config.get('dummysection','MONGODB_USERNAME').strip("'").strip('"') pwd = config.get('dummysection','MONGODB_PWD').strip("'").strip('"') @@ -29,11 +29,11 @@ pwd = configs['mongo_pwd'] elif(option == "test"): - configBuffer = StringIO.StringIO() + configBuffer = io.StringIO() configBuffer.write('[dummysection]\n') configBuffer.write(open('/srv/buildingdepot/CentralService/cs_config').read()) configBuffer.seek(0, os.SEEK_SET) - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.readfp(configBuffer) user=config.get('dummysection','MONGODB_USERNAME').strip("'").strip('"') pwd = config.get('dummysection','MONGODB_PWD').strip("'").strip('"') @@ -63,5 +63,5 @@ 'buildings':[], 'admins':[]}) -print "\n Created a super user with following credentials. Please login and change password immediately \n user id "\ - ": admin@buildingdepot.org \n password: " + tempPwd +print("\n Created a super user with following credentials. Please login and change password immediately \n user id "\ + ": admin@buildingdepot.org \n password: " + tempPwd) diff --git a/testing/BD-Performance-Test/results/parse.py b/testing/BD-Performance-Test/results/parse.py index 9efb2d97..96c58a57 100644 --- a/testing/BD-Performance-Test/results/parse.py +++ b/testing/BD-Performance-Test/results/parse.py @@ -1,4 +1,4 @@ -from __future__ import print_function + from os import listdir import json for f in listdir('.'): From 87b28bf32ae1c169538e3f0fcdb65a47aad4f7b5 Mon Sep 17 00:00:00 2001 From: Shreyas Nagare Date: Tue, 2 Jun 2020 15:36:44 -0400 Subject: [PATCH 02/70] Fix flask app imports --- buildingdepot/CentralService/__init__.py | 6 +++--- buildingdepot/CentralService/main.py | 6 +++--- buildingdepot/DataService/__init__.py | 4 ++-- buildingdepot/DataService/main.py | 4 ++-- buildingdepot/DataService/wsgi.py | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/buildingdepot/CentralService/__init__.py b/buildingdepot/CentralService/__init__.py index d5b89104..dc290ef1 100755 --- a/buildingdepot/CentralService/__init__.py +++ b/buildingdepot/CentralService/__init__.py @@ -11,10 +11,10 @@ """ import os -from app import create_app -from app.models.cs_models import User +from .app import create_app +from .app.models.cs_models import User from flask_script import Manager, Shell -from app.rest_api.register import register_view +from .app.rest_api.register import register_view app = create_app(os.getenv('FLASK_CONFIG') or 'dev') manager = Manager(app) diff --git a/buildingdepot/CentralService/main.py b/buildingdepot/CentralService/main.py index 94650585..f5d9bf1f 100755 --- a/buildingdepot/CentralService/main.py +++ b/buildingdepot/CentralService/main.py @@ -13,10 +13,10 @@ # This is for BD docker container only import os -from app import create_app -from app.models.cs_models import User +from .app import create_app +from .app.models.cs_models import User from flask_script import Manager, Shell, Server -from app.rest_api.register import register_view +from .app.rest_api.register import register_view app = create_app('deploy') manager = Manager(app) diff --git a/buildingdepot/DataService/__init__.py b/buildingdepot/DataService/__init__.py index 2f4617eb..a1601366 100755 --- a/buildingdepot/DataService/__init__.py +++ b/buildingdepot/DataService/__init__.py @@ -11,9 +11,9 @@ """ import os -from app import create_app +from .app import create_app from flask_script import Manager, Shell -from app.rest_api.register import register_view +from .app.rest_api.register import register_view app = create_app(os.getenv('FLASK_CONFIG') or 'dev') manager = Manager(app) diff --git a/buildingdepot/DataService/main.py b/buildingdepot/DataService/main.py index 5bd64e87..6cfdfe36 100755 --- a/buildingdepot/DataService/main.py +++ b/buildingdepot/DataService/main.py @@ -13,9 +13,9 @@ # This is for BD docker container only import os -from app import create_app +from .app import create_app from flask_script import Manager, Shell, Server -from app.rest_api.register import register_view +from .app.rest_api.register import register_view app = create_app(os.getenv('FLASK_CONFIG') or 'dev') manager = Manager(app) diff --git a/buildingdepot/DataService/wsgi.py b/buildingdepot/DataService/wsgi.py index b36c50a2..875fc132 100644 --- a/buildingdepot/DataService/wsgi.py +++ b/buildingdepot/DataService/wsgi.py @@ -13,9 +13,9 @@ # This is for BD docker container only import os -from app import create_app +from .app import create_app from flask_script import Manager, Shell, Server -from app.rest_api.register import register_view +from .app.rest_api.register import register_view app = create_app(os.getenv('FLASK_CONFIG') or 'dev') manager = Manager(app) From c76888900bdb2544404f85ee33a9dfa611287c74 Mon Sep 17 00:00:00 2001 From: Shreyas Nagare Date: Tue, 2 Jun 2020 15:37:14 -0400 Subject: [PATCH 03/70] Fix xmlrpc imports --- buildingdepot/CentralReplica/main.py | 6 +++--- buildingdepot/CentralService/app/__init__.py | 2 +- buildingdepot/CentralService/app/oauth_bd/views.py | 2 +- buildingdepot/CentralService/app/rpc/defs.py | 2 +- buildingdepot/DataService/app/__init__.py | 2 +- buildingdepot/DataService/app/oauth_bd/views.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/buildingdepot/CentralReplica/main.py b/buildingdepot/CentralReplica/main.py index bac13a25..50c4f636 100755 --- a/buildingdepot/CentralReplica/main.py +++ b/buildingdepot/CentralReplica/main.py @@ -10,9 +10,9 @@ """ import redis -from SimpleXMLRPCServer import SimpleXMLRPCServer -from SocketServer import ThreadingMixIn -from models import * +from xmlrpc.server import SimpleXMLRPCServer +from socketserver import ThreadingMixIn +from .models import * from mongoengine import connect from .config import Config diff --git a/buildingdepot/CentralService/app/__init__.py b/buildingdepot/CentralService/app/__init__.py index 87021b5a..a2b09dd3 100755 --- a/buildingdepot/CentralService/app/__init__.py +++ b/buildingdepot/CentralService/app/__init__.py @@ -20,7 +20,7 @@ from flask_login import LoginManager from flask_bootstrap import Bootstrap from flask_oauthlib.provider import OAuth2Provider -from xmlrpclib import ServerProxy +from xmlrpc.client import ServerProxy import redis diff --git a/buildingdepot/CentralService/app/oauth_bd/views.py b/buildingdepot/CentralService/app/oauth_bd/views.py index e01c8ee4..5f830e7c 100755 --- a/buildingdepot/CentralService/app/oauth_bd/views.py +++ b/buildingdepot/CentralService/app/oauth_bd/views.py @@ -18,7 +18,7 @@ from flask_oauthlib.client import OAuth from werkzeug.security import gen_salt from bson.objectid import ObjectId -from xmlrpclib import ServerProxy +from xmlrpc.client import ServerProxy from ..rest_api import responses import sys, os, binascii diff --git a/buildingdepot/CentralService/app/rpc/defs.py b/buildingdepot/CentralService/app/rpc/defs.py index c37ee4c4..a8a02ebc 100755 --- a/buildingdepot/CentralService/app/rpc/defs.py +++ b/buildingdepot/CentralService/app/rpc/defs.py @@ -1,7 +1,7 @@ from .. import svr from ..rest_api.helper import get_ds, get_sg_ds from ..models.cs_models import DataService -from xmlrpclib import ServerProxy +from xmlrpc.client import ServerProxy def create_sensor(sensor_id, email, building, fields = None, parent = None): diff --git a/buildingdepot/DataService/app/__init__.py b/buildingdepot/DataService/app/__init__.py index e011dbc9..1b2ae621 100755 --- a/buildingdepot/DataService/app/__init__.py +++ b/buildingdepot/DataService/app/__init__.py @@ -21,7 +21,7 @@ from flask import Flask from mongoengine import connect, register_connection from flask_bootstrap import Bootstrap -from xmlrpclib import ServerProxy +from xmlrpc.client import ServerProxy from flask_oauthlib.provider import OAuth2Provider import redis diff --git a/buildingdepot/DataService/app/oauth_bd/views.py b/buildingdepot/DataService/app/oauth_bd/views.py index 1034c43c..f3e99b23 100755 --- a/buildingdepot/DataService/app/oauth_bd/views.py +++ b/buildingdepot/DataService/app/oauth_bd/views.py @@ -19,7 +19,7 @@ from flask_oauthlib.client import OAuth from werkzeug.security import gen_salt from bson.objectid import ObjectId -from xmlrpclib import ServerProxy +from xmlrpc.client import ServerProxy import sys, os, binascii from mongoengine import * From 0868fee87990645f1e45034f3487a6625b20ed4c Mon Sep 17 00:00:00 2001 From: Shreyas Nagare Date: Tue, 2 Jun 2020 15:43:58 -0400 Subject: [PATCH 04/70] More flask app import fixes --- buildingdepot/CentralService/app/api_0_0/resources/utils.py | 2 +- buildingdepot/CentralService/app/central/views.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildingdepot/CentralService/app/api_0_0/resources/utils.py b/buildingdepot/CentralService/app/api_0_0/resources/utils.py index cbb4b8be..40f4bb6c 100755 --- a/buildingdepot/CentralService/app/api_0_0/resources/utils.py +++ b/buildingdepot/CentralService/app/api_0_0/resources/utils.py @@ -1,7 +1,7 @@ from functools import wraps from flask import g, jsonify -from app.common import PAGE_SIZE +from ..common import PAGE_SIZE from ..errors import not_allowed from ...rest_api.helper import get_email from ...rest_api import responses diff --git a/buildingdepot/CentralService/app/central/views.py b/buildingdepot/CentralService/app/central/views.py index 9f8b5808..a2bb0e71 100755 --- a/buildingdepot/CentralService/app/central/views.py +++ b/buildingdepot/CentralService/app/central/views.py @@ -14,7 +14,7 @@ """ import json,requests,math -from app.common import PAGE_SIZE +from ..common import PAGE_SIZE from uuid import uuid4 from flask import render_template, request, redirect, url_for, jsonify, session, flash from flask_login import login_required From 4c7206c31db07e2a5832bc38e78cf4017e3baf6e Mon Sep 17 00:00:00 2001 From: Shreyas Nagare Date: Tue, 2 Jun 2020 15:44:32 -0400 Subject: [PATCH 05/70] Fix jinja2 templates --- buildingdepot/CentralService/app/templates/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildingdepot/CentralService/app/templates/index.html b/buildingdepot/CentralService/app/templates/index.html index 395846ee..3426c9ca 100755 --- a/buildingdepot/CentralService/app/templates/index.html +++ b/buildingdepot/CentralService/app/templates/index.html @@ -40,7 +40,7 @@
BuildingDepot
- {% if current_user.is_authenticated() %} + {% if current_user.is_authenticated %} {% endif %} + + + +
-
- - + +
+
+
+ - -
-
-
-
- -
-

Buildings

-

All the buildings that are present within the deployment of BuildingDepot are defined here. When adding a new building a BuildingTemplate has to be selected which defines the structure of this building. The tags that are available to be assigned to this building are dependent on the BuildingTemplate. Tags can be selected and the values for each of them can be specified here. Each tag can have multiple values specified for it. Building can be defined in the CentralService at http://www.example.com:81/api/building.

-
-

Create a new Building

-

This request creates a new Building with name, description and building template to be used in the building specified by the user.

-
-

Example request:

-
POST /api/building HTTP/1.1
+
+                    
+
+
+
+ +
+

Buildings

+

All the buildings that are present within the deployment of BuildingDepot are defined + here. When adding a new building a BuildingTemplate has to be selected which defines the + structure of this building. The tags that are available to be assigned to this building + are dependent on the BuildingTemplate. Tags can be selected and the values for each of + them can be specified here. Each tag can have multiple values specified for it. Building + can be defined in the CentralService at http://www.example.com:81/api/building. +

+ -
-

Get Building Details

-

This request retrieves name, description and template to used in the building specified in the request.

-
-

Example request:

-
GET /api/building/Test_Building HTTP/1.1
+
+
+
+
+
+
+

Get Building Details

+

This request retrieves name, description and template to used in the building + specified in the request.

+
+

Example request:

+
+
GET /api/building/Test_Building HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
-{   "success": "True",
-    "name": "Test_Building",
-    "description":"New Building",
+{   "success": "True",
+    "name": "Test_Building",
+    "description":"New Building",
     "template": "Test_Building_Template"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": " Building does not exist"
 }
-
-
-
-
-
-

Delete Building

-

This request deletes the requested Building and the template assigned to it.

-
-

Example request:

-
DELETE /api/building/Test_Building HTTP/1.1
+
+
+
+
+
+
+

Delete Building

+

This request deletes the requested Building and the template assigned to it.

+
+

Example request:

+
+
DELETE /api/building/Test_Building HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": " Building does not exist"
 }
 
 {
-  "success": "False",
-  "error": " Building is in use"
+  "success": "False",
+  "error": " Building is in use"
 }
-
-
-
-
-
-

Create a new Building Tag

-

This request creates a new Tag Value pair for a Building

-
-

Example request:

-
POST /api/building/WeanHall/tags HTTP/1.1
+
+
+
+
+
+
+

Create a new Building Tag

+

This request creates a new Tag Value pair for a Building

+
+

Example request:

+ -
-

Get Building Tag Details

-

This request retrieves name, description and template to used in the building specified in the request.

-
-

Example request:

-
GET /api/building/WeanHall/tags HTTP/1.1
+
+
+
+
+
+
+

Get Building Tag Details

+

This request retrieves name, description and template to used in the building + specified in the request.

+
+

Example request:

+
+
GET /api/building/WeanHall/tags HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-    "success": "True",
+    "success": "True",
     "pairs": {
               "Room": [],
-              "corridor": ["floor"],
+              "corridor": ["floor"],
               "floor": []
                       },
     "tags": [
-                  {  "value": "1",
+                  {  "value": "1",
                      "parents": [],
-                     "name": "floor",
-                     "can_delete": false
+                     "name": "floor",
+                     "can_delete": false
                   },
                   {
-                      "value": "10",
+                      "value": "10",
                       "parents": [
                                    {
-                                      "name": "floor",
-                                      "value": "1"
+                                      "name": "floor",
+                                      "value": "1"
                                       }
                                   ],
-                      "name": "corridor",
-                      "can_delete": true
+                      "name": "corridor",
+                      "can_delete": true
                   }
              ]
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": "One of the buildings does not exist"
 }
 
 {
-  "success": "False",
-  "error": " Missing parameters"
+  "success": "False",
+  "error": " Missing parameters"
 }
-
-
-
-
-
-

Delete Building Tags

-

This request deletes the requested Building and the template assigned to it.

-
-

Example request:

-
DELETE /api/building/WeanHall/tags HTTP/1.1
+
+
+
+
+
+ -
+ +
+
+
+
+
+ + +
+
+
-
- + +
-
- - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/CentralService/buildingtemplate.html b/buildingdepot/Documentation/build/html/api/CentralService/buildingtemplate.html index e7c0435c..39e29d7e 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/buildingtemplate.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/buildingtemplate.html @@ -1,195 +1,185 @@ - - - - + + + - - - - - BuildingTemplate — BuildingDepot 3.2.9 documentation - + - - + - + BuildingTemplate — BuildingDepot 3.2.9 documentation - - - - + - - - - - - - - - + + - - - + + + + - - + - -
- +
+ +
- - + +
+
+
+ - -
-
-
-
- -
-

BuildingTemplate

-

Each building within BuildingDepot has a BuildingTemplate as a foundation. The BuildingTemplate helps define the structure of the building. The user has to assign a set of tags to the BuildingTemplate on creation which can be used later on for all the sensors within that building. BuildingTemplate can be defined in the CentralService at http://www.example.com:81/api/buildingtemplate.

-
-

Create a Building Template

-

This request creates a Building Template with the name, description and tagtypes to be used in the buildingtemplate specified by the user.

-
-

Example request:

-
POST /api/template HTTP/1.1
+
+                    
+
+
+
+ +
+

BuildingTemplate

+

Each building within BuildingDepot has a BuildingTemplate as a foundation. The + BuildingTemplate helps define the structure of the building. The user has to assign a + set of tags to the BuildingTemplate on creation which can be used later on for all the + sensors within that building. BuildingTemplate can be defined in the CentralService at + http://www.example.com:81/api/buildingtemplate. +

+
+

Create a Building Template

+

This request creates a Building Template with the name, description and tagtypes to + be used in the buildingtemplate specified by the user.

+
+

Example request:

+ -
-

Get BuildingTemplate Details

-

This request retrieves name, description and tagtypes used in the buildingtemplate specified in the request.

-
-

Example request:

-
GET /api/template/Test_Building_Template HTTP/1.1
+
+
+
+
+
+
+

Get BuildingTemplate Details

+

This request retrieves name, description and tagtypes used in the buildingtemplate + specified in the request.

+
+

Example request:

+
+
GET /api/template/Test_Building_Template HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
-{   "success": "True",
-    "name": "Test_Building_Template",
-    "description":"New Building Template",
-    "tags": ["floor","room","corridor"]
+{   "success": "True",
+    "name": "Test_Building_Template",
+    "description":"New Building Template",
+    "tags": ["floor","room","corridor"]
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
-{  "success": "False",
+{  "success": "False",
   "error": " BuildingTemplate does not exist"
   }
-
-
-
-
-
-

Delete Building Template

-

This request deletes the requested BuildingTemplate and the Tagtypes assigned to it.

-
-

Example request:

-
DELETE /api/template/Test_Building_Template  HTTP/1.1
+
+
+
+
+
+
+

Delete Building Template

+

This request deletes the requested BuildingTemplate and the Tagtypes assigned to + it.

+
+

Example request:

+
+
DELETE /api/template/Test_Building_Template  HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": " BuildingTemplate does not exist"
 }
 
 {
-  "success": "False",
+  "success": "False",
   "error": " BuildingTemplate is in use"
 }
-
-
-
-
-
+ +
+
+
+
+
+ +
+
+
-
-
- +
+ +
+ +
+

+ © Copyright 2020, SynergyLabs. + +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
-
-
- - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/CentralService/dataservice.html b/buildingdepot/Documentation/build/html/api/CentralService/dataservice.html index 6cabdebc..988f4ae3 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/dataservice.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/dataservice.html @@ -1,201 +1,203 @@ - - - - + + + - - - - - DataService — BuildingDepot 3.2.9 documentation - - - - + - + - - - + DataService — BuildingDepot 3.2.9 documentation - - - - - + - - - - + + - - - + + + - - + + - -
- +
+ +
- - + +
+
+
+ - -
-
-
-
- -
-

DataService

-

The DataService is where all the data related to sensors and the timeseries data of each sensor resides. All the access control related functionality is defined at centralservice is also enforced within the DataService. A new DataService can be defined in the CentralService at http://www.example.com:81/api/dataservice.

-
-

Create a new DataService

-

This request creates a new DataService with description,host and port where the datservice will function.

-
-

Example request:

-
POST /api/dataservice HTTP/1.1
+
+                    
+
+
+
+ +
+

DataService +

+

The DataService is where all the data related to sensors and the timeseries data of each + sensor resides. All the access control related functionality is defined at + centralservice is also enforced within the DataService. A new DataService can be defined + in the CentralService at http://www.example.com:81/api/dataservice. +

+
+

Create a new DataService

+

This request creates a new DataService with description,host and port where the + datservice will function.

+
+

Example request:

+ -
-

Get DataService Details

-

This request retrieves name, description, hostname and port to used in the dataservice specified in the request.

-
-

Example request:

-
GET /api/dataservice/ds3 HTTP/1.1
+
+
+
+
+
+
+

Get DataService Details

+

This request retrieves name, description, hostname and port to used in the + dataservice specified in the request.

+
+

Example request:

+
+
GET /api/dataservice/ds3 HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
-{   "success": "True",
+{   "success": "True",
       "name": "ds3"
-      "description":"Test_ds3",
-      "host":"127.0.0.3",
+      "description":"Test_ds3",
+      "host":"127.0.0.3",
       "port":"83"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": " DataService does not exist"
 }
-
-
-
-
-
-

Delete DataService

-

This request deletes the requested DataService from Building Depot.

-
-

Example request:

-
DELETE /api/dataservice/ds3 HTTP/1.1
+
+
+
+
+
+
+

Delete DataService

+

This request deletes the requested DataService from Building Depot.

+
+

Example request:

+
+
DELETE /api/dataservice/ds3 HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": "DataService doesn't exist"
 }
 
 {
-  "success": "False",
+  "success": "False",
   "error": "Cannot delete DataService, contains buildings."
 }
-
-
-
-
-
-

Assign Buildings to DataService

-

This request assigns a specific building to DataService. Once the building is assigned to a specific DataService, the DataService handles sensor datastreams from the building.

-
-

Example request:

-
POST /api/dataservice/ds1/buildings HTTP/1.1
+
+
+
+
+
+
+

Assign Buildings to DataService

+

This request assigns a specific building to DataService. Once the building is + assigned to a specific DataService, the DataService handles sensor datastreams from + the building.

+
+

Example request:

+ -
-

Get Building Details from DataService

-

This request retrieves the names of buildings that the specified DataService hosts.

-
-

Example request:

-
GET /api/dataservice/ds1/buildings HTTP/1.1
+
+
+
+
+
+
+

Get Building Details from DataService +

+

This request retrieves the names of buildings that the specified DataService + hosts.

+
+

Example request:

+
+
GET /api/dataservice/ds1/buildings HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "True",
-  "buildings": ["NSH", "GHC"]
+  "success": "True",
+  "buildings": ["NSH", "GHC"]
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": " DataService doesn't exist"
 }
-
-
-
-
-
-

Remove Buildings from DataService

-

This request removes specified buildings from a DataService.

-
-

Example request:

-
DELETE /api/dataservice/ds1/buildings HTTP/1.1
+
+
+
+
+
+
+

Remove Buildings from DataService

+

This request removes specified buildings from a DataService.

+
+

Example request:

+ -
-

Grant Admin Privileges on DataService

-

This request grants CRUD (create/read/update/delete) privileges on the DataService to the specified users.

-
-

Example request:

-
POST /api/dataservice/ds1/admins HTTP/1.1
+
+
+
+
+
+
+

Grant Admin Privileges on DataService +

+

This request grants CRUD (create/read/update/delete) privileges on the DataService to + the specified users.

+
+

Example request:

+ -
-

Get List of Admins from DataService

-

This request retrieves the list of users who have the admin privileges on the specified DataService.

-
-

Example request:

-
GET /api/dataservice/ds1/buildings HTTP/1.1
+
+
+
+
+
+
+

Get List of Admins from DataService

+

This request retrieves the list of users who have the admin privileges on the + specified DataService.

+
+

Example request:

+
+
GET /api/dataservice/ds1/buildings HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "True",
-  "admins": ["user1@buildingdepot.org", "user2@buildingdepot.org"]
+  "success": "True",
+  "admins": ["user1@buildingdepot.org", "user2@buildingdepot.org"]
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": " DataService doesn't exist"
 }
-
-
-
-
-
-

Revoke Admin Privileges on DataService

-

This request revokes admin privileges on DataService from the specified users.

-
-

Example request:

-
DELETE /api/dataservice/ds1/admins HTTP/1.1
+
+
+
+
+
+ +
+
+
+
+ + +
+
+
-
-
-

- © Copyright 2020, SynergyLabs. -

-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. +
- +
+

+ © Copyright 2020, SynergyLabs. +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
-
-
- - - - - - - - - - - - - - - - - - - - - +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/CentralService/index.html b/buildingdepot/Documentation/build/html/api/CentralService/index.html index c1465ed4..2ec975d0 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/index.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/index.html @@ -1,334 +1,421 @@ - - - - + + + - - - - - CentralService APIs — BuildingDepot 3.2.9 documentation - + - - + - + CentralService APIs — BuildingDepot 3.2.9 documentation - - - - + - - - - - - - - - + + - - + + + - - + - -
- - - -
- - - + +
-
+ + + +
+
+ + +
+ + + + +
+
+
+
+ +
+

CentralService APIs

+

All urls in this chapter are with respect to the base url of the CentralService. For + example: If the CentralService is at http://www.example.com:81 + then a url such as /service/tagtype refers to http://www.example.com:81/api/tagtype + account.

+

Note: In order to access the CentralService all users will first have to + generate an OAuth Token using the Client ID and secret Client Key that they obtain from + their account at the CentralService. Once logged into the CentralService users can go to + the OAuth tab and generate a Client ID and Key that should never be shared with any + other users.

+

Once the Client ID and Key have been generated the user can request BuildingDepot for the + access token. The access token will be valid for the next 24 hours after which another + access token will have to be generated.The OAuth token should also never be shared + publicly.

+

This OAuth token will have to be sent in the headers of all the requests made to + BuildingDepot.

+ +
+ + +
+
+ + +
+
- +
- -
-
-
-
- -
-

CentralService APIs

-

All urls in this chapter are with respect to the base url of the CentralService. For example: If the CentralService is at http://www.example.com:81 then a url such as /service/tagtype refers to http://www.example.com:81/api/tagtype account.

-

Note: In order to access the CentralService all users will first have to generate an OAuth Token using the Client ID and secret Client Key that they obtain from their account at the CentralService. Once logged into the CentralService users can go to the OAuth tab and generate a Client ID and Key that should never be shared with any other users.

-

Once the Client ID and Key have been generated the user can request BuildingDepot for the access token. The access token will be valid for the next 24 hours after which another access token will have to be generated.The OAuth token should also never be shared publicly.

-

This OAuth token will have to be sent in the headers of all the requests made to BuildingDepot.

- -
- -
-
-
- - - -
+ + + + -
-

- © Copyright 2020, SynergyLabs. -

-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + -
- - - - + - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/CentralService/oauth.html b/buildingdepot/Documentation/build/html/api/CentralService/oauth.html index 6d592026..8db4c90f 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/oauth.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/oauth.html @@ -1,277 +1,264 @@ - - - - + + + - - - - - OAuth — BuildingDepot 3.2.9 documentation - - - - + - + - - - + OAuth — BuildingDepot 3.2.9 documentation - - - - - + - - - - + + - - - + + + - - + + - -
- +
+ +
- - + +
+
+
+ - -
-
-
-
- -
-

OAuth

-

Every query to BuildingDepot has to be authenticated by an access token. The client id and secret key required to generate the access token can be obtained after logging into the CentralService. After these have been obtained the access token can be generated by using the following request.

-
-

Generating access tokens

-

Generate an access token using the client id and secret key obtained from the CentralService. Each access token is valid for 24 hours from the time of generation.

-
-

Example request:

-
GET /oauth/access_token/client_id=BOCWEJSnwJ8UJ4mfPiP8CqCX0QGHink6PFbmTnx0/
-client_secret=1gk1pBQHiK6vHQULOndEucULq0Tf5H9vKjAUbIBVX0qMjsC9uQ HTTP/1.1
+
+                    
+
+
+
+ +
+

OAuth

+

Every query to BuildingDepot has to be authenticated by an access token. The client id + and secret key required to generate the access token can be obtained after logging into + the CentralService. After these have been obtained the access token can be generated by + using the following request.

+
+

Generating access tokens

+

Generate an access token using the client id and secret key obtained from the + CentralService. Each access token is valid for 24 hours from the time of + generation.

+
+

Example request:

+
+
GET /oauth/access_token/client_id=BOCWEJSnwJ8UJ4mfPiP8CqCX0QGHink6PFbmTnx0/
+client_secret=1gk1pBQHiK6vHQULOndEucULq0Tf5H9vKjAUbIBVX0qMjsC9uQ HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "access_token": "528d58481bc728a5eb57e73a49ba4539"
 }
-
-
-
-
-
+ +
+
+
+
+
+ + +
+
+
-
-
-

- © Copyright 2020, SynergyLabs. -

-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. +
- +
+

+ © Copyright 2020, SynergyLabs. +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
-
- - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/CentralService/permission.html b/buildingdepot/Documentation/build/html/api/CentralService/permission.html index 034428cd..7de3adca 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/permission.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/permission.html @@ -1,246 +1,287 @@ - - - - + + + - - - - - Permission — BuildingDepot 3.2.9 documentation - + - - + - + Permission — BuildingDepot 3.2.9 documentation - - - - + - - - - - - - - - + + - - - + + + + - - + - -
- - - - -
+
- - - - - -
-
- + -
+
- - -
-
-
-
- -
-

Permission

-

The Permissions are created between SensorGroups and UserGroups in Building Depot which come together to form the access control lists.Here we select a User Group and a Sensor Group and a permission value with which we want to associate these both. There are three levels of permission defined in BuildingDepot which are ‘d/r’ (deny read) ,’r’ (read), ‘r/w’ (read write) and ‘r/w/p’ (read write permission). If there are multiple permission mappings between a user and a sensor then the one that is most restrictive is chosen. Permissions can be defined in the CentralService at http://www.example.com:81/api/permission.

-
-

Create Permission

-

This request creates a new Permission link between a UserGroup and a SensorGroup.

- --- - - - - -
JSON Parameters:
 
    -
  • -
    data (dictionary) – Contains the permission value for sensorgroup and usergroup
    -
      -
    • sensor_group (string) – Name of the sensor_group
    • -
    • user_group (string) – Name of the user_group
    • -
    • -
      permission (string) – Permission level
      -
        -
      • r (string) – Read - Will give read only access to the sensors
      • -
      • rw (string) – Read-Write - Will give read and write access to the sensors
      • -
      • dr (string) – Deny-read - Will deny any access to the sensors
      • -
      • rwp (string) – Read-Write-Permission - Highest level of permission that can be assigned. Will give read and write access to the sensors. In addition to this the user will be able to add/remove tags from the sensor.
      • -
      -
      -
      -
    • -
    -
    -
    -
  • -
-
-
--- - - - - - - - -
returns:
    -
  • success (string) – Returns ‘True’ if data is posted successfully otherwise ‘False’
  • -
  • error (string) – An additional value that will be present only if the request fails specifying the cause for failure
  • -
-
status 200:

Success

-
status 401:

Unauthorized Credentials

-
-
-
-
-

Example request:

-
POST /api/permission HTTP/1.1
+        
+
+
+        
+
+ + +
+ + + + +
+
+
+
+ +
+

Permission

+

The Permissions are created between SensorGroups and UserGroups in Building Depot which + come together to form the access control lists.Here we select a User Group and a Sensor + Group and a permission value with which we want to associate these both. There are three + levels of permission defined in BuildingDepot which are ‘d/r’ (deny read) ,’r’ (read), + ‘r/w’ (read write) and ‘r/w/p’ (read write permission). If there are multiple permission + mappings between a user and a sensor then the one that is most restrictive is chosen. + Permissions can be defined in the CentralService at http://www.example.com:81/api/permission. +

+
+

Create Permission

+

This request creates a new Permission link between a UserGroup and a SensorGroup.

+ + + + + + + + + + + + +
JSON Parameters:
  +
    +
  • +
    +
    data (dictionary) – Contains + the permission value for sensorgroup and usergroup +
    +
    +
      +
    • sensor_group (string) + – Name of the sensor_group +
    • +
    • user_group (string) – + Name of the user_group +
    • +
    • +
      +
      permission + (string) – Permission level +
      +
      +
        +
      • r + (string) – Read - Will + give read only access to the sensors +
      • +
      • rw + (string) – Read-Write - + Will give read and write access to + the sensors +
      • +
      • dr + (string) – Deny-read - + Will deny any access to the sensors +
      • +
      • rwp + (string) – + Read-Write-Permission - Highest + level of permission that can be + assigned. Will give read and write + access to the sensors. In addition + to this the user will be able to + add/remove tags from the sensor. +
      • +
      +
      +
      +
    • +
    +
    +
    +
  • +
+
+
+ + + + + + + + + + + + + + + + + +
returns: +
    +
  • success (string) – + Returns ‘True’ if data is posted successfully + otherwise ‘False’ +
  • +
  • error (string) – + An additional value that will be present only if + the request fails specifying the cause for + failure +
  • +
+
status 200:

Success

+
status 401:

Unauthorized + Credentials

+
+
+
+
+
+

Example request:

+ -
-

Read Permission

-

This request retrieves Permission level assigned for existing SensorGroup and UserGroup.

-
-

Example request:

-
GET /api/permission?user_group=Test_User_Group&sensor_group=Test_Sensor_Group HTTP/1.1
+
+
+
+
+
+
+

Read Permission

+

This request retrieves Permission level assigned for existing SensorGroup and + UserGroup.

+
+

Example request:

+
+
GET /api/permission?user_group=Test_User_Group&sensor_group=Test_Sensor_Group HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
   "permission": "r"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": " Permission does not exist"
 }
-
-
-
-
-
-

Delete Permission

-

This request deletes the permission link between the UserGroup and SensorGroup

-
-

Example request:

-
DELETE /api/permission?user_group=Test_User_Group&sensor_group=Test_Sensor_Group HTTP/1.1
+
+
+
+
+
+
+

Delete Permission

+

This request deletes the permission link between the UserGroup and SensorGroup

+
+

Example request:

+
+
DELETE /api/permission?user_group=Test_User_Group&sensor_group=Test_Sensor_Group HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": " Permission does not exist"
 }
 
 {
-  "success": "False",
+  "success": "False",
   "error": " You are not authorized to delete this permission"
 }
 
 {
-  "success": "False",
-  "error": "Missing parameters"
+  "success": "False",
+  "error": "Missing parameters"
 }
-
-
-
-
-
+
+
+
+
+
+
+ +
+
+
-
-
- +
+ +
+ +
+

+ © Copyright 2020, SynergyLabs. + +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
- - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/CentralService/sensor.html b/buildingdepot/Documentation/build/html/api/CentralService/sensor.html index e7861e3a..9db71817 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/sensor.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/sensor.html @@ -1,203 +1,196 @@ - - - - + + + - - - - - Sensor — BuildingDepot 3.2.9 documentation - - - - + - + - - - + Sensor — BuildingDepot 3.2.9 documentation - - - - - + - - - - + + - - - + + + - - + + - -
- +
+ +
- - + +
+
+
+ - -
-
-
-
- -
-

Sensor

-

The Sensor collection manages Sensors for Locations associated with the CentralService.Sensors can be defined in the CentralService at http://www.example.com:81/api/sensor. -Sensor access is restricted to Central Service Users with permissions for the Sensor and to the Admin who owns the Sensor.

-
-

Create a Sensor

-

Creates a new Sensor point in BuildingDepot and returns the UUID.

-
-

Example request:

-
POST /api/sensor HTTP/1.1
+
+                    
+
+
+
+ +
+

Sensor

+

The Sensor collection manages Sensors for Locations associated with the + CentralService.Sensors can be defined in the CentralService at http://www.example.com:81/api/sensor. + Sensor access is restricted to Central Service Users with permissions for + the Sensor and to the Admin who owns the Sensor.

+
+

Create a Sensor

+

Creates a new Sensor point in BuildingDepot and returns the UUID.

+
+

Example request:

+ -
-

Get Sensor details

-

Retrieves all the details of the sensor based on the uuid specified

-
-

Example request:

-
GET /api/sensor/8aac1048-aa9f-41c9-9c20-6dd81339c7de HTTP/1.1
+
+
+
+
+
+
+

Get Sensor details

+

Retrieves all the details of the sensor based on the uuid specified

+
+

Example request:

+
+
GET /api/sensor/8aac1048-aa9f-41c9-9c20-6dd81339c7de HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-    "success": "True",
-    "building": "NSH",
-    "name": "8aac1048-aa9f-41c9-9c20-6dd81339c7de",
-    "source_identifier": "Sensor_Tag",
-    "source_name": "Test_Sensor",
+    "success": "True",
+    "building": "NSH",
+    "name": "8aac1048-aa9f-41c9-9c20-6dd81339c7de",
+    "source_identifier": "Sensor_Tag",
+    "source_name": "Test_Sensor",
     "views_owned": [
       {
-        "fields": "EMI-0",
-        "id": "280bc754-a963-4740-89f4-bdae9ede76f6",
-        "source_name": "Averages"
+        "fields": "EMI-0",
+        "id": "280bc754-a963-4740-89f4-bdae9ede76f6",
+        "source_name": "Averages"
       },
       {
-        "fields": "EMI-2, EMI-3",
-        "id": "6336a9d7-6f65-4572-9e52-78fa3808c92f",
+        "fields": "EMI-2, EMI-3",
+        "id": "6336a9d7-6f65-4572-9e52-78fa3808c92f",
         "source_name": "Min, Max EMI"
       }
     ]
 }
-
-
-
-
-
-

Delete a Sensor

-

Delete the Sensor associated with sensor_uuid.

-
-

Attention

-

Restricted to Admins only

-

Currently can only be done through the GUI

-
-
-
-

Search Sensors

-

The Search API is used search sensors based on uuid,source_name,source_identifier, building, Tag and MetaData. Multiple search queries can be sent in a single request.

- --- - - - - -
JSON Parameters:
 
    -
  • -
    data (dictionary) – Contains the list of Search Query key-value pairs
    -
      -
    • ID (list) – UUID of the Sensor
    • -
    • Building (list) – Building in which the sensor is located
    • -
    • Tags (list) – List of tags owned by the sensor. The are given as key,value pairs.
    • -
    • Metadata (list) – List of metadata owned by the sensor.The are given as key,value pairs.
    • -
    • Source_Identifier (list) – Source identifier of the sensor
    • -
    • Source_Name (list) – Source name of the sensor
    • -
    -
    -
    -
  • -
-
-
-

Example request:

-
POST /api/sensor/search HTTP/1.1
+
+
+
+
+
+
+

Delete a Sensor

+

Delete the Sensor associated with sensor_uuid.

+
+

Attention

+

Restricted to Admins only

+

Currently can only be done through the GUI

+
+
+
+

Search Sensors

+

The Search API is used search sensors based on uuid,source_name,source_identifier, + building, Tag and MetaData. Multiple search queries can be sent in a single + request.

+ + + + + + + + + + + + +
JSON Parameters:
  +
    +
  • +
    +
    data (dictionary) – Contains + the list of Search Query key-value pairs +
    +
    +
      +
    • ID (list) – UUID of + the Sensor +
    • +
    • Building (list) – + Building in which the sensor is located +
    • +
    • Tags (list) – List of + tags owned by the sensor. The are given as key,value + pairs. +
    • +
    • Metadata (list) – List + of metadata owned by the sensor.The are given as + key,value pairs. +
    • +
    • Source_Identifier + (list) – Source identifier of the + sensor +
    • +
    • Source_Name (list) – + Source name of the sensor +
    • +
    +
    +
    +
  • +
+
+
+

Example request:

+ -
-

Add Tags to a Sensor

-

This request adds tags (key-value pairs) to a particular sensor. To get the available tags that can be added to the sensor, please use the get tags of a sensor API to fetch the list of available tags.

-
-

Example request:

-
POST /api/sensor/be2a09a5-4ef6-4c67-886e-272c37e7e38f/tags HTTP/1.1
+
+
+
+
+
+
+

Add Tags to a Sensor

+

This request adds tags (key-value pairs) to a particular sensor. To get the available + tags that can be added to the sensor, please use the get tags of a sensor API to + fetch the list of available tags.

+ -
-
-

Get Tags of a Sensor

-

This request retrieves two lists of key-value pairs, one list contains the array of eligible tags that can be attached to this sensor and the other list contains the array of tags that are currently attached to this sensor.

-
-

Example request:

-
GET /api/sensor/26da099a-3fe0-4966-b068-14f51bcedb6e/tags HTTP/1.1
+
+
+
+
+
+
+

Get Tags of a Sensor

+

This request retrieves two lists of key-value pairs, one list contains the array of + eligible tags that can be attached to this sensor and the other list contains the + array of tags that are currently attached to this sensor.

+ -
-
-

Create a Sensor View

-

Creates a new Sensor View for a sensor point in BuildingDepot. Each sensor may have multiple fields of data, however, -the user may only want to receive or request a subset of data. This API creates a view for the sensor and returns the -UUID for the sensor.

-
-

Example request:

-
POST /api/sensor/8aac1048-aa9f-41c9-9c20-6dd81339c7de/views HTTP/1.1
+
+
+
+
+
+
+

Create a Sensor View

+

Creates a new Sensor View for a sensor point in BuildingDepot. Each sensor may have + multiple fields of data, however, + the user may only want to receive or request a subset of data. This API creates a + view for the sensor and returns the + UUID for the sensor.

+ -
-
-

Get Sensor View details

-

Retrieves all the views of the sensor based on the sensor uuid specified

-
-

Example request:

-
GET /api/sensor/6cf53d24-e3a3-41bd-b2b5-8f109694f628 HTTP/1.1
+
+
+
+
+
+ -
-

Delete a Sensor View

-

This request deletes a sensor view of a sensor.

-
-

Example request:

-
DELETE /api/sensor/8aac1048-aa9f-41c9-9c20-6dd81339c7de/views/22d807bf-af67-493a-80b7-2690d26c9244 HTTP/1.1
+
+
+
+
+
+
+

Delete a Sensor View

+

This request deletes a sensor view of a sensor.

+
+

Example request:

+
+
DELETE /api/sensor/8aac1048-aa9f-41c9-9c20-6dd81339c7de/views/22d807bf-af67-493a-80b7-2690d26c9244 HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response (for success):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for success):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": "Permission does not exist"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": "Communication failure with DataService"
 }
-
-
-
-
-
-

SensorGroups and UserGroups

-
-
BuildingDepot restricts access to sensors to users on three levels. A user can have either of these types of access to a sensor:
-
    -
  • Read
  • -
  • Read/Write
  • -
  • Deny Read
  • -
  • Read/Write/Permission
  • -
-
-
-

As the names suggest a user with read access to a sensor will be able to read all the datapoints of the sensors. A user with Read/Write access will be able to both read and write (if supported by the sensor) to the sensors. With Deny Read a user will not be able to read any datapoints of the sensor.

-

The basis of deciding these permissions is dependent on the abstraction of SensorGroups and UserGroups within BuildingDepot.

-

SensorGroups are created on the basis of tags that are specified at the time of creation. All sensors with the specified tags will be a part of the SensorGroup that is created. Usergroups are basically a list of users which are connected to a SensorGroup via a “Permissions” link. This link is what defines the level of access that the users in the UserGroup have to the sensors in the SensorGroup.

-
-
+ +
+
+
+
+
+

SensorGroups and UserGroups

+
+
BuildingDepot restricts access to sensors to users on three levels. A user can + have either of these types of access to a sensor: +
+
+
    +
  • Read
  • +
  • Read/Write
  • +
  • Deny Read
  • +
  • Read/Write/Permission
  • +
+
+
+

As the names suggest a user with read access to a sensor will be able to read all the + datapoints of the sensors. A user with Read/Write access will be able to both read + and write (if supported by the sensor) to the sensors. With Deny Read a user will + not be able to read any datapoints of the sensor.

+

The basis of deciding these permissions is dependent on the abstraction of + SensorGroups and UserGroups within BuildingDepot.

+

SensorGroups are created on the basis of tags that are specified at the time of + creation. All sensors with the specified tags will be a part of the SensorGroup that + is created. Usergroups are basically a list of users which are connected to a + SensorGroup via a “Permissions” link. This link is what defines the level of access + that the users in the UserGroup have to the sensors in the SensorGroup.

+
+
+ + +
+
+ + +
+
+
-
-
-
- - - + -
-
-

- © Copyright 2020, SynergyLabs. + + + + -

-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. -
+ - - - + - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/CentralService/sensorgroup.html b/buildingdepot/Documentation/build/html/api/CentralService/sensorgroup.html index e5f3cd62..5f59995f 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/sensorgroup.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/sensorgroup.html @@ -1,197 +1,191 @@ - - - - + + + - - - - - SensorGroups — BuildingDepot 3.2.9 documentation - + - - + - + SensorGroups — BuildingDepot 3.2.9 documentation - - - - + - - - - - - - - - + + - - - + + + + - - + - -
- +
+ +
- - + +
+
+
+ - -
-
-
-
- -
-

SensorGroups

-

SensorGroups are a virtual collection of sensors that are created based on the tags that are specified. Each sensor may consist a set of tags. The list of sensors that belong to a SensorGroup can be changed by modifying the tags attached to this SensorGroup. All sensors having the current tags will fall under this SensorGroup automatically for any subsequent operations. SensorGroups can be defined in the CentralService at http://www.example.com:81/api/sensorgroup.

-
-

Create SensorGroup

-

This request creates a new SensorGroup with the name and description in the building specified by the user.

-
-

Example request:

-
POST /api/sensor_group HTTP/1.1
+
+                    
+
+
+
+ +
+

SensorGroups

+

SensorGroups are a virtual collection of sensors that are created based on the tags that + are specified. Each sensor may consist a set of tags. The list of sensors that belong to + a SensorGroup can be changed by modifying the tags attached to this SensorGroup. All + sensors having the current tags will fall under this SensorGroup automatically for any + subsequent operations. SensorGroups can be defined in the CentralService at http://www.example.com:81/api/sensorgroup. +

+
+

Create SensorGroup

+

This request creates a new SensorGroup with the name and description in the building + specified by the user.

+
+

Example request:

+ -
-

Get SensorGroup Details

-

This request retrieves the details of a SensorGroup

-
-

Example request:

-
GET /api/sensor_group/Test HTTP/1.1
+
+
+
+
+
+
+

Get SensorGroup Details

+

This request retrieves the details of a SensorGroup

+
+

Example request:

+
+
GET /api/sensor_group/Test HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response (for success):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for success):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success" : "true"
-  "name":"Test",
+  "name":"Test",
   "description": "A SensorGroup for Test"
   "building":"NSH"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": "SensorGroup does not exist"
 }
-
-
-
-
-
-

Delete SensorGroup

-

This request deletes the SensorGroup

-
-

Example request:

-
DELETE /api/sensor_group/Test HTTP/1.1
+
+
+
+
+
+
+

Delete SensorGroup

+

This request deletes the SensorGroup

+
+

Example request:

+
+
DELETE /api/sensor_group/Test HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response (for success):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for success):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": "SensorGroup does not exist"
 }
-
-
-
-
-
-

Add tags to SensorGroup

-

This request adds the tags specified in the request to the SensorGroup

-

Note: The list of tags sent in this request will overwrite the previous list.

-
-

Example request:

-
POST /api/sensor_group/test/tags HTTP/1.1
+
+
+
+
+
+
+

Add tags to SensorGroup

+

This request adds the tags specified in the request to the SensorGroup

+

Note: The list of tags sent in this request will overwrite the previous list.

+
+

Example request:

+
+
POST /api/sensor_group/test/tags HTTP/1.1
 Accept: application/json; charset=utf-8
 
 
@@ -310,30 +348,46 @@ 

Add tags to SensorGroup

-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
 }
-
-
-
-
-
-

Get list of tags in SensorGroup

-

This request retrieves two lists of key-value pairs, one list contains the array of eligible tags that can be attached to this SensorGroup and the other list contains the array of tags that are currently attached to this SensorGroup.

-
-

Example request:

-
GET /api/sensor_group/test/tags HTTP/1.1
+
+
+
+
+
+
+

Get list of tags in SensorGroup

+

This request retrieves two lists of key-value pairs, one list contains the array of + eligible tags that can be attached to this SensorGroup and the other list contains + the array of tags that are currently attached to this SensorGroup.

+
+

Example request:

+
+
GET /api/sensor_group/test/tags HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+ -
-
-
+ +
+
+
+
+
+ + +
+
+
-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. - +
+
+

+ © Copyright 2020, SynergyLabs. + +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
-
-
- - - - - - - - - - - - - - - - - - - - - +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/CentralService/tagtype.html b/buildingdepot/Documentation/build/html/api/CentralService/tagtype.html index 93ef57e8..48fe6804 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/tagtype.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/tagtype.html @@ -1,194 +1,183 @@ - - - - + + + - - - - - TagType — BuildingDepot 3.2.9 documentation - + - - + - + TagType — BuildingDepot 3.2.9 documentation - - - - + - - - - - - - - - + + - - - + + + + - - + - -
- +
+ +
- - + +
+
+
+ - -
-
-
-
- -
-

TagType

-

Tag Types are used to describe the structure and domains of buildings and help in categorising sensors that can be easily allocated in groups to different users. TagType can be defined in the CentralService at http://www.example.com:81/api/tagtype. TagsTypes have a hierarchical structure i.e. a tag can have both parent tags and children tags. They play a very crucial role within BuildingDepot in defining permissions that restrict access to sensors based on the permissions a user has. Also, A building template is supported by a group of tag types allocated to it.

-
-

Add TagType

-

This request creates a new TagType in BuildingDepot which will be used in the Building template to define the structure of the Buildings.

-
-

Example request:

-
POST /api/tagtype HTTP/1.1
+
+                    
+
+
+
+ +
+

TagType +

+

Tag Types are used to describe the structure and domains of buildings and help in + categorising sensors that can be easily allocated in groups to different users. TagType + can be defined in the CentralService at http://www.example.com:81/api/tagtype. + TagsTypes have a hierarchical structure i.e. a tag can have both parent tags and + children tags. They play a very crucial role within BuildingDepot in defining + permissions that restrict access to sensors based on the permissions a user has. Also, A + building template is supported by a group of tag types allocated to it.

+
+

Add TagType

+

This request creates a new TagType in BuildingDepot which will be used in the + Building template to define the structure of the Buildings.

+
+

Example request:

+ -
-

Get TagType

-

This request fetches information about a TagType in BuildingDepot.

-
-

Example request:

-
GET /api/tagtype/floor HTTP/1.1
+
+
+
+
+
+
+

Get TagType

+

This request fetches information about a TagType in BuildingDepot.

+
+

Example request:

+
+
GET /api/tagtype/floor HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response (for success):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for success):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
   "children": [  "corridor"
                   ],
-  "description": null,
-  "name": "floor",
+  "description": null,
+  "name": "floor",
   "parents": [],
   "success": "True"
 
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
-  "error": "TagType does not exist"
+  "success": "False",
+  "error": "TagType does not exist"
 }
-
-
-
-
-
+ +
+
+
+
+
+ + +
+
+
+ -
-
- +
+ +
+

+ © Copyright 2020, SynergyLabs. + +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
-
-
- - - - - - - - - - - - - - - - - - - - - +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/CentralService/user.html b/buildingdepot/Documentation/build/html/api/CentralService/user.html index b364dae9..53e98e8a 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/user.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/user.html @@ -1,195 +1,186 @@ - - - - + + + - - - - - User — BuildingDepot 3.2.9 documentation - + - - + - + User — BuildingDepot 3.2.9 documentation - - - - + - - - - - - - - - + + - - - + + + + - - + - -
- +
+ +
- - + +
+
+
+ - -
-
-
-
- -
-

User

-

The Users of BuildingDepot have either of the two roles SuperUser and Default User through which we maintain the access control. The Super User is the admin of BuildingDepot who has permission to add,remove,read,write,delete any entity. The Default User has limited access and does not have permission to add,remove any building and dataservice related entity.Only the SuperUser can add another user and the SuperUser by default in every Building Depot installation is admin@buildingdepot.org. A new User can be added by the SuperUser in the CentralService at http://www.example.com:81/api/user.

-
-

Add a new User

-

This request creates a new User in the Central Service. Only the SuperUser can add a new user

-
-

Example request:

-
POST /api/user HTTP/1.1
+
+                    
+
+
+
+ +
+

User

+

The Users of BuildingDepot have either of the two roles SuperUser and Default User + through which we maintain the access control. The Super User is the admin of + BuildingDepot who has permission to add,remove,read,write,delete any entity. The Default + User has limited access and does not have permission to add,remove any building and + dataservice related entity.Only the SuperUser can add another user and the SuperUser by + default in every Building Depot installation is admin@buildingdepot.org. + A new User can be added by the SuperUser in the CentralService at http://www.example.com:81/api/user. +

+
+

Add a new User

+

This request creates a new User in the Central Service. Only the SuperUser can add a + new user

+
+

Example request:

+ -
-

Get User Details

-

This request retrieves first name, last_name, email and role of the User specified in the request.

-
-

Example request:

-
GET /api/user/newuser@gmail.com HTTP/1.1
+
+
+
+
+
+
+

Get User Details

+

This request retrieves first name, last_name, email and role of the User specified in + the request.

+
+

Example request:

+
+
GET /api/user/newuser@gmail.com HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
-{   "success": "True",
+{   "success": "True",
       "first_name": "New"
-      "last_name":"User",
-      "email":"newuser@gmail.com",
+      "last_name":"User",
+      "email":"newuser@gmail.com",
       "role":"super"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
-  "error": " User does not exist"
+  "success": "False",
+  "error": " User does not exist"
 }
-
-
-
-
-
-

Remove User

-

This request deletes the requested User from Building Depot.Only the Super user can delete the User in BuildingDepot.

-
-

Example request:

-
DELETE /api/User/newuser@gmail.com HTTP/1.1
+
+
+
+
+
+
+

Remove User

+

This request deletes the requested User from Building Depot.Only the Super user can + delete the User in BuildingDepot.

+
+

Example request:

+
+
DELETE /api/User/newuser@gmail.com HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
-  "error": " User does not exist"
+  "success": "False",
+  "error": " User does not exist"
 }
-
-
-
-
-
+ +
+
+
+
+
+ +
+
+
-
-
- +
+ +
+ +
+

+ © Copyright 2020, SynergyLabs. + +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
-
-
- - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/CentralService/usergroup.html b/buildingdepot/Documentation/build/html/api/CentralService/usergroup.html index 18f3a3d3..4c49f0f8 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/usergroup.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/usergroup.html @@ -1,197 +1,187 @@ - - - - + + + - - - - - Usergroups — BuildingDepot 3.2.9 documentation - + - - + - + Usergroups — BuildingDepot 3.2.9 documentation - - - - + - - - - - - - - - + + - - - + + + + - - + - -
- +
+ +
- - + +
+
+
+ - -
-
-
-
- -
-

Usergroups

-

Usergroups are as the name suggests a group of users formed using the id’s with which they are registered in BuildingDepot. Usergroups when combined with SensorGroups help in bringing about the Access Control functions that BuildingDepot provides.UserGroups can be defined in the CentralService at http://www.example.com:81/api/usergroup.

-
-

Create UserGroup

-

This request creates a new UserGroup with the name and description as specified by the user.

-
-

Example request:

-
POST /api/user_group HTTP/1.1
+
+                    
+
+
+
+ +
+

Usergroups

+

Usergroups are as the name suggests a group of users formed using the id’s with which + they are registered in BuildingDepot. Usergroups when combined with SensorGroups help in + bringing about the Access Control functions that BuildingDepot provides.UserGroups can + be defined in the CentralService at http://www.example.com:81/api/usergroup. +

+
+

Create UserGroup

+

This request creates a new UserGroup with the name and description as specified by + the user.

+
+

Example request:

+ -
-

Get UserGroup Details

-

This request retrieves the details of a UserGroup

-
-

Example request:

-
GET /api/user_group/Test HTTP/1.1
+
+
+
+
+
+
+

Get UserGroup Details

+

This request retrieves the details of a UserGroup

+
+

Example request:

+
+
GET /api/user_group/Test HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response (for success):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for success):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success" : "true",
-  "name":"Test",
+  "success" : "true",
+  "name":"Test",
   "description":"A UserGroup for Test"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": "Usergroup does not exist"
 }
-
-
-
-
-
-

Delete UserGroup

-

This request deletes the UserGroup

-
-

Example request:

-
DELETE /api/user_group/<name> HTTP/1.1
+
+
+
+
+
+
+

Delete UserGroup

+

This request deletes the UserGroup

+
+

Example request:

+
+
DELETE /api/user_group/<name> HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response (for success):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for success):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success": "False",
+  "success": "False",
   "error": "Usergroup does not exist"
 }
-
-
-
-
-
-

Add users to UserGroup

-

This request adds the users specified in the request to the usergroup

-

Note: The list of users sent in this request will overwrite the previous list

-
-

Example request:

-
POST /api/user_group/Test/users HTTP/1.1
+
+
+
+
+
+
+

Add users to UserGroup

+

This request adds the users specified in the request to the usergroup

+

Note: The list of users sent in this request will overwrite the previous list

+ -
-
-

Get list of users in UserGroup

-

This request retrieves the list of users that are in the specified UserGroup

-
-

Example request:

-
GET /api/user_group/Test/users HTTP/1.1
+
+
+
+
+
+
+

Get list of users in UserGroup

+

This request retrieves the list of users that are in the specified UserGroup

+
+

Example request:

+
+
GET /api/user_group/Test/users HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "users": [
              {
-                "user_id":"synergy@gmail.com",
+                "user_id":"synergy@gmail.com",
                 "manager": true
              },
              {
-                "user_id":"test@gmail.com",
+                "user_id":"test@gmail.com",
                 "manager": false
              }
            ]
 }
-
-
-
-
-
+ +
+
+
+
+
+ + +
+
+
-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. - +
+
+

+ © Copyright 2020, SynergyLabs. + +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
-
-
- - - - - - - - - - - - - - - - - - - - - +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/DataService/index.html b/buildingdepot/Documentation/build/html/api/DataService/index.html index 3975e707..49f891ff 100755 --- a/buildingdepot/Documentation/build/html/api/DataService/index.html +++ b/buildingdepot/Documentation/build/html/api/DataService/index.html @@ -1,267 +1,263 @@ - - - - + + + - - - - - DataService APIs — BuildingDepot 3.2.9 documentation - + - - + - + DataService APIs — BuildingDepot 3.2.9 documentation - - - - + - - - - - - - - - + + - - + + + - - + - -
- +
+ + + BuildingDepot -
- - + - -
-
- +
+ 3.2.9 +
+
+
+ + + +
+
+
+ +
+ +
+ + + +
+
+ + +
+ +
-
- +
+
+ + +
- - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/DataService/oauth.html b/buildingdepot/Documentation/build/html/api/DataService/oauth.html index 2c9a72c8..0fa3a656 100644 --- a/buildingdepot/Documentation/build/html/api/DataService/oauth.html +++ b/buildingdepot/Documentation/build/html/api/DataService/oauth.html @@ -1,270 +1,251 @@ - - - - + + + - - - - - OAuth — BuildingDepot 3.2.9 documentation - - - - + - + - - - + OAuth — BuildingDepot 3.2.9 documentation - - - - - + - - - - + + - - - + + + - - + + - -
- +
+ +
- - + +
+
+
+ - -
-
-
-
- -
-

OAuth

-

Every query to BuildingDepot has to be authenticated by an access token. The client id and secret key required to generate the access token can be obtained after logging into the CentralService. After these have been obtained the access token can be generated by using the following request.

-
-

Generating access tokens

-

Generate an access token using the client id and secret key obtained from the CentralService. Each access token is valid for 24 hours from the time of generation.

-
-

Example request:

-
GET /oauth/access_token/client_id=BOCWEJSnwJ8UJ4mfPiP8CqCX0QGHink6PFbmTnx0/
-client_secret=1gk1pBQHiK6vHQULOndEucULq0Tf5H9vKjAUbIBVX0qMjsC9uQ HTTP/1.1
+
+                    
+
+
+
+ +
+

OAuth

+

Every query to BuildingDepot has to be authenticated by an access token. The client id + and secret key required to generate the access token can be obtained after logging into + the CentralService. After these have been obtained the access token can be generated by + using the following request.

+
+

Generating access tokens

+

Generate an access token using the client id and secret key obtained from the + CentralService. Each access token is valid for 24 hours from the time of + generation.

+
+

Example request:

+
+
GET /oauth/access_token/client_id=BOCWEJSnwJ8UJ4mfPiP8CqCX0QGHink6PFbmTnx0/
+client_secret=1gk1pBQHiK6vHQULOndEucULq0Tf5H9vKjAUbIBVX0qMjsC9uQ HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "access_token": "528d58481bc728a5eb57e73a49ba4539"
 }
-
-
-
-
-
+ +
+
+
+
+
+ + +
+
+
-
-
-

- © Copyright 2020, SynergyLabs. -

-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. +
- +
+

+ © Copyright 2020, SynergyLabs. +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
-
- - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/DataService/pubsub.html b/buildingdepot/Documentation/build/html/api/DataService/pubsub.html index a356e011..72ddcd76 100755 --- a/buildingdepot/Documentation/build/html/api/DataService/pubsub.html +++ b/buildingdepot/Documentation/build/html/api/DataService/pubsub.html @@ -1,225 +1,221 @@ - - - - + + + - - - - - Apps — BuildingDepot 3.2.9 documentation - + - - + - + Apps — BuildingDepot 3.2.9 documentation - - - - + - - - - - - - - - + + - - + + + - - + - -
- +
+ +
- - + +
+
+
+ - -
-
-
-
- -
-

Apps

-

DataService Apps API allows users interact with the underlying app models. This -API handles the registration and deletion of apps from the system.

-
-

Get List of Registered Apps

-

This retrieves a list of applications of the current user. This API first -registers the application to the system, then it opens up a rabbitMQ queue.

-
-

Example request:

-
GET /api/apps HTTP/1.1
+
+                    
+
+
+
+ +
+

Apps

+

DataService Apps API allows users interact with the underlying app models. This + API handles the registration and deletion of apps from the system.

+
+

Get List of Registered Apps

+

This retrieves a list of applications of the current user. This API first + registers the application to the system, then it opens up a rabbitMQ queue.

+
+

Example request:

+
+
GET /api/apps HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response (for success):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for success):

+
+
HTTP/1.1 200 OK
 Content-Type: application/json; charset=utf-8
 
 {
-  "success": "True",
+  "success": "True",
   "app_list": [
-    "app_example_1", "app_example_2", "app_example_3"
+    "app_example_1", "app_example_2", "app_example_3"
   ]
 }
-
-
-

Example response (for failure):

-
HTTP/1.1 200 OK
+
+
+
+

Example response (for failure):

+
+
HTTP/1.1 200 OK
 Content-Type: application.json; charset=utf-8
 
 {
   "success": "False",
   "error": "Missing Parameters"
 }
-
-
-
-
-
-

Register a New App

-

This stores a new app for the current user.

-

If there already exists an application with the given name, this API call has no effect on BuildingDepot.

-
-

Example request:

-
POST /api/apps HTTP/1.1
+
+
+
+
+
+
+

Register a New App

+

This stores a new app for the current user.

+

If there already exists an application with the given name, this API call has no + effect on BuildingDepot.

+
+

Example request:

+ -
-

Delete an App

-

This deletes an app of the current user.

-
-

Example request:

-
DELETE /api/apps HTTP/1.1
+
+
+
+
+
+
+

Delete an App

+

This deletes an app of the current user.

+
+

Example request:

+ -
-

Subscribe to a Sensor

-

This is used to subscribes to the sensor data.

-
-

Example request:

-
POST /api/apps HTTP/1.1
+
+
+
+
+
+ -
-

Unsubscribe from a Sensor

-

This is used to unsubscribes from the sensor data.

-
-

Example request:

-
DELETE /api/apps HTTP/1.1
+
+
+
+
+
+ +
+
+
+
+ + +
+
+
+ -
-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. - +
+
+

+ © Copyright 2020, SynergyLabs. + +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
-
-
- - - - - - - - - - - - - - - - - - - - - +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/api/DataService/sensordata.html b/buildingdepot/Documentation/build/html/api/DataService/sensordata.html index 7309dacd..3246482c 100755 --- a/buildingdepot/Documentation/build/html/api/DataService/sensordata.html +++ b/buildingdepot/Documentation/build/html/api/DataService/sensordata.html @@ -1,189 +1,170 @@ - - - - + + + - - - - - Timeseries — BuildingDepot 3.2.9 documentation - - - - + - + - - - + Timeseries — BuildingDepot 3.2.9 documentation - - - - - + - - - - + + - - - + + + - - + + - -
- +
+ +
- - + +
+
+
+ - -
-
-
-
- -
-

Timeseries

-

The Sensor collection manages Sensors for Locations associated with the DataService. -Sensor access is restricted to Central Service Users with permissions for the Sensor and to the Admin who owns the Sensor.

-
-

Post Timeseries Datapoints

-

This stores datapoints in the timeseries of the specified Sensorpoint.

-

The first datapoint that is posted to the uuid defines the datatype for all further timeseries datapoints e.g. if the first datapoint posted to a certain uuid is a int then all further datapoints have to be ints.

-
-

Example request:

-
POST /api/sensor/timeseries HTTP/1.1
+
+                    
+
+
+
+ +
+

Timeseries

+

The Sensor collection manages Sensors for Locations associated with the DataService. + Sensor access is restricted to Central Service Users with permissions for + the Sensor and to the Admin who owns the Sensor.

+
+ +

Post Timeseries Datapoints

+

This stores datapoints in the timeseries of the specified Sensorpoint.

+

The first datapoint that is posted to the uuid defines the datatype for all further + timeseries datapoints e.g. if the first datapoint posted to a certain uuid is a int + then all further datapoints have to be ints.

+
+

Example request:

+
+
POST /api/sensor/timeseries HTTP/1.1
 Accept: application/json; charset=utf-8
 
 { "data":     [
@@ -215,35 +196,51 @@ 

TimeseriesExample response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
   "success": "True"
 }
-
-
-

-
-
-

Read Timeseries Datapoints

-

This retreives a list of datapoints for the timeseries of the specified Sensorpoint

-

Note: Both interval and resolution are specified with the time value appended by the type of the value e.g. 10s for 10 seconds or 10m for 10 minutes.

-
-

Example request:

-
GET /sensor/<sensor-uuid>/timeseries?start_time=1445535722&end_time=1445789516&resolution=10s HTTP/1.1
+
+
+
+
+
+
+

Read Timeseries Datapoints

+

This retreives a list of datapoints for the timeseries of the specified + Sensorpoint

+

Note: Both interval and resolution are specified with the time value appended by the + type of the value e.g. 10s for 10 seconds or 10m for 10 minutes.

+
+

Example request:

+
+
GET /sensor/<sensor-uuid>/timeseries?start_time=1445535722&end_time=1445789516&resolution=10s HTTP/1.1
 Accept: application/json; charset=utf-8
-
-
-

Example response:

-
HTTP/1.1 200 OK
+
+
+
+

Example response:

+
+
HTTP/1.1 200 OK
 Content-Type: application/json
 
 {
-  "success":"True",
+  "success":"True",
   "data": {
     "series": [
       {
@@ -252,7 +249,8 @@ 

Read Timeseries Datapoints"inserted_at", "value" ], - "name": "35b137b2-c7c6-4608-8489-1c3f0ee7e2d5", + "name": "35b137b2-c7c6-4608-8489-1c3f0ee7e2d5", "values": [ [ "2015-10-22T17:41:44.762495917Z", @@ -274,79 +272,76 @@

Read Timeseries Datapoints] } } -

-
-
-
-
+ +
+
+
+
+
+ + +
+
+
-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. - +
+
+

+ © Copyright 2020, SynergyLabs. + +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
-
-
- - - - - - - - - - - - - - - - - - - - - +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/centralservice.html b/buildingdepot/Documentation/build/html/centralservice.html index 0366c712..6a45ea2e 100755 --- a/buildingdepot/Documentation/build/html/centralservice.html +++ b/buildingdepot/Documentation/build/html/centralservice.html @@ -1,349 +1,419 @@ - - - - + + + - - - - - Central Service — BuildingDepot 3.2.9 documentation - - - - + - + - - - + Central Service — BuildingDepot 3.2.9 documentation - - - - - + - - - - + + - - + + - - + + - -
- - - -
+
- - + +
-
+ + + +
+
+ + +
+ + + + +
+
+
+
+ + _images/BuildingDepot.svg +
+

Central Service

+

The Central Service within BuildingDepot is the part of the system that holds all the + core metadata. Starting from the structures of the Buildings to the DataServices that + lie in an installation the CentralService plays a very important role in organising the + data within BuildingDepot in a meaningful way. A brief explanation will be provided here + of each of the options available in the CentralService.

+

We define any entity to which a timeseries can be associated with as a Point. A Point can + be + measurements from sensors, or commands to turn a light on/off, or a configuration + parameter + such as cycle type in a washing machine or even a fault indicator. This includes both + real­world + sensors/actuators, as well as virtual sensors/actuators created in the Central Service + as + abstractions of RealWorld sensors/actuators (such as a ‘building average temperature + sensor’). + Virtual and RealWorld points are treated identically within the CentralService, with + differences + occurring at the level of connectors (see Connectors document for interfacing between + the + CentralService and sensors). In BuildingDepot, each point is given a UUID (universally + unique ID) and + metadata is associated with it using tags.

+

Tags are key value pairs associated with a point. For example, an office temperature + sensor + would be associated with tags like “Room = 300”, “Type = Temperature Sensor”, “Unit = + Fahrenheit” and so on. Tags themselves can refer to complex entities and be associated + with + other tags. For example, Room 300 can be associated with its metadata such as area and + usage type . Tags form the core of BuildingDepot metadata, and are used for searching + and defining permissions.

+

BuildingDepot supports pre­defined tag types that acts as a template for a user to start + tagging entities + in a building. These templates are provided to support standard naming convention, such + as the + tags defined by Project Haystack2. These tags are also used as the key search mechanism + within BuildingDepot. Using REST APIs, users can query for individual entities based on + single tag + (such as a Room = 300) or based on more complex combinations of tags (Room = 300 and + Type = Occupancy and Building = Example_Building). All entities which meet the + requirements + of the search are returned as JSON objects which contain their UUID, tags, and Metadata. + In addition to tags on entities, BuildingDepot also utilizes context based tags for + Users. Depending on + how a user logs in (e.g. with or without admin privileges) they will have a context tag + added to + determine the privileges that they enjoy (user credentials). Users groups are created by + assigning a user­group tag to each user which is part of the group. This is of + particular + importance later when determining permissions.

+

In addition to User Groups, Sensor groups are as the name suggests a set of points that + have + been grouped together on the basis of the tags that the user selected while creating the + group. + While creating a Sensor group each individual points that the user wants to put in the + group do + not have to be manually added. Simply selecting the tag will automatically add at the + backend + all the points containing that tag into this group. + Sensor groups and User groups come together to form the access control lists. Access + control + lists are a key element in BuildingDepot to facilitate both privacy and security. For + pairs of User + Groups and Sensor Groups, we choose a permission value with which we want to associate. + There are four levels of permission defined in BuildingDepot which are ‘d/r’ (deny read) + ,’r’ (read) , ‘r/w’ + (read write) and ‘r/w/p’ (read write permission). If there are multiple permission + mappings + between a user and a point then the one that is most restrictive is chosen. The deny + read + permission level, in particular, is important for maintaining privacy of data for + various groups + simultaneously using BuildingDepot for a building.

+
+
Different evels of permission access:
+
+
    +
  • d/r: Deny/Read will deny any access to the points
  • +
  • r: Read will give read only access to the points
  • +
  • r/w: Read/Write will give read and write access to the + points (such as changing values of actuators) +
  • +
  • r/w/p: Read/Write/Permission is the highest level of + permission that can be assigned. Will give read and write access to the + points. This permission also allows users to alter permissions for the + points (see above). +
  • +
+
+
Note:
+
+
    +
  • The ownership level of permission is assigned at the point of + creation. It has all privileges of r/w/p. Additionally, it cannot be revoked + or changed under any circumstances. +
  • +
  • The super users of BuildingDepot have r/w/p access to all the + points. +
  • +
+
+
+

When a r/w/p permission link is created between the UserGroup “Home_usergroup” and Sensor + Group “Home”. All users in UserGroup get r/w/p access to points in SensorGroup. Any user + can + create any permission link that they want but the set of points that the users in the + UserGroup + get access to in the SensorGroup that they have been given permission to will depend on + the + user that has created the permission. Only the points that the creator of this + permission has + r/w/p access to will be the points that the users will gain access to based on this + permission link.

+ _images/CSComponents.svg +
+

OAuth +

+

To generate an OAuth token a client id and client secret key are required. These are + generated within the DataService by the user through the GUI. These values will be + valid until the user regenerates them for that certain account. The process to + generate an OAuth token after these values have been obtained is defined in the REST + API Documentation.

+
+
+

TagType

+

Tags are an integral part of BuildingDepot and play an important role in organising + and categorising the sensors and their data. Users can create new tags here which + will be used in various places throughout BuildingDepot. When creating each tag + parent tag(s) can be specified for each tag enabling us to create a tag hierarchy + that proves to be very useful when defining structures such as Buildings. Here only + the tag names are specified and the values for these tags are specified later on. + Each tag can have multiple values if needed.

+
+
+

BuildingTemplate

+

Each building within BuildingDepot has a BuildingTemplate as a foundation. The + BuildingTemplate helps define the structure of the building. The user has to assign + a set of tags to the BuildingTemplate on creation which can be used later on for all + the sensors within that building.

+
+
+

Building

+

All the buildings that are present within the deployment of BuildingDepot are defined + here. When adding a new building a BuildingTemplate has to be selected which defines + the structure of this building. The tags that are available to be assigned to this + building are dependent on the BuildingTemplate. Tags can be selected and the values + for each of them can be specified here. Each tag can have multiple values specified + for it.

+
+
+

Data Services

+

BuildingDepot consists of a single CentralService and if needed multiple + DataServices. The number of DataServices to deploy is a decision that is completely + left to the user. A DataService per building is an ideal choice that we suggest. + Each DataService has to be specified within the DataService’s section in the + CentralService. For each DataService all the buildings that belong to it also have + to be selected and added. The admins for each DataService who will have complete + administrative control over this DataService also have to be specified here.

+

Note: The first DataService has to be called “ds1”.

+
+
+

Sensor +

+

Individual sensor points are defined here. After adding a sensor a UUID is generated + which will be the unique identifier used in all further transactions with + BuildingDepot whether it be reading a datapoint from a sensor or posting a bunch of + datapoints to a sensor. Each sensor can also have a set of tags attached to it that + not only help in categorising them in a meaningful way but also are critical for + defining the access control lists later on. The option to attach metadata that is + specific to this sensor is also provided. Sensors can be searched for using either + the tags or metadata as a filter.

+
+
+

Sensor Group

+

Sensor groups are as the name suggests a set of sensors that have been grouped + together on the basis of the tags that the user selected while creating the group. + While creating a Sensor groups each individual sensor that the user wants to put in + the group do not have to be manual added. Simply selecting the tag will + automatically add at the backend all the sensors containing that tag into this + group.

+
+
+

User Group

+

Similar to Sensor groups, User groups are a list of users that have been categorised + into one group. Groups are created using the user email id that was used during + registration.

+
+
+

Permission

+

In the permissions section Sensor groups and User groups come together to form the + access control lists. Here we select a User Group and a Sensor Group and a + permission value with which we want to associate these both. There are three levels + of permission defined in BuildingDepot which are ‘d/r’ (deny read) ,’r’ (read), + ‘r/w’ (read write) and ‘r/w/p’ (read write permission). If there are multiple + permission mappings between a user and a sensor then the one that is most + restrictive is chosen.

+
+
+ + +
+
+ + +
+
- +
- -
-
-
-
- - _images/BuildingDepot.svg -
-

Central Service

-

The Central Service within BuildingDepot is the part of the system that holds all the core metadata. Starting from the structures of the Buildings to the DataServices that lie in an installation the CentralService plays a very important role in organising the data within BuildingDepot in a meaningful way. A brief explanation will be provided here of each of the options available in the CentralService.

-

We define any entity to which a timeseries can be associated with as a Point. A Point can be -measurements from sensors, or commands to turn a light on/off, or a configuration parameter -such as cycle type in a washing machine or even a fault indicator. This includes both real­world -sensors/actuators, as well as virtual sensors/actuators created in the Central Service as -abstractions of RealWorld sensors/actuators (such as a ‘building average temperature sensor’). -Virtual and RealWorld points are treated identically within the CentralService, with differences -occurring at the level of connectors (see Connectors document for interfacing between the -CentralService and sensors). In BuildingDepot, each point is given a UUID (universally unique ID) and -metadata is associated with it using tags.

-

Tags are key value pairs associated with a point. For example, an office temperature sensor -would be associated with tags like “Room = 300”, “Type = Temperature Sensor”, “Unit = -Fahrenheit” and so on. Tags themselves can refer to complex entities and be associated with -other tags. For example, Room 300 can be associated with its metadata such as area and -usage type . Tags form the core of BuildingDepot metadata, and are used for searching and defining permissions.

-

BuildingDepot supports pre­defined tag types that acts as a template for a user to start tagging entities -in a building. These templates are provided to support standard naming convention, such as the -tags defined by Project Haystack2. These tags are also used as the key search mechanism -within BuildingDepot. Using REST APIs, users can query for individual entities based on single tag -(such as a Room = 300) or based on more complex combinations of tags (Room = 300 and -Type = Occupancy and Building = Example_Building). All entities which meet the requirements -of the search are returned as JSON objects which contain their UUID, tags, and Metadata. -In addition to tags on entities, BuildingDepot also utilizes context based tags for Users. Depending on -how a user logs in (e.g. with or without admin privileges) they will have a context tag added to -determine the privileges that they enjoy (user credentials). Users groups are created by -assigning a user­group tag to each user which is part of the group. This is of particular -importance later when determining permissions.

-

In addition to User Groups, Sensor groups are as the name suggests a set of points that have -been grouped together on the basis of the tags that the user selected while creating the group. -While creating a Sensor group each individual points that the user wants to put in the group do -not have to be manually added. Simply selecting the tag will automatically add at the backend -all the points containing that tag into this group. -Sensor groups and User groups come together to form the access control lists. Access control -lists are a key element in BuildingDepot to facilitate both privacy and security. For pairs of User -Groups and Sensor Groups, we choose a permission value with which we want to associate. -There are four levels of permission defined in BuildingDepot which are ‘d/r’ (deny read) ,’r’ (read) , ‘r/w’ -(read write) and ‘r/w/p’ (read write permission). If there are multiple permission mappings -between a user and a point then the one that is most restrictive is chosen. The deny read -permission level, in particular, is important for maintaining privacy of data for various groups -simultaneously using BuildingDepot for a building.

-
-
Different evels of permission access:
-
    -
  • d/r: Deny/Read will deny any access to the points
  • -
  • r: Read will give read only access to the points
  • -
  • r/w: Read/Write will give read and write access to the points (such as changing values of actuators)
  • -
  • r/w/p: Read/Write/Permission is the highest level of permission that can be assigned. Will give read and write access to the points. This permission also allows users to alter permissions for the points (see above).
  • -
-
-
Note:
-
    -
  • The ownership level of permission is assigned at the point of creation. It has all privileges of r/w/p. Additionally, it cannot be revoked or changed under any circumstances.
  • -
  • The super users of BuildingDepot have r/w/p access to all the points.
  • -
-
-
-

When a r/w/p permission link is created between the UserGroup “Home_usergroup” and Sensor -Group “Home”. All users in UserGroup get r/w/p access to points in SensorGroup. Any user can -create any permission link that they want but the set of points that the users in the UserGroup -get access to in the SensorGroup that they have been given permission to will depend on the -user that has created the permission. Only the points that the creator of this permission has -r/w/p access to will be the points that the users will gain access to based on this permission link.

-_images/CSComponents.svg -
-

OAuth

-

To generate an OAuth token a client id and client secret key are required. These are generated within the DataService by the user through the GUI. These values will be valid until the user regenerates them for that certain account. The process to generate an OAuth token after these values have been obtained is defined in the REST API Documentation.

-
-
-

TagType

-

Tags are an integral part of BuildingDepot and play an important role in organising and categorising the sensors and their data. Users can create new tags here which will be used in various places throughout BuildingDepot. When creating each tag parent tag(s) can be specified for each tag enabling us to create a tag hierarchy that proves to be very useful when defining structures such as Buildings. Here only the tag names are specified and the values for these tags are specified later on. Each tag can have multiple values if needed.

-
-
-

BuildingTemplate

-

Each building within BuildingDepot has a BuildingTemplate as a foundation. The BuildingTemplate helps define the structure of the building. The user has to assign a set of tags to the BuildingTemplate on creation which can be used later on for all the sensors within that building.

-
-
-

Building

-

All the buildings that are present within the deployment of BuildingDepot are defined here. When adding a new building a BuildingTemplate has to be selected which defines the structure of this building. The tags that are available to be assigned to this building are dependent on the BuildingTemplate. Tags can be selected and the values for each of them can be specified here. Each tag can have multiple values specified for it.

-
-
-

Data Services

-

BuildingDepot consists of a single CentralService and if needed multiple DataServices. The number of DataServices to deploy is a decision that is completely left to the user. A DataService per building is an ideal choice that we suggest. Each DataService has to be specified within the DataService’s section in the CentralService. For each DataService all the buildings that belong to it also have to be selected and added. The admins for each DataService who will have complete administrative control over this DataService also have to be specified here.

-

Note: The first DataService has to be called “ds1”.

-
-
-

Sensor

-

Individual sensor points are defined here. After adding a sensor a UUID is generated which will be the unique identifier used in all further transactions with BuildingDepot whether it be reading a datapoint from a sensor or posting a bunch of datapoints to a sensor. Each sensor can also have a set of tags attached to it that not only help in categorising them in a meaningful way but also are critical for defining the access control lists later on. The option to attach metadata that is specific to this sensor is also provided. Sensors can be searched for using either the tags or metadata as a filter.

-
-
-

Sensor Group

-

Sensor groups are as the name suggests a set of sensors that have been grouped together on the basis of the tags that the user selected while creating the group. While creating a Sensor groups each individual sensor that the user wants to put in the group do not have to be manual added. Simply selecting the tag will automatically add at the backend all the sensors containing that tag into this group.

-
-
-

User Group

-

Similar to Sensor groups, User groups are a list of users that have been categorised into one group. Groups are created using the user email id that was used during registration.

-
-
-

Permission

-

In the permissions section Sensor groups and User groups come together to form the access control lists. Here we select a User Group and a Sensor Group and a permission value with which we want to associate these both. There are three levels of permission defined in BuildingDepot which are ‘d/r’ (deny read) ,’r’ (read), ‘r/w’ (read write) and ‘r/w/p’ (read write permission). If there are multiple permission mappings between a user and a sensor then the one that is most restrictive is chosen.

-
-
-
-
- - - + + + + -
-
-

- © Copyright 2020, SynergyLabs. + -

-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. -
- -
- - - + - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/dataservice.html b/buildingdepot/Documentation/build/html/dataservice.html index ce06b999..a57478fb 100755 --- a/buildingdepot/Documentation/build/html/dataservice.html +++ b/buildingdepot/Documentation/build/html/dataservice.html @@ -1,265 +1,251 @@ - - - - + + + - - - - - Data Service — BuildingDepot 3.2.9 documentation - - - - + - + - - - + Data Service — BuildingDepot 3.2.9 documentation - - - - - + - - - - + + - - + + - - + + - -
- +
+ +
- - + +
+
+
+ - - -
-
-
-
- - _images/BuildingDepot.svg -
-

Data Service

-

The DataService is the service with which users will be interacting directly most of the time. It’s within the DataService that all the data related to sensors and the timeseries data of each sensor resides. All the access control related functionality is defined and enforced within the DataService. OAuth access tokens which are required by every query that is sent to BuildingDepot are also generated via the DataService. A brief explanation will be provided here of each of the options available in the DataService.

-

DataService stores point time series data points from the underlying point networks. The -DataService manages the points and time series data points of points allocated to it. A -DataService may belong to any single administrative group that requires sole control over who -can access the underlying point data. Different buildings on a campus might desire their own -DataService. Thus it is up to an institution to determine how many DataServices are needed -depending on the specific groups that exist and their needs.

-

DataService needs to query CentralService for user accounts, building tags and permission -information. The communication is immensely frequent as almost every request to DataService -needs user authentication and permission check. Therefore, only keeping a single -CentralService would be a performance bottleneck. To resolve this issue, we set up the -CentralService in a master­slave mode. The master CentralService only accepts write requests -and each of its replicas undertakes read requests from a single DataService. In this way, the -request traffic load can be balanced on all replicas.

-_images/DSComponents.svg -
-

Sensor

-

The time-series data of all the points in buildings associated with the Data Service is stored here. The sensor UUID(s) are used in all further time-series transactions with BuildingDepot whether it be reading a datapoint from a sensor or posting a bunch of datapoints to a sensor.The time-series data of all the points in buildings associated with a certain Data Service is stored here. The sensor UUID(s) are used in all further time-series transactions with BuildingDepot whether it be reading a datapoint from a sensor or posting a bunch of datapoints to a sensor.

-
-
-

Apps

-

BuildingDepot allows users to subscribe to sensors’ time-series data. This can be done by registering a new app and associating it with the desired sensor UUIDs. All the information about a user’s apps is located here.

-
-
+
+
+
+
+ + _images/BuildingDepot.svg +
+

Data Service

+

The DataService is the service with which users will be interacting directly most of the + time. It’s within the DataService that all the data related to sensors and the + timeseries data of each sensor resides. All the access control related functionality is + defined and enforced within the DataService. OAuth access tokens which are required by + every query that is sent to BuildingDepot are also generated via the DataService. A + brief explanation will be provided here of each of the options available in the + DataService.

+

DataService stores point time series data points from the underlying point networks. The + DataService manages the points and time series data points of points allocated to it. A + DataService may belong to any single administrative group that requires sole control + over who + can access the underlying point data. Different buildings on a campus might desire their + own + DataService. Thus it is up to an institution to determine how many DataServices are + needed + depending on the specific groups that exist and their needs.

+

DataService needs to query CentralService for user accounts, building tags and permission + information. The communication is immensely frequent as almost every request to + DataService + needs user authentication and permission check. Therefore, only keeping a single + CentralService would be a performance bottleneck. To resolve this issue, we set up the + CentralService in a master­slave mode. The master CentralService only accepts write + requests + and each of its replicas undertakes read requests from a single DataService. In this + way, the + request traffic load can be balanced on all replicas.

+ _images/DSComponents.svg +
+

Sensor +

+

The time-series data of all the points in buildings associated with the Data Service + is stored here. The sensor UUID(s) are used in all further time-series transactions + with BuildingDepot whether it be reading a datapoint from a sensor or posting a + bunch of datapoints to a sensor.The time-series data of all the points in buildings + associated with a certain Data Service is stored here. The sensor UUID(s) are used + in all further time-series transactions with BuildingDepot whether it be reading a + datapoint from a sensor or posting a bunch of datapoints to a sensor.

+
+
+

Apps

+

BuildingDepot allows users to subscribe to sensors’ time-series data. This can be + done by registering a new app and associating it with the desired sensor UUIDs. All + the information about a user’s apps is located here.

+
+
+ + +
+
+
+ -
-
- +
+ +
+

+ © Copyright 2020, SynergyLabs. + +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + + +
-
- - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/genindex.html b/buildingdepot/Documentation/build/html/genindex.html index 81ec3bcb..bc662768 100755 --- a/buildingdepot/Documentation/build/html/genindex.html +++ b/buildingdepot/Documentation/build/html/genindex.html @@ -1,228 +1,185 @@ - - - - - + + + - - - - - Index — BuildingDepot 3.2.9 documentation - + - - + - + Index — BuildingDepot 3.2.9 documentation - - - - + - - - - - + + + - - - - - - + - -
- +
+ +
- - + +
+
+
+
    +
  • Docs »
  • +
  • Index
  • +
  • +
  • +
-
+
+
+
+
-
    - -
  • Docs »
  • - -
  • Index
  • - - -
  • - - - -
  • - -
- -
-
-
-
- +

Index

-

Index

+
+ +
-
- -
+
+
+
-
-
-
- -
+
-
-

- © Copyright 2020, SynergyLabs. +

+

+ © Copyright 2020, SynergyLabs. -

-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. -
+ +
-
-
- - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/http-routingtable.html b/buildingdepot/Documentation/build/html/http-routingtable.html index 0e1990f2..69d2dac1 100755 --- a/buildingdepot/Documentation/build/html/http-routingtable.html +++ b/buildingdepot/Documentation/build/html/http-routingtable.html @@ -1,354 +1,534 @@ - + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> - - - + + + HTTP Routing Table — BuildingDepot 3.2.9 documentation - - - + + + - - + + + + + + - - - - - + - - + + -
-
+ +
+
- -
- -

HTTP Routing Table

+
+ + +

HTTP Routing Table

+ +
+ /api | + /oauth | + /sensor +
-
- /api | - /oauth | - /sensor -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
 
+ /api
+ GET /api/apps + +
+ GET /api/building/<building_name>/tags +
+ GET + /api/building/<name> +
+ GET /api/dataservice/<name> +
+ GET /api/dataservice/<name>/admins +
+ GET /api/dataservice/<name>/buildings +
+ GET /api/permission?user_group=<user_group>&sensor_group=<sensor_group> + +
+ GET + /api/sensor/<name> +
+ GET + /api/sensor/<name>/tags +
+ GET + /api/sensor/<name>/views +
+ GET /api/sensor_group/<name> +
+ GET /api/sensor_group/<name>/tags +
+ GET + /api/tagtype/<name> +
+ GET /api/template/<name> +
+ GET + /api/user/<email> +
+ GET + /api/user_group/<name> +
+ GET /api/user_group/<name>/users +
+ POST + /api/apps +
+ POST + /api/building +
+ POST /api/building/<building_name>/tags +
+ POST + /api/dataservice +
+ POST /api/dataservice/<name>/admins +
+ POST /api/dataservice/<name>/building +
+ POST + /api/permission +
+ POST + /api/sensor +
+ POST + /api/sensor/<name>/tags +
+ POST + /api/sensor/<name>/view +
+ POST + /api/sensor/search +
+ POST + /api/sensor/timeseries +
+ POST + /api/sensor_group +
+ POST /api/sensor_group/<name>/tags +
+ POST + /api/tagtype +
+ POST + /api/template +
+ POST + /api/user +
+ POST + /api/user_group +
+ POST /api/user_group/<name>/users +
+ DELETE + /api/apps +
+ DELETE /api/building/<building_name>/tags +
+ DELETE + /api/building/<name> +
+ DELETE /api/dataservice/<name> +
+ DELETE /api/dataservice/<name>/admins +
+ DELETE /api/dataservice/<name>/buildings +
+ DELETE /api/permission?user_group=<user_group>&sensor_group=<sensor_group> + +
+ DELETE /api/sensor/<uuid>/views/<view_uuid> +
+ DELETE /api/sensor_group/<name> +
+ DELETE /api/template/<name> +
+ DELETE + /api/user/<email> +
+ DELETE + /api/user_group/Test +
 
+ /oauth
+ GET /oauth/access_token/client_id=<client_id>/client_secret=<client_secret> + +
 
+ /sensor
+ GET /sensor/<sensor-uuid>/timeseries?start_time=<start_timestamp>&end_time=<end_timestamp>&resolution=<resolution_units> + +
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
- /api
- GET /api/apps -
- GET /api/building/<building_name>/tags -
- GET /api/building/<name> -
- GET /api/dataservice/<name> -
- GET /api/dataservice/<name>/admins -
- GET /api/dataservice/<name>/buildings -
- GET /api/permission?user_group=<user_group>&sensor_group=<sensor_group> -
- GET /api/sensor/<name> -
- GET /api/sensor/<name>/tags -
- GET /api/sensor/<name>/views -
- GET /api/sensor_group/<name> -
- GET /api/sensor_group/<name>/tags -
- GET /api/tagtype/<name> -
- GET /api/template/<name> -
- GET /api/user/<email> -
- GET /api/user_group/<name> -
- GET /api/user_group/<name>/users -
- POST /api/apps -
- POST /api/building -
- POST /api/building/<building_name>/tags -
- POST /api/dataservice -
- POST /api/dataservice/<name>/admins -
- POST /api/dataservice/<name>/building -
- POST /api/permission -
- POST /api/sensor -
- POST /api/sensor/<name>/tags -
- POST /api/sensor/<name>/view -
- POST /api/sensor/search -
- POST /api/sensor/timeseries -
- POST /api/sensor_group -
- POST /api/sensor_group/<name>/tags -
- POST /api/tagtype -
- POST /api/template -
- POST /api/user -
- POST /api/user_group -
- POST /api/user_group/<name>/users -
- DELETE /api/apps -
- DELETE /api/building/<building_name>/tags -
- DELETE /api/building/<name> -
- DELETE /api/dataservice/<name> -
- DELETE /api/dataservice/<name>/admins -
- DELETE /api/dataservice/<name>/buildings -
- DELETE /api/permission?user_group=<user_group>&sensor_group=<sensor_group> -
- DELETE /api/sensor/<uuid>/views/<view_uuid> -
- DELETE /api/sensor_group/<name> -
- DELETE /api/template/<name> -
- DELETE /api/user/<email> -
- DELETE /api/user_group/Test -
 
- /oauth
- GET /oauth/access_token/client_id=<client_id>/client_secret=<client_secret> -
 
- /sensor
- GET /sensor/<sensor-uuid>/timeseries?start_time=<start_timestamp>&end_time=<end_timestamp>&resolution=<resolution_units> -
+
-
-
-
- + - - - + \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/index.html b/buildingdepot/Documentation/build/html/index.html index 23cade40..3dd4c63c 100755 --- a/buildingdepot/Documentation/build/html/index.html +++ b/buildingdepot/Documentation/build/html/index.html @@ -1,302 +1,318 @@ - - - - + + + - - - - - Building Depot v3.2.9 — BuildingDepot 3.2.9 documentation - - - - + - + - - - + Building Depot v3.2.9 — BuildingDepot 3.2.9 documentation - - - - - + - - - - + + - + - - + + - -
- - - -
+ +
-
+ + + +
+
+ + +
+ + + + +
+
+
+
+ +
+

Building Depot v3.2.9

+
+

Overview

+

This is the official documentation of BuildingDepot v3.2.9. BuildingDepot is + essentialy an Extensible and Distributed Architecture for Sensor Data Storage, + Access and Sharing.

+

Building Depot has two essential components a Central Service and a Data Service + :

+

Central Service - A central directory containing details of all the + buildings,users

+

Data Service - The core component of BD and is responsible for handling the actual + sensor data. Exposes a RESTful API for retrieving data and inserting data into the + system.

+

An institution has a single CentralService that houses data of all buildings and user + accounts on campus, and multiple DataServices, each of which may contain sensor data + of several buildings.

+

A DataService may belong to any single administrative group that requires sole + control over who can access the underlying sensor data points. Different buildings + on a campus might desire their own DataService.

+
+

CentralService

+

Read more about the CentralService

+ +
+
+

DataService

+

Read more about the DataService

+
+ +
+
+
+
+

Download

+

You can get the latest BuildingDepot package (tar.gz) from buildingdepot.org +

+
+
+

Install

+
+ +
+
+
+

Getting Started

+

The Getting + started document will help you guide through the initial setup after installing + BuildingDepot.

+
+
+

API Documentation

+ +
+
+ + +
+
+
+ + + + +
+ +
+

+ © Copyright 2020, SynergyLabs. + +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + +
+ +
+
- +
- -
-
-
-
- -
-

Building Depot v3.2.9

-
-

Overview

-

This is the official documentation of BuildingDepot v3.2.9. BuildingDepot is essentialy an Extensible and Distributed Architecture for Sensor Data Storage, Access and Sharing.

-

Building Depot has two essential components a Central Service and a Data Service :

-

Central Service - A central directory containing details of all the buildings,users

-

Data Service - The core component of BD and is responsible for handling the actual sensor data. Exposes a RESTful API for retrieving data and inserting data into the system.

-

An institution has a single CentralService that houses data of all buildings and user accounts on campus, and multiple DataServices, each of which may contain sensor data of several buildings.

-

A DataService may belong to any single administrative group that requires sole control over who can access the underlying sensor data points. Different buildings on a campus might desire their own DataService.

-
-

CentralService

-

Read more about the CentralService

- -
-
-

DataService

-

Read more about the DataService

-
- -
-
-
-
-

Download

-

You can get the latest BuildingDepot package (tar.gz) from buildingdepot.org

-
-
-

Install

- -
-
-

Getting Started

-

The Getting started document will help you guide through the initial setup after installing BuildingDepot.

-
-
-

API Documentation

- -
-
-
-
- - - + + + + -
-
-

- © Copyright 2020, SynergyLabs. + -

-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. -
- -
-
- - + -
- - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/install.html b/buildingdepot/Documentation/build/html/install.html index 8ffb41b2..e5cdf1ee 100755 --- a/buildingdepot/Documentation/build/html/install.html +++ b/buildingdepot/Documentation/build/html/install.html @@ -1,224 +1,224 @@ - - - - + + + - - - - - Installation — BuildingDepot 3.2.9 documentation - - - - + - + - - - + Installation — BuildingDepot 3.2.9 documentation - - - - - + - - - - + + - - + + - - + + - -
- - - -
+
- - + -
+
- - -
-
-
-
- -
-

Installation

-
-

Using install.sh

-
-

Note

-

This installer installs the BD DataService, CentralService, MongoDB, InfluxDB -and Redis on the same machine.

-
-
    -
  1. Extract the package and cd into the folder**:

    -

    $ tar -xzf buildingdepot-3.#.#.tar.gz

    -

    $ cd buildingdepot-3.#.#/

    -
  2. -
  3. Run the installer

    -

    $ ./install.sh

    -

    This will install BuildingDepot in the default installation location -/srv/buildingdepot with the following directory structure:

    -
    buildingdepot
    -|-- CentralService - CentralService
    -|-- DataService - DataService
    -|-- CentralReplica - The central replica that is present at every DataService
    -+-- venv - Python Virtual Environment
    -
    -
    -
  4. -
  5. After installation please go the CentralService on port 81 of your installation and create a DataService to start off with called “ds1”. If you would like to use another name for your DataService do ensure that the name is accordingly changed in the config.py file in the DataService folder.

    -
  6. -
-
-
-

What’s installed

-
    -
  • The following packages are installed using apt-get

    -
    openssl
    +        
    +
    +
    +        
    +
    + + +
    + + + + +
    +
    +
    +
    + +
    + +

    Installation

    +
    +

    Using install.sh

    +
    +

    Note

    +

    This installer installs the BD DataService, CentralService, MongoDB, + InfluxDB + and Redis on the same machine.

    +
    +
      +
    1. Extract the package and cd into the folder**:

      +

      $ + tar -xzf buildingdepot-3.#.#.tar.gz

      +

      $ + cd buildingdepot-3.#.#/

      +
    2. +
    3. Run the installer

      +

      $ + ./install.sh

      +

      This will install BuildingDepot in the default installation location + /srv/buildingdepot + with the following directory structure:

      +
      +
      buildingdepot
      +|-- CentralService - CentralService
      +|-- DataService - DataService
      +|-- CentralReplica - The central replica that is present at every DataService
      ++-- venv - Python Virtual Environment
      +
      +
      +
      +
    4. +
    5. After installation please go the CentralService on port 81 of + your installation and create a DataService to start off with called “ds1”. If + you would like to use another name for your DataService do ensure that the name + is accordingly changed in the config.py file in the DataService folder.

      +
    6. +
    +
    +
    +

    What’s installed

    +
      +
    • The following packages are installed using apt-get

      +
      +
      openssl
       python-setuptools
       python-dev
       build-essential
      -python-software-properties
      +python-software-properties
       mongodb
       python-pip
       nginx
       supervisor
       redis-server
       influxdb
      -
      -
      -
    • -
    • The following packages are installed in the python virtual environment

      -
      Flask
      +
      +
      +
      +
    • +
    • The following packages are installed in the python virtual + environment

      +
      +
      Flask
       mongoengine
       flask-restful
       Flask-HTTPAuth
      @@ -231,99 +231,113 @@ 

      What’s installedredis influxdb pymongo -

      -
      -
    • -
    -
    -
    -
    -

    Configuration

    -

    The BD Installer configures BD with some default values.

    -

    The CentralService can be accessed on port 81 and the DataService on port 82.

    -
    -

    DataService

    -

    To access the DataService, go to

    -
    URL - http://<host>:82
    -
    -
    -
    -
    -

    CentralService

    -

    To access the CentralService, go to

    -
    URL - http://<host>:81
    -
    -
    -
    -
    +
    +
    +
    +
  • +
+
+
+
+ +

Configuration

+

The BD Installer configures BD with some default values.

+

The CentralService can be accessed on port 81 and the DataService on port 82.

+
+ +

DataService

+

To access the DataService, go to

+
+
URL - http://<host>:82
+
+
+
+
+
+ +

CentralService

+

To access the CentralService, go to

+
+
URL - http://<host>:81
+
+
+
+
+
+ + +
+
+ + +
+
+ - - -
- - - + -
-
-

- © Copyright 2020, SynergyLabs. + + + + -

-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. -
+ - - - + - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/buildingdepot/Documentation/build/html/search.html b/buildingdepot/Documentation/build/html/search.html index 15045efe..6bd51982 100755 --- a/buildingdepot/Documentation/build/html/search.html +++ b/buildingdepot/Documentation/build/html/search.html @@ -1,238 +1,198 @@ - - - - + + + - - - - - Search — BuildingDepot 3.2.9 documentation - + - - + - + Search — BuildingDepot 3.2.9 documentation - - - - + - - - - - + + + - - - - - - + - -
- +
+ +
- - + +
+
+
+
    +
  • Docs »
  • +
  • Search
  • +
  • +
  • +
+
+
+
+
-
+ -
    - -
  • Docs »
  • - -
  • Search
  • - - -
  • - -
  • - -
- -
-
-
-
- - - - -
- -
- -
-
-
- - -
- -
-

- © Copyright 2020, SynergyLabs. - -

-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. - -
+
+ +
+ +
+
+
+ + +
+ +
+

+ © Copyright 2020, SynergyLabs. + +

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + +
+
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/buildingdepot/Documentation/build/html/source/index.html b/buildingdepot/Documentation/build/html/source/index.html index 345e4b7e..b11de22b 100644 --- a/buildingdepot/Documentation/build/html/source/index.html +++ b/buildingdepot/Documentation/build/html/source/index.html @@ -1,236 +1,203 @@ - - - - + + + - - - - - Welcome to BuildingDepot v3.2.9’s documentation! — BuildingDepot 3.2.9 documentation - + - - + - + Welcome to BuildingDepot v3.2.9’s documentation! — BuildingDepot 3.2.9 documentation - - - - + - - - - - + + + - - - - - - + - -
- +
+ +
- - + +
+
+
+ -
    - -
  • Docs »
  • - -
  • Welcome to BuildingDepot v3.2.9’s documentation!
  • - - -
  • - - - View page source - - -
  • - -
- -
-
-
-
- -
-

Welcome to BuildingDepot v3.2.9’s documentation!

-
-
-
-
-

Indices and tables

- -
+
+
+
+
+ +
+

Welcome to BuildingDepot v3.2.9’s documentation! +

+
+
+
+
+

Indices and tables

+ +
-
-
-
- +
+
+
-
-
-

- © Copyright 2020, SynergyLabs. +


-

-
- Built with Sphinx and ❤️ using a custom theme based on Read the Docs. +
+

+ © Copyright 2020, SynergyLabs. -

+

+
+ Built with Sphinx and ❤️ using a custom theme based on Read the Docs. + + +
- - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/source/conf.py b/buildingdepot/Documentation/source/conf.py index ed9fdf49..a547f616 100755 --- a/buildingdepot/Documentation/source/conf.py +++ b/buildingdepot/Documentation/source/conf.py @@ -7,15 +7,14 @@ # -- Project information ----------------------------------------------------- -project = 'BuildingDepot' -copyright = '2020, SynergyLabs' -author = 'SynergyLabs' +project = "BuildingDepot" +copyright = "2020, SynergyLabs" +author = "SynergyLabs" # The short X.Y version -version = '3.2.9' +version = "3.2.9" # The full version, including alpha/beta/rc tags -release = '3.2.9' - +release = "3.2.9" # -- General configuration --------------------------------------------------- @@ -27,21 +26,21 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.todo', - 'sphinx.ext.githubpages', + "sphinx.ext.todo", + "sphinx.ext.githubpages", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -53,11 +52,10 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path . -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' - +pygments_style = "sphinx" # -- Options for HTML output ------------------------------------------------- @@ -74,7 +72,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # Custom sidebar templates, must be a dictionary that maps document names # to template names. @@ -85,7 +83,8 @@ # 'searchbox.html']``. # # html_sidebars = {} -#---sphinx-themes----- -html_theme = 'neo_rtd_theme' +# ---sphinx-themes----- +html_theme = "neo_rtd_theme" import sphinx_theme + html_theme_path = [sphinx_theme.get_html_theme_path()] diff --git a/buildingdepot/Documentation/source/images/BuildingDepot.svg b/buildingdepot/Documentation/source/images/BuildingDepot.svg index 75024beb..b3087e2b 100644 --- a/buildingdepot/Documentation/source/images/BuildingDepot.svg +++ b/buildingdepot/Documentation/source/images/BuildingDepot.svg @@ -1 +1,392 @@ - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/source/images/CSComponents.svg b/buildingdepot/Documentation/source/images/CSComponents.svg index 6d99d886..ef24e5c7 100644 --- a/buildingdepot/Documentation/source/images/CSComponents.svg +++ b/buildingdepot/Documentation/source/images/CSComponents.svg @@ -1 +1,70 @@ - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/source/images/DSComponents.svg b/buildingdepot/Documentation/source/images/DSComponents.svg index a17b8174..cc3e5949 100644 --- a/buildingdepot/Documentation/source/images/DSComponents.svg +++ b/buildingdepot/Documentation/source/images/DSComponents.svg @@ -1 +1,28 @@ - \ No newline at end of file + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/buildingdepot/Documentation/source/source/conf.py b/buildingdepot/Documentation/source/source/conf.py index 766b1226..40750f03 100644 --- a/buildingdepot/Documentation/source/source/conf.py +++ b/buildingdepot/Documentation/source/source/conf.py @@ -28,7 +28,6 @@ # The full version, including alpha/beta/rc tags release = "" - # -- General configuration --------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. @@ -67,7 +66,6 @@ # The name of the Pygments (syntax highlighting) style to use. pygments_style = "sphinx" - # -- Options for HTML output ------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for @@ -102,7 +100,6 @@ # Output file base name for HTML help builder. htmlhelp_basename = "BuildingDepotv329doc" - # -- Options for LaTeX output ------------------------------------------------ latex_elements = { @@ -133,7 +130,6 @@ ), ] - # -- Options for manual page output ------------------------------------------ # One entry per manual page. List of tuples @@ -148,7 +144,6 @@ ) ] - # -- Options for Texinfo output ---------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples diff --git a/buildingdepot/Documentation/source/source/index.rst b/buildingdepot/Documentation/source/source/index.rst index e9f61510..3f0f003e 100644 --- a/buildingdepot/Documentation/source/source/index.rst +++ b/buildingdepot/Documentation/source/source/index.rst @@ -1,7 +1,7 @@ .. BuildingDepot v3.2.9 documentation master file, created by - sphinx-quickstart on Mon Feb 24 20:13:25 2020. - You can adapt this file completely to your liking, but it should at least - contain the root `toctree` directive. +sphinx-quickstart on Mon Feb 24 20:13:25 2020. +You can adapt this file completely to your liking, but it should at least +contain the root `toctree` directive. Welcome to BuildingDepot v3.2.9's documentation! ================================================ diff --git a/buildingdepot/Instrumentation/comment.py b/buildingdepot/Instrumentation/comment.py index 27842a45..8601428b 100644 --- a/buildingdepot/Instrumentation/comment.py +++ b/buildingdepot/Instrumentation/comment.py @@ -7,10 +7,10 @@ filename = sys.argv[1] -f = open(filename, 'rb') +f = open(filename, "rb") for line in f: - if line == '@instrument\n': - print("# " + line, end=' ') - else: - print(line, end=' ') \ No newline at end of file + if line == "@instrument\n": + print("# " + line, end=" ") + else: + print(line, end=" ") diff --git a/buildingdepot/Instrumentation/instrument.py b/buildingdepot/Instrumentation/instrument.py index ae4292cc..2285708c 100644 --- a/buildingdepot/Instrumentation/instrument.py +++ b/buildingdepot/Instrumentation/instrument.py @@ -15,11 +15,11 @@ """ import _thread -import time -from functools import wraps -import traceback import os import random +import time +import traceback +from functools import wraps global process_unique_id global seq_dict @@ -30,7 +30,7 @@ beginningOfTime = time.time() # Location of file where the instrumentation logs will be written to -logfile = '/srv/buildingdepot/Instrumentation/instrument.csv' +logfile = "/srv/buildingdepot/Instrumentation/instrument.csv" # Toggle for enabling/disabling instrumentation enable_instrumentation = True @@ -39,17 +39,18 @@ # that only 70% of the logs are collected (uniformly randomly) and rest are dropped. sampling_rate = 1 - """A unique ID needs to be generated for every request so that all the calls made by it can be tracked sequentially. The unique ID is generated using a Cantor pairing function. """ + + def compute_request_id(): global process_unique_id pid = os.getpid() # Using Cantor pairing function val = process_unique_id + pid - request_id = process_unique_id + (((val)*(val + 1))/2) + request_id = process_unique_id + (((val) * (val + 1)) / 2) return str(request_id) @@ -75,25 +76,26 @@ def func_wrapper(*args, **kwargs): seq_dict[request_id] = seq + 1 # Time the function execution - start = (time.time() - beginningOfTime)*1000 + start = (time.time() - beginningOfTime) * 1000 ret = func(*args, **kwargs) - end = (time.time() - beginningOfTime)*1000 - + end = (time.time() - beginningOfTime) * 1000 + # Format the log string logString = request_id + "," + str(seq) + "," + func.__name__ + "," - for i in range(0,seq): + for i in range(0, seq): logString = "\t" + logString - logString = logString + "%0.2f,%0.2f,%0.2f\n" % (start, end, end-start) + logString = logString + "%0.2f,%0.2f,%0.2f\n" % (start, end, end - start) logs.append(logString) # Flush logs to file if seq == 0: logs = sorted(logs, key=lambda str: str.strip()) - with open(logfile, 'a') as file: + with open(logfile, "a") as file: for item in logs: file.write(item) del logs[:] return ret + return func_wrapper diff --git a/buildingdepot/Instrumentation/logSummarizer.py b/buildingdepot/Instrumentation/logSummarizer.py index b9c401e7..dd2ec06f 100644 --- a/buildingdepot/Instrumentation/logSummarizer.py +++ b/buildingdepot/Instrumentation/logSummarizer.py @@ -7,7 +7,7 @@ import sys filename = sys.argv[1] -averages = {} # Mapping between function and total time taken + elements seen +averages = {} # Mapping between function and total time taken + elements seen """ LOG FORMAT (comma separated): @@ -18,21 +18,28 @@ """ -f = open(filename, 'rb') +f = open(filename, "rb") reader = csv.reader(f) logs = list(reader) for log in logs: - if log[2] in list(averages.keys()): - averages[log[2]][0] += float(log[5]) - averages[log[2]][1] += 1 - else: - averages[log[2]] = [float(log[5]), 1] + if log[2] in list(averages.keys()): + averages[log[2]][0] += float(log[5]) + averages[log[2]][1] += 1 + else: + averages[log[2]] = [float(log[5]), 1] print("\nAVERAGES FOR TIME TAKEN (Function wise): ") for key, value in list(averages.items()): - print((" " + key + "(): " + str(value[0]/value[1]) + "ms (" + str(value[1]) + " calls)")) + print( + ( + " " + + key + + "(): " + + str(value[0] / value[1]) + + "ms (" + + str(value[1]) + + " calls)" + ) + ) print() - - - diff --git a/buildingdepot/Instrumentation/uncomment.py b/buildingdepot/Instrumentation/uncomment.py index 349d0e89..eae34367 100644 --- a/buildingdepot/Instrumentation/uncomment.py +++ b/buildingdepot/Instrumentation/uncomment.py @@ -7,10 +7,10 @@ filename = sys.argv[1] -f = open(filename, 'rb') +f = open(filename, "rb") for line in f: - if line == '# @instrument\n': - print("@instrument\n", end=' ') - else: - print(line, end=' ') \ No newline at end of file + if line == "# @instrument\n": + print("@instrument\n", end=" ") + else: + print(line, end=" ") diff --git a/configs/uwsgi_cs.ini b/configs/uwsgi_cs.ini index ed8e1bf2..bcf3267c 100755 --- a/configs/uwsgi_cs.ini +++ b/configs/uwsgi_cs.ini @@ -1,20 +1,20 @@ [uwsgi] -socket=/var/sockets/cs.sock -pyhome=/srv/buildingdepot/venv -pythonpath=/srv/buildingdepot -pythonpath=/srv/buildingdepot/CentralService -module=CentralService:app -workers=32 +socket = /var/sockets/cs.sock +pyhome = /srv/buildingdepot/venv +pythonpath = /srv/buildingdepot +pythonpath = /srv/buildingdepot/CentralService +module = CentralService:app +workers = 32 cheaper = 4 cheaper-step = 4 -master=true -chmod=666 -harakiri=30 -post-buffering=4096 +master = true +chmod = 666 +harakiri = 30 +post-buffering = 4096 -logto=/var/log/buildingdepot/CentralService/uwsgi-app.log -log-maxsize=1000000000 -disable-logging=false +logto = /var/log/buildingdepot/CentralService/uwsgi-app.log +log-maxsize = 1000000000 +disable-logging = false -env=CS_SETTINGS=/srv/buildingdepot/CentralService/cs_config -env=BD=/srv/buildingdepot/ +env = CS_SETTINGS=/srv/buildingdepot/CentralService/cs_config +env = BD=/srv/buildingdepot/ diff --git a/configs/uwsgi_ds.ini b/configs/uwsgi_ds.ini index 28033ce6..87e59ff9 100755 --- a/configs/uwsgi_ds.ini +++ b/configs/uwsgi_ds.ini @@ -1,20 +1,20 @@ [uwsgi] -socket=/var/sockets/ds.sock -pyhome=/srv/buildingdepot/venv -pythonpath=/srv/buildingdepot -pythonpath=/srv/buildingdepot/DataService -module=DataService:app -workers=32 +socket = /var/sockets/ds.sock +pyhome = /srv/buildingdepot/venv +pythonpath = /srv/buildingdepot +pythonpath = /srv/buildingdepot/DataService +module = DataService:app +workers = 32 cheaper = 4 cheaper-step = 4 -master=true -chmod=666 -harakiri=30 -post-buffering=4096 +master = true +chmod = 666 +harakiri = 30 +post-buffering = 4096 -logto=/var/log/buildingdepot/DataService/uwsgi-app.log -log-maxsize=1000000000 -disable-logging=false +logto = /var/log/buildingdepot/DataService/uwsgi-app.log +log-maxsize = 1000000000 +disable-logging = false -env=DS_SETTINGS=/srv/buildingdepot/DataService/ds_config -env=BD=/srv/buildingdepot/ +env = DS_SETTINGS=/srv/buildingdepot/DataService/ds_config +env = BD=/srv/buildingdepot/ diff --git a/install.sh b/install.sh index 6fc78e5e..9e717a33 100755 --- a/install.sh +++ b/install.sh @@ -8,8 +8,8 @@ DEPLOY_DS=true # Check and make sure we are running as root or sudo (?) ################################################################################ if [[ $UID -ne 0 ]]; then - echo -e "\n$0 must be run as root. Most functions require super-user priviledges!\n" - exit 1 + echo -e "\n$0 must be run as root. Most functions require super-user priviledges!\n" + exit 1 fi BD=/srv/buildingdepot/ @@ -22,336 +22,333 @@ mkdir -p /var/log/buildingdepot/CentralService mkdir -p /var/log/buildingdepot/DataService mkdir -p /var/sockets +function setup_venv() { + cp pip_packages.list $1 + cd $1 -function setup_venv { - cp pip_packages.list $1 - cd $1 + virtualenv ./venv + source venv/bin/activate - virtualenv ./venv - source venv/bin/activate + pip3 install --upgrade pip + pip3 install --upgrade setuptools + pip3 install --upgrade -r pip_packages.list - pip3 install --upgrade pip - pip3 install --upgrade setuptools - pip3 install --upgrade -r pip_packages.list + pip3 install --upgrade uWSGI + mkdir -p /etc/uwsgi/apps-available/ - pip3 install --upgrade uWSGI - mkdir -p /etc/uwsgi/apps-available/ - - echo "Would you like to use Google Firebase for your notification system? Please enter [y/n]" - read response - if [ "$response" == "Y" ] || [ "$response" == "y" ]; then - pip install "firebase-admin==2.18.0" - fi + echo "Would you like to use Google Firebase for your notification system? Please enter [y/n]" + read response + if [ "$response" == "Y" ] || [ "$response" == "y" ]; then + pip3 install "firebase-admin==4.5.0" + fi - deactivate - cd - + deactivate + cd - } # Deploy apps -function deploy_centralservice { - setup_venv /srv/buildingdepot/ - - #copy and untar new dataservice tarball - cp -r buildingdepot/CentralService /srv/buildingdepot/ - cp -r buildingdepot/DataService /srv/buildingdepot/ - cp -r buildingdepot/CentralReplica /srv/buildingdepot/ - cp -r buildingdepot/OAuth2Server /srv/buildingdepot/ - cp -r buildingdepot/Documentation /srv/buildingdepot/ - cd /srv/buildingdepot - # copy uwsgi files - cp configs/uwsgi_cs.ini /etc/uwsgi/apps-available/cs.ini - - # Create supervisor config - cp configs/supervisor-cs.conf /etc/supervisor/conf.d/ - - # Create supervisor config for central replica - cp configs/supervisor-replica.conf /etc/supervisor/conf.d/ - - # Create nginx config - rm -f /etc/nginx/sites-enabled/default +function deploy_centralservice() { + setup_venv /srv/buildingdepot/ + + #copy and untar new dataservice tarball + cp -r buildingdepot/CentralService /srv/buildingdepot/ + cp -r buildingdepot/DataService /srv/buildingdepot/ + cp -r buildingdepot/CentralReplica /srv/buildingdepot/ + cp -r buildingdepot/OAuth2Server /srv/buildingdepot/ + cp -r buildingdepot/Documentation /srv/buildingdepot/ + cd /srv/buildingdepot + # copy uwsgi files + cp configs/uwsgi_cs.ini /etc/uwsgi/apps-available/cs.ini + + # Create supervisor config + cp configs/supervisor-cs.conf /etc/supervisor/conf.d/ + + # Create supervisor config for central replica + cp configs/supervisor-replica.conf /etc/supervisor/conf.d/ + + # Create nginx config + rm -f /etc/nginx/sites-enabled/default } -function deploy_dataservice { - setup_venv /srv/buildingdepot/ +function deploy_dataservice() { + setup_venv /srv/buildingdepot/ - cd /srv/buildingdepot + cd /srv/buildingdepot - # copy uwsgi files - cp configs/uwsgi_ds.ini /etc/uwsgi/apps-available/ds.ini + # copy uwsgi files + cp configs/uwsgi_ds.ini /etc/uwsgi/apps-available/ds.ini - # Create supervisor config - cp configs/supervisor-ds.conf /etc/supervisor/conf.d/ + # Create supervisor config + cp configs/supervisor-ds.conf /etc/supervisor/conf.d/ - # Create nginx config - rm -f /etc/nginx/sites-enabled/default + # Create nginx config + rm -f /etc/nginx/sites-enabled/default } - -function joint_deployment_fix { - # Create join nginx config - rm -f /etc/nginx/sites-enabled/default - cd /srv/buildingdepot - #Setting up SSL - echo "Do you have a SSL certificate and key that you would like to use? Please enter [y/n]" - read response - #If user already has certificate - if [ "$response" == "Y" ] || [ "$response" == "y" ]; then - echo "Please enter the path to the certificate:" - read cert_path - sed -i "s||$cert_path|g" /srv/buildingdepot/configs/together_ssl.conf - echo "Please enter the path to the key:" - read key_path - sed -i "s||$key_path|g" /srv/buildingdepot/configs/together_ssl.conf - echo "Please enter the ip address or the domain name of this installation" - read domain - sed -i "s||$domain|g" /srv/buildingdepot/configs/together_ssl.conf - cp configs/together_ssl.conf /etc/nginx/sites-available/together.conf - else - cp configs/together.conf /etc/nginx/sites-available/together.conf - fi - ln -sf /etc/nginx/sites-available/together.conf /etc/nginx/sites-enabled/together.conf +function joint_deployment_fix() { + # Create join nginx config + rm -f /etc/nginx/sites-enabled/default + cd /srv/buildingdepot + #Setting up SSL + echo "Do you have a SSL certificate and key that you would like to use? Please enter [y/n]" + read response + #If user already has certificate + if [ "$response" == "Y" ] || [ "$response" == "y" ]; then + echo "Please enter the path to the certificate:" + read cert_path + sed -i "s||$cert_path|g" /srv/buildingdepot/configs/together_ssl.conf + echo "Please enter the path to the key:" + read key_path + sed -i "s||$key_path|g" /srv/buildingdepot/configs/together_ssl.conf + echo "Please enter the ip address or the domain name of this installation" + read domain + sed -i "s||$domain|g" /srv/buildingdepot/configs/together_ssl.conf + cp configs/together_ssl.conf /etc/nginx/sites-available/together.conf + else + cp configs/together.conf /etc/nginx/sites-available/together.conf + fi + ln -sf /etc/nginx/sites-available/together.conf /etc/nginx/sites-enabled/together.conf } -function deploy_config { - cp -r configs/ /srv/buildingdepot - mkdir /var/sockets +function deploy_config() { + cp -r configs/ /srv/buildingdepot + mkdir /var/sockets } -function install_packages { - apt-get install -y curl - apt-get install -y apt-transport-https - source /etc/lsb-release - - - #Add keys for rabbitmq - echo "deb https://dl.bintray.com/rabbitmq/debian ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list - echo "deb https://dl.bintray.com/rabbitmq-erlang/debian ${DISTRIB_CODENAME} erlang" | sudo tee -a /etc/apt/sources.list.d/bintray.rabbitmq.list - wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - - # Add keys to install influxdb - curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - - echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list - # Add keys to install mongodb - wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add - - if [ $DISTRIB_CODENAME == "bionic" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list - elif [ $DISTRIB_CODENAME == "xenial" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list - elif [ $DISTRIB_CODENAME == "trusty" ]; then - echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list - fi - apt-get update -y - apt-get install - apt-get -y install python3-pip - apt-get install -y mongodb-org=4.0.5 mongodb-org-server=4.0.5 mongodb-org-shell=4.0.5 mongodb-org-mongos=4.0.5 mongodb-org-tools=4.0.5 - apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common - apt-get install -y nginx - apt-get install -y supervisor - apt-get install -y redis-server - pip3 install --upgrade virtualenv - apt-get install -y wget - apt-get install -y influxdb - service influxdb start - service mongod start - apt-get install -y rabbitmq-server - apt-get install -y nodejs - apt-get install -y npm - sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf - service postfix restart - systemctl enable mongod.service +function install_packages() { + apt-get install -y curl + apt-get install -y apt-transport-https + source /etc/lsb-release + + #Add keys for rabbitmq + echo "deb https://dl.bintray.com/rabbitmq/debian ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list + echo "deb https://dl.bintray.com/rabbitmq-erlang/debian ${DISTRIB_CODENAME} erlang" | sudo tee -a /etc/apt/sources.list.d/bintray.rabbitmq.list + wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - + # Add keys to install influxdb + curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - + echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list + # Add keys to install mongodb + wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add - + if [ $DISTRIB_CODENAME == "bionic" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list + elif [ $DISTRIB_CODENAME == "xenial" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list + elif [ $DISTRIB_CODENAME == "trusty" ]; then + echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list + fi + apt-get update -y + apt-get install + apt-get -y install python3-pip + apt-get install -y mongodb-org=4.0.5 mongodb-org-server=4.0.5 mongodb-org-shell=4.0.5 mongodb-org-mongos=4.0.5 mongodb-org-tools=4.0.5 + apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common + apt-get install -y nginx + apt-get install -y supervisor + apt-get install -y redis-server + pip3 install --upgrade virtualenv + apt-get install -y wget + apt-get install -y influxdb + service influxdb start + service mongod start + apt-get install -y rabbitmq-server + apt-get install -y nodejs + apt-get install -y npm + sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf + service postfix restart + systemctl enable mongod.service } -function setup_gmail { - echo "Please register an app in your Google API manager, generate an OAuth token and refresh token" - echo "For more details refer to this url: https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough" - echo "Please enter your Gmail id" - read email_id - echo "Please enter your client id" - read client_id - echo "Please enter your client secret" - read client_secret - echo "Please enter access token" - read access_token - echo "Please enter refresh token" - read refresh_token - echo "EMAIL = 'GMAIL'" >> $BD/CentralService/cs_config - echo "EMAIL_ID = '$email_id'" >> $BD/CentralService/cs_config - echo "ACCESS_TOKEN = '$access_token'" >> $BD/CentralService/cs_config - echo "REFRESH_TOKEN = '$refresh_token'" >> $BD/CentralService/cs_config - echo "CLIENT_ID = '$client_id'" >> $BD/CentralService/cs_config - echo "CLIENT_SECRET = '$client_secret'" >> $BD/CentralService/cs_config +function setup_gmail() { + echo "Please register an app in your Google API manager, generate an OAuth token and refresh token" + echo "For more details refer to this url: https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough" + echo "Please enter your Gmail id" + read email_id + echo "Please enter your client id" + read client_id + echo "Please enter your client secret" + read client_secret + echo "Please enter access token" + read access_token + echo "Please enter refresh token" + read refresh_token + echo "EMAIL = 'GMAIL'" >>$BD/CentralService/cs_config + echo "EMAIL_ID = '$email_id'" >>$BD/CentralService/cs_config + echo "ACCESS_TOKEN = '$access_token'" >>$BD/CentralService/cs_config + echo "REFRESH_TOKEN = '$refresh_token'" >>$BD/CentralService/cs_config + echo "CLIENT_ID = '$client_id'" >>$BD/CentralService/cs_config + echo "CLIENT_SECRET = '$client_secret'" >>$BD/CentralService/cs_config } -function setup_email { - echo "BuildingDepot requires a Mail Transfer Agent. Would you like to install one or use your gmail account?" - echo "Note: If you use GMail, it is advised to create a new account for this purpose." - echo "Enter Y to install an MTA and N to use your GMail account." - read response - if [ "$response" == "Y" ] || [ "$response" == "y" ]; then - sudo apt-get install -y mailutils - sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf - service postfix restart - while true; do - echo "Please enter email address to send test mail:" - read email_id - n=$(od -An -N2 -i /dev/random) - echo $n | mail -s "Test email from BuildingDepot" $email_id - echo "Please enter the number you received in the mail" - read input - if [ $input == $n ]; then - echo "EMAIL = 'LOCAL'" >> $BD/CentralService/cs_config - echo "EMAIL_ID = 'admin@buildingdepot.org'" >> $BD/CentralService/cs_config - break - else - echo "Verification failed. Enter R to retry, Y to use GMail" - read response - if [ "$response" == "R" ] || [ "$response" == "r" ]; then - continue - elif [ "$response" == 'Y' ] || [ "$response" == 'y' ]; then - setup_gmail - break - else - echo "Invalid input! Exiting!" - exit - fi - fi - done - else - setup_gmail - fi +function setup_email() { + echo "BuildingDepot requires a Mail Transfer Agent. Would you like to install one or use your gmail account?" + echo "Note: If you use GMail, it is advised to create a new account for this purpose." + echo "Enter Y to install an MTA and N to use your GMail account." + read response + if [ "$response" == "Y" ] || [ "$response" == "y" ]; then + sudo apt-get install -y mailutils + sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf + service postfix restart + while true; do + echo "Please enter email address to send test mail:" + read email_id + n=$(od -An -N2 -i /dev/random) + echo $n | mail -s "Test email from BuildingDepot" $email_id + echo "Please enter the number you received in the mail" + read input + if [ $input == $n ]; then + echo "EMAIL = 'LOCAL'" >>$BD/CentralService/cs_config + echo "EMAIL_ID = 'admin@buildingdepot.org'" >>$BD/CentralService/cs_config + break + else + echo "Verification failed. Enter R to retry, Y to use GMail" + read response + if [ "$response" == "R" ] || [ "$response" == "r" ]; then + continue + elif [ "$response" == 'Y' ] || [ "$response" == 'y' ]; then + setup_gmail + break + else + echo "Invalid input! Exiting!" + exit + fi + fi + done + else + setup_gmail + fi } -function setup_notifications { - echo "BuildingDepot uses notifications to alert users or systems of events in real-time. By default, " - echo "BuildingDepot uses RabbitMQ to deliver messages but we also support Google Firebase Cloud Messaging (FCM), " - echo "which allows BuildingDepot to send push notifications to mobile users." - echo "Would you like to use Google FCM?" - echo "Enter Y to use Google FCM and N to use RabbitMQ" +function setup_notifications() { + echo "BuildingDepot uses notifications to alert users or systems of events in real-time. By default, " + echo "BuildingDepot uses RabbitMQ to deliver messages but we also support Google Firebase Cloud Messaging (FCM), " + echo "which allows BuildingDepot to send push notifications to mobile users." + echo "Would you like to use Google FCM?" + echo "Enter Y to use Google FCM and N to use RabbitMQ" + read response + if [ "$response" == "Y" ] || [ "$response" == "y" ]; then + echo "Please provide the absolute path of where your Service Account JSON file is, which contains the keys for your FCM project." read response - if [ "$response" == "Y" ] || [ "$response" == "y" ]; then - echo "Please provide the absolute path of where your Service Account JSON file is, which contains the keys for your FCM project." - read response - if [ ! -z "$response" ]; then - echo "NOTIFICATION_TYPE = 'FIREBASE'" >> $BD/CentralService/cs_config - echo "FIREBASE_CREDENTIALS = '$response'" >> $BD/CentralService/cs_config - fi + if [ ! -z "$response" ]; then + echo "NOTIFICATION_TYPE = 'FIREBASE'" >>$BD/CentralService/cs_config + echo "FIREBASE_CREDENTIALS = '$response'" >>$BD/CentralService/cs_config fi + fi } -function setup_packages { +function setup_packages() { + + echo + echo "Securing BD Packages" + echo "--------------------" + echo "Enter Y to auto-generate credentials for packages (MongoDB,InfluxDB & Redis). Credentials are stored in cs_config file (or) Enter N to input individual package credentials" + read response + if [ "$response" == "Y" ] || [ "$response" == "y" ]; then + ## Add MongoDB Admin user + mongoUsername=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) + mongoPassword=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) + echo "MONGODB_USERNAME = '$mongoUsername'" >>$BD/CentralService/cs_config + echo "MONGODB_PWD = '$mongoPassword'" >>$BD/CentralService/cs_config + echo "MONGODB_USERNAME = '$mongoUsername'" >>$BD/DataService/ds_config + echo "MONGODB_PWD = '$mongoPassword'" >>$BD/DataService/ds_config + echo " MONGODB_USERNAME = '$mongoUsername'" >>$BD/CentralReplica/config.py + echo " MONGODB_PWD = '$mongoPassword'" >>$BD/CentralReplica/config.py + mongo --eval "db.getSiblingDB('admin').createUser({user:'$mongoUsername',pwd:'$mongoPassword',roles:['userAdminAnyDatabase','dbAdminAnyDatabase','readWriteAnyDatabase']})" + # Enable MongoDB authorization + echo "security:" >>/etc/mongod.conf + echo " authorization: \"enabled\"" >>/etc/mongod.conf + service mongod restart + + sleep 2 + + ## Add InfluxDB Admin user + influxUsername=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) + influxPassword=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) + echo "INFLUXDB_USERNAME = '$influxUsername'" >>$BD/DataService/ds_config + echo "INFLUXDB_PWD = '$influxPassword'" >>$BD/DataService/ds_config + sleep 1 + curl -d "q=CREATE USER $influxUsername WITH PASSWORD '$influxPassword' WITH ALL PRIVILEGES" -X POST http://localhost:8086/query + sed -ir 's/# auth-enabled = false/auth-enabled = true/g' /etc/influxdb/influxdb.conf + service influxdb restart + + sleep 2 + + ## Add Redis Admin user + redisPassword=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1) + echo "REDIS_PWD = '$redisPassword'" >>$BD/CentralService/cs_config + echo "REDIS_PWD = '$redisPassword'" >>$BD/DataService/ds_config + echo " REDIS_PWD = '$redisPassword'" >>$BD/CentralReplica/config.py + sed -i -e '/#.* requirepass / s/.*/ requirepass '$redisPassword'/' /etc/redis/redis.conf + service redis restart echo - echo "Securing BD Packages" - echo "--------------------" - echo "Enter Y to auto-generate credentials for packages (MongoDB,InfluxDB & Redis). Credentials are stored in cs_config file (or) Enter N to input individual package credentials" - read response - if [ "$response" == "Y" ] || [ "$response" == "y" ]; then - ## Add MongoDB Admin user - mongoUsername=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) - mongoPassword=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) - echo "MONGODB_USERNAME = '$mongoUsername'" >> $BD/CentralService/cs_config - echo "MONGODB_PWD = '$mongoPassword'" >> $BD/CentralService/cs_config - echo "MONGODB_USERNAME = '$mongoUsername'" >> $BD/DataService/ds_config - echo "MONGODB_PWD = '$mongoPassword'" >> $BD/DataService/ds_config - echo " MONGODB_USERNAME = '$mongoUsername'" >> $BD/CentralReplica/config.py - echo " MONGODB_PWD = '$mongoPassword'" >> $BD/CentralReplica/config.py - mongo --eval "db.getSiblingDB('admin').createUser({user:'$mongoUsername',pwd:'$mongoPassword',roles:['userAdminAnyDatabase','dbAdminAnyDatabase','readWriteAnyDatabase']})" - # Enable MongoDB authorization - echo "security:" >> /etc/mongod.conf - echo " authorization: \"enabled\"">> /etc/mongod.conf - service mongod restart - - sleep 2 - - ## Add InfluxDB Admin user - influxUsername=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1) - influxPassword=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) - echo "INFLUXDB_USERNAME = '$influxUsername'">> $BD/DataService/ds_config - echo "INFLUXDB_PWD = '$influxPassword'">> $BD/DataService/ds_config - sleep 1 - curl -d "q=CREATE USER $influxUsername WITH PASSWORD '$influxPassword' WITH ALL PRIVILEGES" -X POST http://localhost:8086/query - sed -ir 's/# auth-enabled = false/auth-enabled = true/g' /etc/influxdb/influxdb.conf - service influxdb restart - - sleep 2 - - ## Add Redis Admin user - redisPassword=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 64 | head -n 1) - echo "REDIS_PWD = '$redisPassword'">> $BD/CentralService/cs_config - echo "REDIS_PWD = '$redisPassword'">> $BD/DataService/ds_config - echo " REDIS_PWD = '$redisPassword'" >> $BD/CentralReplica/config.py - sed -i -e '/#.* requirepass / s/.*/ requirepass '$redisPassword'/' /etc/redis/redis.conf - service redis restart - - echo - echo "Auto-Generated User Credentials for BuildingDepot Packages [MongoDB,InfluxDB & Redis]" - echo - - elif [ "$response" == 'N' ] || [ "$response" == 'n' ]; then - ## Add MongoDB Admin user - echo "Enter MongoDB Username: " - read mongoUsername - echo "Enter MongoDB Password: " - read -s mongoPassword - echo "MONGODB_USERNAME = '$mongoUsername'" >> $BD/CentralService/cs_config - echo "MONGODB_PWD = '$mongoPassword'" >> $BD/CentralService/cs_config - echo "MONGODB_USERNAME = '$mongoUsername'" >> $BD/DataService/ds_config - echo "MONGODB_PWD = '$mongoPassword'" >> $BD/DataService/ds_config - echo " MONGODB_USERNAME = '$mongoUsername'" >> $BD/CentralReplica/config.py - echo " MONGODB_PWD = '$mongoPassword'" >> $BD/CentralReplica/config.py - mongo --eval "db.getSiblingDB('admin').createUser({user:'$mongoUsername',pwd:'$mongoPassword',roles:['userAdminAnyDatabase','dbAdminAnyDatabase','readWriteAnyDatabase']})" - # Enable MongoDB authorization - echo "security:" >> /etc/mongod.conf - echo " authorization: \"enabled\"">> /etc/mongod.conf - service mongod restart - - sleep 2 - - ## Add InfluxDB Admin user - echo - echo "Enter InfluxDB Username: " - read influxUsername - echo "Enter InfluxDB Password: " - read -s influxPassword - echo "INFLUXDB_USERNAME = '$influxUsername'">> $BD/DataService/ds_config - echo "INFLUXDB_PWD = '$influxPassword'">> $BD/DataService/ds_config - sleep 1 - curl -d "q=CREATE USER $influxUsername WITH PASSWORD '$influxPassword' WITH ALL PRIVILEGES" -X POST http://localhost:8086/query - sed -ir 's/# auth-enabled = false/auth-enabled = true/g' /etc/influxdb/influxdb.conf - service influxdb restart - - sleep 2 - - ## Add Redis Admin user - echo - echo "Enter Redis Username: " - read redisUsername - echo "Enter Redis Password: " - read -s redisPassword - echo "REDIS_PWD = '$redisPassword'">> $BD/CentralService/cs_config - echo "REDIS_PWD = '$redisPassword'">> $BD/DataService/ds_config - echo " REDIS_PWD = '$redisPassword'" >> $BD/CentralReplica/config.py - sed -i -e '/#.* requirepass / s/.*/ requirepass '$redisPassword'/' /etc/redis/redis.conf - service redis restart - - echo - echo "Saved User Credentials for BuildingDepot Packages" - echo - - else - echo - echo "Invalid option please Try again." - setup_packages - fi + echo "Auto-Generated User Credentials for BuildingDepot Packages [MongoDB,InfluxDB & Redis]" + echo + + elif [ "$response" == 'N' ] || [ "$response" == 'n' ]; then + ## Add MongoDB Admin user + echo "Enter MongoDB Username: " + read mongoUsername + echo "Enter MongoDB Password: " + read -s mongoPassword + echo "MONGODB_USERNAME = '$mongoUsername'" >>$BD/CentralService/cs_config + echo "MONGODB_PWD = '$mongoPassword'" >>$BD/CentralService/cs_config + echo "MONGODB_USERNAME = '$mongoUsername'" >>$BD/DataService/ds_config + echo "MONGODB_PWD = '$mongoPassword'" >>$BD/DataService/ds_config + echo " MONGODB_USERNAME = '$mongoUsername'" >>$BD/CentralReplica/config.py + echo " MONGODB_PWD = '$mongoPassword'" >>$BD/CentralReplica/config.py + mongo --eval "db.getSiblingDB('admin').createUser({user:'$mongoUsername',pwd:'$mongoPassword',roles:['userAdminAnyDatabase','dbAdminAnyDatabase','readWriteAnyDatabase']})" + # Enable MongoDB authorization + echo "security:" >>/etc/mongod.conf + echo " authorization: \"enabled\"" >>/etc/mongod.conf + service mongod restart + + sleep 2 + + ## Add InfluxDB Admin user + echo + echo "Enter InfluxDB Username: " + read influxUsername + echo "Enter InfluxDB Password: " + read -s influxPassword + echo "INFLUXDB_USERNAME = '$influxUsername'" >>$BD/DataService/ds_config + echo "INFLUXDB_PWD = '$influxPassword'" >>$BD/DataService/ds_config + sleep 1 + curl -d "q=CREATE USER $influxUsername WITH PASSWORD '$influxPassword' WITH ALL PRIVILEGES" -X POST http://localhost:8086/query + sed -ir 's/# auth-enabled = false/auth-enabled = true/g' /etc/influxdb/influxdb.conf + service influxdb restart + + sleep 2 + + ## Add Redis Admin user + echo + echo "Enter Redis Username: " + read redisUsername + echo "Enter Redis Password: " + read -s redisPassword + echo "REDIS_PWD = '$redisPassword'" >>$BD/CentralService/cs_config + echo "REDIS_PWD = '$redisPassword'" >>$BD/DataService/ds_config + echo " REDIS_PWD = '$redisPassword'" >>$BD/CentralReplica/config.py + sed -i -e '/#.* requirepass / s/.*/ requirepass '$redisPassword'/' /etc/redis/redis.conf + service redis restart + + echo + echo "Saved User Credentials for BuildingDepot Packages" + echo + + else + echo + echo "Invalid option please Try again." + setup_packages + fi } deploy_config install_packages if [ "$DEPLOY_CS" = true ]; then - deploy_centralservice + deploy_centralservice fi if [ "$DEPLOY_DS" = true ]; then - deploy_dataservice + deploy_dataservice fi service mongod start @@ -361,10 +358,9 @@ sleep 5 supervisorctl restart all service influxdb start - if [ "$DEPLOY_TOGETHER" = true ]; then - joint_deployment_fix - service nginx restart + joint_deployment_fix + service nginx restart fi rm -rf configs @@ -373,7 +369,6 @@ popd setup_email setup_notifications - # Create Database on InfluxDB curl -d "q=CREATE DATABASE buildingdepot" -X POST http://localhost:8086/query setup_packages diff --git a/license.txt b/license.txt index 6a24a904..cf76ad96 100644 --- a/license.txt +++ b/license.txt @@ -1,5 +1,5 @@ Copyright (c) 2015-2016, Carnegie Mellon University - & + & Copyright (c) 2013-2016, The Regents of the University of California All rights reserved. diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index e7ccfd3d..9045054a 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -8,8 +8,8 @@ DEPLOY_DS=true # Check and make sure we are running as root or sudo (?) ################################################################################ if [[ $UID -ne 0 ]]; then - echo -e "\n$0 must be run as root. Most functions require super-user priviledges!\n" - exit 1 + echo -e "\n$0 must be run as root. Most functions require super-user priviledges!\n" + exit 1 fi BD=/srv/buildingdepot/ @@ -22,210 +22,207 @@ mkdir -p /var/log/buildingdepot/CentralService mkdir -p /var/log/buildingdepot/DataService mkdir -p /var/sockets +function setup_venv() { + cp pip_packages.list $1 + cd $1 -function setup_venv { - cp pip_packages.list $1 - cd $1 + virtualenv ./venv + source venv/bin/activate - virtualenv ./venv - source venv/bin/activate + pip3 install --upgrade pip + pip3 install --upgrade setuptools + pip3 install --upgrade -r pip_packages.list + pip install "firebase-admin==4.5.0" + pip3 install --upgrade uWSGI + mkdir -p /etc/uwsgi/apps-available/ - pip3 install --upgrade pip - pip3 install --upgrade setuptools - pip3 install --upgrade -r pip_packages.list - pip install "firebase-admin==4.5.0" - pip3 install --upgrade uWSGI - mkdir -p /etc/uwsgi/apps-available/ - - deactivate - cd - + deactivate + cd - } # Deploy apps -function deploy_centralservice { - setup_venv /srv/buildingdepot/ - - #copy and untar new dataservice tarball - cp -r buildingdepot/CentralService /srv/buildingdepot/ - cp -r buildingdepot/DataService /srv/buildingdepot/ - cp -r buildingdepot/CentralReplica /srv/buildingdepot/ - cp -r buildingdepot/Documentation /srv/buildingdepot/ - cd /srv/buildingdepot - # copy uwsgi files - cp configs/uwsgi_cs.ini /etc/uwsgi/apps-available/cs.ini - - # Create supervisor config - cp configs/supervisor-cs.conf /etc/supervisor/conf.d/ - - # Create supervisor config for central replica - cp configs/supervisor-replica.conf /etc/supervisor/conf.d/ - - # Create nginx config - rm -f /etc/nginx/sites-enabled/default +function deploy_centralservice() { + setup_venv /srv/buildingdepot/ + + #copy and untar new dataservice tarball + cp -r buildingdepot/CentralService /srv/buildingdepot/ + cp -r buildingdepot/DataService /srv/buildingdepot/ + cp -r buildingdepot/CentralReplica /srv/buildingdepot/ + cp -r buildingdepot/Documentation /srv/buildingdepot/ + cd /srv/buildingdepot + # copy uwsgi files + cp configs/uwsgi_cs.ini /etc/uwsgi/apps-available/cs.ini + + # Create supervisor config + cp configs/supervisor-cs.conf /etc/supervisor/conf.d/ + + # Create supervisor config for central replica + cp configs/supervisor-replica.conf /etc/supervisor/conf.d/ + + # Create nginx config + rm -f /etc/nginx/sites-enabled/default } -function deploy_dataservice { - setup_venv /srv/buildingdepot/ +function deploy_dataservice() { + setup_venv /srv/buildingdepot/ - cd /srv/buildingdepot + cd /srv/buildingdepot - # copy uwsgi files - cp configs/uwsgi_ds.ini /etc/uwsgi/apps-available/ds.ini + # copy uwsgi files + cp configs/uwsgi_ds.ini /etc/uwsgi/apps-available/ds.ini - # Create supervisor config - cp configs/supervisor-ds.conf /etc/supervisor/conf.d/ + # Create supervisor config + cp configs/supervisor-ds.conf /etc/supervisor/conf.d/ - # Create nginx config - rm -f /etc/nginx/sites-enabled/default + # Create nginx config + rm -f /etc/nginx/sites-enabled/default } - -function joint_deployment_fix { - # Create join nginx config - rm -f /etc/nginx/sites-enabled/default - cd /srv/buildingdepot - #Setting up SSL - echo "Skipping SSL configuration..." - #If user already has certificate - cp configs/together.conf /etc/nginx/sites-available/together.conf - ln -sf /etc/nginx/sites-available/together.conf /etc/nginx/sites-enabled/together.conf +function joint_deployment_fix() { + # Create join nginx config + rm -f /etc/nginx/sites-enabled/default + cd /srv/buildingdepot + #Setting up SSL + echo "Skipping SSL configuration..." + #If user already has certificate + cp configs/together.conf /etc/nginx/sites-available/together.conf + ln -sf /etc/nginx/sites-available/together.conf /etc/nginx/sites-enabled/together.conf } -function deploy_config { - cp -r configs/ /srv/buildingdepot - mkdir /var/sockets +function deploy_config() { + cp -r configs/ /srv/buildingdepot + mkdir /var/sockets } -function install_packages { - apt-get install -y curl - apt-get install -y apt-transport-https - source /etc/lsb-release - - - #Add keys for rabbitmq - echo "deb https://dl.bintray.com/rabbitmq/debian ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list - echo "deb https://dl.bintray.com/rabbitmq-erlang/debian ${DISTRIB_CODENAME} erlang" | sudo tee -a /etc/apt/sources.list.d/bintray.rabbitmq.list - wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - - # Add keys to install influxdb - curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - - echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list - # Add keys to install mongodb - wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add - - if [ $DISTRIB_CODENAME == "bionic" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list - elif [ $DISTRIB_CODENAME == "xenial" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list - elif [ $DISTRIB_CODENAME == "trusty" ]; then - echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list - fi - apt-get update -y - apt-get install - apt-get install -y python3-pip - apt-get install -y mongodb-org=4.0.5 mongodb-org-server=4.0.5 mongodb-org-shell=4.0.5 mongodb-org-mongos=4.0.5 mongodb-org-tools=4.0.5 - apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common - apt-get install -y nginx - apt-get install -y supervisor - apt-get install -y redis-server - pip3 install --upgrade virtualenv - apt-get install -y wget - apt-get install -y influxdb - service influxdb start - service mongod start - apt-get install -y rabbitmq-server - DEBIAN_FRONTEND=noninteractive apt-get install -y postfix - apt-get install -y nodejs - apt-get install -y npm - sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf - service postfix restart - systemctl enable mongod.service +function install_packages() { + apt-get install -y curl + apt-get install -y apt-transport-https + source /etc/lsb-release + + #Add keys for rabbitmq + echo "deb https://dl.bintray.com/rabbitmq/debian ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list + echo "deb https://dl.bintray.com/rabbitmq-erlang/debian ${DISTRIB_CODENAME} erlang" | sudo tee -a /etc/apt/sources.list.d/bintray.rabbitmq.list + wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - + # Add keys to install influxdb + curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - + echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list + # Add keys to install mongodb + wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add - + if [ $DISTRIB_CODENAME == "bionic" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list + elif [ $DISTRIB_CODENAME == "xenial" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list + elif [ $DISTRIB_CODENAME == "trusty" ]; then + echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list + fi + apt-get update -y + apt-get install + apt-get install -y python3-pip + apt-get install -y mongodb-org=4.0.5 mongodb-org-server=4.0.5 mongodb-org-shell=4.0.5 mongodb-org-mongos=4.0.5 mongodb-org-tools=4.0.5 + apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common + apt-get install -y nginx + apt-get install -y supervisor + apt-get install -y redis-server + pip3 install --upgrade virtualenv + apt-get install -y wget + apt-get install -y influxdb + service influxdb start + service mongod start + apt-get install -y rabbitmq-server + DEBIAN_FRONTEND=noninteractive apt-get install -y postfix + apt-get install -y nodejs + apt-get install -y npm + sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf + service postfix restart + systemctl enable mongod.service } -function setup_gmail { - echo "Please register an app in your Google API manager, generate an OAuth token and refresh token" - echo "For more details refer to this url: https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough" - echo "Please enter your Gmail id" - read email_id - echo "Please enter your client id" - read client_id - echo "Please enter your client secret" - read client_secret - echo "Please enter access token" - read access_token - echo "Please enter refresh token" - read refresh_token - echo "EMAIL = 'GMAIL'" >> $BD/CentralService/cs_config - echo "EMAIL_ID = '$email_id'" >> $BD/CentralService/cs_config - echo "ACCESS_TOKEN = '$access_token'" >> $BD/CentralService/cs_config - echo "REFRESH_TOKEN = '$refresh_token'" >> $BD/CentralService/cs_config - echo "CLIENT_ID = '$client_id'" >> $BD/CentralService/cs_config - echo "CLIENT_SECRET = '$client_secret'" >> $BD/CentralService/cs_config +function setup_gmail() { + echo "Please register an app in your Google API manager, generate an OAuth token and refresh token" + echo "For more details refer to this url: https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough" + echo "Please enter your Gmail id" + read email_id + echo "Please enter your client id" + read client_id + echo "Please enter your client secret" + read client_secret + echo "Please enter access token" + read access_token + echo "Please enter refresh token" + read refresh_token + echo "EMAIL = 'GMAIL'" >>$BD/CentralService/cs_config + echo "EMAIL_ID = '$email_id'" >>$BD/CentralService/cs_config + echo "ACCESS_TOKEN = '$access_token'" >>$BD/CentralService/cs_config + echo "REFRESH_TOKEN = '$refresh_token'" >>$BD/CentralService/cs_config + echo "CLIENT_ID = '$client_id'" >>$BD/CentralService/cs_config + echo "CLIENT_SECRET = '$client_secret'" >>$BD/CentralService/cs_config } -function setup_email { - echo "BuildingDepot requires a Mail Transfer Agent. Would you like to install one or use your gmail account?" - echo "Note: If you use GMail, it is advised to create a new account for this purpose." - echo "Installing an MTA..." - sudo apt-get install -y mailutils - sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf - service postfix restart - echo "EMAIL = 'LOCAL'" >> $BD/CentralService/cs_config - echo "EMAIL_ID = 'admin@buildingdepot.org'" >> $BD/CentralService/cs_config +function setup_email() { + echo "BuildingDepot requires a Mail Transfer Agent. Would you like to install one or use your gmail account?" + echo "Note: If you use GMail, it is advised to create a new account for this purpose." + echo "Installing an MTA..." + sudo apt-get install -y mailutils + sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf + service postfix restart + echo "EMAIL = 'LOCAL'" >>$BD/CentralService/cs_config + echo "EMAIL_ID = 'admin@buildingdepot.org'" >>$BD/CentralService/cs_config } -function setup_packages { - echo - echo "Securing BD Packages" - echo "--------------------" - echo "Auto-generating credentials for packages (MongoDB,InfluxDB & Redis)..." - ## Add MongoDB Admin user - mongoUsername="user$(openssl rand -hex 16)" - mongoPassword=$(openssl rand -hex 32) - echo "MONGODB_USERNAME = '$mongoUsername'" >> $BD/CentralService/cs_config - echo "MONGODB_PWD = '$mongoPassword'" >> $BD/CentralService/cs_config - echo "MONGODB_USERNAME = '$mongoUsername'" >> $BD/DataService/ds_config - echo "MONGODB_PWD = '$mongoPassword'" >> $BD/DataService/ds_config - echo " MONGODB_USERNAME = '$mongoUsername'" >> $BD/CentralReplica/config.py - echo " MONGODB_PWD = '$mongoPassword'" >> $BD/CentralReplica/config.py - mongo --eval "db.getSiblingDB('admin').createUser({user:'$mongoUsername',pwd:'$mongoPassword',roles:['userAdminAnyDatabase','dbAdminAnyDatabase','readWriteAnyDatabase']})" - # Enable MongoDB authorization - echo "security:" >> /etc/mongod.conf - echo " authorization: \"enabled\"">> /etc/mongod.conf - service mongod restart - - sleep 2 - - ## Add InfluxDB Admin user - influxUsername="user$(openssl rand -hex 16)" - influxPassword=$(openssl rand -hex 32) - echo "INFLUXDB_USERNAME = '$influxUsername'">> $BD/DataService/ds_config - echo "INFLUXDB_PWD = '$influxPassword'">> $BD/DataService/ds_config - sleep 1 - curl -d "q=CREATE USER $influxUsername WITH PASSWORD '$influxPassword' WITH ALL PRIVILEGES" -X POST http://localhost:8086/query - sed -ir 's/# auth-enabled = false/auth-enabled = true/g' /etc/influxdb/influxdb.conf - service influxdb restart - - sleep 2 - - ## Add Redis Admin user - redisPassword=$(openssl rand -hex 64) - echo "REDIS_PWD = '$redisPassword'">> $BD/CentralService/cs_config - echo "REDIS_PWD = '$redisPassword'">> $BD/DataService/ds_config - echo " REDIS_PWD = '$redisPassword'" >> $BD/CentralReplica/config.py - sed -i -e '/#.* requirepass / s/.*/ requirepass '$redisPassword'/' /etc/redis/redis.conf - service redis restart - - echo - echo "Auto-Generated User Credentials for BuildingDepot Packages [MongoDB,InfluxDB & Redis]" - echo +function setup_packages() { + echo + echo "Securing BD Packages" + echo "--------------------" + echo "Auto-generating credentials for packages (MongoDB,InfluxDB & Redis)..." + ## Add MongoDB Admin user + mongoUsername="user$(openssl rand -hex 16)" + mongoPassword=$(openssl rand -hex 32) + echo "MONGODB_USERNAME = '$mongoUsername'" >>$BD/CentralService/cs_config + echo "MONGODB_PWD = '$mongoPassword'" >>$BD/CentralService/cs_config + echo "MONGODB_USERNAME = '$mongoUsername'" >>$BD/DataService/ds_config + echo "MONGODB_PWD = '$mongoPassword'" >>$BD/DataService/ds_config + echo " MONGODB_USERNAME = '$mongoUsername'" >>$BD/CentralReplica/config.py + echo " MONGODB_PWD = '$mongoPassword'" >>$BD/CentralReplica/config.py + mongo --eval "db.getSiblingDB('admin').createUser({user:'$mongoUsername',pwd:'$mongoPassword',roles:['userAdminAnyDatabase','dbAdminAnyDatabase','readWriteAnyDatabase']})" + # Enable MongoDB authorization + echo "security:" >>/etc/mongod.conf + echo " authorization: \"enabled\"" >>/etc/mongod.conf + service mongod restart + + sleep 2 + + ## Add InfluxDB Admin user + influxUsername="user$(openssl rand -hex 16)" + influxPassword=$(openssl rand -hex 32) + echo "INFLUXDB_USERNAME = '$influxUsername'" >>$BD/DataService/ds_config + echo "INFLUXDB_PWD = '$influxPassword'" >>$BD/DataService/ds_config + sleep 1 + curl -d "q=CREATE USER $influxUsername WITH PASSWORD '$influxPassword' WITH ALL PRIVILEGES" -X POST http://localhost:8086/query + sed -ir 's/# auth-enabled = false/auth-enabled = true/g' /etc/influxdb/influxdb.conf + service influxdb restart + + sleep 2 + + ## Add Redis Admin user + redisPassword=$(openssl rand -hex 64) + echo "REDIS_PWD = '$redisPassword'" >>$BD/CentralService/cs_config + echo "REDIS_PWD = '$redisPassword'" >>$BD/DataService/ds_config + echo " REDIS_PWD = '$redisPassword'" >>$BD/CentralReplica/config.py + sed -i -e '/#.* requirepass / s/.*/ requirepass '$redisPassword'/' /etc/redis/redis.conf + service redis restart + + echo + echo "Auto-Generated User Credentials for BuildingDepot Packages [MongoDB,InfluxDB & Redis]" + echo } deploy_config install_packages if [ "$DEPLOY_CS" = true ]; then - deploy_centralservice + deploy_centralservice fi if [ "$DEPLOY_DS" = true ]; then - deploy_dataservice + deploy_dataservice fi service mongod start @@ -236,10 +233,9 @@ sleep 5 supervisorctl restart all service influxdb start - if [ "$DEPLOY_TOGETHER" = true ]; then - joint_deployment_fix - service nginx restart + joint_deployment_fix + service nginx restart fi rm -rf configs @@ -247,7 +243,6 @@ rm -rf configs popd setup_email - # Create Database on InfluxDB curl -d "q=CREATE DATABASE buildingdepot" -X POST http://localhost:8086/query setup_packages diff --git a/scripts/bd_install.sh b/scripts/bd_install.sh index 4e561f21..1174feb0 100755 --- a/scripts/bd_install.sh +++ b/scripts/bd_install.sh @@ -43,8 +43,6 @@ function get_os_ver() { } get_os_ver - - DEPLOY_TOGETHER=true DEPLOY_CS=true DEPLOY_DS=true @@ -53,229 +51,223 @@ DEPLOY_DS=true # Check and make sure we are running as root or sudo (?) ################################################################################ if [[ $UID -ne 0 ]]; then - echo -e "\n$0 must be run as root. Most functions require super-user priviledges!\n" - exit 1 + echo -e "\n$0 must be run as root. Most functions require super-user priviledges!\n" + exit 1 fi BD=/srv/buildingdepot/ pushd $(pwd) - mkdir -p /srv/buildingdepot mkdir -p /var/log/buildingdepot/CentralService mkdir -p /var/log/buildingdepot/DataService mkdir -p /var/sockets || true # Deploy apps -function deploy_centralservice { - setup_venv /srv/buildingdepot/ - - #copy and untar new dataservice tarball - cp -r buildingdepot/CentralService /srv/buildingdepot/ - cp -r buildingdepot/DataService /srv/buildingdepot/ - cp -r buildingdepot/CentralReplica /srv/buildingdepot/ - #cp -r buildingdepot/OAuth2Server /srv/buildingdepot/ - cp -r buildingdepot/Documentation /srv/buildingdepot/ - cd /srv/buildingdepot - # copy uwsgi files - cp configs/uwsgi_cs.ini /etc/uwsgi/apps-available/cs.ini - - # Create supervisor config - cp configs/supervisor-cs.conf /etc/supervisor/conf.d/ - - # Create supervisor config for central replica - cp configs/supervisor-replica.conf /etc/supervisor/conf.d/ - - # Create nginx config - rm -f /etc/nginx/sites-enabled/default +function deploy_centralservice() { + setup_venv /srv/buildingdepot/ + + #copy and untar new dataservice tarball + cp -r buildingdepot/CentralService /srv/buildingdepot/ + cp -r buildingdepot/DataService /srv/buildingdepot/ + cp -r buildingdepot/CentralReplica /srv/buildingdepot/ + #cp -r buildingdepot/OAuth2Server /srv/buildingdepot/ + cp -r buildingdepot/Documentation /srv/buildingdepot/ + cd /srv/buildingdepot + # copy uwsgi files + cp configs/uwsgi_cs.ini /etc/uwsgi/apps-available/cs.ini + + # Create supervisor config + cp configs/supervisor-cs.conf /etc/supervisor/conf.d/ + + # Create supervisor config for central replica + cp configs/supervisor-replica.conf /etc/supervisor/conf.d/ + + # Create nginx config + rm -f /etc/nginx/sites-enabled/default } -function deploy_dataservice { - setup_venv /srv/buildingdepot/ +function deploy_dataservice() { + setup_venv /srv/buildingdepot/ - cd /srv/buildingdepot + cd /srv/buildingdepot - # copy uwsgi files - cp configs/uwsgi_ds.ini /etc/uwsgi/apps-available/ds.ini + # copy uwsgi files + cp configs/uwsgi_ds.ini /etc/uwsgi/apps-available/ds.ini - # Create supervisor config - cp configs/supervisor-ds.conf /etc/supervisor/conf.d/ + # Create supervisor config + cp configs/supervisor-ds.conf /etc/supervisor/conf.d/ - # Create nginx config - rm -f /etc/nginx/sites-enabled/default + # Create nginx config + rm -f /etc/nginx/sites-enabled/default } - -function joint_deployment_fix { - # Create join nginx config - rm -f /etc/nginx/sites-enabled/default - cd /srv/buildingdepot - #Setting up SSL - ssl_conf_file='configs/bd_config.json' - get_config_value 'cert_path' - cert_path=$res - get_config_value 'key_path' - key_path=$res - get_config_value 'domain' - domain=$res - sed -i "s||$cert_path|g" /srv/buildingdepot/configs/together_ssl.conf - sed -i "s||$key_path|g" /srv/buildingdepot/configs/together_ssl.conf - sed -i "s||$domain|g" /srv/buildingdepot/configs/together_ssl.conf - cp configs/together_ssl.conf /etc/nginx/sites-available/together.conf - ln -sf /etc/nginx/sites-available/together.conf /etc/nginx/sites-enabled/together.conf +function joint_deployment_fix() { + # Create join nginx config + rm -f /etc/nginx/sites-enabled/default + cd /srv/buildingdepot + #Setting up SSL + ssl_conf_file='configs/bd_config.json' + get_config_value 'cert_path' + cert_path=$res + get_config_value 'key_path' + key_path=$res + get_config_value 'domain' + domain=$res + sed -i "s||$cert_path|g" /srv/buildingdepot/configs/together_ssl.conf + sed -i "s||$key_path|g" /srv/buildingdepot/configs/together_ssl.conf + sed -i "s||$domain|g" /srv/buildingdepot/configs/together_ssl.conf + cp configs/together_ssl.conf /etc/nginx/sites-available/together.conf + ln -sf /etc/nginx/sites-available/together.conf /etc/nginx/sites-enabled/together.conf } -function deploy_config { - cp -r configs/ /srv/buildingdepot - mkdir -p /var/sockets || true +function deploy_config() { + cp -r configs/ /srv/buildingdepot + mkdir -p /var/sockets || true } -function install_packages { - apt-get install -y curl jq - apt-get install -y apt-transport-https - # Update rabbitmq key - wget -O - "https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc" | sudo apt-key add - - echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/rabbitmq.list - curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - - source /etc/lsb-release - echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list - sleep 10 - apt-get update - apt-get install - apt-get -y install python3-pip - apt-get install -y mongodb - apt-get install -y openssl python3-setuptools python3-dev build-essential - if [ "$OS_VER" = "18.04" ]; - then - apt-get install -y software-properties-common - else - apt-get install -y python3-software-properties - fi - apt-get install -y nginx - apt-get install -y supervisor - apt-get install -y redis-server - pip3 install --upgrade virtualenv - apt-get install -y wget - sudo apt-get install -y influxdb - sudo service influxdb start - sleep 10 - sudo apt-get install rabbitmq-server - #sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf - #service postfix restart +function install_packages() { + apt-get install -y curl jq + apt-get install -y apt-transport-https + # Update rabbitmq key + wget -O - "https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc" | sudo apt-key add - + echo 'deb http://www.rabbitmq.com/debian/ testing main' | sudo tee /etc/apt/sources.list.d/rabbitmq.list + curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - + source /etc/lsb-release + echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list + sleep 10 + apt-get update + apt-get install + apt-get -y install python3-pip + apt-get install -y mongodb + apt-get install -y openssl python3-setuptools python3-dev build-essential + if [ "$OS_VER" = "18.04" ]; then + apt-get install -y software-properties-common + else + apt-get install -y python3-software-properties + fi + apt-get install -y nginx + apt-get install -y supervisor + apt-get install -y redis-server + pip3 install --upgrade virtualenv + apt-get install -y wget + sudo apt-get install -y influxdb + sudo service influxdb start + sleep 10 + sudo apt-get install rabbitmq-server + #sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf + #service postfix restart } -function setup_venv { - cp -f pip_packages.list $1 || true - cd $1 +function setup_venv() { + cp -f pip_packages.list $1 || true + cd $1 - virtualenv ./venv - source venv/bin/activate + virtualenv ./venv + source venv/bin/activate - pip3 install --upgrade pip - pip3 install --upgrade setuptools - pip3 install --upgrade -r pip_packages.list + pip3 install --upgrade pip + pip3 install --upgrade setuptools + pip3 install --upgrade -r pip_packages.list - pip3 install --upgrade uWSGI - mkdir -p /etc/uwsgi/apps-available/ + pip3 install --upgrade uWSGI + mkdir -p /etc/uwsgi/apps-available/ - deactivate - cd - + deactivate + cd - } -function get_config_value { - prefix='.["' - postfix='"]' - res=$(jq $prefix$1$postfix configs/bd_config.json) - res=${res:1:$(expr ${#res} - 2)} +function get_config_value() { + prefix='.["' + postfix='"]' + res=$(jq $prefix$1$postfix configs/bd_config.json) + res=${res:1:$(expr ${#res} - 2)} } -function set_redis_credentials { +function set_redis_credentials() { echo $BD get_config_value 'redis_pwd' redis_pwd=$res - echo "REDIS_PWD = '$redis_pwd'">> $BD/CentralService/cs_config - echo "">> $BD/DataService/ds_config - echo "REDIS_PWD = '$redis_pwd'">> $BD/DataService/ds_config - echo " REDIS_PWD = '$redis_pwd'" >> $BD/CentralReplica/config.py + echo "REDIS_PWD = '$redis_pwd'" >>$BD/CentralService/cs_config + echo "" >>$BD/DataService/ds_config + echo "REDIS_PWD = '$redis_pwd'" >>$BD/DataService/ds_config + echo " REDIS_PWD = '$redis_pwd'" >>$BD/CentralReplica/config.py sed -i -e '/#.* requirepass / s/.*/ requirepass '$redis_pwd'/' /etc/redis/redis.conf service redis restart } -function set_influxdb_credentials { +function set_influxdb_credentials() { ## Add InfluxDB Admin user get_config_value 'influx_user' influx_user=$res get_config_value 'influx_pwd' influx_pwd=$res - echo "INFLUXDB_USERNAME = '$influx_user'">> $BD/DataService/ds_config - echo "INFLUXDB_PWD = '$influx_pwd'">> $BD/DataService/ds_config + echo "INFLUXDB_USERNAME = '$influx_user'" >>$BD/DataService/ds_config + echo "INFLUXDB_PWD = '$influx_pwd'" >>$BD/DataService/ds_config sleep 1 curl -d "q=CREATE USER $influx_user WITH PASSWORD '$influx_pwd' WITH ALL PRIVILEGES" -X POST http://localhost:8086/query sed -ir 's/# auth-enabled = false/auth-enabled = true/g' /etc/influxdb/influxdb.conf - service influxdb restart + service influxdb restart } -function set_mongodb_credentials { +function set_mongodb_credentials() { get_config_value 'mongo_user' mongo_user=$res get_config_value 'mongo_pwd' mongo_pwd=$res - echo "MONGODB_USERNAME = '$mongo_user'" >> $BD/CentralService/cs_config - echo "MONGODB_PWD = '$mongo_pwd'" >> $BD/CentralService/cs_config - echo "MONGODB_USERNAME = '$mongo_user'" >> $BD/DataService/ds_config - echo "MONGODB_PWD = '$mongo_pwd'" >> $BD/DataService/ds_config - echo " MONGODB_USERNAME = '$mongo_user'" >> $BD/CentralReplica/config.py - echo " MONGODB_PWD = '$mongo_pwd'" >> $BD/CentralReplica/config.py + echo "MONGODB_USERNAME = '$mongo_user'" >>$BD/CentralService/cs_config + echo "MONGODB_PWD = '$mongo_pwd'" >>$BD/CentralService/cs_config + echo "MONGODB_USERNAME = '$mongo_user'" >>$BD/DataService/ds_config + echo "MONGODB_PWD = '$mongo_pwd'" >>$BD/DataService/ds_config + echo " MONGODB_USERNAME = '$mongo_user'" >>$BD/CentralReplica/config.py + echo " MONGODB_PWD = '$mongo_pwd'" >>$BD/CentralReplica/config.py mongo --eval "db.getSiblingDB('admin').createUser({user:'$mongo_user',pwd:'$mongo_pwd',roles:['userAdminAnyDatabase','dbAdminAnyDatabase','readWriteAnyDatabase']})" || true # Enable MongoDB authorization lastline=$(cat /etc/mongodb.conf | tail -1) auth_opt="auth = true" if ["$lastline" != "$auth_opt"]; then - echo $auth_opt >> /etc/mongodb.conf + echo $auth_opt >>/etc/mongodb.conf fi #echo "security:" >> /etc/mongod.conf #echo " authorization: \"enabled\"">> /etc/mongod.conf service mongodb restart - } - -function set_credentials { +function set_credentials() { set_redis_credentials set_influxdb_credentials set_mongodb_credentials } - -function setup_gmail { - get_config_value 'client_id' - client_id=$res - get_config_value 'client_secret' - client_secret=$res - get_config_value 'email' - email_id=$res - get_config_value 'refresh_token' - refresh_token=$res - get_config_value 'access_token' - access_token=$res - echo "EMAIL = 'GMAIL'" >> $BD/CentralService/cs_config - echo "EMAIL_ID = '$email_id'" >> $BD/CentralService/cs_config - echo "ACCESS_TOKEN = '$access_token'" >> $BD/CentralService/cs_config - echo "REFRESH_TOKEN = '$refresh_token'" >> $BD/CentralService/cs_config - echo "CLIENT_ID = '$client_id'" >> $BD/CentralService/cs_config - echo "CLIENT_SECRET = '$client_secret'" >> $BD/CentralService/cs_config +function setup_gmail() { + get_config_value 'client_id' + client_id=$res + get_config_value 'client_secret' + client_secret=$res + get_config_value 'email' + email_id=$res + get_config_value 'refresh_token' + refresh_token=$res + get_config_value 'access_token' + access_token=$res + echo "EMAIL = 'GMAIL'" >>$BD/CentralService/cs_config + echo "EMAIL_ID = '$email_id'" >>$BD/CentralService/cs_config + echo "ACCESS_TOKEN = '$access_token'" >>$BD/CentralService/cs_config + echo "REFRESH_TOKEN = '$refresh_token'" >>$BD/CentralService/cs_config + echo "CLIENT_ID = '$client_id'" >>$BD/CentralService/cs_config + echo "CLIENT_SECRET = '$client_secret'" >>$BD/CentralService/cs_config } deploy_config install_packages cp configs/nginx.conf /etc/nginx/nginx.conf if [ "$DEPLOY_CS" = true ]; then - deploy_centralservice + deploy_centralservice fi if [ "$DEPLOY_DS" = true ]; then - deploy_dataservice + deploy_dataservice fi /etc/init.d/mongodb start @@ -288,8 +280,8 @@ service influxdb start set_credentials if [ "$DEPLOY_TOGETHER" = true ]; then - joint_deployment_fix - service nginx restart + joint_deployment_fix + service nginx restart fi rm -rf configs diff --git a/scripts/bd_oauth2.py b/scripts/bd_oauth2.py index ea95138b..06389ec4 100644 --- a/scripts/bd_oauth2.py +++ b/scripts/bd_oauth2.py @@ -6,7 +6,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # - # http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -63,294 +63,322 @@ import base64 import imaplib import json -from optparse import OptionParser import smtplib import sys -import urllib.request, urllib.parse, urllib.error +import urllib.error +import urllib.parse +import urllib.request +from optparse import OptionParser def SetupOptionParser(): - # Usage message is the module's docstring. - parser = OptionParser(usage=__doc__) - parser.add_option('--generate_oauth2_token', - action='store_true', - dest='generate_oauth2_token', - help='generates an OAuth2 token for testing') - parser.add_option('--generate_oauth2_string', - action='store_true', - dest='generate_oauth2_string', - help='generates an initial client response string for ' - 'OAuth2') - parser.add_option('--client_id', - default=None, - help='Client ID of the application that is authenticating. ' - 'See OAuth2 documentation for details.') - parser.add_option('--client_secret', - default=None, - help='Client secret of the application that is ' - 'authenticating. See OAuth2 documentation for ' - 'details.') - parser.add_option('--access_token', - default=None, - help='OAuth2 access token') - parser.add_option('--refresh_token', - default=None, - help='OAuth2 refresh token') - parser.add_option('--scope', - default='https://mail.google.com/', - help='scope for the access token. Multiple scopes can be ' - 'listed separated by spaces with the whole argument ' - 'quoted.') - parser.add_option('--test_imap_authentication', - action='store_true', - dest='test_imap_authentication', - help='attempts to authenticate to IMAP') - parser.add_option('--test_smtp_authentication', - action='store_true', - dest='test_smtp_authentication', - help='attempts to authenticate to SMTP') - parser.add_option('--user', - default=None, - help='email address of user whose account is being ' - 'accessed') - return parser + # Usage message is the module's docstring. + parser = OptionParser(usage=__doc__) + parser.add_option( + "--generate_oauth2_token", + action="store_true", + dest="generate_oauth2_token", + help="generates an OAuth2 token for testing", + ) + parser.add_option( + "--generate_oauth2_string", + action="store_true", + dest="generate_oauth2_string", + help="generates an initial client response string for " "OAuth2", + ) + parser.add_option( + "--client_id", + default=None, + help="Client ID of the application that is authenticating. " + "See OAuth2 documentation for details.", + ) + parser.add_option( + "--client_secret", + default=None, + help="Client secret of the application that is " + "authenticating. See OAuth2 documentation for " + "details.", + ) + parser.add_option("--access_token", default=None, help="OAuth2 access token") + parser.add_option("--refresh_token", default=None, help="OAuth2 refresh token") + parser.add_option( + "--scope", + default="https://mail.google.com/", + help="scope for the access token. Multiple scopes can be " + "listed separated by spaces with the whole argument " + "quoted.", + ) + parser.add_option( + "--test_imap_authentication", + action="store_true", + dest="test_imap_authentication", + help="attempts to authenticate to IMAP", + ) + parser.add_option( + "--test_smtp_authentication", + action="store_true", + dest="test_smtp_authentication", + help="attempts to authenticate to SMTP", + ) + parser.add_option( + "--user", + default=None, + help="email address of user whose account is being " "accessed", + ) + return parser # The URL root for accessing Google Accounts. -GOOGLE_ACCOUNTS_BASE_URL = 'https://accounts.google.com' - +GOOGLE_ACCOUNTS_BASE_URL = "https://accounts.google.com" # Hardcoded dummy redirect URI for non-web apps. -REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob' +REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob" def AccountsUrl(command): - """Generates the Google Accounts URL. + """Generates the Google Accounts URL. - Args: - command: The command to execute. + Args: + command: The command to execute. - Returns: - A URL for the given command. - """ - return '%s/%s' % (GOOGLE_ACCOUNTS_BASE_URL, command) + Returns: + A URL for the given command. + """ + return "%s/%s" % (GOOGLE_ACCOUNTS_BASE_URL, command) def UrlEscape(text): - # See OAUTH 5.1 for a definition of which characters need to be escaped. - return urllib.parse.quote(text, safe='~-._') + # See OAUTH 5.1 for a definition of which characters need to be escaped. + return urllib.parse.quote(text, safe="~-._") def UrlUnescape(text): - # See OAUTH 5.1 for a definition of which characters need to be escaped. - return urllib.parse.unquote(text) + # See OAUTH 5.1 for a definition of which characters need to be escaped. + return urllib.parse.unquote(text) def FormatUrlParams(params): - """Formats parameters into a URL query string. + """Formats parameters into a URL query string. - Args: - params: A key-value map. + Args: + params: A key-value map. - Returns: - A URL query string version of the given parameters. - """ - param_fragments = [] - for param in sorted(iter(list(params.items())), key=lambda x: x[0]): - param_fragments.append('%s=%s' % (param[0], UrlEscape(param[1]))) - return '&'.join(param_fragments) + Returns: + A URL query string version of the given parameters. + """ + param_fragments = [] + for param in sorted(iter(list(params.items())), key=lambda x: x[0]): + param_fragments.append("%s=%s" % (param[0], UrlEscape(param[1]))) + return "&".join(param_fragments) -def GeneratePermissionUrl(client_id, scope='https://mail.google.com/'): - """Generates the URL for authorizing access. +def GeneratePermissionUrl(client_id, scope="https://mail.google.com/"): + """Generates the URL for authorizing access. - This uses the "OAuth2 for Installed Applications" flow described at - https://developers.google.com/accounts/docs/OAuth2InstalledApp + This uses the "OAuth2 for Installed Applications" flow described at + https://developers.google.com/accounts/docs/OAuth2InstalledApp - Args: - client_id: Client ID obtained by registering your app. - scope: scope for access token, e.g. 'https://mail.google.com' - Returns: - A URL that the user should visit in their browser. - """ - params = {} - params['client_id'] = client_id - params['redirect_uri'] = REDIRECT_URI - params['scope'] = scope - params['response_type'] = 'code' - return '%s?%s' % (AccountsUrl('o/oauth2/auth'), - FormatUrlParams(params)) + Args: + client_id: Client ID obtained by registering your app. + scope: scope for access token, e.g. 'https://mail.google.com' + Returns: + A URL that the user should visit in their browser. + """ + params = {} + params["client_id"] = client_id + params["redirect_uri"] = REDIRECT_URI + params["scope"] = scope + params["response_type"] = "code" + return "%s?%s" % (AccountsUrl("o/oauth2/auth"), FormatUrlParams(params)) def AuthorizeTokens(client_id, client_secret, authorization_code): - """Obtains OAuth access token and refresh token. - - This uses the application portion of the "OAuth2 for Installed Applications" - flow at https://developers.google.com/accounts/docs/OAuth2InstalledApp#handlingtheresponse - - Args: - client_id: Client ID obtained by registering your app. - client_secret: Client secret obtained by registering your app. - authorization_code: code generated by Google Accounts after user grants - permission. - Returns: - The decoded response from the Google Accounts server, as a dict. Expected - fields include 'access_token', 'expires_in', and 'refresh_token'. - """ - params = {} - params['client_id'] = client_id - params['client_secret'] = client_secret - params['code'] = authorization_code - params['redirect_uri'] = REDIRECT_URI - params['grant_type'] = 'authorization_code' - request_url = AccountsUrl('o/oauth2/token') - - response = urllib.request.urlopen(request_url, urllib.parse.urlencode(params)).read() - return json.loads(response) + """Obtains OAuth access token and refresh token. + + This uses the application portion of the "OAuth2 for Installed Applications" + flow at https://developers.google.com/accounts/docs/OAuth2InstalledApp#handlingtheresponse + + Args: + client_id: Client ID obtained by registering your app. + client_secret: Client secret obtained by registering your app. + authorization_code: code generated by Google Accounts after user grants + permission. + Returns: + The decoded response from the Google Accounts server, as a dict. Expected + fields include 'access_token', 'expires_in', and 'refresh_token'. + """ + params = {} + params["client_id"] = client_id + params["client_secret"] = client_secret + params["code"] = authorization_code + params["redirect_uri"] = REDIRECT_URI + params["grant_type"] = "authorization_code" + request_url = AccountsUrl("o/oauth2/token") + + response = urllib.request.urlopen( + request_url, urllib.parse.urlencode(params) + ).read() + return json.loads(response) def RefreshToken(client_id, client_secret, refresh_token): - """Obtains a new token given a refresh token. - - See https://developers.google.com/accounts/docs/OAuth2InstalledApp#refresh - - Args: - client_id: Client ID obtained by registering your app. - client_secret: Client secret obtained by registering your app. - refresh_token: A previously-obtained refresh token. - Returns: - The decoded response from the Google Accounts server, as a dict. Expected - fields include 'access_token', 'expires_in', and 'refresh_token'. - """ - params = {} - params['client_id'] = client_id - params['client_secret'] = client_secret - params['refresh_token'] = refresh_token - params['grant_type'] = 'refresh_token' - request_url = AccountsUrl('o/oauth2/token') - - response = urllib.request.urlopen(request_url, urllib.parse.urlencode(params)).read() - return json.loads(response) + """Obtains a new token given a refresh token. + + See https://developers.google.com/accounts/docs/OAuth2InstalledApp#refresh + + Args: + client_id: Client ID obtained by registering your app. + client_secret: Client secret obtained by registering your app. + refresh_token: A previously-obtained refresh token. + Returns: + The decoded response from the Google Accounts server, as a dict. Expected + fields include 'access_token', 'expires_in', and 'refresh_token'. + """ + params = {} + params["client_id"] = client_id + params["client_secret"] = client_secret + params["refresh_token"] = refresh_token + params["grant_type"] = "refresh_token" + request_url = AccountsUrl("o/oauth2/token") + + response = urllib.request.urlopen( + request_url, urllib.parse.urlencode(params) + ).read() + return json.loads(response) def GenerateOAuth2String(username, access_token, base64_encode=True): - """Generates an IMAP OAuth2 authentication string. + """Generates an IMAP OAuth2 authentication string. - See https://developers.google.com/google-apps/gmail/oauth2_overview + See https://developers.google.com/google-apps/gmail/oauth2_overview - Args: - username: the username (email address) of the account to authenticate - access_token: An OAuth2 access token. - base64_encode: Whether to base64-encode the output. + Args: + username: the username (email address) of the account to authenticate + access_token: An OAuth2 access token. + base64_encode: Whether to base64-encode the output. - Returns: - The SASL argument for the OAuth2 mechanism. - """ - auth_string = 'user=%s\1auth=Bearer %s\1\1' % (username, access_token) - if base64_encode: - auth_string = base64.b64encode(auth_string) - return auth_string + Returns: + The SASL argument for the OAuth2 mechanism. + """ + auth_string = "user=%s\1auth=Bearer %s\1\1" % (username, access_token) + if base64_encode: + auth_string = base64.b64encode(auth_string) + return auth_string def TestImapAuthentication(user, auth_string): - """Authenticates to IMAP with the given auth_string. + """Authenticates to IMAP with the given auth_string. - Prints a debug trace of the attempted IMAP connection. + Prints a debug trace of the attempted IMAP connection. - Args: - user: The Gmail username (full email address) - auth_string: A valid OAuth2 string, as returned by GenerateOAuth2String. - Must not be base64-encoded, since imaplib does its own base64-encoding. - """ - print() - imap_conn = imaplib.IMAP4_SSL('imap.gmail.com') - imap_conn.debug = 4 - imap_conn.authenticate('XOAUTH2', lambda x: auth_string) - imap_conn.select('INBOX') + Args: + user: The Gmail username (full email address) + auth_string: A valid OAuth2 string, as returned by GenerateOAuth2String. + Must not be base64-encoded, since imaplib does its own base64-encoding. + """ + print() + imap_conn = imaplib.IMAP4_SSL("imap.gmail.com") + imap_conn.debug = 4 + imap_conn.authenticate("XOAUTH2", lambda x: auth_string) + imap_conn.select("INBOX") def TestSmtpAuthentication(user, auth_string): - """Authenticates to SMTP with the given auth_string. + """Authenticates to SMTP with the given auth_string. - Args: - user: The Gmail username (full email address) - auth_string: A valid OAuth2 string, not base64-encoded, as returned by - GenerateOAuth2String. - """ - print() - smtp_conn = smtplib.SMTP('smtp.gmail.com', 587) - smtp_conn.set_debuglevel(True) - smtp_conn.ehlo('test') - smtp_conn.starttls() - smtp_conn.docmd('AUTH', 'XOAUTH2 ' + base64.b64encode(auth_string)) + Args: + user: The Gmail username (full email address) + auth_string: A valid OAuth2 string, not base64-encoded, as returned by + GenerateOAuth2String. + """ + print() + smtp_conn = smtplib.SMTP("smtp.gmail.com", 587) + smtp_conn.set_debuglevel(True) + smtp_conn.ehlo("test") + smtp_conn.starttls() + smtp_conn.docmd("AUTH", "XOAUTH2 " + base64.b64encode(auth_string)) def RequireOptions(options, *args): - missing = [arg for arg in args if getattr(options, arg) is None] - if missing: - print(('Missing options: %s' % ' '.join(missing))) - sys.exit(-1) + missing = [arg for arg in args if getattr(options, arg) is None] + if missing: + print(("Missing options: %s" % " ".join(missing))) + sys.exit(-1) def main(argv): - options_parser = SetupOptionParser() - (options, args) = options_parser.parse_args() - if options.refresh_token: - RequireOptions(options, 'client_id', 'client_secret') - response = RefreshToken(options.client_id, options.client_secret, - options.refresh_token) - print(('Access Token: %s' % response['access_token'])) - print(('Access Token Expiration Seconds: %s' % response['expires_in'])) - elif options.generate_oauth2_string: - RequireOptions(options, 'user', 'access_token') - print(('OAuth2 argument:\n' + - GenerateOAuth2String(options.user, options.access_token))) - elif options.generate_oauth2_token: - RequireOptions(options, 'client_id', 'client_secret') - print('To authorize token, visit this url and follow the directions:') - print((' %s' % GeneratePermissionUrl(options.client_id, options.scope))) - authorization_code = eval(input('Enter verification code: ')) - response = AuthorizeTokens(options.client_id, options.client_secret, - authorization_code) - print(('Refresh Token: %s' % response['refresh_token'])) - print(('Access Token: %s' % response['access_token'])) - print(('Access Token Expiration Seconds: %s' % response['expires_in'])) - elif options.test_imap_authentication: - RequireOptions(options, 'user', 'access_token') - TestImapAuthentication(options.user, - GenerateOAuth2String(options.user, options.access_token, - base64_encode=False)) - elif options.test_smtp_authentication: - RequireOptions(options, 'user', 'access_token') - TestSmtpAuthentication(options.user, - GenerateOAuth2String(options.user, options.access_token, - base64_encode=False)) - else: - options_parser.print_help() - print('Nothing to do, exiting.') - return + options_parser = SetupOptionParser() + (options, args) = options_parser.parse_args() + if options.refresh_token: + RequireOptions(options, "client_id", "client_secret") + response = RefreshToken( + options.client_id, options.client_secret, options.refresh_token + ) + print(("Access Token: %s" % response["access_token"])) + print(("Access Token Expiration Seconds: %s" % response["expires_in"])) + elif options.generate_oauth2_string: + RequireOptions(options, "user", "access_token") + print( + ( + "OAuth2 argument:\n" + + GenerateOAuth2String(options.user, options.access_token) + ) + ) + elif options.generate_oauth2_token: + RequireOptions(options, "client_id", "client_secret") + print("To authorize token, visit this url and follow the directions:") + print((" %s" % GeneratePermissionUrl(options.client_id, options.scope))) + authorization_code = eval(input("Enter verification code: ")) + response = AuthorizeTokens( + options.client_id, options.client_secret, authorization_code + ) + print(("Refresh Token: %s" % response["refresh_token"])) + print(("Access Token: %s" % response["access_token"])) + print(("Access Token Expiration Seconds: %s" % response["expires_in"])) + elif options.test_imap_authentication: + RequireOptions(options, "user", "access_token") + TestImapAuthentication( + options.user, + GenerateOAuth2String( + options.user, options.access_token, base64_encode=False + ), + ) + elif options.test_smtp_authentication: + RequireOptions(options, "user", "access_token") + TestSmtpAuthentication( + options.user, + GenerateOAuth2String( + options.user, options.access_token, base64_encode=False + ), + ) + else: + options_parser.print_help() + print("Nothing to do, exiting.") + return + def main_bd(): - #oauth2 --user=xxx@gmail.com \ - # --client_id=1038[...].apps.googleusercontent.com \ - # --client_secret=VWFn8LIKAMC-MsjBMhJeOplZ \ - # --generate_oauth2_token - cred_filename = 'configs/bd_config.json' - with open(cred_filename, 'r') as fp: - d = json.load(fp) - cid = d['client_id'] - csec = d['client_secret'] - print('To authorize token, visit this url and follow the directions:') - print((' %s' % GeneratePermissionUrl(cid))) - authorization_code = eval(input('Enter verification code: ')) - response = AuthorizeTokens(cid, csec, authorization_code) - with open(cred_filename, 'r') as fp: - d = json.load(fp) - d['refresh_token'] = response['refresh_token'] - d['access_token'] = response['access_token'] - with open(cred_filename, 'w') as fp: - json.dump(d, fp, indent=2) - -if __name__ == '__main__': - #main(sys.argv) - main_bd() + # oauth2 --user=xxx@gmail.com \ + # --client_id=1038[...].apps.googleusercontent.com \ + # --client_secret=VWFn8LIKAMC-MsjBMhJeOplZ \ + # --generate_oauth2_token + cred_filename = "configs/bd_config.json" + with open(cred_filename, "r") as fp: + d = json.load(fp) + cid = d["client_id"] + csec = d["client_secret"] + print("To authorize token, visit this url and follow the directions:") + print((" %s" % GeneratePermissionUrl(cid))) + authorization_code = eval(input("Enter verification code: ")) + response = AuthorizeTokens(cid, csec, authorization_code) + with open(cred_filename, "r") as fp: + d = json.load(fp) + d["refresh_token"] = response["refresh_token"] + d["access_token"] = response["access_token"] + with open(cred_filename, "w") as fp: + json.dump(d, fp, indent=2) + + +if __name__ == "__main__": + # main(sys.argv) + main_bd() diff --git a/setup_bd.py b/setup_bd.py index bc3f2b24..34fb881b 100644 --- a/setup_bd.py +++ b/setup_bd.py @@ -1,67 +1,88 @@ #!/srv/buildingdepot/venv/bin/python -import json,sys -import io,os,configparser -import string,random +import configparser +import io +import json +import os +import random +import string +import sys from pymongo import MongoClient from werkzeug.security import generate_password_hash print("Setting up BuildingDepot.. ") -option = sys.argv[1:][0] #get arguments +option = sys.argv[1:][0] # get arguments # Create a temporary password -tempPwd = ''.join(random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for _ in range(16)) +tempPwd = "".join( + random.choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) + for _ in range(16) +) # Get Username and Password for MongoDB -if (option == "install"): +if option == "install": configBuffer = io.StringIO() - configBuffer.write('[dummysection]\n') - configBuffer.write(open('/srv/buildingdepot/CentralService/cs_config').read()) + configBuffer.write("[dummysection]\n") + configBuffer.write(open("/srv/buildingdepot/CentralService/cs_config").read()) configBuffer.seek(0, os.SEEK_SET) config = configparser.ConfigParser() config.readfp(configBuffer) - user=config.get('dummysection','MONGODB_USERNAME').strip("'").strip('"') - pwd = config.get('dummysection','MONGODB_PWD').strip("'").strip('"') + user = config.get("dummysection", "MONGODB_USERNAME").strip("'").strip('"') + pwd = config.get("dummysection", "MONGODB_PWD").strip("'").strip('"') -elif(option == "bd_install"): - configs = json.load(open('configs/bd_config.json', 'r')) - user = configs['mongo_user'] - pwd = configs['mongo_pwd'] +elif option == "bd_install": + configs = json.load(open("configs/bd_config.json", "r")) + user = configs["mongo_user"] + pwd = configs["mongo_pwd"] -elif(option == "test"): +elif option == "test": configBuffer = io.StringIO() - configBuffer.write('[dummysection]\n') - configBuffer.write(open('/srv/buildingdepot/CentralService/cs_config').read()) + configBuffer.write("[dummysection]\n") + configBuffer.write(open("/srv/buildingdepot/CentralService/cs_config").read()) configBuffer.seek(0, os.SEEK_SET) config = configparser.ConfigParser() config.readfp(configBuffer) - user=config.get('dummysection','MONGODB_USERNAME').strip("'").strip('"') - pwd = config.get('dummysection','MONGODB_PWD').strip("'").strip('"') - configs = json.load(open('benchmarking-tools/functional-testing-tool/tests/config.json', 'r')) + user = config.get("dummysection", "MONGODB_USERNAME").strip("'").strip('"') + pwd = config.get("dummysection", "MONGODB_PWD").strip("'").strip('"') + configs = json.load( + open("benchmarking-tools/functional-testing-tool/tests/config.json", "r") + ) test_config = dict(configs) - test_config['password'] = tempPwd - with open('benchmarking-tools/functional-testing-tool/tests/config.json', 'w') as output: + test_config["password"] = tempPwd + with open( + "benchmarking-tools/functional-testing-tool/tests/config.json", "w" + ) as output: json.dump(test_config, output) else: exit(0) -#Create BuildingDepot Database -client = MongoClient(username=user, - password=pwd, - authSource='admin') +# Create BuildingDepot Database +client = MongoClient(username=user, password=pwd, authSource="admin") db = client.buildingdepot -db.user.insert({"email":"admin@buildingdepot.org", - "password":generate_password_hash(tempPwd), - "first_name":"Admin", - "first_login":True, - "role":"super"}) -db.data_service.insert({'name':'ds1', - 'description':'', - 'host':'127.0.0.1', - 'port':82, - 'buildings':[], - 'admins':[]}) +db.user.insert( + { + "email": "admin@buildingdepot.org", + "password": generate_password_hash(tempPwd), + "first_name": "Admin", + "first_login": True, + "role": "super", + } +) +db.data_service.insert( + { + "name": "ds1", + "description": "", + "host": "127.0.0.1", + "port": 82, + "buildings": [], + "admins": [], + } +) -print(("\n Created a super user with following credentials. Please login and change password immediately \n user id "\ - ": admin@buildingdepot.org \n password: " + tempPwd)) +print( + ( + "\n Created a super user with following credentials. Please login and change password immediately \n user id " + ": admin@buildingdepot.org \n password: " + tempPwd + ) +) From 32a32092eb634547f1b47a61a611c5e3886fb20e Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Tue, 22 Dec 2020 20:36:45 +0530 Subject: [PATCH 30/70] Update Mocha timeout --- benchmarking-tools/functional-testing-tool/tests/all.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmarking-tools/functional-testing-tool/tests/all.js b/benchmarking-tools/functional-testing-tool/tests/all.js index d138f8ac..20e2a2a9 100644 --- a/benchmarking-tools/functional-testing-tool/tests/all.js +++ b/benchmarking-tools/functional-testing-tool/tests/all.js @@ -8,7 +8,7 @@ var expect = require('chai').expect, const uuid = require('uuid/v4') describe('An authorized superuser should be able to ', function () { - this.timeout(5000); + this.timeout(10000); it('generate an access token', function (done) { if (config['clientID'].length && config['clientSecret'].length) { centralApi.get('/oauth/access_token/client_id=' + config['clientID'] + '/client_secret=' + config['clientSecret']) From 268576bf2d70e9659cee705c1ed9cae29612f582 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 8 Jan 2021 20:00:33 +0530 Subject: [PATCH 31/70] Test on Ubuntu 20.04 --- .github/workflows/test_bd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index 66562a84..5695daad 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -16,7 +16,7 @@ on: jobs: build: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: python-version: [3.5.10, 3.6.12, 3.7.9, 3.8.6] From f3d44635a1d8fc89ac6d3a6314048a8b305dc661 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 8 Jan 2021 20:02:51 +0530 Subject: [PATCH 32/70] Revert tests to Ubuntu 18.04 --- .github/workflows/test_bd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index 5695daad..66562a84 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -16,7 +16,7 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-18.04 strategy: matrix: python-version: [3.5.10, 3.6.12, 3.7.9, 3.8.6] From 584187855f7c00eacff436b25c76c578d791a2b6 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 9 Apr 2021 10:35:16 -0400 Subject: [PATCH 33/70] Update test_bd.yml workflow --- .github/workflows/test_bd.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index 66562a84..fced6eb3 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -19,13 +19,14 @@ jobs: runs-on: ubuntu-18.04 strategy: matrix: - python-version: [3.5.10, 3.6.12, 3.7.9, 3.8.6] + python-version: ['3.5', '3.6', '3.7.4', '3.8'] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + architecture: x64 - name: Install BuildingDepot run: | sudo bash -x ./script_for_github_actions.sh From 3497e6716c6fc22f39de9687d08d0fea800a97bc Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 9 Apr 2021 10:38:14 -0400 Subject: [PATCH 34/70] Remove unsupported Python versions --- .github/workflows/test_bd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index fced6eb3..7bcb20b9 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-18.04 strategy: matrix: - python-version: ['3.5', '3.6', '3.7.4', '3.8'] + python-version: ['3.6.13"', '3.7.10', '3.8.9'] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From d3898536c1744ce4a67f50cf59a41fcedaa1cc2b Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 9 Apr 2021 10:44:58 -0400 Subject: [PATCH 35/70] Remove arch x64 --- .github/workflows/test_bd.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index 7bcb20b9..acc8c55d 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -26,7 +26,6 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - architecture: x64 - name: Install BuildingDepot run: | sudo bash -x ./script_for_github_actions.sh From ea290e75842471b708e5a781cd6e9bab32fc6423 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 9 Apr 2021 10:45:48 -0400 Subject: [PATCH 36/70] Fix typo --- .github/workflows/test_bd.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index acc8c55d..50cf8e06 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -19,13 +19,14 @@ jobs: runs-on: ubuntu-18.04 strategy: matrix: - python-version: ['3.6.13"', '3.7.10', '3.8.9'] + python-version: ['3.6.13', '3.7.10', '3.8.9'] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + architecture: x64 - name: Install BuildingDepot run: | sudo bash -x ./script_for_github_actions.sh From 7f18f7c679f3735fc0cc7080794c7a6fdf080c1a Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 9 Apr 2021 10:53:45 -0400 Subject: [PATCH 37/70] Add continue-on-error --- .github/workflows/test_bd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index 50cf8e06..0006a6f7 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -2,7 +2,7 @@ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions name: BuildingDepot - +continue-on-error: true on: push: branches: From e662e54b4597bb685eea25ede33141ec3a8b01c6 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 9 Apr 2021 10:56:07 -0400 Subject: [PATCH 38/70] Disable fast-fail --- .github/workflows/test_bd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index 0006a6f7..5f640d76 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -2,7 +2,6 @@ # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions name: BuildingDepot -continue-on-error: true on: push: branches: @@ -15,9 +14,10 @@ on: - develop jobs: build: - + continue-on-error: runs-on: ubuntu-18.04 strategy: + fail-fast: false matrix: python-version: ['3.6.13', '3.7.10', '3.8.9'] steps: From 0c8f7ca333e2b7e0287b652584edb579b4b09d77 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 9 Apr 2021 10:56:44 -0400 Subject: [PATCH 39/70] Fix workflow --- .github/workflows/test_bd.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index 5f640d76..c714804f 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -14,7 +14,6 @@ on: - develop jobs: build: - continue-on-error: runs-on: ubuntu-18.04 strategy: fail-fast: false From 67ba5d24aea34757b62c781be79a8d92006b2cc7 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 4 Jun 2021 08:57:34 -0400 Subject: [PATCH 40/70] Merge Updates to DataService APIs to have batch inputs #110 --- .../rest_api/notifications/notification.py | 24 ++-- .../CentralService/app/rest_api/register.py | 6 +- .../app/rest_api/app_subscription.py | 33 +++--- .../DataService/app/rest_api/apps.py | 111 ++++++++++-------- .../DataService/app/rest_api/responses.py | 22 ++-- install.sh | 2 +- script_for_github_actions.sh | 4 +- 7 files changed, 108 insertions(+), 94 deletions(-) diff --git a/buildingdepot/CentralService/app/rest_api/notifications/notification.py b/buildingdepot/CentralService/app/rest_api/notifications/notification.py index 040bbc86..3a36fd80 100644 --- a/buildingdepot/CentralService/app/rest_api/notifications/notification.py +++ b/buildingdepot/CentralService/app/rest_api/notifications/notification.py @@ -29,15 +29,15 @@ def get_notification_client_id(client_email): class NotificationClientIdService(MethodView): @check_oauth def post(self): - data = request.get_json()['data'] - print('We got the request') - print('Want to save the ID ' + data['id']) - if data is None or data['id'] is None: + data = request.get_json()["data"] + print("We got the request") + print("Want to save the ID " + data["id"]) + if data is None or data["id"] is None: return jsonify(responses.missing_parameters) - print('No params missing') + print("No params missing") if get_notification_client_id(get_email()) is None: - print('Saving the ID for client ' + str(get_email())) - NotificationClientId(email=get_email(), client_id=data['id']).save() + print("Saving the ID for client " + str(get_email())) + NotificationClientId(email=get_email(), client_id=data["id"]).save() else: return jsonify(responses.client_id_already_exists) @@ -45,13 +45,15 @@ def post(self): @check_oauth def put(self): - data = request.get_json()['data'] + data = request.get_json()["data"] - if data is None or data['id'] is None: + if data is None or data["id"] is None: return jsonify(responses.missing_parameters) try: - notifications_collection = NotificationClientId.objects(email=get_email()).first() - notifications_collection.update(set__client_id=data['id']) + notifications_collection = NotificationClientId.objects( + email=get_email() + ).first() + notifications_collection.update(set__client_id=data["id"]) except RuntimeError as error: print("Error", error) diff --git a/buildingdepot/CentralService/app/rest_api/register.py b/buildingdepot/CentralService/app/rest_api/register.py index 4241c547..c756e1a6 100755 --- a/buildingdepot/CentralService/app/rest_api/register.py +++ b/buildingdepot/CentralService/app/rest_api/register.py @@ -28,10 +28,8 @@ def register_view(app_obj): "/api/template/", view_func=template_view, methods=["GET", "DELETE"] ) - template_tagtypes_view = ( - buildingtemplate_tagtypes.BuildingTemplateTagtypeService.as_view( - "template_tagtypes_api" - ) + template_tagtypes_view = buildingtemplate_tagtypes.BuildingTemplateTagtypeService.as_view( + "template_tagtypes_api" ) # post creates/modifies building templates # get returns information on a specified building template. diff --git a/buildingdepot/DataService/app/rest_api/app_subscription.py b/buildingdepot/DataService/app/rest_api/app_subscription.py index e558bf5c..e6aaa3df 100755 --- a/buildingdepot/DataService/app/rest_api/app_subscription.py +++ b/buildingdepot/DataService/app/rest_api/app_subscription.py @@ -22,7 +22,6 @@ class AppSubscriptionService(MethodView): - @check_oauth def post(self): """ @@ -38,25 +37,27 @@ def post(self): } """ - json_data = request.get_json()['data'] + json_data = request.get_json()["data"] email = get_email() try: - app_id = json_data['app'] - sensor = json_data['sensor'] + app_id = json_data["app"] + sensor = json_data["sensor"] except Exception as e: return jsonify(responses.missing_parameters) - app_list = Application._get_collection().find({'user': email})[0]['apps'] + app_list = Application._get_collection().find({"user": email})[0]["apps"] pubsub = connect_broker() if pubsub is None: return jsonify(responses.broker_connection_failure) for app in app_list: - if app_id == app['value']: + if app_id == app["value"]: try: channel = pubsub.channel() - channel.queue_bind(exchange=exchange, queue=app['value'], routing_key=sensor) - r.sadd(''.join(['apps:', sensor]), app['value']) + channel.queue_bind( + exchange=exchange, queue=app["value"], routing_key=sensor + ) + r.sadd("".join(["apps:", sensor]), app["value"]) except Exception as e: print("Failed to bind queue " + str(e)) @@ -89,25 +90,27 @@ def delete(self): } """ - json_data = request.get_json()['data'] + json_data = request.get_json()["data"] email = get_email() try: - app_id = json_data['app'] - sensor = json_data['sensor'] + app_id = json_data["app"] + sensor = json_data["sensor"] except Exception as e: return jsonify(responses.missing_parameters) - app_list = Application._get_collection().find({'user': email})[0]['apps'] + app_list = Application._get_collection().find({"user": email})[0]["apps"] pubsub = connect_broker() if pubsub is None: return jsonify(responses.broker_connection_failure) for app in app_list: - if app_id == app['value']: + if app_id == app["value"]: try: channel = pubsub.channel() - channel.queue_unbind(exchange=exchange, queue=app['value'], routing_key=sensor) - r.srem(''.join(['apps:', sensor]), app['value']) + channel.queue_unbind( + exchange=exchange, queue=app["value"], routing_key=sensor + ) + r.srem("".join(["apps:", sensor]), app["value"]) except Exception as e: print("Failed to bind queue " + str(e)) print(traceback.print_exc()) diff --git a/buildingdepot/DataService/app/rest_api/apps.py b/buildingdepot/DataService/app/rest_api/apps.py index 23a3a908..cbbb05fb 100755 --- a/buildingdepot/DataService/app/rest_api/apps.py +++ b/buildingdepot/DataService/app/rest_api/apps.py @@ -37,12 +37,12 @@ def get(self): email = get_email() if email is None: return jsonify(responses.missing_parameters) - apps = Application._get_collection().find({'user': email}) + apps = Application._get_collection().find({"user": email}) if apps.count() == 0: app_list = [] else: - app_list = apps[0]['apps'] - return jsonify({'success': 'True', 'app_list': app_list}) + app_list = apps[0]["apps"] + return jsonify({"success": "True", "app_list": app_list}) @check_oauth def post(self): @@ -61,31 +61,34 @@ def post(self): error_flag = False json_data = request.get_json() - if 'data' not in json_data.keys(): + if "data" not in json_data.keys(): return jsonify(responses.missing_parameters) - elif 'name' not in json_data['data'].keys(): + elif "name" not in json_data["data"].keys(): return jsonify(responses.missing_parameters) else: - name = json_data['data']['name'] + name = json_data["data"]["name"] - apps = Application._get_collection().find({'user': email}) + apps = Application._get_collection().find({"user": email}) app_list = [] json_result = {} if apps.count() != 0: - app_list = apps[0]['apps'] + app_list = apps[0]["apps"] if not isinstance(name, list): for app in app_list: - if name == app['name']: - return jsonify({'success': 'True', 'app_id': app['value']}) + if name == app["name"]: + return jsonify({"success": "True", "app_id": app["value"]}) else: json_result = {} for app in app_list: for nm in name: - if nm == app['name']: - json_result[nm] = {'success': 'True', 'app_id': app['value']} + if nm == app["name"]: + json_result[nm] = { + "success": "True", + "app_id": app["value"], + } if len(json_result.keys()) == len(name): - return jsonify({'success': 'True', 'app_id': json_result}) + return jsonify({"success": "True", "app_id": json_result}) pubsub = connect_broker() if pubsub is None: @@ -104,11 +107,11 @@ def post(self): return jsonify(responses.queue_creation_failure) if apps.count() == 0: - Application(user=email, - apps=[{'name': name, - 'value': result.method.queue}]).save() + Application( + user=email, apps=[{"name": name, "value": result.method.queue}] + ).save() else: - app_list.append({'name': name, 'value': result.method.queue}) + app_list.append({"name": name, "value": result.method.queue}) Application.objects(user=email).update(set__apps=app_list) if pubsub: @@ -118,7 +121,7 @@ def post(self): except Exception as e: print("Failed to end RabbitMQ session" + str(e)) - return jsonify({'success': 'True', 'app_id': result.method.queue}) + return jsonify({"success": "True", "app_id": result.method.queue}) elif isinstance(name, list): if not app_list: @@ -130,10 +133,10 @@ def post(self): result = channel.queue_declare(durable=True) json_result[nm] = {} - json_result[nm] = {'success': 'True'} - json_result[nm]['app_id'] = result.method.queue + json_result[nm] = {"success": "True"} + json_result[nm]["app_id"] = result.method.queue - app_list.append({'name': nm, 'value': result.method.queue}) + app_list.append({"name": nm, "value": result.method.queue}) except Exception as e: print("Failed to create queue " + str(e)) @@ -141,7 +144,10 @@ def post(self): if channel: channel.close() error_flag = True - json_result[nm] = {'success': 'False', 'error': 'Failed to create queue'} + json_result[nm] = { + "success": "False", + "error": "Failed to create queue", + } if pubsub: try: @@ -151,15 +157,14 @@ def post(self): print("Failed to end RabbitMQ session" + str(e)) if apps.count() == 0: - Application(user=email, - apps=app_list).save() + Application(user=email, apps=app_list).save() else: Application.objects(user=email).update(set__apps=app_list) if error_flag: - return jsonify({'success': 'False', 'app_id': json_result}) + return jsonify({"success": "False", "app_id": json_result}) else: - return jsonify({'success': 'True', 'app_id': json_result}) + return jsonify({"success": "True", "app_id": json_result}) return jsonify(responses.success_false) @@ -181,28 +186,28 @@ def delete(self): """ # get current user's list of applications email = get_email() - apps = Application._get_collection().find({'user': email}) + apps = Application._get_collection().find({"user": email}) app_to_be_deleted = [] json_result = {} error_flag = False channel = None - name = '' + name = "" json_data = request.get_json() - if 'data' not in json_data.keys(): + if "data" not in json_data.keys(): return jsonify(responses.missing_parameters) - elif 'name' not in json_data['data'].keys(): + elif "name" not in json_data["data"].keys(): return jsonify(responses.missing_parameters) else: - name = json_data['data']['name'] + name = json_data["data"]["name"] # check whether there is an application with the given name # case 1 - there is already an application instance for the given user if apps.count() > 0: if not isinstance(name, list): app_to_be_deleted = None - app_filter = filter(lambda x: x['name'] == name, apps[0]['apps']) + app_filter = filter(lambda x: x["name"] == name, apps[0]["apps"]) if len(app_filter) > 0: app_to_be_deleted = app_filter[0] @@ -211,11 +216,14 @@ def delete(self): json_result = {} error_flag = False for nm in name: - app_filter = filter(lambda x: x['name'] == nm, apps[0]['apps']) + app_filter = filter(lambda x: x["name"] == nm, apps[0]["apps"]) if len(app_filter) > 0: app_to_be_deleted.append(app_filter[0]) else: - json_result[nm] = {'success': 'False', 'error': 'Application does not exist'} + json_result[nm] = { + "success": "False", + "error": "Application does not exist", + } error_flag = True # If there is no application to be deleted @@ -226,16 +234,16 @@ def delete(self): if pubsub is None: return jsonify(responses.broker_connection_failure) - if not isinstance(name, list): try: channel = pubsub.channel() - if 'value' in app_to_be_deleted.keys(): - result = channel.queue_delete(queue=app_to_be_deleted['value']) + if "value" in app_to_be_deleted.keys(): + result = channel.queue_delete(queue=app_to_be_deleted["value"]) - new_app_list = list(filter(lambda x: x['name'] != name, - apps[0]['apps'])) + new_app_list = list( + filter(lambda x: x["name"] != name, apps[0]["apps"]) + ) Application.objects(user=email).update(set__apps=new_app_list) except Exception as e: @@ -258,11 +266,11 @@ def delete(self): for app_to_delete in app_to_be_deleted: try: channel = pubsub.channel() - if 'value' in app_to_delete.keys(): - result = channel.queue_delete(queue=app_to_delete['value']) + if "value" in app_to_delete.keys(): + result = channel.queue_delete(queue=app_to_delete["value"]) - json_result[app_to_delete['name']] = {} - json_result[app_to_delete['name']] = {'success': 'True'} + json_result[app_to_delete["name"]] = {} + json_result[app_to_delete["name"]] = {"success": "True"} except Exception as e: print("Failed to create queue " + str(e)) @@ -270,11 +278,14 @@ def delete(self): if channel: channel.close() error_flag = True - json_result[app_to_delete['name']] = {'success': 'False', - 'error': 'Failed to create queue'} - - new_app_list = list(filter(lambda x: x['name'] not in name, - apps[0]['apps'])) + json_result[app_to_delete["name"]] = { + "success": "False", + "error": "Failed to create queue", + } + + new_app_list = list( + filter(lambda x: x["name"] not in name, apps[0]["apps"]) + ) Application.objects(user=email).update(set__apps=new_app_list) if pubsub: @@ -286,8 +297,8 @@ def delete(self): print("Failed to end RabbitMQ session" + str(e)) if error_flag: - return jsonify({'success': 'False', 'name': json_result}) + return jsonify({"success": "False", "name": json_result}) else: - return jsonify({'success': 'True', 'name': json_result}) + return jsonify({"success": "True", "name": json_result}) return jsonify(responses.success_false) diff --git a/buildingdepot/DataService/app/rest_api/responses.py b/buildingdepot/DataService/app/rest_api/responses.py index 23dd52c2..eaced022 100755 --- a/buildingdepot/DataService/app/rest_api/responses.py +++ b/buildingdepot/DataService/app/rest_api/responses.py @@ -10,14 +10,14 @@ @license: CMU License. See License file for details. """ -success_true = {'success': 'True'} -success_false = {'success': 'False'} -missing_data = {'success': 'False', 'error': 'Missing data'} -missing_parameters = {'success': 'False', 'error': 'Missing parameters'} -resolution_high = {'success': 'False', 'error': 'Too many points for this resolution'} -broker_connection_failure = {'success': 'False', 'error': 'Failed to connect broker'} -queue_creation_failure = {'success': 'False', 'error': 'Failed to create queue'} -queue_deletion_failure = {'success': 'False', 'error': 'Failed to delete queue'} -queue_binding_failure = {'success': 'False', 'error': 'Failed to bind queue'} -queue_unbinding_failure = {'success': 'False', 'error': 'Failed to unbind queue'} -application_does_not_exist = {'success': 'False', 'error': 'Application does not exist'} +success_true = {"success": "True"} +success_false = {"success": "False"} +missing_data = {"success": "False", "error": "Missing data"} +missing_parameters = {"success": "False", "error": "Missing parameters"} +resolution_high = {"success": "False", "error": "Too many points for this resolution"} +broker_connection_failure = {"success": "False", "error": "Failed to connect broker"} +queue_creation_failure = {"success": "False", "error": "Failed to create queue"} +queue_deletion_failure = {"success": "False", "error": "Failed to delete queue"} +queue_binding_failure = {"success": "False", "error": "Failed to bind queue"} +queue_unbinding_failure = {"success": "False", "error": "Failed to unbind queue"} +application_does_not_exist = {"success": "False", "error": "Application does not exist"} diff --git a/install.sh b/install.sh index 9e717a33..8551557f 100755 --- a/install.sh +++ b/install.sh @@ -32,7 +32,7 @@ function setup_venv() { pip3 install --upgrade pip pip3 install --upgrade setuptools pip3 install --upgrade -r pip_packages.list - + pip3 install "firebase-admin==4.5.0" pip3 install --upgrade uWSGI mkdir -p /etc/uwsgi/apps-available/ diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index 6a23aa15..9ec3e679 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -120,9 +120,9 @@ function install_packages { fi apt-get update -y apt-get install - apt-get install -y python-pip + apt-get install -y python3-pip apt-get install -y mongodb-org=4.0.5 mongodb-org-server=4.0.5 mongodb-org-shell=4.0.5 mongodb-org-mongos=4.0.5 mongodb-org-tools=4.0.5 - apt-get install -y openssl python-setuptools python-dev build-essential software-properties-common + apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common apt-get install -y nginx apt-get install -y supervisor apt-get install -y redis-server From 3de6ad1ccf588c0361dc1908ff4229791df063ad Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 4 Jun 2021 08:58:12 -0400 Subject: [PATCH 41/70] Update copyright year --- buildingdepot/CentralReplica/main.py | 2 +- buildingdepot/CentralReplica/models.py | 2 +- buildingdepot/CentralService/__init__.py | 2 +- buildingdepot/CentralService/app/__init__.py | 2 +- buildingdepot/CentralService/app/auth/forms.py | 2 +- buildingdepot/CentralService/app/auth/views.py | 2 +- buildingdepot/CentralService/app/central/forms.py | 2 +- buildingdepot/CentralService/app/central/utils.py | 2 +- buildingdepot/CentralService/app/central/views.py | 2 +- buildingdepot/CentralService/app/models/cs_models.py | 2 +- buildingdepot/CentralService/app/oauth_bd/views.py | 2 +- buildingdepot/CentralService/app/rest_api/buildings/building.py | 2 +- .../CentralService/app/rest_api/buildings/building_tags.py | 2 +- .../app/rest_api/buildingtemplate/buildingtemplate.py | 2 +- .../app/rest_api/buildingtemplate/buildingtemplate_tagtypes.py | 2 +- .../CentralService/app/rest_api/dataservices/dataservice.py | 2 +- .../CentralService/app/rest_api/dataservices/ds_admins.py | 2 +- .../CentralService/app/rest_api/dataservices/ds_buildings.py | 2 +- buildingdepot/CentralService/app/rest_api/helper.py | 2 +- .../CentralService/app/rest_api/notifications/notification.py | 2 +- .../app/rest_api/notifications/push_notifications.py | 2 +- .../CentralService/app/rest_api/permissions/permission.py | 2 +- .../app/rest_api/permissions/permission_request.py | 2 +- .../CentralService/app/rest_api/permissions/permission_uuid.py | 2 +- buildingdepot/CentralService/app/rest_api/responses.py | 2 +- .../CentralService/app/rest_api/sensorgroups/sensorgroup.py | 2 +- .../CentralService/app/rest_api/sensorgroups/sg_tags.py | 2 +- buildingdepot/CentralService/app/rest_api/sensors/search.py | 2 +- buildingdepot/CentralService/app/rest_api/sensors/sensor.py | 2 +- .../CentralService/app/rest_api/sensors/sensor_tags.py | 2 +- .../CentralService/app/rest_api/sensors/sensor_views.py | 2 +- buildingdepot/CentralService/app/rest_api/tagtype/tagtype.py | 2 +- .../CentralService/app/rest_api/usergroups/ug_users.py | 2 +- .../CentralService/app/rest_api/usergroups/usergroup.py | 2 +- buildingdepot/CentralService/app/rest_api/users/user.py | 2 +- buildingdepot/CentralService/app/rest_api/views.py | 2 +- buildingdepot/CentralService/main.py | 2 +- buildingdepot/DataService/__init__.py | 2 +- buildingdepot/DataService/app/__init__.py | 2 +- buildingdepot/DataService/app/api_0_0/errors.py | 2 +- buildingdepot/DataService/app/api_0_0/resources/utils.py | 2 +- buildingdepot/DataService/app/auth/forms.py | 2 +- buildingdepot/DataService/app/auth/views.py | 2 +- buildingdepot/DataService/app/models/ds_models.py | 2 +- buildingdepot/DataService/app/oauth_bd/views.py | 2 +- buildingdepot/DataService/app/rest_api/app_subscription.py | 2 +- buildingdepot/DataService/app/rest_api/apps.py | 2 +- buildingdepot/DataService/app/rest_api/helper.py | 2 +- buildingdepot/DataService/app/rest_api/responses.py | 2 +- buildingdepot/DataService/app/rest_api/timeseries.py | 2 +- buildingdepot/DataService/app/rest_api/utils.py | 2 +- buildingdepot/DataService/app/rest_api/views.py | 2 +- buildingdepot/DataService/app/service/forms.py | 2 +- buildingdepot/DataService/app/service/views.py | 2 +- buildingdepot/DataService/main.py | 2 +- buildingdepot/DataService/wsgi.py | 2 +- .../Documentation/build/html/_sources/source/index.rst.txt | 2 +- .../build/html/_static/fonts/fontawesome-webfont.svg | 2 +- buildingdepot/Documentation/build/html/_static/language_data.js | 2 +- .../Documentation/build/html/api/CentralService/building.html | 2 +- .../build/html/api/CentralService/buildingtemplate.html | 2 +- .../build/html/api/CentralService/dataservice.html | 2 +- .../Documentation/build/html/api/CentralService/index.html | 2 +- .../Documentation/build/html/api/CentralService/oauth.html | 2 +- .../Documentation/build/html/api/CentralService/permission.html | 2 +- .../Documentation/build/html/api/CentralService/sensor.html | 2 +- .../build/html/api/CentralService/sensorgroup.html | 2 +- .../Documentation/build/html/api/CentralService/tagtype.html | 2 +- .../Documentation/build/html/api/CentralService/user.html | 2 +- .../Documentation/build/html/api/CentralService/usergroup.html | 2 +- .../Documentation/build/html/api/DataService/index.html | 2 +- .../Documentation/build/html/api/DataService/oauth.html | 2 +- .../Documentation/build/html/api/DataService/pubsub.html | 2 +- .../Documentation/build/html/api/DataService/sensordata.html | 2 +- buildingdepot/Documentation/build/html/centralservice.html | 2 +- buildingdepot/Documentation/build/html/dataservice.html | 2 +- buildingdepot/Documentation/build/html/genindex.html | 2 +- buildingdepot/Documentation/build/html/http-routingtable.html | 2 +- buildingdepot/Documentation/build/html/index.html | 2 +- buildingdepot/Documentation/build/html/install.html | 2 +- buildingdepot/Documentation/build/html/search.html | 2 +- buildingdepot/Documentation/build/html/source/index.html | 2 +- buildingdepot/Documentation/source/conf.py | 2 +- buildingdepot/Documentation/source/source/conf.py | 2 +- buildingdepot/Documentation/source/source/index.rst | 2 +- 85 files changed, 85 insertions(+), 85 deletions(-) diff --git a/buildingdepot/CentralReplica/main.py b/buildingdepot/CentralReplica/main.py index 943af2c2..e2154f3d 100755 --- a/buildingdepot/CentralReplica/main.py +++ b/buildingdepot/CentralReplica/main.py @@ -5,7 +5,7 @@ Contains the definitions for all the RPC's that the DataService calls in order to avoid talking to the CentralService all the time. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralReplica/models.py b/buildingdepot/CentralReplica/models.py index c3242dc3..52d2b72f 100755 --- a/buildingdepot/CentralReplica/models.py +++ b/buildingdepot/CentralReplica/models.py @@ -7,7 +7,7 @@ these tables can have any of the parameters defined within the class. Needs them for the RPCs -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: See License file for details. """ diff --git a/buildingdepot/CentralService/__init__.py b/buildingdepot/CentralService/__init__.py index 13a44cba..ed017f55 100755 --- a/buildingdepot/CentralService/__init__.py +++ b/buildingdepot/CentralService/__init__.py @@ -6,7 +6,7 @@ config file or falls back to the default one. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/__init__.py b/buildingdepot/CentralService/app/__init__.py index 54a1d0b5..37ee3bb0 100755 --- a/buildingdepot/CentralService/app/__init__.py +++ b/buildingdepot/CentralService/app/__init__.py @@ -11,7 +11,7 @@ services such as the main centralservice,auth service are registered as blueprints. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/auth/forms.py b/buildingdepot/CentralService/app/auth/forms.py index 1751ab4f..c249b714 100755 --- a/buildingdepot/CentralService/app/auth/forms.py +++ b/buildingdepot/CentralService/app/auth/forms.py @@ -5,7 +5,7 @@ Contains all the forms for the CentralService authorization functions. The two forms that are used are for login and for creating a new user. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/auth/views.py b/buildingdepot/CentralService/app/auth/views.py index 726e1d20..adace4dc 100755 --- a/buildingdepot/CentralService/app/auth/views.py +++ b/buildingdepot/CentralService/app/auth/views.py @@ -6,7 +6,7 @@ The functionalities available are for registering a new user,logging in and logging out. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/central/forms.py b/buildingdepot/CentralService/app/central/forms.py index aa5cd035..c84e7692 100755 --- a/buildingdepot/CentralService/app/central/forms.py +++ b/buildingdepot/CentralService/app/central/forms.py @@ -6,7 +6,7 @@ in the frontend of the CentralService such as the form to create new buildings, tags,dataserivces etc. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/central/utils.py b/buildingdepot/CentralService/app/central/utils.py index 40f19633..a4418bef 100755 --- a/buildingdepot/CentralService/app/central/utils.py +++ b/buildingdepot/CentralService/app/central/utils.py @@ -5,7 +5,7 @@ Contains the definitions for all helper functions that are used by the main CentralService. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/central/views.py b/buildingdepot/CentralService/app/central/views.py index ab2f7d68..969e2abd 100755 --- a/buildingdepot/CentralService/app/central/views.py +++ b/buildingdepot/CentralService/app/central/views.py @@ -9,7 +9,7 @@ For example opening up http://localhost:81/central/tagtype on your installation of BD will call the tagtype() function -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/models/cs_models.py b/buildingdepot/CentralService/app/models/cs_models.py index 6d36d44f..c8beb8e0 100755 --- a/buildingdepot/CentralService/app/models/cs_models.py +++ b/buildingdepot/CentralService/app/models/cs_models.py @@ -6,7 +6,7 @@ Each class here is a Table in MongoDB where each value that is inserted into these tables can have any of the paramteres defined within the class -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/oauth_bd/views.py b/buildingdepot/CentralService/app/oauth_bd/views.py index be9c572a..08e79442 100755 --- a/buildingdepot/CentralService/app/oauth_bd/views.py +++ b/buildingdepot/CentralService/app/oauth_bd/views.py @@ -5,7 +5,7 @@ Contains all the class and method definitions required for the OAuth token generation and verification -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/buildings/building.py b/buildingdepot/CentralService/app/rest_api/buildings/building.py index 7e2b81f7..2d0683d6 100755 --- a/buildingdepot/CentralService/app/rest_api/buildings/building.py +++ b/buildingdepot/CentralService/app/rest_api/buildings/building.py @@ -7,7 +7,7 @@ defined for any of the tagtypes that the template it is based on contains. Buildings can also have metadata attached to them. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/buildings/building_tags.py b/buildingdepot/CentralService/app/rest_api/buildings/building_tags.py index 41b01278..ba217f44 100755 --- a/buildingdepot/CentralService/app/rest_api/buildings/building_tags.py +++ b/buildingdepot/CentralService/app/rest_api/buildings/building_tags.py @@ -7,7 +7,7 @@ For each of the tagtypes present in the template on which this building is based on, can have multiple unique values defined for them. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate.py b/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate.py index 403d7e4c..07671e2a 100644 --- a/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate.py +++ b/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate.py @@ -8,7 +8,7 @@ can be used by all buildings that are based on that specific building template. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ from flask import jsonify, request diff --git a/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate_tagtypes.py b/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate_tagtypes.py index f71c87cd..f61a67be 100644 --- a/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate_tagtypes.py +++ b/buildingdepot/CentralService/app/rest_api/buildingtemplate/buildingtemplate_tagtypes.py @@ -5,7 +5,7 @@ This module handles the interactions with the buildingtemplate tagtypes. Takes care of all the CRUD operations on buildingtemplate tagtypes. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/dataservices/dataservice.py b/buildingdepot/CentralService/app/rest_api/dataservices/dataservice.py index 14d31a71..ffaf4477 100755 --- a/buildingdepot/CentralService/app/rest_api/dataservices/dataservice.py +++ b/buildingdepot/CentralService/app/rest_api/dataservices/dataservice.py @@ -6,7 +6,7 @@ of all the CRUD operations on dataservices. Each dataservice will have a list of buildings and admins that belong to it. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/dataservices/ds_admins.py b/buildingdepot/CentralService/app/rest_api/dataservices/ds_admins.py index a9fdc5ed..0e45bde6 100755 --- a/buildingdepot/CentralService/app/rest_api/dataservices/ds_admins.py +++ b/buildingdepot/CentralService/app/rest_api/dataservices/ds_admins.py @@ -6,7 +6,7 @@ dataservice. It handles all the CRUD operations for the admins list present in each dataservice. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/dataservices/ds_buildings.py b/buildingdepot/CentralService/app/rest_api/dataservices/ds_buildings.py index 0f7a6bb9..697f8a8e 100755 --- a/buildingdepot/CentralService/app/rest_api/dataservices/ds_buildings.py +++ b/buildingdepot/CentralService/app/rest_api/dataservices/ds_buildings.py @@ -6,7 +6,7 @@ dataservice. It handles all the CRUD operations for the buildings list present in each dataservice. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/helper.py b/buildingdepot/CentralService/app/rest_api/helper.py index 423fb7fa..73105754 100755 --- a/buildingdepot/CentralService/app/rest_api/helper.py +++ b/buildingdepot/CentralService/app/rest_api/helper.py @@ -5,7 +5,7 @@ This module contains all the helper functions needed for the api's such as conversion of timestamps, strings etc. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ import base64 diff --git a/buildingdepot/CentralService/app/rest_api/notifications/notification.py b/buildingdepot/CentralService/app/rest_api/notifications/notification.py index 3a36fd80..b1ecd439 100644 --- a/buildingdepot/CentralService/app/rest_api/notifications/notification.py +++ b/buildingdepot/CentralService/app/rest_api/notifications/notification.py @@ -4,7 +4,7 @@ This module handles setting up and managing notifications for a given ID. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/notifications/push_notifications.py b/buildingdepot/CentralService/app/rest_api/notifications/push_notifications.py index ef685d6d..be34a2a1 100644 --- a/buildingdepot/CentralService/app/rest_api/notifications/push_notifications.py +++ b/buildingdepot/CentralService/app/rest_api/notifications/push_notifications.py @@ -8,7 +8,7 @@ then this class must be extended in another file. After extending this class and implementing 'send', you must update cs_config to point to the implementation that should be loaded. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/permissions/permission.py b/buildingdepot/CentralService/app/rest_api/permissions/permission.py index c70b1e4d..5d77a19e 100755 --- a/buildingdepot/CentralService/app/rest_api/permissions/permission.py +++ b/buildingdepot/CentralService/app/rest_api/permissions/permission.py @@ -5,7 +5,7 @@ This module handles interacting with the underlying permission models. It handles the required CRUD operations for permissions. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ import sys diff --git a/buildingdepot/CentralService/app/rest_api/permissions/permission_request.py b/buildingdepot/CentralService/app/rest_api/permissions/permission_request.py index 71ccf3be..99215700 100644 --- a/buildingdepot/CentralService/app/rest_api/permissions/permission_request.py +++ b/buildingdepot/CentralService/app/rest_api/permissions/permission_request.py @@ -5,7 +5,7 @@ This module handles interacting with the underlying permission models. It handles the required CRUD operations for permissions. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/permissions/permission_uuid.py b/buildingdepot/CentralService/app/rest_api/permissions/permission_uuid.py index 1825fdac..56c3efb8 100644 --- a/buildingdepot/CentralService/app/rest_api/permissions/permission_uuid.py +++ b/buildingdepot/CentralService/app/rest_api/permissions/permission_uuid.py @@ -5,7 +5,7 @@ This module handles interacting with the underlying permission models. It handles the required CRUD operations for permissions. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/responses.py b/buildingdepot/CentralService/app/rest_api/responses.py index 4a559c96..5e0fca2e 100755 --- a/buildingdepot/CentralService/app/rest_api/responses.py +++ b/buildingdepot/CentralService/app/rest_api/responses.py @@ -6,7 +6,7 @@ to the user under certain failure and success conditions are defined here in this file -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/sensorgroups/sensorgroup.py b/buildingdepot/CentralService/app/rest_api/sensorgroups/sensorgroup.py index 7b11952e..be60af65 100755 --- a/buildingdepot/CentralService/app/rest_api/sensorgroups/sensorgroup.py +++ b/buildingdepot/CentralService/app/rest_api/sensorgroups/sensorgroup.py @@ -8,7 +8,7 @@ list of the sensors that fall in this group. This list is further used for acl's and other purposes. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ import sys diff --git a/buildingdepot/CentralService/app/rest_api/sensorgroups/sg_tags.py b/buildingdepot/CentralService/app/rest_api/sensorgroups/sg_tags.py index d96df4c9..451dfda1 100755 --- a/buildingdepot/CentralService/app/rest_api/sensorgroups/sg_tags.py +++ b/buildingdepot/CentralService/app/rest_api/sensorgroups/sg_tags.py @@ -7,7 +7,7 @@ it updates the cache where a list is maintained of the sensors that fall in each group. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/sensors/search.py b/buildingdepot/CentralService/app/rest_api/sensors/search.py index 9ede69ca..0137d27f 100755 --- a/buildingdepot/CentralService/app/rest_api/sensors/search.py +++ b/buildingdepot/CentralService/app/rest_api/sensors/search.py @@ -6,7 +6,7 @@ search for Sensors based on a combination of the parameters that a sensor contains such as Tags,Building,Source identifier,uuid etc. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/sensors/sensor.py b/buildingdepot/CentralService/app/rest_api/sensors/sensor.py index 326064a0..c488c13e 100755 --- a/buildingdepot/CentralService/app/rest_api/sensors/sensor.py +++ b/buildingdepot/CentralService/app/rest_api/sensors/sensor.py @@ -7,7 +7,7 @@ retrieving sensor details. It manages the underlying cache, and will ensure that the cache gets updated as needed. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/sensors/sensor_tags.py b/buildingdepot/CentralService/app/rest_api/sensors/sensor_tags.py index dcc2a1d7..19e7804d 100755 --- a/buildingdepot/CentralService/app/rest_api/sensors/sensor_tags.py +++ b/buildingdepot/CentralService/app/rest_api/sensors/sensor_tags.py @@ -8,7 +8,7 @@ update/remove tags from a sensor -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: See License file for details. """ import sys diff --git a/buildingdepot/CentralService/app/rest_api/sensors/sensor_views.py b/buildingdepot/CentralService/app/rest_api/sensors/sensor_views.py index cb7fad44..20d11819 100755 --- a/buildingdepot/CentralService/app/rest_api/sensors/sensor_views.py +++ b/buildingdepot/CentralService/app/rest_api/sensors/sensor_views.py @@ -7,7 +7,7 @@ retrieving sensor view details. It manages the underlying cache, and will ensure that the cache gets updated as needed. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/tagtype/tagtype.py b/buildingdepot/CentralService/app/rest_api/tagtype/tagtype.py index 30b552f4..ab26011d 100755 --- a/buildingdepot/CentralService/app/rest_api/tagtype/tagtype.py +++ b/buildingdepot/CentralService/app/rest_api/tagtype/tagtype.py @@ -6,7 +6,7 @@ of all the CRUD operations on the tagtypes. Each tagtype can have parent and children tagtypes specifed for it. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/usergroups/ug_users.py b/buildingdepot/CentralService/app/rest_api/usergroups/ug_users.py index 2e81f99f..ab68b23d 100755 --- a/buildingdepot/CentralService/app/rest_api/usergroups/ug_users.py +++ b/buildingdepot/CentralService/app/rest_api/usergroups/ug_users.py @@ -7,7 +7,7 @@ it updates the cache where a list is maintained of the users that fall in each user group. This list is further used for acl's and other purposes. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ import sys diff --git a/buildingdepot/CentralService/app/rest_api/usergroups/usergroup.py b/buildingdepot/CentralService/app/rest_api/usergroups/usergroup.py index 147ab88e..0086e440 100755 --- a/buildingdepot/CentralService/app/rest_api/usergroups/usergroup.py +++ b/buildingdepot/CentralService/app/rest_api/usergroups/usergroup.py @@ -6,7 +6,7 @@ It handles the common services for user groups, such as making a new one or deleting an existing one. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ import sys diff --git a/buildingdepot/CentralService/app/rest_api/users/user.py b/buildingdepot/CentralService/app/rest_api/users/user.py index 98ad2880..bb3507c4 100755 --- a/buildingdepot/CentralService/app/rest_api/users/user.py +++ b/buildingdepot/CentralService/app/rest_api/users/user.py @@ -7,7 +7,7 @@ an email is sent out to the specified id with a temporary password that will have to be changed on first login. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/CentralService/app/rest_api/views.py b/buildingdepot/CentralService/app/rest_api/views.py index 9031c6e0..c447b8c3 100755 --- a/buildingdepot/CentralService/app/rest_api/views.py +++ b/buildingdepot/CentralService/app/rest_api/views.py @@ -7,7 +7,7 @@ requests will also have an additional check where the ACL's are referenced to see if the user has access to the specific sensor -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ from flask import request, jsonify diff --git a/buildingdepot/CentralService/main.py b/buildingdepot/CentralService/main.py index de419e59..9fc63637 100755 --- a/buildingdepot/CentralService/main.py +++ b/buildingdepot/CentralService/main.py @@ -6,7 +6,7 @@ config file or falls back to the default one. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/__init__.py b/buildingdepot/DataService/__init__.py index 2ebc4142..1743d6c2 100755 --- a/buildingdepot/DataService/__init__.py +++ b/buildingdepot/DataService/__init__.py @@ -6,7 +6,7 @@ config file or falls back to the default one. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/app/__init__.py b/buildingdepot/DataService/app/__init__.py index 131c285f..da6ec324 100755 --- a/buildingdepot/DataService/app/__init__.py +++ b/buildingdepot/DataService/app/__init__.py @@ -14,7 +14,7 @@ services such as the main dataservice,rest_api and oauth service are registered as blueprints. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: See License file for details. """ diff --git a/buildingdepot/DataService/app/api_0_0/errors.py b/buildingdepot/DataService/app/api_0_0/errors.py index e5115dea..d9e2f379 100755 --- a/buildingdepot/DataService/app/api_0_0/errors.py +++ b/buildingdepot/DataService/app/api_0_0/errors.py @@ -4,7 +4,7 @@ Function definitions for various HTTP errors than can be thrown. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ from flask import jsonify diff --git a/buildingdepot/DataService/app/api_0_0/resources/utils.py b/buildingdepot/DataService/app/api_0_0/resources/utils.py index 517d2481..c555a1e2 100755 --- a/buildingdepot/DataService/app/api_0_0/resources/utils.py +++ b/buildingdepot/DataService/app/api_0_0/resources/utils.py @@ -6,7 +6,7 @@ called to authenticate,validate email,define what level of access the user has to the specified sensor. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/app/auth/forms.py b/buildingdepot/DataService/app/auth/forms.py index 20538c8f..9aca696e 100755 --- a/buildingdepot/DataService/app/auth/forms.py +++ b/buildingdepot/DataService/app/auth/forms.py @@ -4,7 +4,7 @@ Class definition for the login form -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ from flask_wtf import FlaskForm diff --git a/buildingdepot/DataService/app/auth/views.py b/buildingdepot/DataService/app/auth/views.py index 05ab7654..67e8d3e5 100755 --- a/buildingdepot/DataService/app/auth/views.py +++ b/buildingdepot/DataService/app/auth/views.py @@ -4,7 +4,7 @@ Functions for user login and logout from the DataService -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/app/models/ds_models.py b/buildingdepot/DataService/app/models/ds_models.py index cbc168c2..c3b3dac9 100755 --- a/buildingdepot/DataService/app/models/ds_models.py +++ b/buildingdepot/DataService/app/models/ds_models.py @@ -6,7 +6,7 @@ Each class here is a Table in MongoDB where each value that is inserted into these tables can have any of the paramteres defined within the class -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/app/oauth_bd/views.py b/buildingdepot/DataService/app/oauth_bd/views.py index bd84b4c2..64ff2ed2 100755 --- a/buildingdepot/DataService/app/oauth_bd/views.py +++ b/buildingdepot/DataService/app/oauth_bd/views.py @@ -5,7 +5,7 @@ Contains all the class and method definitions required for the OAuth token generation and verification -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/app/rest_api/app_subscription.py b/buildingdepot/DataService/app/rest_api/app_subscription.py index e6aaa3df..c7e41298 100755 --- a/buildingdepot/DataService/app/rest_api/app_subscription.py +++ b/buildingdepot/DataService/app/rest_api/app_subscription.py @@ -6,7 +6,7 @@ subscribe the sensors that the user requests to the app id specified. It also accordingly handles the unsubscription of sensors from the apps. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/app/rest_api/apps.py b/buildingdepot/DataService/app/rest_api/apps.py index cbbb05fb..9b826b68 100755 --- a/buildingdepot/DataService/app/rest_api/apps.py +++ b/buildingdepot/DataService/app/rest_api/apps.py @@ -5,7 +5,7 @@ This module handles interacting with the underlying app models. It handles the registration and deletion of apps from the system. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/app/rest_api/helper.py b/buildingdepot/DataService/app/rest_api/helper.py index a4797f77..b38317c9 100755 --- a/buildingdepot/DataService/app/rest_api/helper.py +++ b/buildingdepot/DataService/app/rest_api/helper.py @@ -5,7 +5,7 @@ This module contains all the helper functions needed for the api's such as conversion of timestamps, strings etc. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ import json diff --git a/buildingdepot/DataService/app/rest_api/responses.py b/buildingdepot/DataService/app/rest_api/responses.py index eaced022..9fb27333 100755 --- a/buildingdepot/DataService/app/rest_api/responses.py +++ b/buildingdepot/DataService/app/rest_api/responses.py @@ -6,7 +6,7 @@ to the user under certain failure and success conditions are defined here in this file -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/app/rest_api/timeseries.py b/buildingdepot/DataService/app/rest_api/timeseries.py index ba37ec6b..ef50f4c5 100755 --- a/buildingdepot/DataService/app/rest_api/timeseries.py +++ b/buildingdepot/DataService/app/rest_api/timeseries.py @@ -6,7 +6,7 @@ handles all the logic for inserting a data value and reading from the underlying data stores. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ import influxdb diff --git a/buildingdepot/DataService/app/rest_api/utils.py b/buildingdepot/DataService/app/rest_api/utils.py index cfe65c11..632a3823 100755 --- a/buildingdepot/DataService/app/rest_api/utils.py +++ b/buildingdepot/DataService/app/rest_api/utils.py @@ -7,7 +7,7 @@ CentralService such as valid tags, list of buildings etc. will have to go through this if data is not found in the cache -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/app/rest_api/views.py b/buildingdepot/DataService/app/rest_api/views.py index 2b97efe4..84acddb8 100755 --- a/buildingdepot/DataService/app/rest_api/views.py +++ b/buildingdepot/DataService/app/rest_api/views.py @@ -7,7 +7,7 @@ requests will also have an additional check where the ACL's are referenced to see if the user has access to the specific sensor -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/app/service/forms.py b/buildingdepot/DataService/app/service/forms.py index 60598a35..c32e8f5e 100755 --- a/buildingdepot/DataService/app/service/forms.py +++ b/buildingdepot/DataService/app/service/forms.py @@ -5,7 +5,7 @@ Contains the definitions for all the forms that will be shown to the user in the frontend of the DataService. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/app/service/views.py b/buildingdepot/DataService/app/service/views.py index 00d4d490..bf02d08b 100755 --- a/buildingdepot/DataService/app/service/views.py +++ b/buildingdepot/DataService/app/service/views.py @@ -9,7 +9,7 @@ For example opening up http://localhost:81/service/sensor on your installation of BD will call the sensor() function -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/main.py b/buildingdepot/DataService/main.py index 4f735b0e..35bdbe05 100755 --- a/buildingdepot/DataService/main.py +++ b/buildingdepot/DataService/main.py @@ -6,7 +6,7 @@ config file or falls back to the default one. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/DataService/wsgi.py b/buildingdepot/DataService/wsgi.py index c68fd884..351362f0 100644 --- a/buildingdepot/DataService/wsgi.py +++ b/buildingdepot/DataService/wsgi.py @@ -6,7 +6,7 @@ config file or falls back to the default one. -@copyright: (c) 2020 SynergyLabs +@copyright: (c) 2021 SynergyLabs @license: CMU License. See License file for details. """ diff --git a/buildingdepot/Documentation/build/html/_sources/source/index.rst.txt b/buildingdepot/Documentation/build/html/_sources/source/index.rst.txt index e9f61510..5b4bf26a 100644 --- a/buildingdepot/Documentation/build/html/_sources/source/index.rst.txt +++ b/buildingdepot/Documentation/build/html/_sources/source/index.rst.txt @@ -1,5 +1,5 @@ .. BuildingDepot v3.2.9 documentation master file, created by - sphinx-quickstart on Mon Feb 24 20:13:25 2020. + sphinx-quickstart on Mon Feb 24 20:13:25 2021. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. diff --git a/buildingdepot/Documentation/build/html/_static/fonts/fontawesome-webfont.svg b/buildingdepot/Documentation/build/html/_static/fonts/fontawesome-webfont.svg index 397dfbe8..e2f6b07c 100644 --- a/buildingdepot/Documentation/build/html/_static/fonts/fontawesome-webfont.svg +++ b/buildingdepot/Documentation/build/html/_static/fonts/fontawesome-webfont.svg @@ -1191,7 +1191,7 @@ + d="M2021 1525q28 -20 28 -53v-1408q0 -20 -11 -36t-29 -23l-640 -256q-24 -11 -48 0l-616 246l-616 -246q-10 -5 -24 -5q-19 0 -36 11q-28 20 -28 53v1408q0 20 11 36t29 23l640 256q24 11 48 0l616 -246l616 246q32 13 60 -6zM736 1390v-1270l576 -230v1270zM128 1173 v-1270l544 217v1270zM1920 107v1270l-544 -217v-1270z"/> Delete Building Tags

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/CentralService/buildingtemplate.html b/buildingdepot/Documentation/build/html/api/CentralService/buildingtemplate.html index 39e29d7e..1cbb1682 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/buildingtemplate.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/buildingtemplate.html @@ -362,7 +362,7 @@

Delete Building Template

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/CentralService/dataservice.html b/buildingdepot/Documentation/build/html/api/CentralService/dataservice.html index 988f4ae3..d8bb81b9 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/dataservice.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/dataservice.html @@ -747,7 +747,7 @@

Revoke Admin Privileges on DataService

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/CentralService/index.html b/buildingdepot/Documentation/build/html/api/CentralService/index.html index 2ec975d0..4340c8fd 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/index.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/index.html @@ -374,7 +374,7 @@

CentralService APIs

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/CentralService/oauth.html b/buildingdepot/Documentation/build/html/api/CentralService/oauth.html index 8db4c90f..72502f07 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/oauth.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/oauth.html @@ -217,7 +217,7 @@

Generating access tokens

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/CentralService/permission.html b/buildingdepot/Documentation/build/html/api/CentralService/permission.html index 7de3adca..12ad74b2 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/permission.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/permission.html @@ -462,7 +462,7 @@

Delete Permission

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/CentralService/sensor.html b/buildingdepot/Documentation/build/html/api/CentralService/sensor.html index 9db71817..aa463a36 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/sensor.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/sensor.html @@ -795,7 +795,7 @@

SensorGroups and UserGroups

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/CentralService/sensorgroup.html b/buildingdepot/Documentation/build/html/api/CentralService/sensorgroup.html index 5f59995f..b64af9ea 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/sensorgroup.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/sensorgroup.html @@ -453,7 +453,7 @@

Get list of tags in SensorGroup

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/CentralService/tagtype.html b/buildingdepot/Documentation/build/html/api/CentralService/tagtype.html index 48fe6804..0b1d1b8a 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/tagtype.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/tagtype.html @@ -297,7 +297,7 @@

Get TagType

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/CentralService/user.html b/buildingdepot/Documentation/build/html/api/CentralService/user.html index 53e98e8a..257a3e6c 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/user.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/user.html @@ -361,7 +361,7 @@

Remove User

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/CentralService/usergroup.html b/buildingdepot/Documentation/build/html/api/CentralService/usergroup.html index 4c49f0f8..5b3479d1 100755 --- a/buildingdepot/Documentation/build/html/api/CentralService/usergroup.html +++ b/buildingdepot/Documentation/build/html/api/CentralService/usergroup.html @@ -439,7 +439,7 @@

Get list of users in UserGroup

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/DataService/index.html b/buildingdepot/Documentation/build/html/api/DataService/index.html index 49f891ff..78689017 100755 --- a/buildingdepot/Documentation/build/html/api/DataService/index.html +++ b/buildingdepot/Documentation/build/html/api/DataService/index.html @@ -216,7 +216,7 @@

DataService APIs

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/DataService/oauth.html b/buildingdepot/Documentation/build/html/api/DataService/oauth.html index 0fa3a656..d563a101 100644 --- a/buildingdepot/Documentation/build/html/api/DataService/oauth.html +++ b/buildingdepot/Documentation/build/html/api/DataService/oauth.html @@ -204,7 +204,7 @@

Generating access tokens

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/DataService/pubsub.html b/buildingdepot/Documentation/build/html/api/DataService/pubsub.html index 72ddcd76..92cabb3c 100755 --- a/buildingdepot/Documentation/build/html/api/DataService/pubsub.html +++ b/buildingdepot/Documentation/build/html/api/DataService/pubsub.html @@ -499,7 +499,7 @@

Unsubscribe from a Sensor

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/api/DataService/sensordata.html b/buildingdepot/Documentation/build/html/api/DataService/sensordata.html index 3246482c..78b9df43 100755 --- a/buildingdepot/Documentation/build/html/api/DataService/sensordata.html +++ b/buildingdepot/Documentation/build/html/api/DataService/sensordata.html @@ -300,7 +300,7 @@

Read Timeseries Datapoints

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/centralservice.html b/buildingdepot/Documentation/build/html/centralservice.html index 6a45ea2e..69226ba7 100755 --- a/buildingdepot/Documentation/build/html/centralservice.html +++ b/buildingdepot/Documentation/build/html/centralservice.html @@ -372,7 +372,7 @@

Permission

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/dataservice.html b/buildingdepot/Documentation/build/html/dataservice.html index a57478fb..6d23b1af 100755 --- a/buildingdepot/Documentation/build/html/dataservice.html +++ b/buildingdepot/Documentation/build/html/dataservice.html @@ -204,7 +204,7 @@

Apps

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/genindex.html b/buildingdepot/Documentation/build/html/genindex.html index bc662768..bcb8fb65 100755 --- a/buildingdepot/Documentation/build/html/genindex.html +++ b/buildingdepot/Documentation/build/html/genindex.html @@ -138,7 +138,7 @@

Index

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/http-routingtable.html b/buildingdepot/Documentation/build/html/http-routingtable.html index 69d2dac1..efa25926 100755 --- a/buildingdepot/Documentation/build/html/http-routingtable.html +++ b/buildingdepot/Documentation/build/html/http-routingtable.html @@ -521,7 +521,7 @@

Quick search

diff --git a/buildingdepot/Documentation/build/html/install.html b/buildingdepot/Documentation/build/html/install.html index e5cdf1ee..f70ed4b9 100755 --- a/buildingdepot/Documentation/build/html/install.html +++ b/buildingdepot/Documentation/build/html/install.html @@ -296,7 +296,7 @@

CentralService

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/search.html b/buildingdepot/Documentation/build/html/search.html index 6bd51982..2de48042 100755 --- a/buildingdepot/Documentation/build/html/search.html +++ b/buildingdepot/Documentation/build/html/search.html @@ -143,7 +143,7 @@

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/build/html/source/index.html b/buildingdepot/Documentation/build/html/source/index.html index b11de22b..eb182faa 100644 --- a/buildingdepot/Documentation/build/html/source/index.html +++ b/buildingdepot/Documentation/build/html/source/index.html @@ -156,7 +156,7 @@

Indices and tables

- © Copyright 2020, SynergyLabs. + © Copyright 2021, SynergyLabs.

diff --git a/buildingdepot/Documentation/source/conf.py b/buildingdepot/Documentation/source/conf.py index a547f616..64f64299 100755 --- a/buildingdepot/Documentation/source/conf.py +++ b/buildingdepot/Documentation/source/conf.py @@ -8,7 +8,7 @@ # -- Project information ----------------------------------------------------- project = "BuildingDepot" -copyright = "2020, SynergyLabs" +copyright = "2021, SynergyLabs" author = "SynergyLabs" # The short X.Y version diff --git a/buildingdepot/Documentation/source/source/conf.py b/buildingdepot/Documentation/source/source/conf.py index 40750f03..412ee7d0 100644 --- a/buildingdepot/Documentation/source/source/conf.py +++ b/buildingdepot/Documentation/source/source/conf.py @@ -20,7 +20,7 @@ # -- Project information ----------------------------------------------------- project = "BuildingDepot v3.3.0" -copyright = "2020, SynergyLabs@CMU" +copyright = "2021, SynergyLabs@CMU" author = "Shreyas Nagare" # The short X.Y version diff --git a/buildingdepot/Documentation/source/source/index.rst b/buildingdepot/Documentation/source/source/index.rst index 3f0f003e..da94d05a 100644 --- a/buildingdepot/Documentation/source/source/index.rst +++ b/buildingdepot/Documentation/source/source/index.rst @@ -1,5 +1,5 @@ .. BuildingDepot v3.2.9 documentation master file, created by -sphinx-quickstart on Mon Feb 24 20:13:25 2020. +sphinx-quickstart on Mon Feb 24 20:13:25 2021. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. From b4d4c42dc1a2c9886d26bb892ddf4c7d3d314ba5 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Fri, 4 Jun 2021 09:01:18 -0400 Subject: [PATCH 42/70] Add Python3 safety type casts --- .../app/rest_api/app_subscription.py | 12 ++--- .../DataService/app/rest_api/apps.py | 50 +++++++++---------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/buildingdepot/DataService/app/rest_api/app_subscription.py b/buildingdepot/DataService/app/rest_api/app_subscription.py index c7e41298..b33edbfe 100755 --- a/buildingdepot/DataService/app/rest_api/app_subscription.py +++ b/buildingdepot/DataService/app/rest_api/app_subscription.py @@ -60,8 +60,8 @@ def post(self): r.sadd("".join(["apps:", sensor]), app["value"]) except Exception as e: - print("Failed to bind queue " + str(e)) - print(traceback.print_exc()) + print(("Failed to bind queue " + str(e))) + print((traceback.print_exc())) return jsonify(responses.queue_binding_failure) if pubsub: @@ -69,7 +69,7 @@ def post(self): channel.close() pubsub.close() except Exception as e: - print("Failed to end RabbitMQ session" + str(e)) + print(("Failed to end RabbitMQ session" + str(e))) return jsonify(responses.success_true) @@ -112,8 +112,8 @@ def delete(self): ) r.srem("".join(["apps:", sensor]), app["value"]) except Exception as e: - print("Failed to bind queue " + str(e)) - print(traceback.print_exc()) + print(("Failed to bind queue " + str(e))) + print((traceback.print_exc())) return jsonify(responses.queue_binding_failure) if pubsub: @@ -121,7 +121,7 @@ def delete(self): channel.close() pubsub.close() except Exception as e: - print("Failed to end RabbitMQ session" + str(e)) + print(("Failed to end RabbitMQ session" + str(e))) return jsonify(responses.success_true) diff --git a/buildingdepot/DataService/app/rest_api/apps.py b/buildingdepot/DataService/app/rest_api/apps.py index 9b826b68..4d13682c 100755 --- a/buildingdepot/DataService/app/rest_api/apps.py +++ b/buildingdepot/DataService/app/rest_api/apps.py @@ -61,9 +61,9 @@ def post(self): error_flag = False json_data = request.get_json() - if "data" not in json_data.keys(): + if "data" not in list(json_data.keys()): return jsonify(responses.missing_parameters) - elif "name" not in json_data["data"].keys(): + elif "name" not in list(json_data["data"].keys()): return jsonify(responses.missing_parameters) else: name = json_data["data"]["name"] @@ -87,7 +87,7 @@ def post(self): "app_id": app["value"], } - if len(json_result.keys()) == len(name): + if len(list(json_result.keys())) == len(name): return jsonify({"success": "True", "app_id": json_result}) pubsub = connect_broker() @@ -100,8 +100,8 @@ def post(self): channel = pubsub.channel() result = channel.queue_declare(durable=True) except Exception as e: - print("Failed to create queue " + str(e)) - print(traceback.print_exc()) + print(("Failed to create queue " + str(e))) + print((traceback.print_exc())) if channel: channel.close() return jsonify(responses.queue_creation_failure) @@ -119,7 +119,7 @@ def post(self): channel.close() pubsub.close() except Exception as e: - print("Failed to end RabbitMQ session" + str(e)) + print(("Failed to end RabbitMQ session" + str(e))) return jsonify({"success": "True", "app_id": result.method.queue}) @@ -139,8 +139,8 @@ def post(self): app_list.append({"name": nm, "value": result.method.queue}) except Exception as e: - print("Failed to create queue " + str(e)) - print(traceback.print_exc()) + print(("Failed to create queue " + str(e))) + print((traceback.print_exc())) if channel: channel.close() error_flag = True @@ -154,7 +154,7 @@ def post(self): channel.close() pubsub.close() except Exception as e: - print("Failed to end RabbitMQ session" + str(e)) + print(("Failed to end RabbitMQ session" + str(e))) if apps.count() == 0: Application(user=email, apps=app_list).save() @@ -195,9 +195,9 @@ def delete(self): name = "" json_data = request.get_json() - if "data" not in json_data.keys(): + if "data" not in list(json_data.keys()): return jsonify(responses.missing_parameters) - elif "name" not in json_data["data"].keys(): + elif "name" not in list(json_data["data"].keys()): return jsonify(responses.missing_parameters) else: name = json_data["data"]["name"] @@ -207,7 +207,7 @@ def delete(self): if apps.count() > 0: if not isinstance(name, list): app_to_be_deleted = None - app_filter = filter(lambda x: x["name"] == name, apps[0]["apps"]) + app_filter = [x for x in apps[0]["apps"] if x["name"] == name] if len(app_filter) > 0: app_to_be_deleted = app_filter[0] @@ -216,7 +216,7 @@ def delete(self): json_result = {} error_flag = False for nm in name: - app_filter = filter(lambda x: x["name"] == nm, apps[0]["apps"]) + app_filter = [x for x in apps[0]["apps"] if x["name"] == nm] if len(app_filter) > 0: app_to_be_deleted.append(app_filter[0]) else: @@ -238,17 +238,15 @@ def delete(self): try: channel = pubsub.channel() - if "value" in app_to_be_deleted.keys(): + if "value" in list(app_to_be_deleted.keys()): result = channel.queue_delete(queue=app_to_be_deleted["value"]) - new_app_list = list( - filter(lambda x: x["name"] != name, apps[0]["apps"]) - ) + new_app_list = list([x for x in apps[0]["apps"] if x["name"] != name]) Application.objects(user=email).update(set__apps=new_app_list) except Exception as e: - print("Failed to create queue " + str(e)) - print(traceback.print_exc()) + print(("Failed to create queue " + str(e))) + print((traceback.print_exc())) if channel: channel.close() return jsonify(responses.queue_creation_failure) @@ -258,7 +256,7 @@ def delete(self): channel.close() pubsub.close() except Exception as e: - print("Failed to end RabbitMQ session" + str(e)) + print(("Failed to end RabbitMQ session" + str(e))) return jsonify(responses.success_true) @@ -266,15 +264,15 @@ def delete(self): for app_to_delete in app_to_be_deleted: try: channel = pubsub.channel() - if "value" in app_to_delete.keys(): + if "value" in list(app_to_delete.keys()): result = channel.queue_delete(queue=app_to_delete["value"]) json_result[app_to_delete["name"]] = {} json_result[app_to_delete["name"]] = {"success": "True"} except Exception as e: - print("Failed to create queue " + str(e)) - print(traceback.print_exc()) + print(("Failed to create queue " + str(e))) + print((traceback.print_exc())) if channel: channel.close() error_flag = True @@ -283,9 +281,7 @@ def delete(self): "error": "Failed to create queue", } - new_app_list = list( - filter(lambda x: x["name"] not in name, apps[0]["apps"]) - ) + new_app_list = list([x for x in apps[0]["apps"] if x["name"] not in name]) Application.objects(user=email).update(set__apps=new_app_list) if pubsub: @@ -294,7 +290,7 @@ def delete(self): channel.close() pubsub.close() except Exception as e: - print("Failed to end RabbitMQ session" + str(e)) + print(("Failed to end RabbitMQ session" + str(e))) if error_flag: return jsonify({"success": "False", "name": json_result}) From f5659c887a158e0ee10fb2351a65e100ff52bf71 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Wed, 9 Jun 2021 18:04:02 -0400 Subject: [PATCH 43/70] Fix circular imports --- buildingdepot/DataService/app/rest_api/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildingdepot/DataService/app/rest_api/helper.py b/buildingdepot/DataService/app/rest_api/helper.py index b38317c9..8bcfbe10 100755 --- a/buildingdepot/DataService/app/rest_api/helper.py +++ b/buildingdepot/DataService/app/rest_api/helper.py @@ -17,7 +17,7 @@ from .. import exchange, r from ..models.ds_models import Building, TagType, User -from ..oauth_bd.views import Token +from ..auth.views import Token def get_email(): From 2f4631c566ab9fbdee1be612d338996cf9e47495 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Wed, 9 Jun 2021 18:15:53 -0400 Subject: [PATCH 44/70] Fix pika queue declarations --- buildingdepot/DataService/app/rest_api/apps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildingdepot/DataService/app/rest_api/apps.py b/buildingdepot/DataService/app/rest_api/apps.py index 4d13682c..a2b7984d 100755 --- a/buildingdepot/DataService/app/rest_api/apps.py +++ b/buildingdepot/DataService/app/rest_api/apps.py @@ -98,7 +98,7 @@ def post(self): channel = None try: channel = pubsub.channel() - result = channel.queue_declare(durable=True) + result = channel.queue_declare(queue="", durable=True) except Exception as e: print(("Failed to create queue " + str(e))) print((traceback.print_exc())) @@ -130,7 +130,7 @@ def post(self): channel = None try: channel = pubsub.channel() - result = channel.queue_declare(durable=True) + result = channel.queue_declare(queue="", durable=True) json_result[nm] = {} json_result[nm] = {"success": "True"} From e532b02a71b4520ea8e277fb02659fb4cc8535de Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Wed, 9 Jun 2021 18:33:38 -0400 Subject: [PATCH 45/70] Use shell context errors --- buildingdepot/CentralService/__init__.py | 7 ++----- buildingdepot/DataService/__init__.py | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/buildingdepot/CentralService/__init__.py b/buildingdepot/CentralService/__init__.py index ed017f55..d0f49974 100755 --- a/buildingdepot/CentralService/__init__.py +++ b/buildingdepot/CentralService/__init__.py @@ -11,22 +11,19 @@ """ import os -from flask_script import Manager, Shell from .app import create_app from .app.models.cs_models import User from .app.rest_api.register import register_view app = create_app(os.getenv("FLASK_CONFIG") or "dev") -manager = Manager(app) register_view(app) +@app.shell_context_processor def make_shell_context(): return dict(app=app, User=User) -manager.add_command("shell", Shell(make_context=make_shell_context)) - if __name__ == "__main__": - manager.run() + app.run() diff --git a/buildingdepot/DataService/__init__.py b/buildingdepot/DataService/__init__.py index 1743d6c2..c9037047 100755 --- a/buildingdepot/DataService/__init__.py +++ b/buildingdepot/DataService/__init__.py @@ -17,10 +17,9 @@ from .app.rest_api.register import register_view app = create_app(os.getenv("FLASK_CONFIG") or "dev") -manager = Manager(app) register_view(app) - +@app.shell_context_processor def make_shell_context(): return dict(app=app) @@ -29,7 +28,5 @@ def get_current(): return app -manager.add_command("shell", Shell(make_context=make_shell_context)) - if __name__ == "__main__": - manager.run() + app.run() From dd04c2ce4e6b418428fb8f476a7e1e38f9553bfb Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Wed, 9 Jun 2021 18:46:51 -0400 Subject: [PATCH 46/70] Update dependency version --- buildingdepot/CentralService/requirements.txt | 2 +- buildingdepot/pip_packages.list | 2 +- pip_packages.list | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/buildingdepot/CentralService/requirements.txt b/buildingdepot/CentralService/requirements.txt index 380cecb0..0c91305b 100755 --- a/buildingdepot/CentralService/requirements.txt +++ b/buildingdepot/CentralService/requirements.txt @@ -2,7 +2,7 @@ aniso8601==8.0.0 email-validator==1.1.1 Flask-Bootstrap==3.3.7.1 Flask-Login==0.5.0 -Flask-OAuthlib@ https://github.com/shreyasnagare/flask-oauthlib/archive/8900433ef90dbf7b3e5c1c6389db59a9336aecea.tar.gz +Flask-OAuthlib==0.9.6 Flask-Script==2.0.6 Flask-WTF==0.14.3 influxdb==5.3.0 diff --git a/buildingdepot/pip_packages.list b/buildingdepot/pip_packages.list index eba222b0..0c91305b 100755 --- a/buildingdepot/pip_packages.list +++ b/buildingdepot/pip_packages.list @@ -2,7 +2,7 @@ aniso8601==8.0.0 email-validator==1.1.1 Flask-Bootstrap==3.3.7.1 Flask-Login==0.5.0 -Flask-OAuthlib @ https://github.com/shreyasnagare/flask-oauthlib/archive/8900433ef90dbf7b3e5c1c6389db59a9336aecea.tar.gz +Flask-OAuthlib==0.9.6 Flask-Script==2.0.6 Flask-WTF==0.14.3 influxdb==5.3.0 diff --git a/pip_packages.list b/pip_packages.list index eba222b0..0c91305b 100644 --- a/pip_packages.list +++ b/pip_packages.list @@ -2,7 +2,7 @@ aniso8601==8.0.0 email-validator==1.1.1 Flask-Bootstrap==3.3.7.1 Flask-Login==0.5.0 -Flask-OAuthlib @ https://github.com/shreyasnagare/flask-oauthlib/archive/8900433ef90dbf7b3e5c1c6389db59a9336aecea.tar.gz +Flask-OAuthlib==0.9.6 Flask-Script==2.0.6 Flask-WTF==0.14.3 influxdb==5.3.0 From ed2ba3b99304480c5d177f5499db2b2172311d9f Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Wed, 9 Jun 2021 19:05:42 -0400 Subject: [PATCH 47/70] Remove unused imports --- buildingdepot/DataService/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/buildingdepot/DataService/__init__.py b/buildingdepot/DataService/__init__.py index c9037047..5aa44e53 100755 --- a/buildingdepot/DataService/__init__.py +++ b/buildingdepot/DataService/__init__.py @@ -11,7 +11,6 @@ """ import os -from flask_script import Manager, Shell from .app import create_app from .app.rest_api.register import register_view From 0851e6c1a7cbb070118a0af4ecb33c6bdb6f7c72 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Wed, 9 Jun 2021 19:10:24 -0400 Subject: [PATCH 48/70] Add lts keys for node --- install.sh | 1 + script_for_github_actions.sh | 1 + 2 files changed, 2 insertions(+) diff --git a/install.sh b/install.sh index 8551557f..11a031a6 100755 --- a/install.sh +++ b/install.sh @@ -149,6 +149,7 @@ function install_packages() { service influxdb start service mongod start apt-get install -y rabbitmq-server + curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - apt-get install -y nodejs apt-get install -y npm sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index 9ec3e679..7b61d60c 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -133,6 +133,7 @@ function install_packages { service mongod start apt-get install -y rabbitmq-server --fix-missing DEBIAN_FRONTEND=noninteractive apt-get install -y postfix + curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - apt-get install -y nodejs apt-get install -y npm sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf From 82695b793d448fbef55dcfcd8202d35c50f55743 Mon Sep 17 00:00:00 2001 From: Sudershan Boovaraghavan Date: Fri, 11 Jun 2021 15:35:07 -0400 Subject: [PATCH 49/70] bug fixes for rabbitmq build issues --- script_for_github_actions.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index 6e704076..b66bd3d5 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -103,7 +103,8 @@ function install_packages { source /etc/lsb-release #Add keys for rabbitmq - curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | sudo apt-key add - + curl -fsSL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - + # echo "deb https://dl.bintray.com/rabbitmq/debian ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list # echo "deb https://dl.bintray.com/rabbitmq-erlang/debian ${DISTRIB_CODENAME} erlang" | sudo tee -a /etc/apt/sources.list.d/bintray.rabbitmq.list #wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - @@ -257,4 +258,4 @@ setup_packages /srv/buildingdepot/venv/bin/python2.7 setup_bd.py "test" # echo -e "\nInstallation Finished..\n" -supervisorctl restart all +supervisorctl restart all \ No newline at end of file From 20ae3fcafaa794d9f9184c04cd370a13181e0c85 Mon Sep 17 00:00:00 2001 From: Sudershan Boovaraghavan Date: Fri, 11 Jun 2021 16:30:04 -0400 Subject: [PATCH 50/70] bug fixes for rabbitmq build issues --- script_for_github_actions.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index b66bd3d5..4433d219 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -105,6 +105,12 @@ function install_packages { #Add keys for rabbitmq curl -fsSL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - + echo "deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list + echo "deb-src http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list + + echo "deb https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list + echo "deb-src https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list + # echo "deb https://dl.bintray.com/rabbitmq/debian ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list # echo "deb https://dl.bintray.com/rabbitmq-erlang/debian ${DISTRIB_CODENAME} erlang" | sudo tee -a /etc/apt/sources.list.d/bintray.rabbitmq.list #wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - @@ -134,6 +140,11 @@ function install_packages { apt-get install -y influxdb service influxdb start service mongod start + apt-get install -y erlang-base \ + erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \ + erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \ + erlang-runtime-tools erlang-snmp erlang-ssl \ + erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl apt-get install -y rabbitmq-server --fix-missing DEBIAN_FRONTEND=noninteractive apt-get install -y postfix apt-get install -y nodejs From 8249980ad8c4060eb90cb4cb601562a391eb25f7 Mon Sep 17 00:00:00 2001 From: Sudershan Boovaraghavan Date: Fri, 11 Jun 2021 16:50:18 -0400 Subject: [PATCH 51/70] upgrades mongodb versions --- script_for_github_actions.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index 4433d219..7c8f2c5b 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -119,14 +119,18 @@ function install_packages { curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list # Add keys to install mongodb - wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add - - if [ $DISTRIB_CODENAME == "bionic" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list + wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - + if [ $DISTRIB_CODENAME == "focal" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list + elif [ $DISTRIB_CODENAME == "bionic" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list elif [ $DISTRIB_CODENAME == "xenial" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list elif [ $DISTRIB_CODENAME == "trusty" ]; then + wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add - echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list fi + apt-get update -y apt-get install apt-get install -y python-pip From 88c610662ef693642e181a30c2f7f9e4a0e8f305 Mon Sep 17 00:00:00 2001 From: Sudershan Boovaraghavan Date: Fri, 11 Jun 2021 16:53:46 -0400 Subject: [PATCH 52/70] bug fixes for rabbitmq build issues --- script_for_github_actions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index 7c8f2c5b..1d970a5f 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -104,6 +104,7 @@ function install_packages { #Add keys for rabbitmq curl -fsSL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - + curl -1sLf 'https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey' | sudo apt-key add - echo "deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list echo "deb-src http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list @@ -130,7 +131,6 @@ function install_packages { wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add - echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list fi - apt-get update -y apt-get install apt-get install -y python-pip From 121d8bc5ae37b9301a33d15945311d0eab2fb042 Mon Sep 17 00:00:00 2001 From: Sudershan Boovaraghavan Date: Fri, 11 Jun 2021 16:58:30 -0400 Subject: [PATCH 53/70] bug fixes for rabbitmq build issues --- script_for_github_actions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index 1d970a5f..5aaf1ce0 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -134,7 +134,7 @@ function install_packages { apt-get update -y apt-get install apt-get install -y python-pip - apt-get install -y mongodb-org=4.0.5 mongodb-org-server=4.0.5 mongodb-org-shell=4.0.5 mongodb-org-mongos=4.0.5 mongodb-org-tools=4.0.5 + apt-get install -y mongodb-org=4.4 mongodb-org-server=4.4 mongodb-org-shell=4.4 mongodb-org-mongos=4.4 mongodb-org-tools=4.4 apt-get install -y openssl python-setuptools python-dev build-essential software-properties-common apt-get install -y nginx apt-get install -y supervisor From 19787ae70767ca1e300d48d7a91bce4e47d758e7 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Tue, 15 Jun 2021 15:41:35 -0400 Subject: [PATCH 54/70] Bump mongo version --- script_for_github_actions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index 091cf87b..310754c0 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -132,7 +132,7 @@ function install_packages { apt-get update -y apt-get install apt-get install -y python3-pip - apt-get install -y mongodb-org=4.0.5 mongodb-org-server=4.4 mongodb-org-shell=4.4 mongodb-org-mongos=4.4 mongodb-org-tools=4.4 + apt-get install -y mongodb-org=4.4 mongodb-org-server=4.4 mongodb-org-shell=4.4 mongodb-org-mongos=4.4 mongodb-org-tools=4.4 apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common apt-get install -y nginx apt-get install -y supervisor From dbf4ec04734635058169c74fb37e13fcd3d43fbf Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Tue, 15 Jun 2021 15:51:32 -0400 Subject: [PATCH 55/70] Install latest mongodb-org --- script_for_github_actions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index 310754c0..35fca4ba 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -132,7 +132,7 @@ function install_packages { apt-get update -y apt-get install apt-get install -y python3-pip - apt-get install -y mongodb-org=4.4 mongodb-org-server=4.4 mongodb-org-shell=4.4 mongodb-org-mongos=4.4 mongodb-org-tools=4.4 + apt-get install -y mongodb-org apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common apt-get install -y nginx apt-get install -y supervisor From 89a39dd39e64950afe0181596334c97bcf51413a Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Tue, 15 Jun 2021 17:04:52 -0400 Subject: [PATCH 56/70] Bump Ubuntu version to 20.04 for tests --- .github/workflows/test_bd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index c714804f..7f0cd979 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -14,7 +14,7 @@ on: - develop jobs: build: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: From 7dd02541ef97565a08d1fbfd9a14107c67435cc2 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Tue, 15 Jun 2021 17:47:27 -0400 Subject: [PATCH 57/70] Add packagecloud keys for rabbitmq and erlang --- script_for_github_actions.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index 35fca4ba..c893c992 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -101,6 +101,8 @@ function install_packages { source /etc/lsb-release #Add keys for rabbitmq + curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.deb.sh | sudo bash + curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | sudo bash curl -fsSL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - curl -1sLf 'https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey' | sudo apt-key add - From ef2c070595e9dedb15826f18714340abd71d017f Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Tue, 15 Jun 2021 18:18:15 -0400 Subject: [PATCH 58/70] Test erlang fixes --- script_for_github_actions.sh | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index c893c992..429c8c66 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -105,6 +105,15 @@ function install_packages { curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | sudo bash curl -fsSL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - curl -1sLf 'https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey' | sudo apt-key add - + curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | sudo apt-key add - + tee /etc/apt/sources.list.d/bintray.rabbitmq.list < Date: Tue, 15 Jun 2021 18:26:31 -0400 Subject: [PATCH 59/70] Use ubuntu container --- .github/workflows/test_bd.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index 7f0cd979..c53657fb 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -14,7 +14,8 @@ on: - develop jobs: build: - runs-on: ubuntu-20.04 + container: + image: ubuntu/ubuntu:focal-20210416 strategy: fail-fast: false matrix: From 434d4dd1a3359d9ad3869dfeb995d83cbcfcaff9 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Tue, 15 Jun 2021 18:31:10 -0400 Subject: [PATCH 60/70] Fix test_bd.yml --- .github/workflows/test_bd.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index c53657fb..ccfbe1de 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -14,8 +14,9 @@ on: - develop jobs: build: + runs-on: ubuntu-latest container: - image: ubuntu/ubuntu:focal-20210416 + image: ubuntu:focal-20210416 strategy: fail-fast: false matrix: From bd9f2e83709cfeb91093e95c1b8944bc9b678694 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Tue, 15 Jun 2021 18:32:31 -0400 Subject: [PATCH 61/70] Remove sudo --- .github/workflows/test_bd.yml | 2 +- script_for_github_actions.sh | 46 +++++++++++++++++------------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index ccfbe1de..be84bf8d 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -30,7 +30,7 @@ jobs: architecture: x64 - name: Install BuildingDepot run: | - sudo bash -x ./script_for_github_actions.sh + bash -x ./script_for_github_actions.sh - name: Initialize tests run: | cd benchmarking-tools/functional-testing-tool diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index 429c8c66..82ec8f60 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -5,7 +5,7 @@ DEPLOY_CS=true DEPLOY_DS=true ################################################################################ -# Check and make sure we are running as root or sudo (?) +# Check and make sure we are running as root or (?) ################################################################################ if [[ $UID -ne 0 ]]; then echo -e "\n$0 must be run as root. Most functions require super-user priviledges!\n" @@ -101,11 +101,11 @@ function install_packages { source /etc/lsb-release #Add keys for rabbitmq - curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.deb.sh | sudo bash - curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | sudo bash - curl -fsSL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add - - curl -1sLf 'https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey' | sudo apt-key add - - curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | sudo apt-key add - + curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.deb.sh | bash + curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | bash + curl -fsSL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | apt-key add - + curl -1sLf 'https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey' | apt-key add - + curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | apt-key add - tee /etc/apt/sources.list.d/bintray.rabbitmq.list <> $BD/CentralService/cs_config From b36697626745056c83f5e4682bec1c23f7f54708 Mon Sep 17 00:00:00 2001 From: shreyasnagare Date: Tue, 15 Jun 2021 18:35:11 -0400 Subject: [PATCH 62/70] Revert erlang fixes --- script_for_github_actions.sh | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index 82ec8f60..ae686c5c 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -105,15 +105,6 @@ function install_packages { curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | bash curl -fsSL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | apt-key add - curl -1sLf 'https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey' | apt-key add - - curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | apt-key add - - tee /etc/apt/sources.list.d/bintray.rabbitmq.list < Date: Tue, 29 Jun 2021 17:30:39 +0000 Subject: [PATCH 63/70] fixes for python3-BD --- script_for_github_actions.sh | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index ae686c5c..16b1f6d8 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -101,20 +101,10 @@ function install_packages { source /etc/lsb-release #Add keys for rabbitmq - curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.deb.sh | bash curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | bash - curl -fsSL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | apt-key add - - curl -1sLf 'https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey' | apt-key add - - echo "deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee /etc/apt/sources.list.d/rabbitmq.list - echo "deb-src http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee /etc/apt/sources.list.d/rabbitmq.list - - echo "deb https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ ${DISTRIB_CODENAME} main" | tee /etc/apt/sources.list.d/rabbitmq.list - echo "deb-src https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ ${DISTRIB_CODENAME} main" | tee /etc/apt/sources.list.d/rabbitmq.list - -# echo "deb https://dl.bintray.com/rabbitmq/debian ${DISTRIB_CODENAME} main" | tee /etc/apt/sources.list.d/bintray.rabbitmq.list -# echo "deb https://dl.bintray.com/rabbitmq-erlang/debian ${DISTRIB_CODENAME} erlang" | tee -a /etc/apt/sources.list.d/bintray.rabbitmq.list - #wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | apt-key add - + echo "deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee /etc/apt/sources.list.d/rabbitmq-erlang.list + echo "deb-src http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee -a /etc/apt/sources.list.d/rabbitmq-erlang.list # Add keys to install influxdb curl -sL https://repos.influxdata.com/influxdb.key | apt-key add - @@ -134,7 +124,13 @@ function install_packages { apt-get update -y apt-get install apt-get install -y python3-pip - apt-get install -y mongodb-org + + if [ $DISTRIB_CODENAME == "trusty" ]; then + apt-get install -y mongodb-org=4.0.25 mongodb-org-server=4.0.25 mongodb-org-shell=4.0.25 mongodb-org-mongos=4.0.25 mongodb-org-tools=4.0.25 + else + apt-get install -y mongodb-org=4.4.6 mongodb-org-server=4.4.6 mongodb-org-shell=4.4.6 mongodb-org-mongos=4.4.6 mongodb-org-tools=4.4.6 + fi + apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common apt-get install -y nginx apt-get install -y supervisor From 2bbe28cf33fc68da18e66775dabc8868ded3430d Mon Sep 17 00:00:00 2001 From: Sudershan Date: Thu, 15 Jul 2021 21:04:42 -0400 Subject: [PATCH 64/70] Reformat Code --- install.sh | 284 +++++++++++------------ script_for_github_actions.sh | 422 +++++++++++++++++------------------ 2 files changed, 351 insertions(+), 355 deletions(-) diff --git a/install.sh b/install.sh index a12d6008..50a9b6b7 100755 --- a/install.sh +++ b/install.sh @@ -113,61 +113,61 @@ function install_packages() { apt-get install -y apt-transport-https source /etc/lsb-release - # Add keys for Rabbitmq - curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | bash - # Adds Launchpad PPA that provides modern Erlang releases - sudo apt-key adv --keyserver "keyserver.ubuntu.com" --recv-keys "F77F1EDA57EBB1CC" - echo "deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee /etc/apt/sources.list.d/rabbitmq-erlang.list - echo "deb-src http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee -a /etc/apt/sources.list.d/rabbitmq-erlang.list - - # Add keys to install influxdb - curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - - echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list - - # Add keys to install mongodb - wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - - if [ $DISTRIB_CODENAME == "focal" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list - elif [ $DISTRIB_CODENAME == "bionic" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list - elif [ $DISTRIB_CODENAME == "xenial" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list - elif [ $DISTRIB_CODENAME == "trusty" ]; then - wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add - - echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list - fi + # Add keys for Rabbitmq + curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | bash + # Adds Launchpad PPA that provides modern Erlang releases + sudo apt-key adv --keyserver "keyserver.ubuntu.com" --recv-keys "F77F1EDA57EBB1CC" + echo "deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee /etc/apt/sources.list.d/rabbitmq-erlang.list + echo "deb-src http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee -a /etc/apt/sources.list.d/rabbitmq-erlang.list + + # Add keys to install influxdb + curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - + echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list + + # Add keys to install mongodb + wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add - + if [ $DISTRIB_CODENAME == "focal" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list + elif [ $DISTRIB_CODENAME == "bionic" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list + elif [ $DISTRIB_CODENAME == "xenial" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list + elif [ $DISTRIB_CODENAME == "trusty" ]; then + wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add - + echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list + fi - apt-get update -y - apt-get install - apt-get -y install python3-pip + apt-get update -y + apt-get install + apt-get -y install python3-pip - if [ $DISTRIB_CODENAME == "trusty" ]; then - apt-get install -y mongodb-org=4.0.25 mongodb-org-server=4.0.25 mongodb-org-shell=4.0.25 mongodb-org-mongos=4.0.25 mongodb-org-tools=4.0.25 - else - apt-get install -y mongodb-org=4.4.6 mongodb-org-server=4.4.6 mongodb-org-shell=4.4.6 mongodb-org-mongos=4.4.6 mongodb-org-tools=4.4.6 - fi + if [ $DISTRIB_CODENAME == "trusty" ]; then + apt-get install -y mongodb-org=4.0.25 mongodb-org-server=4.0.25 mongodb-org-shell=4.0.25 mongodb-org-mongos=4.0.25 mongodb-org-tools=4.0.25 + else + apt-get install -y mongodb-org=4.4.6 mongodb-org-server=4.4.6 mongodb-org-shell=4.4.6 mongodb-org-mongos=4.4.6 mongodb-org-tools=4.4.6 + fi - apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common - apt-get install -y nginx - apt-get install -y supervisor - apt-get install -y redis-server - pip3 install --upgrade virtualenv - apt-get install -y wget - apt-get install -y influxdb - service influxdb start - service mongod start - apt-get install -y erlang-base \ - erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \ - erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \ - erlang-runtime-tools erlang-snmp erlang-ssl \ - erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl - apt-get install -y rabbitmq-server - curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - - apt-get install -y nodejs - apt-get install -y npm - sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf - service postfix restart - systemctl enable mongod.service + apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common + apt-get install -y nginx + apt-get install -y supervisor + apt-get install -y redis-server + pip3 install --upgrade virtualenv + apt-get install -y wget + apt-get install -y influxdb + service influxdb start + service mongod start + apt-get install -y erlang-base \ + erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \ + erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \ + erlang-runtime-tools erlang-snmp erlang-ssl \ + erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl + apt-get install -y rabbitmq-server + curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - + apt-get install -y nodejs + apt-get install -y npm + sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf + service postfix restart + systemctl enable mongod.service } function setup_gmail() { @@ -231,106 +231,106 @@ function setup_email() { } function setup_notifications() { - echo "BuildingDepot uses notifications to alert users or systems of events in real-time. By default, " - echo "BuildingDepot uses RabbitMQ to deliver messages and we also supports Google Firebase Cloud Messaging (FCM), " - echo "which allows BuildingDepot to send push notifications to mobile users." - echo "Enter Y to select Google FCM and N to select RabbitMQ: " + echo "BuildingDepot uses notifications to alert users or systems of events in real-time. By default, " + echo "BuildingDepot uses RabbitMQ to deliver messages and we also supports Google Firebase Cloud Messaging (FCM), " + echo "which allows BuildingDepot to send push notifications to mobile users." + echo "Enter Y to select Google FCM and N to select RabbitMQ: " + read response + if [ "$response" == "Y" ] || [ "$response" == "y" ]; then + pip3 install "firebase-admin==2.18.0" + echo "Please provide the absolute path of where your Google Service Account JSON file is, which contains the keys for your FCM project." read response - if [ "$response" == "Y" ] || [ "$response" == "y" ]; then - pip3 install "firebase-admin==2.18.0" - echo "Please provide the absolute path of where your Google Service Account JSON file is, which contains the keys for your FCM project." - read response - if [ ! -z "$response" ]; then - echo "NOTIFICATION_TYPE = 'FIREBASE'" >> $BD/CentralService/cs_config - echo "FIREBASE_CREDENTIALS = '$response'" >> $BD/CentralService/cs_config - fi - elif [ "$response" == "N" ] || [ "$response" == "n" ]; then - echo "NOTIFICATION_TYPE = 'RabbitMQ'" >> $BD/CentralService/cs_config + if [ ! -z "$response" ]; then + echo "NOTIFICATION_TYPE = 'FIREBASE'" >>$BD/CentralService/cs_config + echo "FIREBASE_CREDENTIALS = '$response'" >>$BD/CentralService/cs_config fi + elif [ "$response" == "N" ] || [ "$response" == "n" ]; then + echo "NOTIFICATION_TYPE = 'RabbitMQ'" >>$BD/CentralService/cs_config + fi } function setup_packages() { - echo - echo "Securing BD Packages" - echo "--------------------" - echo "Enter Y to auto-generate credentials for packages (MongoDB,InfluxDB & Redis). Credentials are stored in cs_config file (or) Enter N to input individual package credentials" - read response - if [ "$response" == "Y" ] || [ "$response" == "y" ]; then - ## Add MongoDB Admin user - mongoUsername="user$(openssl rand -hex 16)" - mongoPassword=$(openssl rand -hex 32) - echo "MONGODB_USERNAME = '$mongoUsername'" >> $BD/CentralService/cs_config - echo "MONGODB_PWD = '$mongoPassword'" >> $BD/CentralService/cs_config - echo "MONGODB_USERNAME = '$mongoUsername'" >> $BD/DataService/ds_config - echo "MONGODB_PWD = '$mongoPassword'" >> $BD/DataService/ds_config - echo " MONGODB_USERNAME = '$mongoUsername'" >> $BD/CentralReplica/config.py - echo " MONGODB_PWD = '$mongoPassword'" >> $BD/CentralReplica/config.py - mongo --eval "db.getSiblingDB('admin').createUser({user:'$mongoUsername',pwd:'$mongoPassword',roles:['userAdminAnyDatabase','dbAdminAnyDatabase','readWriteAnyDatabase']})" - # Enable MongoDB authorization - echo "security:" >> /etc/mongod.conf - echo " authorization: \"enabled\"">> /etc/mongod.conf - service mongod restart + echo + echo "Securing BD Packages" + echo "--------------------" + echo "Enter Y to auto-generate credentials for packages (MongoDB,InfluxDB & Redis). Credentials are stored in cs_config file (or) Enter N to input individual package credentials" + read response + if [ "$response" == "Y" ] || [ "$response" == "y" ]; then + ## Add MongoDB Admin user + mongoUsername="user$(openssl rand -hex 16)" + mongoPassword=$(openssl rand -hex 32) + echo "MONGODB_USERNAME = '$mongoUsername'" >>$BD/CentralService/cs_config + echo "MONGODB_PWD = '$mongoPassword'" >>$BD/CentralService/cs_config + echo "MONGODB_USERNAME = '$mongoUsername'" >>$BD/DataService/ds_config + echo "MONGODB_PWD = '$mongoPassword'" >>$BD/DataService/ds_config + echo " MONGODB_USERNAME = '$mongoUsername'" >>$BD/CentralReplica/config.py + echo " MONGODB_PWD = '$mongoPassword'" >>$BD/CentralReplica/config.py + mongo --eval "db.getSiblingDB('admin').createUser({user:'$mongoUsername',pwd:'$mongoPassword',roles:['userAdminAnyDatabase','dbAdminAnyDatabase','readWriteAnyDatabase']})" + # Enable MongoDB authorization + echo "security:" >>/etc/mongod.conf + echo " authorization: \"enabled\"" >>/etc/mongod.conf + service mongod restart sleep 2 - ## Add InfluxDB Admin user - influxUsername="user$(openssl rand -hex 16)" - influxPassword=$(openssl rand -hex 32) - echo "INFLUXDB_USERNAME = '$influxUsername'">> $BD/DataService/ds_config - echo "INFLUXDB_PWD = '$influxPassword'">> $BD/DataService/ds_config - sleep 1 - curl -d "q=CREATE USER $influxUsername WITH PASSWORD '$influxPassword' WITH ALL PRIVILEGES" -X POST http://localhost:8086/query - sed -ir 's/# auth-enabled = false/auth-enabled = true/g' /etc/influxdb/influxdb.conf - service influxdb restart + ## Add InfluxDB Admin user + influxUsername="user$(openssl rand -hex 16)" + influxPassword=$(openssl rand -hex 32) + echo "INFLUXDB_USERNAME = '$influxUsername'" >>$BD/DataService/ds_config + echo "INFLUXDB_PWD = '$influxPassword'" >>$BD/DataService/ds_config + sleep 1 + curl -d "q=CREATE USER $influxUsername WITH PASSWORD '$influxPassword' WITH ALL PRIVILEGES" -X POST http://localhost:8086/query + sed -ir 's/# auth-enabled = false/auth-enabled = true/g' /etc/influxdb/influxdb.conf + service influxdb restart sleep 2 - ## Add Redis Admin user - redisPassword=$(openssl rand -hex 64) - echo "REDIS_PWD = '$redisPassword'">> $BD/CentralService/cs_config - echo "REDIS_PWD = '$redisPassword'">> $BD/DataService/ds_config - echo " REDIS_PWD = '$redisPassword'" >> $BD/CentralReplica/config.py - sed -i -e '/#.* requirepass / s/.*/ requirepass '$redisPassword'/' /etc/redis/redis.conf - service redis restart + ## Add Redis Admin user + redisPassword=$(openssl rand -hex 64) + echo "REDIS_PWD = '$redisPassword'" >>$BD/CentralService/cs_config + echo "REDIS_PWD = '$redisPassword'" >>$BD/DataService/ds_config + echo " REDIS_PWD = '$redisPassword'" >>$BD/CentralReplica/config.py + sed -i -e '/#.* requirepass / s/.*/ requirepass '$redisPassword'/' /etc/redis/redis.conf + service redis restart sleep 2 - ## Add RabbitMQ Admin user - rabbitmqUsername="user$(openssl rand -hex 16)" - rabbitmqPassword=$(openssl rand -hex 32) - rabbitmqUsername_endUser="user$(openssl rand -hex 16)" - rabbitmqPassword_endUser=$(openssl rand -hex 32) - echo "RABBITMQ_ADMIN_USERNAME = '$rabbitmqUsername'">> $BD/DataService/ds_config - echo "RABBITMQ_ADMIN_PWD = '$rabbitmqPassword'">> $BD/DataService/ds_config - echo "RABBITMQ_ENDUSER_USERNAME = '$rabbitmqUsername_endUser'">> $BD/DataService/ds_config - echo "RABBITMQ_ENDUSER_PWD = '$rabbitmqPassword_endUser'">> $BD/DataService/ds_config - # Create a Admin user. - rabbitmqctl add_user "$rabbitmqUsername" "$rabbitmqPassword" - # Add Administrative Rights - rabbitmqctl set_user_tags "$rabbitmqUsername" administrator - # Grant necessary permissions - rabbitmqctl set_permissions -p / "$rabbitmqUsername" ".*" ".*" ".*" - # Create a End User. - rabbitmqctl add_user "$rabbitmqUsername_endUser" "$rabbitmqPassword_endUser" - # Add Permissions - rabbitmqctl set_user_tags "$rabbitmqUsername_endUser" - # Grant necessary permissions - rabbitmqctl set_permissions -p / "$rabbitmqUsername_endUser" "" "" ".*" - - echo "BuildingDepot uses RabbitMQ Queues for Publishing and Subscribing to Sensor data. " - echo "Some web front-end use RabbitMQ Queues use rabbitmq_web_stomp plugin" - echo "Enter Y to install rabbitmq_web_stomp plugin: " - read response - if [ "$response" == "Y" ] || [ "$response" == "y" ]; then - rabbitmq-plugins enable rabbitmq_web_stomp - fi + ## Add RabbitMQ Admin user + rabbitmqUsername="user$(openssl rand -hex 16)" + rabbitmqPassword=$(openssl rand -hex 32) + rabbitmqUsername_endUser="user$(openssl rand -hex 16)" + rabbitmqPassword_endUser=$(openssl rand -hex 32) + echo "RABBITMQ_ADMIN_USERNAME = '$rabbitmqUsername'" >>$BD/DataService/ds_config + echo "RABBITMQ_ADMIN_PWD = '$rabbitmqPassword'" >>$BD/DataService/ds_config + echo "RABBITMQ_ENDUSER_USERNAME = '$rabbitmqUsername_endUser'" >>$BD/DataService/ds_config + echo "RABBITMQ_ENDUSER_PWD = '$rabbitmqPassword_endUser'" >>$BD/DataService/ds_config + # Create a Admin user. + rabbitmqctl add_user "$rabbitmqUsername" "$rabbitmqPassword" + # Add Administrative Rights + rabbitmqctl set_user_tags "$rabbitmqUsername" administrator + # Grant necessary permissions + rabbitmqctl set_permissions -p / "$rabbitmqUsername" ".*" ".*" ".*" + # Create a End User. + rabbitmqctl add_user "$rabbitmqUsername_endUser" "$rabbitmqPassword_endUser" + # Add Permissions + rabbitmqctl set_user_tags "$rabbitmqUsername_endUser" + # Grant necessary permissions + rabbitmqctl set_permissions -p / "$rabbitmqUsername_endUser" "" "" ".*" + + echo "BuildingDepot uses RabbitMQ Queues for Publishing and Subscribing to Sensor data. " + echo "Some web front-end use RabbitMQ Queues use rabbitmq_web_stomp plugin" + echo "Enter Y to install rabbitmq_web_stomp plugin: " + read response + if [ "$response" == "Y" ] || [ "$response" == "y" ]; then + rabbitmq-plugins enable rabbitmq_web_stomp + fi sleep 1 - echo - echo "Auto-Generated User Credentials for BuildingDepot Packages [MongoDB,InfluxDB & Redis]" - echo + echo + echo "Auto-Generated User Credentials for BuildingDepot Packages [MongoDB,InfluxDB & Redis]" + echo elif [ "$response" == 'N' ] || [ "$response" == 'n' ]; then ## Add MongoDB Admin user @@ -381,7 +381,7 @@ function setup_packages() { sleep 2 - ## Add RabbitMQ Admin user + ## Add RabbitMQ Admin user echo echo "Enter RabbitMQ Admin Username: " read rabbitmqUsername @@ -405,10 +405,10 @@ function setup_packages() { # Grant necessary permissions rabbitmqctl set_permissions -p / "$rabbitmqUsername_endUser" "" "" ".*" - echo "RABBITMQ_ADMIN_USERNAME = '$rabbitmqUsername'">> $BD/DataService/ds_config - echo "RABBITMQ_ADMIN_PWD = '$rabbitmqPassword'">> $BD/DataService/ds_config - echo "RABBITMQ_ENDUSER_USERNAME = '$rabbitmqUsername_endUser'">> $BD/DataService/ds_config - echo "RABBITMQ_ENDUSER_PWD = '$rabbitmqPassword_endUser'">> $BD/DataService/ds_config + echo "RABBITMQ_ADMIN_USERNAME = '$rabbitmqUsername'" >>$BD/DataService/ds_config + echo "RABBITMQ_ADMIN_PWD = '$rabbitmqPassword'" >>$BD/DataService/ds_config + echo "RABBITMQ_ENDUSER_USERNAME = '$rabbitmqUsername_endUser'" >>$BD/DataService/ds_config + echo "RABBITMQ_ENDUSER_PWD = '$rabbitmqPassword_endUser'" >>$BD/DataService/ds_config echo "BuildingDepot uses RabbitMQ Queues for Publishing and Subscribing to Sensor data. " echo "Some web front-end use RabbitMQ Queues use rabbitmq_web_stomp plugin" @@ -425,9 +425,9 @@ function setup_packages() { echo else - echo - echo "Invalid option please Try again." - setup_packages + echo + echo "Invalid option please Try again." + setup_packages fi } diff --git a/script_for_github_actions.sh b/script_for_github_actions.sh index e53f9a9d..b10d6de0 100755 --- a/script_for_github_actions.sh +++ b/script_for_github_actions.sh @@ -40,241 +40,239 @@ function setup_venv() { cd - } # Deploy apps -function deploy_centralservice { - setup_venv /srv/buildingdepot/ - - #copy and untar new dataservice tarball - cp -r buildingdepot/CentralService /srv/buildingdepot/ - cp -r buildingdepot/DataService /srv/buildingdepot/ - cp -r buildingdepot/CentralReplica /srv/buildingdepot/ - cp -r buildingdepot/Documentation /srv/buildingdepot/ - cd /srv/buildingdepot - # copy uwsgi files - cp configs/uwsgi_cs.ini /etc/uwsgi/apps-available/cs.ini - - # Create supervisor config - cp configs/supervisor-cs.conf /etc/supervisor/conf.d/ - - # Create supervisor config for central replica - cp configs/supervisor-replica.conf /etc/supervisor/conf.d/ - - # Create nginx config - rm -f /etc/nginx/sites-enabled/default +function deploy_centralservice() { + setup_venv /srv/buildingdepot/ + + #copy and untar new dataservice tarball + cp -r buildingdepot/CentralService /srv/buildingdepot/ + cp -r buildingdepot/DataService /srv/buildingdepot/ + cp -r buildingdepot/CentralReplica /srv/buildingdepot/ + cp -r buildingdepot/Documentation /srv/buildingdepot/ + cd /srv/buildingdepot + # copy uwsgi files + cp configs/uwsgi_cs.ini /etc/uwsgi/apps-available/cs.ini + + # Create supervisor config + cp configs/supervisor-cs.conf /etc/supervisor/conf.d/ + + # Create supervisor config for central replica + cp configs/supervisor-replica.conf /etc/supervisor/conf.d/ + + # Create nginx config + rm -f /etc/nginx/sites-enabled/default } -function deploy_dataservice { - setup_venv /srv/buildingdepot/ +function deploy_dataservice() { + setup_venv /srv/buildingdepot/ - cd /srv/buildingdepot + cd /srv/buildingdepot - # copy uwsgi files - cp configs/uwsgi_ds.ini /etc/uwsgi/apps-available/ds.ini + # copy uwsgi files + cp configs/uwsgi_ds.ini /etc/uwsgi/apps-available/ds.ini - # Create supervisor config - cp configs/supervisor-ds.conf /etc/supervisor/conf.d/ + # Create supervisor config + cp configs/supervisor-ds.conf /etc/supervisor/conf.d/ - # Create nginx config - rm -f /etc/nginx/sites-enabled/default + # Create nginx config + rm -f /etc/nginx/sites-enabled/default } - -function joint_deployment_fix { - # Create join nginx config - rm -f /etc/nginx/sites-enabled/default - cd /srv/buildingdepot - #Setting up SSL - echo "Skipping SSL configuration..." - #If user already has certificate - cp configs/together.conf /etc/nginx/sites-available/together.conf - ln -sf /etc/nginx/sites-available/together.conf /etc/nginx/sites-enabled/together.conf +function joint_deployment_fix() { + # Create join nginx config + rm -f /etc/nginx/sites-enabled/default + cd /srv/buildingdepot + #Setting up SSL + echo "Skipping SSL configuration..." + #If user already has certificate + cp configs/together.conf /etc/nginx/sites-available/together.conf + ln -sf /etc/nginx/sites-available/together.conf /etc/nginx/sites-enabled/together.conf } -function deploy_config { - cp -r configs/ /srv/buildingdepot - mkdir /var/sockets +function deploy_config() { + cp -r configs/ /srv/buildingdepot + mkdir /var/sockets } -function install_packages { - apt-get install -y curl - apt-get install -y apt-transport-https - apt-get install -y gnupg - source /etc/lsb-release - - # Add keys for Rabbitmq - curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | bash - # Adds Launchpad PPA that provides modern Erlang releases - sudo apt-key adv --keyserver "keyserver.ubuntu.com" --recv-keys "F77F1EDA57EBB1CC" - echo "deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee /etc/apt/sources.list.d/rabbitmq-erlang.list - echo "deb-src http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee -a /etc/apt/sources.list.d/rabbitmq-erlang.list - - # Add keys to install influxdb - curl -sL https://repos.influxdata.com/influxdb.key | apt-key add - - echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | tee /etc/apt/sources.list.d/influxdb.list - # Add keys to install mongodb - wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add - - if [ $DISTRIB_CODENAME == "focal" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list - elif [ $DISTRIB_CODENAME == "bionic" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list - elif [ $DISTRIB_CODENAME == "xenial" ]; then - echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list - elif [ $DISTRIB_CODENAME == "trusty" ]; then - wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | apt-key add - - echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list - fi - - apt-get update -y - apt-get install - apt-get install -y python3-pip - - if [ $DISTRIB_CODENAME == "trusty" ]; then - apt-get install -y mongodb-org=4.0.25 mongodb-org-server=4.0.25 mongodb-org-shell=4.0.25 mongodb-org-mongos=4.0.25 mongodb-org-tools=4.0.25 - else - apt-get install -y mongodb-org=4.4.6 mongodb-org-server=4.4.6 mongodb-org-shell=4.4.6 mongodb-org-mongos=4.4.6 mongodb-org-tools=4.4.6 - fi - - apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common - apt-get install -y nginx - apt-get install -y supervisor - apt-get install -y redis-server - pip3 install --upgrade virtualenv - apt-get install -y wget - apt-get install -y influxdb - service influxdb start - service mongod start - apt-get install -y erlang-base \ - erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \ - erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \ - erlang-runtime-tools erlang-snmp erlang-ssl \ - erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl - apt-get install -y rabbitmq-server --fix-missing - DEBIAN_FRONTEND=noninteractive apt-get install -y postfix - curl -fsSL https://deb.nodesource.com/setup_lts.x | -E bash - - apt-get install -y nodejs - apt-get install -y npm - sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf - service postfix restart - systemctl enable mongod.service +function install_packages() { + apt-get install -y curl + apt-get install -y apt-transport-https + apt-get install -y gnupg + source /etc/lsb-release + + # Add keys for Rabbitmq + curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.deb.sh | bash + # Adds Launchpad PPA that provides modern Erlang releases + sudo apt-key adv --keyserver "keyserver.ubuntu.com" --recv-keys "F77F1EDA57EBB1CC" + echo "deb http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee /etc/apt/sources.list.d/rabbitmq-erlang.list + echo "deb-src http://ppa.launchpad.net/rabbitmq/rabbitmq-erlang/ubuntu ${DISTRIB_CODENAME} main" | tee -a /etc/apt/sources.list.d/rabbitmq-erlang.list + + # Add keys to install influxdb + curl -sL https://repos.influxdata.com/influxdb.key | apt-key add - + echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | tee /etc/apt/sources.list.d/influxdb.list + # Add keys to install mongodb + wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add - + if [ $DISTRIB_CODENAME == "focal" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list + elif [ $DISTRIB_CODENAME == "bionic" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list + elif [ $DISTRIB_CODENAME == "xenial" ]; then + echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu ${DISTRIB_CODENAME}/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list + elif [ $DISTRIB_CODENAME == "trusty" ]; then + wget -qO - https://www.mongodb.org/static/pgp/server-4.0.asc | apt-key add - + echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/${DISTRIB_ID,,} ${DISTRIB_CODENAME}/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list + fi + + apt-get update -y + apt-get install + apt-get install -y python3-pip + + if [ $DISTRIB_CODENAME == "trusty" ]; then + apt-get install -y mongodb-org=4.0.25 mongodb-org-server=4.0.25 mongodb-org-shell=4.0.25 mongodb-org-mongos=4.0.25 mongodb-org-tools=4.0.25 + else + apt-get install -y mongodb-org=4.4.6 mongodb-org-server=4.4.6 mongodb-org-shell=4.4.6 mongodb-org-mongos=4.4.6 mongodb-org-tools=4.4.6 + fi + + apt-get install -y openssl python3-setuptools python3-dev build-essential software-properties-common + apt-get install -y nginx + apt-get install -y supervisor + apt-get install -y redis-server + pip3 install --upgrade virtualenv + apt-get install -y wget + apt-get install -y influxdb + service influxdb start + service mongod start + apt-get install -y erlang-base \ + erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \ + erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \ + erlang-runtime-tools erlang-snmp erlang-ssl \ + erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl + apt-get install -y rabbitmq-server --fix-missing + DEBIAN_FRONTEND=noninteractive apt-get install -y postfix + curl -fsSL https://deb.nodesource.com/setup_lts.x | -E bash - + apt-get install -y nodejs + apt-get install -y npm + sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf + service postfix restart + systemctl enable mongod.service } -function setup_gmail { - echo "Please register an app in your Google API manager, generate an OAuth token and refresh token" - echo "For more details refer to this url: https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough" - echo "Please enter your Gmail id" - read email_id - echo "Please enter your client id" - read client_id - echo "Please enter your client secret" - read client_secret - echo "Please enter access token" - read access_token - echo "Please enter refresh token" - read refresh_token - echo "EMAIL = 'GMAIL'" >> $BD/CentralService/cs_config - echo "EMAIL_ID = '$email_id'" >> $BD/CentralService/cs_config - echo "ACCESS_TOKEN = '$access_token'" >> $BD/CentralService/cs_config - echo "REFRESH_TOKEN = '$refresh_token'" >> $BD/CentralService/cs_config - echo "CLIENT_ID = '$client_id'" >> $BD/CentralService/cs_config - echo "CLIENT_SECRET = '$client_secret'" >> $BD/CentralService/cs_config +function setup_gmail() { + echo "Please register an app in your Google API manager, generate an OAuth token and refresh token" + echo "For more details refer to this url: https://github.com/google/gmail-oauth2-tools/wiki/OAuth2DotPyRunThrough" + echo "Please enter your Gmail id" + read email_id + echo "Please enter your client id" + read client_id + echo "Please enter your client secret" + read client_secret + echo "Please enter access token" + read access_token + echo "Please enter refresh token" + read refresh_token + echo "EMAIL = 'GMAIL'" >>$BD/CentralService/cs_config + echo "EMAIL_ID = '$email_id'" >>$BD/CentralService/cs_config + echo "ACCESS_TOKEN = '$access_token'" >>$BD/CentralService/cs_config + echo "REFRESH_TOKEN = '$refresh_token'" >>$BD/CentralService/cs_config + echo "CLIENT_ID = '$client_id'" >>$BD/CentralService/cs_config + echo "CLIENT_SECRET = '$client_secret'" >>$BD/CentralService/cs_config } -function setup_email { - echo "BuildingDepot requires a Mail Transfer Agent. Would you like to install one or use your gmail account?" - echo "Note: If you use GMail, it is advised to create a new account for this purpose." - echo "Installing an MTA..." - apt-get install -y mailutils - sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf - service postfix restart - echo "EMAIL = 'LOCAL'" >> $BD/CentralService/cs_config - echo "EMAIL_ID = 'admin@buildingdepot.org'" >> $BD/CentralService/cs_config +function setup_email() { + echo "BuildingDepot requires a Mail Transfer Agent. Would you like to install one or use your gmail account?" + echo "Note: If you use GMail, it is advised to create a new account for this purpose." + echo "Installing an MTA..." + apt-get install -y mailutils + sed -i -e 's/"inet_interfaces = all/"inet_interfaces = loopback-only"/g' /etc/postfix/main.cf + service postfix restart + echo "EMAIL = 'LOCAL'" >>$BD/CentralService/cs_config + echo "EMAIL_ID = 'admin@buildingdepot.org'" >>$BD/CentralService/cs_config } -function setup_packages { - echo - echo "Securing BD Packages" - echo "--------------------" - echo "Auto-generating credentials for packages (MongoDB,InfluxDB & Redis)..." - ## Add MongoDB Admin user - mongoUsername="user$(openssl rand -hex 16)" - mongoPassword=$(openssl rand -hex 32) - echo "MONGODB_USERNAME = '$mongoUsername'" >> $BD/CentralService/cs_config - echo "MONGODB_PWD = '$mongoPassword'" >> $BD/CentralService/cs_config - echo "MONGODB_USERNAME = '$mongoUsername'" >> $BD/DataService/ds_config - echo "MONGODB_PWD = '$mongoPassword'" >> $BD/DataService/ds_config - echo " MONGODB_USERNAME = '$mongoUsername'" >> $BD/CentralReplica/config.py - echo " MONGODB_PWD = '$mongoPassword'" >> $BD/CentralReplica/config.py - mongo --eval "db.getSiblingDB('admin').createUser({user:'$mongoUsername',pwd:'$mongoPassword',roles:['userAdminAnyDatabase','dbAdminAnyDatabase','readWriteAnyDatabase']})" - # Enable MongoDB authorization - echo "security:" >> /etc/mongod.conf - echo " authorization: \"enabled\"">> /etc/mongod.conf - service mongod restart - - sleep 2 - - ## Add InfluxDB Admin user - influxUsername="user$(openssl rand -hex 16)" - influxPassword=$(openssl rand -hex 32) - echo "INFLUXDB_USERNAME = '$influxUsername'">> $BD/DataService/ds_config - echo "INFLUXDB_PWD = '$influxPassword'">> $BD/DataService/ds_config - sleep 1 - curl -d "q=CREATE USER $influxUsername WITH PASSWORD '$influxPassword' WITH ALL PRIVILEGES" -X POST http://localhost:8086/query - sed -ir 's/# auth-enabled = false/auth-enabled = true/g' /etc/influxdb/influxdb.conf - service influxdb restart - - sleep 2 - - ## Add Redis Admin user - redisPassword=$(openssl rand -hex 64) - echo "REDIS_PWD = '$redisPassword'">> $BD/CentralService/cs_config - echo "REDIS_PWD = '$redisPassword'">> $BD/DataService/ds_config - echo " REDIS_PWD = '$redisPassword'" >> $BD/CentralReplica/config.py - sed -i -e '/#.* requirepass / s/.*/ requirepass '$redisPassword'/' /etc/redis/redis.conf - service redis restart - - sleep 2 - - ## Add RabbitMQ Admin user - rabbitmqUsername="user$(openssl rand -hex 16)" - rabbitmqPassword=$(openssl rand -hex 32) - rabbitmqUsername_endUser="user$(openssl rand -hex 16)" - rabbitmqPassword_endUser=$(openssl rand -hex 32) - echo "RABBITMQ_ADMIN_USERNAME = '$rabbitmqUsername'">> $BD/DataService/ds_config - echo "RABBITMQ_ADMIN_PWD = '$rabbitmqPassword'">> $BD/DataService/ds_config - echo "RABBITMQ_ENDUSER_USERNAME = '$rabbitmqUsername_endUser'">> $BD/DataService/ds_config - echo "RABBITMQ_ENDUSER_PWD = '$rabbitmqPassword_endUser'">> $BD/DataService/ds_config - # Create a Admin user. - rabbitmqctl add_user "$rabbitmqUsername" "$rabbitmqPassword" - # Add Administrative Rights - rabbitmqctl set_user_tags "$rabbitmqUsername" administrator - # Grant necessary permissions - rabbitmqctl set_permissions -p / "$rabbitmqUsername" ".*" ".*" ".*" - # Create a End User. - rabbitmqctl add_user "$rabbitmqUsername_endUser" "$rabbitmqPassword_endUser" - # Add Permissions - rabbitmqctl set_user_tags "$rabbitmqUsername_endUser" - # Grant necessary permissions - rabbitmqctl set_permissions -p / "$rabbitmqUsername_endUser" "" "" ".*" - echo "BuildingDepot uses RabbitMQ Queues for Publishing and Subscribing to Sensor data. " - echo "Some web front-end use RabbitMQ Queues use rabbitmq_web_stomp plugin" - echo "Enter Y to install rabbitmq_web_stomp plugin: " - rabbitmq-plugins enable rabbitmq_web_stomp - - sleep 1 - - - echo - echo "Auto-Generated User Credentials for BuildingDepot Packages [MongoDB,InfluxDB & Redis]" - echo +function setup_packages() { + echo + echo "Securing BD Packages" + echo "--------------------" + echo "Auto-generating credentials for packages (MongoDB,InfluxDB & Redis)..." + ## Add MongoDB Admin user + mongoUsername="user$(openssl rand -hex 16)" + mongoPassword=$(openssl rand -hex 32) + echo "MONGODB_USERNAME = '$mongoUsername'" >>$BD/CentralService/cs_config + echo "MONGODB_PWD = '$mongoPassword'" >>$BD/CentralService/cs_config + echo "MONGODB_USERNAME = '$mongoUsername'" >>$BD/DataService/ds_config + echo "MONGODB_PWD = '$mongoPassword'" >>$BD/DataService/ds_config + echo " MONGODB_USERNAME = '$mongoUsername'" >>$BD/CentralReplica/config.py + echo " MONGODB_PWD = '$mongoPassword'" >>$BD/CentralReplica/config.py + mongo --eval "db.getSiblingDB('admin').createUser({user:'$mongoUsername',pwd:'$mongoPassword',roles:['userAdminAnyDatabase','dbAdminAnyDatabase','readWriteAnyDatabase']})" + # Enable MongoDB authorization + echo "security:" >>/etc/mongod.conf + echo " authorization: \"enabled\"" >>/etc/mongod.conf + service mongod restart + + sleep 2 + + ## Add InfluxDB Admin user + influxUsername="user$(openssl rand -hex 16)" + influxPassword=$(openssl rand -hex 32) + echo "INFLUXDB_USERNAME = '$influxUsername'" >>$BD/DataService/ds_config + echo "INFLUXDB_PWD = '$influxPassword'" >>$BD/DataService/ds_config + sleep 1 + curl -d "q=CREATE USER $influxUsername WITH PASSWORD '$influxPassword' WITH ALL PRIVILEGES" -X POST http://localhost:8086/query + sed -ir 's/# auth-enabled = false/auth-enabled = true/g' /etc/influxdb/influxdb.conf + service influxdb restart + + sleep 2 + + ## Add Redis Admin user + redisPassword=$(openssl rand -hex 64) + echo "REDIS_PWD = '$redisPassword'" >>$BD/CentralService/cs_config + echo "REDIS_PWD = '$redisPassword'" >>$BD/DataService/ds_config + echo " REDIS_PWD = '$redisPassword'" >>$BD/CentralReplica/config.py + sed -i -e '/#.* requirepass / s/.*/ requirepass '$redisPassword'/' /etc/redis/redis.conf + service redis restart + + sleep 2 + + ## Add RabbitMQ Admin user + rabbitmqUsername="user$(openssl rand -hex 16)" + rabbitmqPassword=$(openssl rand -hex 32) + rabbitmqUsername_endUser="user$(openssl rand -hex 16)" + rabbitmqPassword_endUser=$(openssl rand -hex 32) + echo "RABBITMQ_ADMIN_USERNAME = '$rabbitmqUsername'" >>$BD/DataService/ds_config + echo "RABBITMQ_ADMIN_PWD = '$rabbitmqPassword'" >>$BD/DataService/ds_config + echo "RABBITMQ_ENDUSER_USERNAME = '$rabbitmqUsername_endUser'" >>$BD/DataService/ds_config + echo "RABBITMQ_ENDUSER_PWD = '$rabbitmqPassword_endUser'" >>$BD/DataService/ds_config + # Create a Admin user. + rabbitmqctl add_user "$rabbitmqUsername" "$rabbitmqPassword" + # Add Administrative Rights + rabbitmqctl set_user_tags "$rabbitmqUsername" administrator + # Grant necessary permissions + rabbitmqctl set_permissions -p / "$rabbitmqUsername" ".*" ".*" ".*" + # Create a End User. + rabbitmqctl add_user "$rabbitmqUsername_endUser" "$rabbitmqPassword_endUser" + # Add Permissions + rabbitmqctl set_user_tags "$rabbitmqUsername_endUser" + # Grant necessary permissions + rabbitmqctl set_permissions -p / "$rabbitmqUsername_endUser" "" "" ".*" + echo "BuildingDepot uses RabbitMQ Queues for Publishing and Subscribing to Sensor data. " + echo "Some web front-end use RabbitMQ Queues use rabbitmq_web_stomp plugin" + echo "Enter Y to install rabbitmq_web_stomp plugin: " + rabbitmq-plugins enable rabbitmq_web_stomp + + sleep 1 + + echo + echo "Auto-Generated User Credentials for BuildingDepot Packages [MongoDB,InfluxDB & Redis]" + echo } deploy_config install_packages if [ "$DEPLOY_CS" = true ]; then - deploy_centralservice + deploy_centralservice fi if [ "$DEPLOY_DS" = true ]; then - deploy_dataservice + deploy_dataservice fi service mongod start @@ -285,10 +283,9 @@ sleep 5 supervisorctl restart all service influxdb start - if [ "$DEPLOY_TOGETHER" = true ]; then - joint_deployment_fix - service nginx restart + joint_deployment_fix + service nginx restart fi rm -rf configs @@ -296,7 +293,6 @@ rm -rf configs popd setup_email - # Create Database on InfluxDB curl -d "q=CREATE DATABASE buildingdepot" -X POST http://localhost:8086/query setup_packages From e2a2444a82b62dd4ffecb7e38668183840d1d97b Mon Sep 17 00:00:00 2001 From: Sudershan Boovaraghavan Date: Thu, 15 Jul 2021 21:20:03 -0400 Subject: [PATCH 65/70] Update test_bd.yml --- .github/workflows/test_bd.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index be84bf8d..48e695ac 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -14,13 +14,12 @@ on: - develop jobs: build: - runs-on: ubuntu-latest - container: - image: ubuntu:focal-20210416 + runs-on: ${{ matrix.os }} strategy: - fail-fast: false matrix: - python-version: ['3.6.13', '3.7.10', '3.8.9'] + os: [ubuntu-18.04, ubuntu-20.04] + python-version: ['3.8.10', '3.9.6'] + fail-fast: false steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} From 450c4354a1f577053f90fbbe89eccb280ab324ea Mon Sep 17 00:00:00 2001 From: Sudershan Boovaraghavan Date: Thu, 15 Jul 2021 21:21:35 -0400 Subject: [PATCH 66/70] Update test_bd.yml --- .github/workflows/test_bd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index 48e695ac..c34343c3 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -29,7 +29,7 @@ jobs: architecture: x64 - name: Install BuildingDepot run: | - bash -x ./script_for_github_actions.sh + sudo bash -x ./script_for_github_actions.sh - name: Initialize tests run: | cd benchmarking-tools/functional-testing-tool From d4d48e7e9751a9242a38aba6ff85dea9eb293fb2 Mon Sep 17 00:00:00 2001 From: Sudershan Boovaraghavan Date: Thu, 15 Jul 2021 22:02:50 -0400 Subject: [PATCH 67/70] Update test_bd.yml --- .github/workflows/test_bd.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index c34343c3..45d6207a 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -7,7 +7,6 @@ on: branches: - master - develop - - python3 pull_request: branches: - master From 5b0e60b5f0e351add6c1993dbcfd646828fc42fa Mon Sep 17 00:00:00 2001 From: Sudershan Boovaraghavan Date: Thu, 15 Jul 2021 22:04:56 -0400 Subject: [PATCH 68/70] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 69b428c9..091ef91e 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -BuildingDepot v3.2.9 +BuildingDepot v3.3 ==================== ![BuildingDepot](https://github.com/synergylabs/BuildingDepot-v3/workflows/BuildingDepot/badge.svg) From 92e8b0bd73db402a3722da43134786302f26392f Mon Sep 17 00:00:00 2001 From: Shreyas Nagare Date: Thu, 2 Jun 2022 15:21:43 -0400 Subject: [PATCH 69/70] Update test_bd.yml --- .github/workflows/test_bd.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index 45d6207a..f44877ae 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -16,16 +16,18 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-18.04, ubuntu-20.04] - python-version: ['3.8.10', '3.9.6'] + os: [ubuntu-18.04] + python-version: ['3.8', '3.10'] fail-fast: false steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} architecture: x64 + - name: Display Python version + run: python --version - name: Install BuildingDepot run: | sudo bash -x ./script_for_github_actions.sh From 3541de681cd8c98ff5955993147a4b0f8f8cc1dc Mon Sep 17 00:00:00 2001 From: Sudershan Boovaraghavan Date: Thu, 2 Jun 2022 15:41:19 -0400 Subject: [PATCH 70/70] Update test_bd.yml --- .github/workflows/test_bd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_bd.yml b/.github/workflows/test_bd.yml index f44877ae..d2948965 100644 --- a/.github/workflows/test_bd.yml +++ b/.github/workflows/test_bd.yml @@ -20,9 +20,9 @@ jobs: python-version: ['3.8', '3.10'] fail-fast: false steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} architecture: x64