Skip to content

Commit

Permalink
Add support YAML config fmt for k8s secrets (#1)
Browse files Browse the repository at this point in the history
* Add support YAML config fmt for k8s secrets

* Add tenant parameterization support

* Update to support latest schema

* Check config format for validity and then dump to secret as is

* Fail immediately if config file is not valid yaml / json

* Do not create user_service RT if users are not implemented for the package

* Add support YAML config fmt for k8s secrets

* Update pypi robot credentials

* Fix merge issue and py3 compatibility update
  • Loading branch information
hayorov authored and spukst3r committed Jul 28, 2017
1 parent 8f81869 commit 635006d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
18 changes: 9 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- '2.7'
- '3.4'
- '3.5'
- '3.6'
before_install:
- pip install --upgrade setuptools pip
- pip install --upgrade setuptools pip
install:
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- pip install -r requirements.txt
- pip install -r test-requirements.txt
script: python setup.py flake8
deploy:
provider: pypi
user: allexx
user: apslite
password:
secure: wBS+ZpqRAl6R37xr3FGXKmc1hhvpUHxRE9nqQhuUUUw2EOopexgrC4YEpiXyfFwdajZfr/OqgYkb2mLSRqlmRc3NSWFbWMF8pkHJQr/bovkwTkjy1QLHNx7nqHYsnIxBE6BxkChhAsr5Qmo9fKyCy2CA2ahHvLDoBztuUaIB+kmlcRRLsCt52YtX9LGHEQBNlowxWkAgA3zKXwu/LPV5syQodh0y7y+XoYw1F9w4DasMxTOWhYqV2yCVTppgEf5RpJUutFP4L/kAaNiT593pd/B5qgLtyQrCRsRclKcrH4yMMBnnSGP2OKd5BRm7f4P65ck3SWWQSHRnBqxlwhkpSwP/6UcVUXHbryCHYHSpUBXYuFZmNZuChSjN5fy0px7F3q1DAzY4oEliZvzDyOuAWXntAWruaHbB0DI1y7kMMmJbeCjjLV7zb1h5gNDlmkeJlVfRhHxE0OxAwSAOnzIDa4jxMQQ8D87dpI5gnd4RxXpH0LUxeujpsN9LOTaoyq051pwvGANndafdcgO1o1xbwJyH8z+EvoIPj0WZW5ExUXikXFkaww2aBBS9G3BdP73jeilZbnM+qqI5liBmCRbYEDvh7S24GiwvfYf6IuuM+cYkZugA8FIZ6j5krwBk4q/0IuWbTPt5IRLzEm7rLDW3qRwlNqMpcMZNB5dCTbzej+s=
secure: wA5257WHW0hWAwr+G1iBNbAUsHrsErB1/bHAD3mNpGoxGZUqggLiF+oHjKkdk/kzpCjyuPArzwHgJ0yCtjjMaNDg7x3LQsbmKkxW+tYIPmMEbKyVNBUVU8CzCnd9ktJp0jP0MFyRlzSmbiqYbF/Zt+jRZgOy8g/oMYtnv3ZgCskKY2MiedMZP8WDp/6jGb28zXxJC9VBrrMx8HAxBx7QLf2ez3JtTm1KBnQ3T2HKXDzvuYyhgB7FtfY7AAC7R3LSqu49oXNSCZ5RjvtMYup3zg77YLcb3fHyTWlVV+QwItikDZCCqPuJyhzZ9CkZpvUrh9dJYbL2Rs9Fnqt0U+wQly1YlnKQ620fUwRvFPV3B4h2m12QBbup4YCFiGufwlk53Wg/R1DuUNCs0RXw0oj+R9jECEuKtcdy7r4dOLWM4In7BT0Uxi0YM33bQcFDVWPAAMCkXCpo8zMvDhsozXbntcPhGar7inWVGf9qpXZzFduGYK8mYaDyKAHD355DzZ3i8kzeMatQj55RZA0fdPRPElkdfq4O28nwIXzmHLTsKnv1InrdBnvoay9lh29MuTojIeQ2A7UTwgrL06LQAASKoL8WG/N6rIXWLolX1NLydlYX2HsvC8eSHoF8YJKWZhlfcFdsyh137+oAPk1o3QrOUt9CgbC3SMsOw14//51gK5k=
on:
tags: true
all_branches: true
Expand Down
39 changes: 24 additions & 15 deletions apsconnectcli/apsconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,21 @@ def install_backend(self, name, image, config_file, healthcheck_path='/',
root_path='/', namespace='default', replicas=2,
force=False):
""" Install connector-backend in the k8s cluster"""

try:
print("Loading config file: {}".format(config_file))
with open(config_file) as f:
config_data = f.read()
yaml.load(config_data) # we only need to check if this is valid YAML or JSON
except yaml.YAMLError as e:
print("Config file should be valid JSON or YAML structure, error: {}".format(e))
exit(1)
except Exception as e:
print("Unable to read config file, error: {}".format(e))
sys.exit(1)
with open(config_file) as config:
try:
print("Loading config file: {}".format(config_file))
config_data, config_format = json.load(config), 'json'
except ValueError as e:
if 'No JSON object' in str(e):
config_data, config_format = yaml.load(config), 'yaml'
else:
raise
except yaml.YAMLError as e:
print("Config file should be valid JSON or YAML structure, error: {}".format(e))
sys.exit(1)
except Exception as e:
print("Unable to read config file, error: {}".format(e))
sys.exit(1)

api_client = _get_k8s_api_client()
api = client.VersionApi(api_client)
Expand All @@ -179,7 +182,7 @@ def install_backend(self, name, image, config_file, healthcheck_path='/',
sys.exit(1)

try:
_create_secret(name, config_data, core_v1, namespace, force)
_create_secret(name, config_format, config_data, core_v1, namespace, force)
print("Create config [ok]")
except Exception as e:
print("Can't create config in cluster, error: {}".format(e))
Expand Down Expand Up @@ -564,11 +567,17 @@ def _get_cfg():
return cfg


def _create_secret(name, data, api, namespace='default', force=False):
def _create_secret(name, data_format, data, api, namespace='default', force=False):
if data_format == 'json':
config = json.dumps(data, ensure_ascii=False).encode('utf-8')
elif data_format == 'yaml':
config = yaml.dump(data, allow_unicode=True, default_flow_style=False)
else:
raise Exception("Unknown config data format: {}".format(data_format))
secret = {
'apiVersion': 'v1',
'data': {
'config': base64.b64encode(data.encode('utf-8')).decode(),
'config': base64.b64encode(config).decode(),
},
'kind': 'Secret',
'metadata': {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
setup(
name='apsconnectcli',
author='Ingram Micro',
version='1.6.10',
version='1.6.11',
keywords='aps apsconnect connector automation',
extras_require={
':python_version<="2.7"': ['backports.tempfile==1.0rc1']},
Expand Down

0 comments on commit 635006d

Please sign in to comment.