From 65503b3e79be91ecd5ed69648e925e14292db933 Mon Sep 17 00:00:00 2001 From: Dolev Farhi Date: Tue, 26 Sep 2023 21:49:14 -0400 Subject: [PATCH] use latest, update docs, remove setup file, change font --- Dockerfile | 5 +---- README.md | 5 ++--- alfred.py | 6 ++++-- core/utils.py | 11 ++++++++++- setup.py | 13 ------------- temp/.keep | 0 templates/index.html | 12 +++++------- version.py | 2 +- 8 files changed, 23 insertions(+), 31 deletions(-) delete mode 100644 setup.py delete mode 100644 temp/.keep diff --git a/Dockerfile b/Dockerfile index f4555da..ae35635 100755 --- a/Dockerfile +++ b/Dockerfile @@ -4,14 +4,13 @@ LABEL description="OPA Alfred" LABEL github="https://github.com/dolevf/Open-Policy-Agent-Alfred" LABEL maintainers="Dolev Farhi" -ARG OPA_BINARY="0.41.0" ARG TARGET_FOLDER=/app WORKDIR $TARGET_FOLDER/ RUN mkdir /app/bin RUN apk add --update curl -RUN curl -L -o bin/opa https://openpolicyagent.org/downloads/v$OPA_BINARY/opa_linux_amd64_static +RUN curl -L -o bin/opa https://openpolicyagent.org/downloads/latest/opa_linux_amd64_static RUN chmod u+x bin/opa COPY requirements.txt /app @@ -22,11 +21,9 @@ COPY static /app/static COPY templates /app/templates COPY temp /app/temp COPY config.py /app -COPY setup.py /app COPY alfred.py /app COPY version.py /app -RUN python3 setup.py RUN chown -R nobody. /app USER nobody diff --git a/README.md b/README.md index def07ff..a029fed 100755 --- a/README.md +++ b/README.md @@ -69,16 +69,15 @@ By default, all builtins are allowed. `pip3 install -r requirements.txt` -`python3 setup.py` ### Download OPA binary For Linux: -`curl -L -o bin/opa https://openpolicyagent.org/downloads/v0.41.0/opa_linux_amd64_static` +`curl -L -o bin/opa https://openpolicyagent.org/downloads/latest/opa_linux_amd64_static` For MacOSX: -`curl -L -o bin/opa https://openpolicyagent.org/downloads/v0.41.0/opa_darwin_amd64` +`curl -L -o bin/opa https://openpolicyagent.org/downloads/latest/opa_darwin_amd64` ### Set permissions `chmod u+x bin/opa` diff --git a/alfred.py b/alfred.py index 092a197..1d9990b 100755 --- a/alfred.py +++ b/alfred.py @@ -96,5 +96,7 @@ def versions(): if not os.path.exists('bin/opa'): print('Error: OPA Binary could not be found in/opa') sys.exit(1) - - app.run(port=5000, host='0.0.0.0', debug=True) + if not os.path.exists(config.SQLITE3_DB_FILE_NAME): + utils.create_db() + + app.run(port=5000, host='0.0.0.0', debug=False) diff --git a/core/utils.py b/core/utils.py index 6a6e742..e853a3d 100755 --- a/core/utils.py +++ b/core/utils.py @@ -2,6 +2,7 @@ import json import tempfile import config +import sqlite3 import uuid tempfile.tempdir = "./temp" @@ -115,4 +116,12 @@ def opa_evaluate(policy, inputs, data=' ', coverage=False): if os.path.exists(temp_file): os.remove(temp_file) - return res \ No newline at end of file + return res + +def create_db(): + connection = sqlite3.connect(config.SQLITE3_DB_FILE_NAME) + cursor = connection.cursor() + cursor.execute('''CREATE TABLE IF NOT EXISTS policies + (id TEXT, policy TEXT, data TEXT, input TEXT)''') + connection.commit() + connection.close() \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index d2374be..0000000 --- a/setup.py +++ /dev/null @@ -1,13 +0,0 @@ -import sqlite3 -import config - -connection = sqlite3.connect(config.SQLITE3_DB_FILE_NAME) - -cursor = connection.cursor() - -cursor.execute('''CREATE TABLE IF NOT EXISTS policies - (id TEXT, policy TEXT, data TEXT, input TEXT)''') - -connection.commit() - -connection.close() \ No newline at end of file diff --git a/temp/.keep b/temp/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/templates/index.html b/templates/index.html index ca7a9f1..1a1f26d 100755 --- a/templates/index.html +++ b/templates/index.html @@ -53,7 +53,9 @@ # Welcome to OPA Alfred! The reasonably usable self-hosted alternative to OPA's Playground -# Enter your policy below :-) +# Found a bug? report at https://github.com/dolevf/Open-Policy-Agent-Alfred/issues + +# Enter your policy below package play @@ -127,7 +129,7 @@ var editor = ace.edit("editor"); editor.session.setMode("ace/mode/golang"); editor.setShowPrintMargin(false); - + var editordata = ace.edit("editordata"); editordata.session.setMode("ace/mode/yaml"); @@ -140,23 +142,19 @@ // Fonts editor.setOptions({ - fontFamily: "Roboto Mono", fontSize: "10pt" }); editorinput.setOptions({ - fontFamily: "Roboto Mono", fontSize: "10pt", wrap: false }); editordata.setOptions({ - fontFamily: "Roboto Mono", fontSize: "10pt" }); editorresult.setOptions({ - fontFamily: "Roboto Mono", fontSize: "10pt" }); @@ -252,7 +250,7 @@ } \ No newline at end of file diff --git a/version.py b/version.py index 9cff1bc..0ad4a58 100755 --- a/version.py +++ b/version.py @@ -1 +1 @@ -VERSION = '1.1.0' +VERSION = '1.1.1'