diff --git a/backdrop/core/config/common.py b/backdrop/core/config/common.py index 85076bbf..76c88b48 100644 --- a/backdrop/core/config/common.py +++ b/backdrop/core/config/common.py @@ -12,6 +12,7 @@ def load_paas_settings(): if service['name'] == 'gds-performance-platform-mongodb-service': credentials = service['credentials'] paas['DATABASE_URL'] = credentials['uri'] + paas['DEFAULT_COLLECTION'] = credentials['name'] ca_cert = b64decode(credentials['ca_certificate_base64']) paas['CA_CERTIFICATE'] = ca_cert if 'REDIS_DATABASE_NUMBER' in os.environ: diff --git a/backdrop/read/api.py b/backdrop/read/api.py index dd7d49a1..6d93f62a 100644 --- a/backdrop/read/api.py +++ b/backdrop/read/api.py @@ -203,7 +203,7 @@ def fetch(data_set_config): data_set = DataSet(storage, data_set_config) try: - query = parse_query_from_request(request) + query = parse_query_from_request(request, app.config) data = data_set.execute_query(query) except InvalidOperationError: diff --git a/backdrop/read/config/development.py b/backdrop/read/config/development.py index 613e305e..e7bd7d06 100644 --- a/backdrop/read/config/development.py +++ b/backdrop/read/config/development.py @@ -4,6 +4,7 @@ STAGECRAFT_URL = 'http://localhost:3103' SIGNON_API_USER_TOKEN = 'development-oauth-access-token' +DEFAULT_COLLECTION = 'default' try: from .development_environment import * diff --git a/backdrop/read/config/production.py b/backdrop/read/config/production.py index 3ded5859..91c3072d 100644 --- a/backdrop/read/config/production.py +++ b/backdrop/read/config/production.py @@ -8,3 +8,4 @@ SIGNON_API_USER_TOKEN = os.getenv('SIGNON_API_USER_TOKEN') LOG_LEVEL = "INFO" SESSION_COOKIE_SECURE = True +DEFAULT_COLLECTION = PAAS.get('DEFAULT_COLLECTION') diff --git a/backdrop/read/config/staging.py b/backdrop/read/config/staging.py index 3ded5859..91c3072d 100644 --- a/backdrop/read/config/staging.py +++ b/backdrop/read/config/staging.py @@ -8,3 +8,4 @@ SIGNON_API_USER_TOKEN = os.getenv('SIGNON_API_USER_TOKEN') LOG_LEVEL = "INFO" SESSION_COOKIE_SECURE = True +DEFAULT_COLLECTION = PAAS.get('DEFAULT_COLLECTION') diff --git a/backdrop/read/config/test.py b/backdrop/read/config/test.py index 885720bb..edab563f 100644 --- a/backdrop/read/config/test.py +++ b/backdrop/read/config/test.py @@ -2,5 +2,6 @@ LOG_LEVEL = "ERROR" DATA_SET_RATE_LIMIT = '10000/second' +DEFAULT_COLLECTION = 'default' from development import STAGECRAFT_URL, SIGNON_API_USER_TOKEN diff --git a/backdrop/read/query.py b/backdrop/read/query.py index f247e7e6..81ab8cac 100644 --- a/backdrop/read/query.py +++ b/backdrop/read/query.py @@ -3,13 +3,12 @@ from backdrop.core.query import Query import re - __all__ = ['parse_query_from_request'] -def parse_query_from_request(request): +def parse_query_from_request(request, config): """Parses a Query object from a flask request""" - return Query.create(**parse_request_args(request.args)) + return Query.create(**parse_request_args(request.args, config.get('DEFAULT_COLLECTION', 'default'))) def if_present(func, value): @@ -18,7 +17,7 @@ def if_present(func, value): return func(value) -def parse_request_args(request_args): +def parse_request_args(request_args, default_collection='default'): args = dict() args['start_at'] = if_present(parse_time_as_utc, @@ -67,7 +66,8 @@ def parse_filter_by(filter_by, is_regex): if ':' in collect_arg: args['collect'].append(tuple(collect_arg.split(':'))) else: - args['collect'].append((collect_arg, 'default')) + args['collect'].append( + (collect_arg, default_collection)) args['flatten'] = if_present(boolify, request_args.get('flatten')) args['inclusive'] = if_present(boolify, request_args.get('inclusive')) diff --git a/backdrop/transformers/config/production.py b/backdrop/transformers/config/production.py index 2249b8b1..535dd48d 100644 --- a/backdrop/transformers/config/production.py +++ b/backdrop/transformers/config/production.py @@ -8,3 +8,4 @@ STAGECRAFT_OAUTH_TOKEN = os.getenv('STAGECRAFT_OAUTH_TOKEN') BACKDROP_READ_URL = 'https://performance-platform-backdrop-read-production.cloudapps.digital/data' BACKDROP_WRITE_URL = 'https://performance-platform-backdrop-write-production.cloudapps.digital/data' +DEFAULT_COLLECTION = PAAS.get('DEFAULT_COLLECTION') diff --git a/backdrop/write/config/development.py b/backdrop/write/config/development.py index 775adcb6..3e393f56 100644 --- a/backdrop/write/config/development.py +++ b/backdrop/write/config/development.py @@ -5,6 +5,7 @@ } STAGECRAFT_COLLECTION_ENDPOINT_TOKEN = 'dev-create-endpoint-token' +DEFAULT_COLLECTION = 'default' try: from development_environment import * diff --git a/backdrop/write/config/production.py b/backdrop/write/config/production.py index 74de2b14..5768ff15 100644 --- a/backdrop/write/config/production.py +++ b/backdrop/write/config/production.py @@ -21,3 +21,4 @@ SECRET_KEY = os.getenv('SECRET_KEY') STAGECRAFT_COLLECTION_ENDPOINT_TOKEN = os.getenv( 'STAGECRAFT_COLLECTION_ENDPOINT_TOKEN') +DEFAULT_COLLECTION = PAAS.get('DEFAULT_COLLECTION') diff --git a/backdrop/write/config/staging.py b/backdrop/write/config/staging.py index cdeb2b26..5e7655a0 100644 --- a/backdrop/write/config/staging.py +++ b/backdrop/write/config/staging.py @@ -13,3 +13,4 @@ SECRET_KEY = os.getenv('SECRET_KEY') STAGECRAFT_COLLECTION_ENDPOINT_TOKEN = os.getenv( 'STAGECRAFT_COLLECTION_ENDPOINT_TOKEN') +DEFAULT_COLLECTION = PAAS.get('DEFAULT_COLLECTION') diff --git a/backdrop/write/config/test.py b/backdrop/write/config/test.py index 4bac569a..a191e8e2 100644 --- a/backdrop/write/config/test.py +++ b/backdrop/write/config/test.py @@ -8,6 +8,7 @@ "evl_volumetrics": ["_timestamp", "service", "transaction"], } BROKER_URL = 'memory://' +DEFAULT_COLLECTION = 'default' from development import (STAGECRAFT_COLLECTION_ENDPOINT_TOKEN, STAGECRAFT_URL, SIGNON_API_USER_TOKEN)