-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d84363
commit 7c257e2
Showing
7 changed files
with
210 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# | ||
# Python deps image | ||
# | ||
FROM python:3.11 AS image-build | ||
|
||
RUN apt update | ||
RUN apt install -y --no-install-recommends \ | ||
build-essential \ | ||
gcc | ||
RUN python -m venv /opt/venv | ||
ENV PATH="/opt/venv/bin:$PATH" | ||
|
||
# Download the Python dependencies | ||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# | ||
# Production image | ||
# | ||
FROM python:3.11 | ||
|
||
# App settings | ||
ENV DEBUG False | ||
WORKDIR /app | ||
EXPOSE 5000 | ||
ENV COQUI_TOS_AGREED=1 | ||
ENV PYTHONUNBUFFERED=1 | ||
|
||
# Install dependencies from the build image venv | ||
COPY --from=image-build /opt/venv /opt/venv | ||
ENV PATH="/opt/venv/bin:$PATH" | ||
|
||
# Install the app | ||
COPY app.py . | ||
COPY gunicorn_config.py . | ||
|
||
# Run the app | ||
CMD ["gunicorn", "-c", "gunicorn_config.py", "app:app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from flask import Flask, request, send_file | ||
from flask_sqlalchemy import SQLAlchemy | ||
import hashlib | ||
import os | ||
|
||
# Initialize Flask | ||
app = Flask(__name__) | ||
|
||
# Database config | ||
DATABASE_HOST = os.environ.get('DB_HOST') | ||
DATABASE_NAME = os.environ.get('DB_NAME') | ||
DATABASE_USER = os.environ.get('DB_USER') | ||
DATABASE_PASS = os.environ.get('DB_PASS') | ||
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://' + DATABASE_USER + ':' + DATABASE_PASS + '@' + DATABASE_HOST + '/' + DATABASE_NAME | ||
|
||
db = SQLAlchemy(app) | ||
|
||
|
||
# Represents the entries in the database | ||
class Token(db.Model): | ||
__tablename__ = 'token' | ||
id = db.Column(db.Integer, primary_key=True) | ||
token = db.Column(db.String(48), unique=True, nullable=False) | ||
|
||
|
||
@app.route('/api/version') | ||
def generate_step(): | ||
print('Request received') | ||
|
||
# Check if the authorization token is included in the request headers | ||
token = request.headers.get('Authorization') | ||
if not token: | ||
return 'Unauthorized', 401 | ||
print('Request has authentication token') | ||
|
||
# Validate the hashed authorization token against the database | ||
hashed_token = hashlib.sha256(token.encode()).hexdigest() | ||
if not Token.query.filter_by(token=hashed_token).first(): | ||
print('Authentication failed') | ||
return 'Unauthorized', 401 | ||
print('Request authenticated') | ||
|
||
return version | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(debug=os.environ.get('DEBUG', False)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: '3' | ||
|
||
services: | ||
compute-1: | ||
build: ../compute | ||
|
||
compute-2: | ||
build: ../compute | ||
|
||
compute-3: | ||
build: ../compute | ||
|
||
auth: | ||
build: ../auth | ||
|
||
manager: | ||
build: ../manager | ||
depends_on: | ||
- compute-1 | ||
- compute-2 | ||
- compute-3 | ||
- auth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
 | ||
|
||
# Stargazer Framework API reference | ||
|
||
All Stargazer nodes operate using the Stargazer Framework API. This document is the definite authority on the API. | ||
|
||
## Authentication | ||
|
||
All Stargazer nodes require an authentication token to be passed as a HTTP header in its API calls: | ||
|
||
`$ curl -X POST -H 'Authorization: $TOKEN'` | ||
|
||
## Common API calls | ||
|
||
The following API calls can be answered by all Stargazer nodes types : | ||
|
||
**version** | ||
|
||
Returns the current node version. | ||
``` | ||
$ curl \ | ||
-H 'Authorization: $TOKEN \ | ||
-H 'Content-Type: application/json' \ | ||
$ENDPOINT/api/version | ||
``` | ||
|
||
**type** | ||
|
||
Returns the node type. | ||
``` | ||
$ curl \ | ||
-H 'Authorization: $TOKEN \ | ||
-H 'Content-Type: application/json' \ | ||
$ENDPOINT/api/type | ||
``` | ||
|
||
## Authentication gateway specific API calls | ||
|
||
The following API calls can only be answered by Stargazer authentication gateway nodes : | ||
|
||
**token/create** | ||
|
||
Registers a new authentication token. Can only be used by authenticating with an admin token. Requires an expiration date to be specified, as well as a boolean specifying if the token is an admin token or not. | ||
``` | ||
$ curl \ | ||
-H 'Authorization: $TOKEN \ | ||
-H 'Content-Type: application/json' \ | ||
-d {"admin": "true", "expiration": "90d"} | ||
$ENDPOINT/api/token/create | ||
``` | ||
|
||
**token/revoke** | ||
|
||
Revokes an existing authentication token. Can only be used by authenticating with an admin token. Effective immediately. | ||
``` | ||
$ curl \ | ||
-H 'Authorization: $TOKEN \ | ||
-H 'Content-Type: application/json' \ | ||
-d {"token": "$TOKEN_TO_REVOKE"} | ||
$ENDPOINT/api/token/revoke | ||
``` | ||
|
||
**token/authenticate** | ||
|
||
Authenticates a token against the database. | ||
``` | ||
$ curl \ | ||
-H 'Authorization: $TOKEN \ | ||
-H 'Content-Type: application/json' \ | ||
-d {"token": "$TOKEN_TO_REVOKE"} | ||
$ENDPOINT/api/token/authenticate | ||
``` | ||
|
||
## Compute node specific API calls | ||
|
||
The following API calls can only be answered by Stargazer compute nodes : | ||
|
||
**aaaa** | ||
|
||
Returns aaaaaaa. | ||
``` | ||
$ curl \ | ||
-H 'Authorization: $TOKEN \ | ||
-H 'Content-Type: application/json' \ | ||
$ENDPOINT/api/aaaaa | ||
``` | ||
|
||
## Manager node specific API calls | ||
|
||
The following API calls can only be answered by Stargazer manager nodes : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
 | ||
|
||
# Stargazer Framework user manual | ||
|
||
--- | ||
|
||
|
||
|
Empty file.