Wip - Add secret support
parent
b3bb8c270f
commit
84113adef3
@ -1,19 +1,19 @@
|
||||
- repo: git://github.com/pre-commit/pre-commit-hooks
|
||||
sha: 'v0.6.0'
|
||||
hooks:
|
||||
- id: check-added-large-files
|
||||
- id: check-docstring-first
|
||||
- id: check-merge-conflict
|
||||
- id: check-yaml
|
||||
- id: end-of-file-fixer
|
||||
- id: flake8
|
||||
args:
|
||||
- --exclude=__init__.py,docs/conf.py
|
||||
- id: autopep8-wrapper
|
||||
- id: requirements-txt-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: git://github.com/asottile/reorder_python_imports
|
||||
sha: 3d86483455ab5bd06cc1069fdd5ac57be5463f10
|
||||
hooks:
|
||||
- id: reorder-python-imports
|
||||
language_version: 'python2.7'
|
||||
- repo: git://github.com/pre-commit/pre-commit-hooks
|
||||
sha: 78818b90cd694c29333ba54d38f9e60b6359ccfc
|
||||
hooks:
|
||||
- id: check-added-large-files
|
||||
- id: check-docstring-first
|
||||
- id: check-merge-conflict
|
||||
- id: check-yaml
|
||||
- id: end-of-file-fixer
|
||||
- id: flake8
|
||||
args:
|
||||
- --exclude=__init__.py,docs/conf.py
|
||||
- id: autopep8-wrapper
|
||||
- id: requirements-txt-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: git://github.com/asottile/reorder_python_imports
|
||||
sha: 2bff31275b3a2fef7d75989ae60e57f1a8616ed6
|
||||
hooks:
|
||||
- id: reorder-python-imports
|
||||
language_version: python2.7
|
||||
|
@ -0,0 +1,32 @@
|
||||
version: '3.1'
|
||||
|
||||
services:
|
||||
testpython3:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile-test.py3
|
||||
command: ["py.test", "--verbose", "-rw", "-m", "v3", "."]
|
||||
|
||||
testpython2:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile-test.py2
|
||||
command: ["py.test", "--verbose", "-rw", "-m", "v3", "."]
|
||||
|
||||
testpython3_debug:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile-test.py3
|
||||
command: ["py.test", "--verbose", "-s", "-rw", "-m", "v3", "."]
|
||||
|
||||
testpython2_debug:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile-test.py2
|
||||
command: ["py.test", "--verbose", "-s", "-rw", "-m", "v3", "."]
|
||||
|
||||
secrets:
|
||||
secret1:
|
||||
file: ./secret1_file
|
||||
secret2:
|
||||
file: ./secret2_file
|
@ -0,0 +1,44 @@
|
||||
"""
|
||||
Get secrets in containers
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
|
||||
class Secrets(object):
|
||||
"Secret loader"
|
||||
|
||||
secret_dir = '/run/secrets'
|
||||
secret_files = ()
|
||||
|
||||
def __init__(self):
|
||||
self._idx = 0
|
||||
if os.path.exists(self.secret_dir):
|
||||
self.secret_files = os.listdir(self.secret_dir)
|
||||
|
||||
def __len__(self):
|
||||
return len(self.secret_files)
|
||||
|
||||
def __getitem__(self, key):
|
||||
if key not in self.secret_files:
|
||||
raise KeyError
|
||||
return self._read_file(key)
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def __next__(self):
|
||||
idx = self._idx
|
||||
self._idx += 1
|
||||
try:
|
||||
self.secret_files[idx]
|
||||
except IndexError:
|
||||
raise StopIteration
|
||||
return self._read_file(file=self.secret_files[idx])
|
||||
|
||||
def _read_file(self, file):
|
||||
with open(os.path.join(self.secret_dir, file), 'r') as s:
|
||||
return s.read()
|
@ -0,0 +1 @@
|
||||
SECRET1
|
@ -0,0 +1 @@
|
||||
SECRET2
|
@ -0,0 +1,6 @@
|
||||
config_files:
|
||||
- /tmp/test_template.yml
|
||||
- /tmp/test_template2.yml.tpl
|
||||
- /tmp/test_template2.yml.tpl: /tmp/test_template3.yml
|
||||
|
||||
debug: true
|
@ -0,0 +1,28 @@
|
||||
# Tests using pytest
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
from yaml import load
|
||||
from yaml import Loader
|
||||
|
||||
from pyentrypoint import Entrypoint
|
||||
|
||||
|
||||
@pytest.mark.v3
|
||||
def test_secret_templates():
|
||||
test_confs = ['configs/secret.yml']
|
||||
for test_conf in test_confs:
|
||||
entry = Entrypoint(conf='configs/secret.yml')
|
||||
|
||||
conf = entry.config
|
||||
|
||||
entry.apply_conf()
|
||||
|
||||
for _, config_file in conf.get_templates():
|
||||
with open(config_file, mode='r') as r:
|
||||
test = load(stream=r, Loader=Loader)
|
||||
|
||||
# test secrets
|
||||
assert test['SECRET']['secret1'] == 'SECRET1'
|
||||
assert test['SECRET']['secret2'] == 'SECRET2'
|
@ -0,0 +1,4 @@
|
||||
SECRET:
|
||||
{% for key, secret in secrets,items() %}
|
||||
'{{key}}': '{{secret}}'
|
||||
{% endfor %}
|
Loading…
Reference in New Issue