import logging
import os
import seria
import yaml

from figgypy.decrypt import (
    gpg_decrypt,
    kms_decrypt
)
from figgypy.exceptions import FiggypyError

log = logging.getLogger('figgypy')
if len(log.handlers) == 0:
    log.addHandler(logging.NullHandler())


class Config(object):
    """Configuration object

    Args:
        f (str): filename
            see below
        aws_access_key_id (optional[str]): access key id
        aws_secret_access_key (optional[str]): secret key
        region_name (optional[str]): aws region

    Returns:
        object: configuration object with attribute dictionary for each
            top level property

    Object can be created with a filename only, relative path, or absolute path.
    If only name or relative path is provided, look in this order:

    1. current directory
    2. `~/.config/<file_name>`
    3. `/etc/<file_name>`

    It is a good idea to include you __package__ in the file name.
    For example, `cfg = Config(os.path.join(__package__, 'config.yaml'))`.
    This way it will look for your_package/config.yaml,
    ~/.config/your_package/config.yaml, and /etc/your_package/config.yaml.
    """
    _dirs = [
        os.curdir,
        os.path.join(os.path.expanduser("~"), '.config'),
        "/etc/"
    ]

    def __init__(self, f):
        self._f = self._get_file(f)
        self._cfg = self._get_cfg(self._f)

    def _get_cfg(self, f):
        """Get configuration from config file"""
        try:
            with open(f, 'r') as _fo:
                try:
                    _seria_in = seria.load(_fo)
                    _y = _seria_in.dump('yaml')
                except Exception as e:
                    raise
        except IOError:
            raise FiggypyError("could not open configuration file")

        _cfg = yaml.load(_y)
        self._post_load_process(_cfg)
        for k, v in _cfg.items():
            setattr(self, k, v)

    def _post_load_process(self, cfg):
        gpg_decrypt(cfg)
        kms_decrypt(cfg, **self._aws_credentials)

    def _get_file(self, f):
        """Get a config file if possible."""
        if os.path.isabs(f):
            return f
        else:
            for d in Config._dirs:
                _f = os.path.join(d, f)
                if os.path.isfile(_f):
                    return _f
            raise FiggypyError("could not find configuration file {} in dirs {}"
                               .format(f, Config._dirs))

@@ -1293,34 +1293,336 @@
 __init__(self, f
-):
+, aws_access_key_id=None, aws_secret_access_key=None,%0A                 region_name=None):%0A        self._aws_credentials = %7B'aws_access_key_id': aws_access_key_id,%0A                                 'aws_secret_access_key': aws_secret_access_key,%0A                                 'region_name': region_name%7D
 %0A        self._f

Add aws credentials to init