Example #1
0
def config():
    logger.debug('Loading configuration')
    from kaptan import Kaptan
    cfg = Kaptan()
    cfg.import_config({
        'authn': {
            'cookie': {
                'secure': False,
                'session_name': 'sid',
                'id_name': 'uid',
                'max_age': 3600
            },
            'oidc': {
                'provider_protocol': 'http',
            }
        },
        'http_server': {
            'endpoints': {
                'login': {
                    'path': '/auth/login'
                },
                'registration': {
                    'path': '/auth/registration'
                }
            }
        },
        'oidc': {
            'iss': 'https://localhost:8889',
        },
    })
    return cfg
Example #2
0
    def format(self, msg, force_pretty=False, tag=None):

        if not self.pretty and not force_pretty:
            return msg
        elif isinstance(msg, (list, tuple)):
            return assert_json(msg, indent=4)
        elif hasattr(msg, 'pretty'):
            msg = getattr(msg, 'pretty')()

        if isinstance(msg, dict):
            clean_dyct = self.cleaner(msg)
            kaptan = Kaptan().import_config(clean_dyct)
            yaml = kaptan.export(handler=LoggerConst.PRETTY_FMT,
                                 explicit_start=True)
            return order_yaml(yaml)

        msg = assert_str(msg, allow_none=True)

        if tag is None:
            return msg
        else:
            return '{ts} - {tag} - {msg}'.format(ts=datetime.now().strftime(
                DateFmt.READABLE),
                                                 tag=tag,
                                                 msg=msg)
Example #3
0
def _load_config(cfg_path):
    """Load config from a given config file.

    Raises `ValidationError` if the config does not define a session name"""
    config = Kaptan()
    config.import_config(str(cfg_path))
    config = tmuxp.config.expand(config.configuration_data)

    if "session_name" not in config:
        raise ValidationError("No session name configured")

    return config
Example #4
0
    def load(self):

        default_conf, user_conf, local_conf = [
            None if not os.path.exists(src) else Kaptan(
                handler=Config.FMT).import_config(src) for src in self.sources
        ]

        assert default_conf is not None,\
            ConfigurationError("Default configuration not found at {}".format(self.sources[0]))

        conf_opts = [local_conf, user_conf,
                     {}]  # if local conf was found, user conf is ignored
        child_conf = filter(
            lambda x: x is not None,
            conf_opts).__next__()  # returns first non empty option

        super().__init__(**join_dicts(default_conf.get(self.namespace, {}),
                                      child_conf.get(self.namespace, {}),
                                      allow_overwrite=True))

        return self
Example #5
0
 def __init__(self, handler=None):
     self.__dict__ = self.__shared_state
     self._cpt = Kaptan(handler)
Example #6
0
def _load_config(file_path):
    cpt = Kaptan()
    return cpt.import_config(file_path)
Example #7
0
 def __init__(self):
     import os
     script_path = os.path.dirname(os.path.abspath(__file__))
     self.path_to_config = script_path + "/config.json"
     self.config = Kaptan(handler="json")
Example #8
0
    def deploy(self,
               img: ImageSpec,
               env_vars,
               mounts,
               cargos,
               ports,
               cmd: list,
               name: str,
               tasks: int = 1,
               allow_probe=False,
               delay_readiness: int = 0):

        [self.load_vol(v, name) for v in cargos]
        vol_refs, vol_defs = self.kube_vols(cargos)
        mount_refs, mount_defs = self.kube_mounts(mounts)
        port_refs, port_defs = self.kube_svc_ports(name, ports)

        container = dict(name=name,
                         image=img.target,
                         imagePullPolicy='Always',
                         command=cmd,
                         resources=self.kube_resources(),
                         volumeMounts=vol_refs + mount_refs,
                         env=self.kube_env_vars(env_vars),
                         ports=port_refs,
                         livenessProbe=self.kube_healthcheck(allow_probe),
                         readinessProbe=self.kube_readiness(delay_readiness))

        template = self.cleaner(
            dict(apiVersion="apps/v1",
                 kind="Deployment",
                 metadata={'name': name},
                 spec=dict(replicas=tasks,
                           selector={'matchLabels': {
                               'app': name
                           }},
                           template=dict(metadata={
                               'labels': {
                                   'app': name
                               },
                               'annotations': {
                                   'updated':
                                   datetime.now().strftime(DateFmt.READABLE)
                               }
                           },
                                         spec={
                                             'containers': [container],
                                             'volumes':
                                             vol_defs + mount_defs,
                                             'imagePullSecrets': [{
                                                 'name':
                                                 self.secret
                                             }]
                                         }))))

        if self.find_depl(name) is None:
            self.LOG.info("Creating deployment '{}'".format(name))
            self.LOG.debug(template)
            yaml = Kaptan().import_config(template).export(handler='yaml')
            depl = Deployment(namespace=self.namespace,
                              create_in_cluster=True,
                              from_template=yaml)
        else:
            self.LOG.info("Updating deployment '{}'".format(name))
            self.LOG.debug(template)
            with K8sBackend(logging_level=logging.ERROR) as k8s_backend:
                k8s_backend.apps_api.replace_namespaced_deployment(
                    name, self.namespace, template)
            depl = self.find_depl(name)

        self.handle_svc(name, port_defs)
        self.handle_autoscaler(name)

        return depl
Example #9
0
    def dump(self):

        return Kaptan().import_config(
            self.as_dict()).export(handler=Config.FMT)