diff --git a/Dockerfile b/Dockerfile index a5ca7ff6..8ba078d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ -# build go-jsonnet and jsonnet-bundler using a go environment +# build jsonnet-bundler using a go environment FROM docker.io/library/golang:1.18 AS builder-go -RUN go install -a github.com/google/go-jsonnet/cmd/jsonnet@v0.20.0 RUN go install -a github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@v0.5.1 # build otterdog using a python environment @@ -42,7 +41,6 @@ ENV BW_RELEASE=${BW_RELEASE} RUN cd /tmp/ && curl -k -L -O https://github.com/bitwarden/clients/releases/download/${BW_RELEASE}/${BW_VERSION} \ && unzip /tmp/${BW_VERSION} -d /usr/bin/ && rm -rf /tmp/${BW_VERSION} -COPY --from=builder-go /go/bin/jsonnet /usr/bin/jsonnet COPY --from=builder-go /go/bin/jb /usr/bin/jb COPY --from=builder-python3 /app/.venv /app/.venv COPY --from=builder-python3 /app/otterdog /app/otterdog diff --git a/README.md b/README.md index c8ec45d9..3d547f1d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ ### System requirements: * python3.10 (mandatory): install using `apt install python3` -* jsonnet (mandatory): install using `go install -a github.com/google/go-jsonnet/cmd/jsonnet@v0.20.0` * jsonnet-bundler (mandatory): install using `go install -a github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@v0.5.1` * bitwarden cli tool (optional): install using `snap install bw` * pass cli tool (optional): install using `apt install pass` diff --git a/otterdog/providers/github/web.py b/otterdog/providers/github/web.py index 301cad89..82425d9b 100644 --- a/otterdog/providers/github/web.py +++ b/otterdog/providers/github/web.py @@ -6,6 +6,9 @@ # SPDX-License-Identifier: MIT # ******************************************************************************* +from functools import cached_property +from typing import Any + from importlib_resources import files from playwright.sync_api import sync_playwright, Page, Error @@ -21,12 +24,14 @@ class WebClient: def __init__(self, credentials: Credentials): self.credentials = credentials + @cached_property + def web_settings_definition(self) -> dict[str, Any]: # load the definition file which describes how the web settings # can be retrieved / modified. utils.print_trace(f"getting web_settings config using jsonnet") web_settings_config = files(resources).joinpath("github-web-settings.jsonnet") - self.web_settings_definition = utils.jsonnet_evaluate_file(str(web_settings_config)) + return utils.jsonnet_evaluate_file(str(web_settings_config)) def get_org_settings(self, org_id: str, included_keys: set[str]) -> dict[str, str]: utils.print_debug("retrieving settings via web interface") diff --git a/otterdog/utils.py b/otterdog/utils.py index eee8b540..c402e044 100644 --- a/otterdog/utils.py +++ b/otterdog/utils.py @@ -6,7 +6,6 @@ # SPDX-License-Identifier: MIT # ******************************************************************************* -import subprocess import json from typing import Any, Callable @@ -154,22 +153,22 @@ def level_down(self) -> None: def jsonnet_evaluate_file(file: str) -> dict[str, Any]: - print_trace(f"evaluating jsonnet file {file}") - status, result = subprocess.getstatusoutput(f"jsonnet {file}") - print_trace(f"result = ({status}, {result})") + import _gojsonnet - if status != 0: - raise RuntimeError(f"failed to evaluate jsonnet file {file}: {result}") + print_trace(f"evaluating jsonnet file {file}") - return json.loads(result) + try: + return json.loads(_gojsonnet.evaluate_file(file)) + except Exception as ex: + raise RuntimeError(f"failed to evaluate jsonnet file: {str(ex)}") def jsonnet_evaluate_snippet(snippet: str) -> dict[str, Any]: - print_trace(f"evaluating jsonnet snippet {snippet}") - status, result = subprocess.getstatusoutput(f'jsonnet -e "{snippet}"') - print_trace(f"result = ({status}, {result})") + import _gojsonnet - if status != 0: - raise RuntimeError(f"failed to evaluate jsonnet snippet {snippet}: {result}") + print_trace(f"evaluating jsonnet snippet {snippet}") - return json.loads(result) + try: + return json.loads(_gojsonnet.evaluate_snippet("", snippet)) + except Exception as ex: + raise RuntimeError(f"failed to evaluate snippet: {str(ex)}") diff --git a/poetry.lock b/poetry.lock index 6dd43b60..27ee3894 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2,22 +2,22 @@ [[package]] name = "attrs" -version = "22.2.0" +version = "23.1.0" description = "Classes Without Boilerplate" category = "main" optional = false -python-versions = ">=3.6" +python-versions = ">=3.7" files = [ - {file = "attrs-22.2.0-py3-none-any.whl", hash = "sha256:29e95c7f6778868dbd49170f98f8818f78f3dc5e0e37c0b1f474e3561b240836"}, - {file = "attrs-22.2.0.tar.gz", hash = "sha256:c9227bfc2f01993c03f68db37d1d15c9690188323c067c641f1a35ca58185f99"}, + {file = "attrs-23.1.0-py3-none-any.whl", hash = "sha256:1f28b4522cdc2fb4256ac1a020c78acf9cba2c6b461ccd2c126f3aa8e8335d04"}, + {file = "attrs-23.1.0.tar.gz", hash = "sha256:6279836d581513a26f1bf235f9acd333bc9115683f14f7e8fae46c98fc50e015"}, ] [package.extras] -cov = ["attrs[tests]", "coverage-enable-subprocess", "coverage[toml] (>=5.3)"] -dev = ["attrs[docs,tests]"] -docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier", "zope.interface"] -tests = ["attrs[tests-no-zope]", "zope.interface"] -tests-no-zope = ["cloudpickle", "cloudpickle", "hypothesis", "hypothesis", "mypy (>=0.971,<0.990)", "mypy (>=0.971,<0.990)", "pympler", "pympler", "pytest (>=4.3.0)", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-mypy-plugins", "pytest-xdist[psutil]", "pytest-xdist[psutil]"] +cov = ["attrs[tests]", "coverage[toml] (>=5.3)"] +dev = ["attrs[docs,tests]", "pre-commit"] +docs = ["furo", "myst-parser", "sphinx", "sphinx-notfound-page", "sphinxcontrib-towncrier", "towncrier", "zope-interface"] +tests = ["attrs[tests-no-zope]", "zope-interface"] +tests-no-zope = ["cloudpickle", "hypothesis", "mypy (>=1.1.1)", "pympler", "pytest (>=4.3.0)", "pytest-mypy-plugins", "pytest-xdist[psutil]"] [[package]] name = "cattrs" @@ -159,6 +159,17 @@ files = [ [package.extras] test = ["pytest (>=6)"] +[[package]] +name = "gojsonnet" +version = "0.20.0" +description = "Python bindings for Jsonnet - The data templating language" +category = "main" +optional = false +python-versions = "*" +files = [ + {file = "gojsonnet-0.20.0.tar.gz", hash = "sha256:9aede3b5734dee1c99dbec75dee3b086baaae92bd262d93f9217e21bf19c9682"}, +] + [[package]] name = "greenlet" version = "2.0.1" @@ -500,18 +511,17 @@ files = [ [[package]] name = "pytest" -version = "7.2.2" +version = "7.3.1" description = "pytest: simple powerful testing with Python" category = "main" optional = false python-versions = ">=3.7" files = [ - {file = "pytest-7.2.2-py3-none-any.whl", hash = "sha256:130328f552dcfac0b1cec75c12e3f005619dc5f874f0a06e8ff7263f0ee6225e"}, - {file = "pytest-7.2.2.tar.gz", hash = "sha256:c99ab0c73aceb050f68929bc93af19ab6db0558791c6a0715723abe9d0ade9d4"}, + {file = "pytest-7.3.1-py3-none-any.whl", hash = "sha256:3799fa815351fea3a5e96ac7e503a96fa51cc9942c3753cda7651b93c1cfa362"}, + {file = "pytest-7.3.1.tar.gz", hash = "sha256:434afafd78b1d78ed0addf160ad2b77a30d35d4bdf8af234fe621919d9ed15e3"}, ] [package.dependencies] -attrs = ">=19.2.0" colorama = {version = "*", markers = "sys_platform == \"win32\""} exceptiongroup = {version = ">=1.0.0rc8", markers = "python_version < \"3.11\""} iniconfig = "*" @@ -520,7 +530,7 @@ pluggy = ">=0.12,<2.0" tomli = {version = ">=1.0.0", markers = "python_version < \"3.11\""} [package.extras] -testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"] +testing = ["argcomplete", "attrs (>=19.2.0)", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"] [[package]] name = "requests" @@ -646,4 +656,4 @@ socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "6ff8fec9405168cebd02508cc6a7f29235a8f71ee32029576a0fa9a070667d57" +content-hash = "6b2372020ef5ade6bb20022ff4471caaacc5b6f94c9c2b50e6014b5c05ee74c1" diff --git a/pyproject.toml b/pyproject.toml index f6aa253f..87d79218 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,8 +16,9 @@ requests = "~2.28.2" jsonschema = "~4.17.3" JSONBender = "~0.9.3" importlib_resources = "~5.12.0" -pytest = "~7.2.1" +pytest = "~7.3.1" requests-cache = "~1.0.1" +gojsonnet = "~0.20.0" [tool.poetry.scripts] otterdog = "otterdog.main:main"