示例#1
0
    def put(self,
            pack_uninstall_request,
            pack_ref,
            requester_user,
            show_secrets=False):
        """
            Create a new config for a pack.

            Handles requests:
                POST /configs/<pack_ref>
        """

        try:
            config_api = ConfigAPI(pack=pack_ref,
                                   values=vars(pack_uninstall_request))
            config_api.validate(validate_against_schema=True)
        except jsonschema.ValidationError as e:
            raise ValueValidationException(str(e))

        self._dump_config_to_disk(config_api)

        config_db = ConfigsRegistrar.save_model(config_api)

        mask_secrets = self._get_mask_secrets(requester_user,
                                              show_secrets=show_secrets)
        return ConfigAPI.from_model(config_db, mask_secrets=mask_secrets)
示例#2
0
    def put(self, pack_uninstall_request, pack_ref):
        """
            Create a new config for a pack.

            Handles requests:
                POST /configs/<pack_ref>
        """

        try:
            config_api = ConfigAPI(pack=pack_ref,
                                   values=vars(pack_uninstall_request))
            config_api.validate(validate_against_schema=True)
        except jsonschema.ValidationError as e:
            raise ValueValidationException(str(e))

        config_content = yaml.safe_dump(config_api.values,
                                        default_flow_style=False)

        configs_path = os.path.join(cfg.CONF.system.base_path, 'configs/')
        config_path = os.path.join(configs_path, '%s.yaml' % config_api.pack)
        with open(config_path, 'w') as f:
            f.write(config_content)

        ConfigsRegistrar.save_model(config_api)

        return config_api
示例#3
0
    def _register_config_for_pack(self, pack, config_path):
        content = {}
        values = self._meta_loader.load(config_path)

        content['pack'] = pack
        content['values'] = values

        config_api = ConfigAPI(**content)
        config_api.validate(validate_against_schema=self._validate_configs)
        config_db = ConfigAPI.to_model(config_api)

        try:
            config_db.id = Config.get_by_pack(config_api.pack).id
        except StackStormDBObjectNotFoundError:
            LOG.debug('Config for pack "%s" not found. Creating new entry.', pack)

        try:
            config_db = Config.add_or_update(config_db)
            extra = {'config_db': config_db}
            LOG.audit('Config for pack "%s" is updated.', config_db.pack, extra=extra)
        except Exception:
            LOG.exception('Failed to config for pack %s.', pack)
            raise

        return config_db
示例#4
0
    def _register_config_for_pack(self, pack, config_path):
        content = {}
        values = self._meta_loader.load(config_path)

        content['pack'] = pack
        content['values'] = values

        config_api = ConfigAPI(**content)
        config_api.validate(validate_against_schema=self._validate_configs)
        config_db = ConfigAPI.to_model(config_api)

        try:
            config_db.id = Config.get_by_pack(config_api.pack).id
        except StackStormDBObjectNotFoundError:
            LOG.debug('Config for pack "%s" not found. Creating new entry.', pack)

        try:
            config_db = Config.add_or_update(config_db)
            extra = {'config_db': config_db}
            LOG.audit('Config for pack "%s" is updated.', config_db.pack, extra=extra)
        except Exception:
            LOG.exception('Failed to config for pack %s.', pack)
            raise

        return config_db
示例#5
0
    def _register_config_for_pack(self, pack, config_path):
        content = {}
        values = self._meta_loader.load(config_path)

        content['pack'] = pack
        content['values'] = values

        config_api = ConfigAPI(**content)
        config_api.validate(validate_against_schema=self._validate_configs)
        config_db = self.save_model(config_api)

        return config_db
示例#6
0
    def _register_config_for_pack(self, pack, config_path):
        content = {}
        values = self._meta_loader.load(config_path)

        content['pack'] = pack
        content['values'] = values

        config_api = ConfigAPI(**content)
        config_api.validate(validate_against_schema=self._validate_configs)
        config_db = self.save_model(config_api)

        return config_db
示例#7
0
    def put(self, pack_uninstall_request, pack_ref, requester_user, show_secrets=False):
        """
            Create a new config for a pack.

            Handles requests:
                POST /configs/<pack_ref>
        """

        try:
            config_api = ConfigAPI(pack=pack_ref, values=vars(pack_uninstall_request))
            config_api.validate(validate_against_schema=True)
        except jsonschema.ValidationError as e:
            raise ValueValidationException(str(e))

        self._dump_config_to_disk(config_api)

        config_db = ConfigsRegistrar.save_model(config_api)

        mask_secrets = self._get_mask_secrets(requester_user, show_secrets=show_secrets)
        return ConfigAPI.from_model(config_db, mask_secrets=mask_secrets)
示例#8
0
    def put(self, pack_uninstall_request, pack_ref):
        """
            Create a new config for the action.

            Handles requests:
                POST /configs/<pack_ref>
        """

        try:
            config_api = ConfigAPI(pack=pack_ref, values=vars(pack_uninstall_request))
            config_api.validate(validate_against_schema=True)
        except jsonschema.ValidationError as e:
            raise ValueValidationException(str(e))

        config_content = yaml.safe_dump(config_api.values, default_flow_style=False)

        configs_path = os.path.join(cfg.CONF.system.base_path, 'configs/')
        config_path = os.path.join(configs_path, '%s.yaml' % config_api.pack)
        with open(config_path, 'w') as f:
            f.write(config_content)

        ConfigsRegistrar.save_model(config_api)

        return config_api
示例#9
0
    def save_model(config_api):
        pack = config_api.pack
        config_db = ConfigAPI.to_model(config_api)

        try:
            config_db.id = Config.get_by_pack(pack).id
        except StackStormDBObjectNotFoundError:
            LOG.debug('Config for pack "%s" not found. Creating new entry.', pack)

        try:
            config_db = Config.add_or_update(config_db)
            extra = {'config_db': config_db}
            LOG.audit('Config for pack "%s" is updated.', config_db.pack, extra=extra)
        except Exception:
            LOG.exception('Failed to save config for pack %s.', pack)
            raise

        return config_db
示例#10
0
    def save_model(config_api):
        pack = config_api.pack
        config_db = ConfigAPI.to_model(config_api)

        try:
            config_db.id = Config.get_by_pack(pack).id
        except StackStormDBObjectNotFoundError:
            LOG.debug('Config for pack "%s" not found. Creating new entry.', pack)

        try:
            config_db = Config.add_or_update(config_db)
            extra = {'config_db': config_db}
            LOG.audit('Config for pack "%s" is updated.', config_db.pack, extra=extra)
        except Exception:
            LOG.exception('Failed to save config for pack %s.', pack)
            raise

        return config_db