コード例 #1
0
ファイル: render_jsonnet.py プロジェクト: steved/appr
def yaml_to_jsonnet(manifestyaml, tla_codes=None):
    jinja_env = jinja2.Environment()
    jinja_env.filters.update(filters.jinja_filters())
    # 1. Resolve old manifest variables
    # Load 'old' manifest.yaml
    tempvars = {
        "manifest":
        convert_utf8(json.loads(json.dumps(yaml.load(manifestyaml))))
    }
    # Get variable from the 'old' manfiest and update  them
    variables = tempvars['manifest'].get("variables", {})
    if tla_codes is not None and 'params' in tla_codes:
        tla = json.loads(tla_codes['params']).get("variables", {})
        variables.update(tla)
    # Resolve the templated variables inside the 'old' manifest
    manifest_tpl = jinja_env.from_string(manifestyaml)

    # 2. Convert 'old' manifest.yaml to manifest.jsonnet
    rendered_manifestyaml = manifest_tpl.render(variables)
    v = {
        "manifest":
        convert_utf8(json.loads(json.dumps(yaml.load(rendered_manifestyaml))))
    }
    # Load the yaml -> jsonnet template
    template = jinja_env.from_string(JSONNET_TEMPLATE)
    templatedjsonnet = template.render(v)
    # @TODO keep yaml format and escape 'jsonnet' commands:  key: "<% $.variables.key %>"
    # jsonnet_str = re.sub(r'[\'"]<%(.*)%>["\']', r"\1", templatedjsonnet)
    return templatedjsonnet
コード例 #2
0
def jsonnet(val, env=None):
    from appr.render_jsonnet import RenderJsonnet
    from appr.utils import convert_utf8
    r = RenderJsonnet()
    if env is not None:
        variables = convert_utf8(json.loads(env))
    return r.render_jsonnet(val, tla_codes=variables)
コード例 #3
0
def jinja_template(val, env=None):
    from appr.utils import convert_utf8
    jinjaenv = jinja_env()
    template = jinjaenv.from_string(val)
    if env is not None:
        variables = convert_utf8(json.loads(env))
    return template.render(variables)
コード例 #4
0
ファイル: kub_base.py プロジェクト: steved/appr
 def prepare_resources(self, dest="/tmp", index=0):
     for resource in self.resources():
         index += 1
         path = os.path.join(dest, "%02d_%s_%s" % (index, self.version, resource['file']))
         f = open(path, 'w')
         f.write(yaml.safe_dump(convert_utf8(resource['value'])))
         resource['filepath'] = f.name
         f.close()
     return index
コード例 #5
0
ファイル: test_plugins.py プロジェクト: steved/appr
def test_install_helm_plugin(helm_home, plugin_home, path, capsys, cli_parser,
                             fake_home, monkeypatch, plugin_helm_tarball,
                             plugin_helm_releases):
    homepath = os.getenv('HOME')
    registry_plugin = os.path.join(homepath, path, "registry")
    if helm_home:
        monkeypatch.setenv("HELM_HOME", os.path.join(homepath, helm_home))

    if plugin_home:
        monkeypatch.setenv("HELM_PLUGIN_DIR",
                           os.path.join(homepath, plugin_home))

    with requests_mock.mock() as m:
        tarname = "helm-registry_%s.tar.gz" % platform.system().lower()
        m.get(
            "https://api.github.com/repos/app-registry/appr-helm-plugin/tags",
            text=plugin_helm_releases)
        m.get(
            "https://github.com/app-registry/appr-helm-plugin/releases/download/v0.5.1/%s"
            % tarname,
            content=plugin_helm_tarball)
        args = parse_args(cli_parser, ["--output", "json", "install", "helm"])
        args.func(args)
        out, err = capsys.readouterr()

        homepath = os.getenv('HOME')
        for fname in ['plugin.yaml', 'appr', 'cnr.sh']:
            assert os.path.exists(
                os.path.join(homepath, registry_plugin, fname))
        output = json.loads(out)
        output.pop('symlink')
        assert convert_utf8(output) == {
            'path':
            os.path.join(homepath, registry_plugin),
            'plugin-version':
            'v0.5.1',
            'platform':
            platform.system().lower(),
            'source':
            'https://github.com/app-registry/appr-helm-plugin/releases/download/v0.5.1/%s'
            % tarname,
            'status':
            'installed'
        }