Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Do not rely on default collection being called default
Browse files Browse the repository at this point in the history
Looks up the default collection name from the vcap settings
  • Loading branch information
rossjones committed Mar 12, 2018
1 parent d3d0ed8 commit 1bed625
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions backdrop/core/config/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion backdrop/read/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions backdrop/read/config/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
1 change: 1 addition & 0 deletions backdrop/read/config/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
1 change: 1 addition & 0 deletions backdrop/read/config/staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
1 change: 1 addition & 0 deletions backdrop/read/config/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions backdrop/read/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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,
Expand Down Expand Up @@ -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'))
Expand Down
1 change: 1 addition & 0 deletions backdrop/transformers/config/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
1 change: 1 addition & 0 deletions backdrop/write/config/development.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
}

STAGECRAFT_COLLECTION_ENDPOINT_TOKEN = 'dev-create-endpoint-token'
DEFAULT_COLLECTION = 'default'

try:
from development_environment import *
Expand Down
1 change: 1 addition & 0 deletions backdrop/write/config/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
1 change: 1 addition & 0 deletions backdrop/write/config/staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
1 change: 1 addition & 0 deletions backdrop/write/config/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1bed625

Please sign in to comment.