# Path: lamvery/clients/kms.py
# class KmsClient(BaseClient):
# 
#     def __init__(self, *args, **kwargs):
#         super(KmsClient, self).__init__(*args, **kwargs)
#         self._kms = self._session.client('kms')
# 
#     def encrypt(self, key_id, text):
#         res = self._kms.encrypt(KeyId=key_id, Plaintext=text)
#         return base64.b64encode(res.get('CiphertextBlob'))
# 
#     def decrypt(self, cipher_text):
#         res = self._kms.decrypt(CiphertextBlob=base64.b64decode(cipher_text))
#         return res.get('Plaintext')


import json
import os
from lamvery.clients.kms import KmsClient
# -*- coding: utf-8 -*-


SECRET_FILE_NAME = '.lamvery_secret.json'
SECRET_DIR = '/tmp/.lamvery-secret'


def get(name):
    data = json.load(open(SECRET_FILE_NAME, 'r'))
    if 'cipher_texts' not in data:
        return None
    if name not in data['cipher_texts']:
        return None
    client = KmsClient(region=data.get('region'))
    return client.decrypt(data['cipher_texts'].get(name))


def file(filename):
    data = json.load(open(SECRET_FILE_NAME, 'r'))
    secret_files = data.get('secret_files', {})

# Path: lamvery/clients/kms.py
# class KmsClient(BaseClient):
# 
#     def __init__(self, *args, **kwargs):
#         super(KmsClient, self).__init__(*args, **kwargs)
#         self._kms = self._session.client('kms')
# 
#     def encrypt(self, key_id, text):
#         res = self._kms.encrypt(KeyId=key_id, Plaintext=text)
#         return base64.b64encode(res.get('CiphertextBlob'))
# 
#     def decrypt(self, cipher_text):
#         res = self._kms.decrypt(CiphertextBlob=base64.b64decode(cipher_text))
#         return res.get('Plaintext')


# Path: lamvery/secret.py
import json
import os
from lamvery.clients.kms import KmsClient

# -*- coding: utf-8 -*-


SECRET_FILE_NAME = '.lamvery_secret.json'
SECRET_DIR = '/tmp/.lamvery-secret'


def get(name):
    data = json.load(open(SECRET_FILE_NAME, 'r'))
    if 'cipher_texts' not in data:
        return None
    if name not in data['cipher_texts']:
        return None
    client = KmsClient(region=data.get('region'))
    return client.decrypt(data['cipher_texts'].get(name))


def file(filename):
    data = json.load(open(SECRET_FILE_NAME, 'r'))
    secret_files = data.get('secret_files', {})

    client = KmsClient(region=data.get('region'))