PKJM_Hccconfigstore/__init__.py"""Retrieve settings and secrets from different storages.""" from .backends import AwsSsmBackend, DockerSecretBackend, DotenvBackend, EnvVarBackend from .store import Store, SettingNotFoundException __all__ = [ 'Store', 'SettingNotFoundException', 'EnvVarBackend', 'DotenvBackend', 'DockerSecretBackend', 'AwsSsmBackend', ] __version__ = '0.5' PK8x Mzœconfigstore/store.pyclass SettingNotFoundException(Exception): pass _no_default = object() class Store(object): def __init__(self, backends): self._backends = tuple(backends) def add_backend(self, backend): self._backends += (backend,) def get_setting(self, key, default=_no_default): for backend in self._backends: ret = backend.get_setting(key) if ret is None: continue return ret if default is not _no_default: return default else: raise SettingNotFoundException( "Couldn't find setting {} in any backend".format(key)) PKaDM configstore/backends/__init__.pyfrom .awsssm import AwsSsmBackend from .docker_secret import DockerSecretBackend from .dotenv import DotenvBackend from .env_var import EnvVarBackend __all__ = [ 'EnvVarBackend', 'DotenvBackend', 'DockerSecretBackend', 'AwsSsmBackend', ] PKaDMZ((configstore/backends/awsssm.pytry: import boto3 from botocore.exceptions import ClientError except ImportError: # pragma: no cover boto3 = None class AwsSsmBackend(object): """Backend for AWS System Manager Parameter Store. You can create an instance with a prefix: AwsSsmBackend('/myapp/pre-prod/') so that a call like store.get_setting('DEBUG') will try to get a parameter named `/myapp/pre-prod/DEBUG`. """ def __init__(self, name_prefix=''): if boto3 is None: raise ImportError('install configstore[awsssm] to use ' 'the AWS SSM backend') self.name_prefix = name_prefix def get_setting(self, param): client = boto3.client('ssm') name = self.name_prefix + param try: res = client.get_parameter(Name=name, WithDecryption=True) except ClientError as exc: if exc.response['Error']['Code'] == 'ParameterNotFound': return None else: raise return res['Parameter']['Value'] PKJMqb%configstore/backends/docker_secret.pyimport os import errno SECRETS_PATH = '/run/secrets' class DockerSecretBackend(object): def __init__(self, secrets_path=SECRETS_PATH): self.secrets_path = secrets_path def get_setting(self, key): path = os.path.join(self.secrets_path, key) try: file = open(path) except IOError as exc: if exc.errno == errno.ENOENT: return None else: raise with file: return file.readline().strip() PKaDM XPPconfigstore/backends/dotenv.pyfrom __future__ import absolute_import try: import dotenv except ImportError: # pragma: no cover dotenv = None class DotenvBackend(object): """Create an instance with a path to the .env file.""" def __init__(self, dotenv_path): if dotenv is None: raise ImportError('install configstore[dotenv] to use ' 'the dotenv backend') with open(dotenv_path) as file: content = file.read() self.config = dotenv.parse_dotenv(content) def get_setting(self, key): return self.config.get(key) PKJMޱ)ssconfigstore/backends/env_var.pyimport os class EnvVarBackend(object): def get_setting(self, config): return os.environ.get(config) PK8x M-4JJ!configstore-0.5.dist-info/LICENSEMIT License Copyright (c) 2017, 2018 Caravan Web Worker Cooperative, Inc Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!Hd BUcconfigstore-0.5.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,rzd&Y)r$[)T&UD"PK!HL$T)_ "configstore-0.5.dist-info/METADATAVQo6~8e-PkbQ &A5e3Hh{wXɊ; A&ښ9N_3Y9֔zuJ췿MtjȫY{ܩtBr@r|*~J|&gv涞ɭ4G+gg"kƺ9t a1Q!\ĉM@*ɱ5AР>q>JzKU9E4J(؞rBV&Wl:}!8_R4nߟN˅k'mgc"pv6)}TO^vqח˓*{->\drIx&$H}g]gL=N1Rcf *5H6ǜW{>qrtk bgB/{B,'ew!+B*\ȶU:"yh<`{? QzD"qX뤔9²z%6:.DG3QJ.fdѻ؂N]%+^ߨ<,q12g;@7^ syGcmWQ+FH765Kdq2oU}d+V5►R/q,KŲL7#Q@*ˊ jP嘏f( he%TAJ߱Gr4 4'dHdA˓7~8w۱$i L%zZ4D/c `|,1PML3D\Y.Ḫ'i!Gڗ`_ "yOx8%4򍝭|Ed2f;k XInX*ӌkjVr4(H?(˴Iێ~,j@&TY{*L[5{7BU6dEH0tn\fN"e=0$t|kCXTl+C_Ú@rzO+rz 2ǯ [Ris}Q5(RXW%и b+ 9NfwĽWdp vY 7< :q>9|0<SS4(4 >LF7YA*7:r(~-,F;<4pCW&}3ύ/Cv/dJZ/Ԫ/lܲ\[T`u&ӅmMsJ~Q h ْaUJ^m_kdHVPûBXڄ\P_PKJM_Hccconfigstore/__init__.pyPK8x Mzœconfigstore/store.pyPKaDM ]configstore/backends/__init__.pyPKaDMZ((configstore/backends/awsssm.pyPKJMqb% configstore/backends/docker_secret.pyPKaDM XPP: configstore/backends/dotenv.pyPKJMޱ)ssconfigstore/backends/env_var.pyPK8x M-4JJ!vconfigstore-0.5.dist-info/LICENSEPK!Hd BUcconfigstore-0.5.dist-info/WHEELPK!HL$T)_ "configstore-0.5.dist-info/METADATAPK!Hyn\ configstore-0.5.dist-info/RECORDPK GI