Skip to content

Commit

Permalink
Upgrade grift to python3
Browse files Browse the repository at this point in the history
  • Loading branch information
vsivaraja committed Oct 3, 2017
1 parent dd3b6c9 commit b502ec8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
6 changes: 3 additions & 3 deletions examples/flask_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

import flask

from config import app_config
from .config import app_config

app = flask.Flask(__name__)
# Set the debug level and configure logging
app.debug = app_config.DEBUG
app.logger.setLevel(app_config.LOG_LEVEL)

# NOT IMPLEMENTED:
# - Use a Postgres database, using app_config.DATABASE_URL as the
# NOT IMPLEMENTED:
# - Use a Postgres database, using app_config.DATABASE_URL as the
# database url
# - Use another API with app_config.API_TOKEN and app_config.API_URL

Expand Down
13 changes: 7 additions & 6 deletions grift/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import os

import requests
import six


@six.add_metaclass(ABCMeta)
class AbstractLoader(object):
"""Base class for loading configuration settings from a source"""
__metaclass__ = ABCMeta
pass

def reload(self):
"""Reload values from the designated source, if possible"""
Expand Down Expand Up @@ -143,7 +144,7 @@ def _fetch_secrets(vault_url, path, token):
resp.raise_for_status()
data = resp.json()
if data.get('errors'):
raise VaultException(u'Error fetching Vault secrets from path {}: {}'
raise VaultException(six.u('Error fetching Vault secrets from path {}: {}')
.format(path, data['errors']))
return data['data']

Expand All @@ -155,7 +156,7 @@ def _fetch_app_role_token(vault_url, role_id, secret_id):
resp.raise_for_status()
data = resp.json()
if data.get('errors'):
raise VaultException(u'Error fetching Vault token: {}'.format(data['errors']))
raise VaultException(six.u('Error fetching Vault token: {}'.format(data['errors'])))
return data['auth']['client_token']

def reload(self):
Expand All @@ -169,7 +170,7 @@ def lookup_token(self):
resp.raise_for_status()
data = resp.json()
if data.get('errors'):
raise VaultException(u'Error looking up Vault token: {}'.format(data['errors']))
raise VaultException(six.u('Error looking up Vault token: {}'.format(data['errors'])))
return data

def renew_token(self):
Expand All @@ -179,7 +180,7 @@ def renew_token(self):
resp.raise_for_status()
data = resp.json()
if data.get('errors'):
raise VaultException(u'Error renewing Vault token: {}'.format(data['errors']))
raise VaultException(six.u('Error renewing Vault token: {}'.format(data['errors'])))
return data


Expand Down
6 changes: 3 additions & 3 deletions grift/property_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def to_native(self, value):
if isinstance(native_value, dict):
return native_value
else:
raise ConversionError(u'Cannot load value as a dict: {}'.format(value))
raise ConversionError(six.u('Cannot load value as a dict: {}'.format(value)))


class ListType(BaseType):
Expand Down Expand Up @@ -66,11 +66,11 @@ def validate_length(self, value):

if self.max_length is not None and list_len > self.max_length:
raise ValidationError(
u'List has {} values; max length is {}'.format(list_len, self.max_length))
six.u('List has {} values; max length is {}'.format(list_len, self.max_length)))

if self.min_length is not None and list_len < self.min_length:
raise ValidationError(
u'List has {} values; min length is {}'.format(list_len, self.min_length))
six.u('List has {} values; min length is {}'.format(list_len, self.min_length)))


class NetworkType(StringType):
Expand Down
3 changes: 2 additions & 1 deletion grift/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2017 Kensho Technologies, Inc.
import os
import six
from unittest import TestCase

from schematics.exceptions import ConversionError
Expand Down Expand Up @@ -139,7 +140,7 @@ def test_as_dict(self):
'ANY_TYPE_PROP': [1, 2, 3],
}
expected_dict = {
'STRING_PROP': u'1',
'STRING_PROP': six.u('1'),
'INT_PROP': 2,
'ANY_TYPE_PROP': [1, 2, 3],
'DIFFERENT_KEY_PROP': None,
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
mock>=2.0.0
requests>=2.7.0
schematics==1.1.1
six==1.11.0
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
install_requires=[
'schematics==1.1.1',
'requests==2.13.0'
'six==1.11.0'
],
)

0 comments on commit b502ec8

Please sign in to comment.