Skip to content

Commit

Permalink
use latest, update docs, remove setup file, change font
Browse files Browse the repository at this point in the history
  • Loading branch information
Dolev Farhi committed Sep 27, 2023
1 parent 939ff38 commit 65503b3
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 31 deletions.
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 4 additions & 2 deletions alfred.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 10 additions & 1 deletion core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import tempfile
import config
import sqlite3
import uuid

tempfile.tempdir = "./temp"
Expand Down Expand Up @@ -115,4 +116,12 @@ def opa_evaluate(policy, inputs, data=' ', coverage=False):
if os.path.exists(temp_file):
os.remove(temp_file)

return res
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()
13 changes: 0 additions & 13 deletions setup.py

This file was deleted.

Empty file removed temp/.keep
Empty file.
12 changes: 5 additions & 7 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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");

Expand All @@ -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"
});

Expand Down Expand Up @@ -252,7 +250,7 @@
}
</script>
<footer class="page-footer font-small bg-dark">
<div class="footer-copyright text-center py-3" style="color: white;">&hearts; Built by <a href="mailto:[email protected]">Dolev Farhi</a></div>
<div class="footer-copyright text-center py-3" style="color: white;">Built by <a href="mailto:[email protected]">Dolev Farhi</a></div>
</footer>
</body>
</html>
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '1.1.0'
VERSION = '1.1.1'

0 comments on commit 65503b3

Please sign in to comment.