# Path: app/lib/conf.py
# APP = meta.APP_NAME
# class MetaConf(object):
# class Config(object):
#     def __init__(self):
#     def resolveMacros(self):
#     def getConfRoot(self):
#     def getSnapPath(self):
#     def getConfPaths(self):
#     def __init__(self, **kwargs):
#     def load(self, conf_type, *file_path):
#     def get(self, section, key):
#     def set(self, section, key, value):
#     def show(self):
#     def save(self):
#     def envGet():
#     def envGet2(key):
#     def envSet(self, **kwargs):
#     def envShow(self):
#     def getConfig(self, file):
#     def parseConfig(file):
# 
# Path: app/__metadata__.py
# APP_NAME = 'LXDUI'
# APP_CLI_CMD = 'lxdui'
# VERSION = '2.2'
# GIT_URL = 'https://github.com/AdaptiveScale/lxdui.git'
# LXD_URL = 'http://localhost:8443'
# LICENSE = 'Apache 2.0'
# AUTHOR = 'AdaptiveScale, Inc.'
# AUTHOR_URL = 'http://www.adaptivescale.com'
# AUTHOR_EMAIL = 'info@adaptivescale.com'
# KEYWORDS = 'lxc lxc-containers lxd'
# IMAGE_HUB = 'http://hub.kuti.io'
# AUTO_LOAD_CONFIG = True
# DEFAULT_CONFIG_FORMAT = 'ini'


from app.lib import conf
from OpenSSL import crypto
from socket import gethostname
from app import __metadata__ as meta
import logging

log = logging.getLogger(__name__)

class Certificate(object):

    def __init__(self):
        self.conf = conf.Config()
        self.key_file = self.conf.get(meta.APP_NAME, 'lxdui.ssl.key')
        self.cert_file = self.conf.get(meta.APP_NAME, 'lxdui.ssl.cert')
        self.key, self.cert = self.create()

    # Create a self signed certificate
    def create(self):
        # create a key pair
        k = crypto.PKey()
        k.generate_key(crypto.TYPE_RSA, 1024)

        # set the certificate configuration parameters
        section = meta.APP_NAME + '_CERT'
        country = self.conf.get(section, 'lxdui.cert.country')
        state = self.conf.get(section, 'lxdui.cert.state')
        locale = self.conf.get(section, 'lxdui.cert.locale')

# Path: app/lib/conf.py
# APP = meta.APP_NAME
# class MetaConf(object):
# class Config(object):
#     def __init__(self):
#     def resolveMacros(self):
#     def getConfRoot(self):
#     def getSnapPath(self):
#     def getConfPaths(self):
#     def __init__(self, **kwargs):
#     def load(self, conf_type, *file_path):
#     def get(self, section, key):
#     def set(self, section, key, value):
#     def show(self):
#     def save(self):
#     def envGet():
#     def envGet2(key):
#     def envSet(self, **kwargs):
#     def envShow(self):
#     def getConfig(self, file):
#     def parseConfig(file):
# 
# Path: app/__metadata__.py
# APP_NAME = 'LXDUI'
# APP_CLI_CMD = 'lxdui'
# VERSION = '2.2'
# GIT_URL = 'https://github.com/AdaptiveScale/lxdui.git'
# LXD_URL = 'http://localhost:8443'
# LICENSE = 'Apache 2.0'
# AUTHOR = 'AdaptiveScale, Inc.'
# AUTHOR_URL = 'http://www.adaptivescale.com'
# AUTHOR_EMAIL = 'info@adaptivescale.com'
# KEYWORDS = 'lxc lxc-containers lxd'
# IMAGE_HUB = 'http://hub.kuti.io'
# AUTO_LOAD_CONFIG = True
# DEFAULT_CONFIG_FORMAT = 'ini'


# Path: app/lib/cert.py
from app.lib import conf
from OpenSSL import crypto
from socket import gethostname
from app import __metadata__ as meta
import logging


log = logging.getLogger(__name__)

class Certificate(object):

    def __init__(self):
        self.conf = conf.Config()
        self.key_file = self.conf.get(meta.APP_NAME, 'lxdui.ssl.key')
        self.cert_file = self.conf.get(meta.APP_NAME, 'lxdui.ssl.cert')
        self.key, self.cert = self.create()

    # Create a self signed certificate
    def create(self):
        # create a key pair
        k = crypto.PKey()
        k.generate_key(crypto.TYPE_RSA, 1024)

        # set the certificate configuration parameters
        section = meta.APP_NAME + '_CERT'
        country = self.conf.get(section, 'lxdui.cert.country')
        state = self.conf.get(section, 'lxdui.cert.state')
        locale = self.conf.get(section, 'lxdui.cert.locale')

        org = self.conf.get(section, 'lxdui.cert.org')