Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions conf/appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,25 @@
'name': 'github',
'type': 'github'
}
},
'default': {
'ref': CONFIG_PROVIDER_DEFAULT,
'meta-info': {
'name': 'default',
'type': CONFIG_PROVIDER_DEFAULT,
}
}
}

CONFIG_PROVIDER_LIST = os.getenv(
'CONFIG_PROVIDER_LIST', 'default,etcd').split(',')

MIME_JSON = 'application/json'
MIME_YAML = 'application/yaml'
MIME_HTML = 'text/html'
MIME_ROOT_V1 = 'application/vnd.configservice.root.v1+json'
MIME_HEALTH_V1 = 'application/vnd.configservice.health.v1+json'
MIME_ROOT_V1 = 'application/vnd.totem-config-service.root.v1+json'
MIME_HEALTH_V1 = 'application/vnd.totem.health-v1+json'
MIME_PROVIDERS_V1 = 'application/vnd.totem-config-service.providers.v1+json'
MIME_PROVIDER_V1 = 'application/vnd.totem-config-service.provider.v1+json'

SCHEMA_ROOT_V1 = 'root-v1'
SCHEMA_HEALTH_V1 = 'health-v1'
SCHEMA_PROVIDERS_V1 = 'providers-v1'
SCHEMA_PROVIDER_V1 = 'provider-v1'
SCHEMA_CONFIG_META_V1 = 'config-meta-v1'

API_MAX_PAGE_SIZE = 1000
API_DEFAULT_PAGE_SIZE = 10
Expand Down
2 changes: 1 addition & 1 deletion configservice/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.1'
__version__ = '0.1.0'
12 changes: 2 additions & 10 deletions configservice/cluster_config/effective.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,7 @@ def merge(current_config, provider, *merge_paths):
return dict_merge(
current_config,
provider.load(name, *merge_paths))

use_paths = list(paths)
while True:
for provider in self.providers:
merged_config = merge(merged_config, provider, *use_paths)
if use_paths:
use_paths.pop()
else:
break

for provider in self.providers:
merged_config = merge(merged_config, provider, *paths)
return merged_config
return cached(name, *paths)
4 changes: 3 additions & 1 deletion configservice/cluster_config/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def _github_fetch(self, owner, repo, ref, name):
'{path}'.format(**path_params)
resp = requests.get(hub_url, params=query_params, auth=self.auth)
if resp.status_code == 200:
return base64.decodebytes(resp.json()[u'content'].encode('utf-8'))
# Py2 compatibility
# TODO:Once we migrate to PY3, change this to decodebytes
return base64.decodestring(resp.json()[u'content'].encode('utf-8'))
elif resp.status_code == 404:
return None
else:
Expand Down
1 change: 1 addition & 0 deletions configservice/jinja/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'sukrit'
52 changes: 52 additions & 0 deletions configservice/jinja/conditions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from future.builtins import ( # noqa
bytes, dict, int, list, object, range, str,
ascii, chr, hex, input, next, oct, open,
pow, round, filter, map, zip)
import re

__author__ = 'sukrit'

"""
Defines all the filters used for jinja templates (config)
"""

USE_TESTS = ('starting_with', 'matching', )


def apply_conditions(env):
"""
Applies filters on jinja env.

:param env: Jinja environment
:return:
"""

for name in USE_TESTS:
env.tests[name] = globals()[name]
return env


def starting_with(value, prefix):
"""
Filter to check if value starts with prefix
:param value: Input source
:type value: str
:param prefix:
:return: True if matches. False otherwise
:rtype: bool
"""
return str(value).startswith(str(prefix))


def matching(value, pattern, casesensitive=True):
"""
Filter that performs a regex match

:param value: Input source
:type value: str
:param pattern: Regex Pattern to be matched
:return: True if matches. False otherwise
:rtype: bool
"""
flags = re.I if not casesensitive else 0
return re.match(str(pattern), str(value), flags) is not None
Loading