Skip to content

Commit

Permalink
implement certificates
Browse files Browse the repository at this point in the history
  • Loading branch information
samj committed Sep 13, 2024
1 parent a64cb4f commit 72ef184
Show file tree
Hide file tree
Showing 24 changed files with 287 additions and 64 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ python .\paios\scripts\setup_environment.py (only on first run)
python -m paios
```

Visit [http://localhost:3080/](http://localhost:3080/)
Visit [https://localhost:8443/](https://localhost:8443/)

### Developers

Expand All @@ -65,5 +65,5 @@ Run the uvicorn server:
python -m paios
```

Visit [http://localhost:3080/](http://localhost:3080/)
Visit [https://localhost:8443/](https://localhost:8443/)

26 changes: 24 additions & 2 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
base_dir = Path(__file__).parent
if base_dir not in sys.path:
sys.path.append(str(base_dir))
from common.paths import backend_dir, venv_dir
from common.paths import backend_dir, venv_dir, cert_dir
from common.config import logging_config

# check environment
Expand All @@ -31,6 +31,10 @@ def cleanup():
#signal.signal(signal.SIGINT, handle_keyboard_interrupt)
#signal.signal(signal.SIGTERM, handle_keyboard_interrupt)

# Ensure certificates are generated
from common.cert import check_cert
check_cert()

# Create the app
logger.info("Creating the app.")
from app import create_app
Expand All @@ -39,9 +43,27 @@ def cleanup():
# Run the app
import uvicorn

cert_path = cert_dir / "cert.pem"
key_path = cert_dir / "key.pem"

logger.info("Running the app with uvicorn.")
try:
uvicorn.run("app:create_app", host="localhost", port=3080, factory=True, workers=1, reload=True, reload_dirs=[backend_dir], reload_excludes=[venv_dir], log_config=logging_config)
uvicorn.run(
"app:create_app",
host="localhost",
port=8443,
factory=True,
workers=1,
reload=True,
reload_dirs=[backend_dir],
reload_excludes=[venv_dir],
log_config=logging_config,
ssl_certfile=str(cert_path),
ssl_keyfile=str(key_path),
#ssl_keyfile_password=key_passphrase # Pass the passphrase if the key is encrypted
)
except PermissionError as e:
logger.error(f"Permission error: {e}. Ensure the application has access to the certificate and key files.")
except KeyboardInterrupt:
#handle_keyboard_interrupt(None, None)
pass
Expand Down
4 changes: 2 additions & 2 deletions apis/paios/abilities.http
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# API testing with Visual Studio Code - REST Client Extention

POST http://localhost:3080/api/v1/abilities/chroma/start
POST https://localhost:8443/api/v1/abilities/chroma/start
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

###

POST http://localhost:3080/api/v1/abilities/chroma/stop
POST https://localhost:8443/api/v1/abilities/chroma/stop
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json
8 changes: 4 additions & 4 deletions apis/paios/asset.http
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# API testing with Visual Studio Code - REST Client Extention

POST http://localhost:3080/api/v1/assets
POST https://localhost:8443/api/v1/assets
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

Expand All @@ -13,7 +13,7 @@ Content-Type: application/json

###

PUT http://localhost:3080/api/v1/assets/1cbb0bc5-bae2-4b9d-9555-f2282f767047
PUT https://localhost:8443/api/v1/assets/1cbb0bc5-bae2-4b9d-9555-f2282f767047
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

Expand All @@ -26,12 +26,12 @@ Content-Type: application/json

###

GET http://localhost:3080/api/v1/assets/1cbb0bc5-bae2-4b9d-9555-f2282f767047
GET https://localhost:8443/api/v1/assets/1cbb0bc5-bae2-4b9d-9555-f2282f767047
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

###

DELETE http://localhost:3080/api/v1/assets/1cbb0bc5-bae2-4b9d-9555-f2282f767047
DELETE https://localhost:8443/api/v1/assets/1cbb0bc5-bae2-4b9d-9555-f2282f767047
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json
4 changes: 2 additions & 2 deletions apis/paios/config.http
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# API testing with Visual Studio Code - REST Client Extention

PUT http://localhost:3080/api/v1/config/openapi-key
PUT https://localhost:8443/api/v1/config/openapi-key
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

"abc123"

###

GET http://localhost:3080/api/v1/config/openapi-key
GET https://localhost:8443/api/v1/config/openapi-key
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json
24 changes: 12 additions & 12 deletions apis/paios/downloads.http
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Test single large download

POST http://localhost:3080/api/v1/downloads
POST https://localhost:8443/api/v1/downloads
Content-Type: application/json

[
Expand All @@ -12,7 +12,7 @@ Content-Type: application/json

### Test single small download

POST http://localhost:3080/api/v1/downloads
POST https://localhost:8443/api/v1/downloads
Content-Type: application/json

[
Expand All @@ -24,7 +24,7 @@ Content-Type: application/json

### Test download with target directory specified

POST http://localhost:3080/api/v1/downloads
POST https://localhost:8443/api/v1/downloads
Content-Type: application/json

[
Expand All @@ -37,7 +37,7 @@ Content-Type: application/json

### Test download without filename specified

POST http://localhost:3080/api/v1/downloads
POST https://localhost:8443/api/v1/downloads
Content-Type: application/json

[
Expand All @@ -48,7 +48,7 @@ Content-Type: application/json

### Test multiple downloads

POST http://localhost:3080/api/v1/downloads
POST https://localhost:8443/api/v1/downloads
Content-Type: application/json

[
Expand All @@ -58,7 +58,7 @@ Content-Type: application/json

###

POST http://localhost:3080/api/v1/downloads
POST https://localhost:8443/api/v1/downloads
Content-Type: application/json

[
Expand All @@ -70,7 +70,7 @@ Content-Type: application/json

###

POST http://localhost:3080/api/v1/downloads
POST https://localhost:8443/api/v1/downloads
Content-Type: application/json

[
Expand All @@ -83,7 +83,7 @@ Content-Type: application/json

### Path traversal attack

POST http://localhost:3080/api/v1/downloads
POST https://localhost:8443/api/v1/downloads
Content-Type: application/json

[
Expand All @@ -95,20 +95,20 @@ Content-Type: application/json

###

POST http://localhost:3080/api/v1/downloads/ac56536c-96a1-4dda-a664-d2262cbf5c7e/pause
POST https://localhost:8443/api/v1/downloads/ac56536c-96a1-4dda-a664-d2262cbf5c7e/pause
Content-Type: application/json

###

POST http://localhost:3080/api/v1/downloads/ac56536c-96a1-4dda-a664-d2262cbf5c7e/resume
POST https://localhost:8443/api/v1/downloads/ac56536c-96a1-4dda-a664-d2262cbf5c7e/resume
Content-Type: application/json

###

GET http://localhost:3080/api/v1/downloads/4fd98231-02ab-4321-ac57-d9dc96fa6d01
GET https://localhost:8443/api/v1/downloads/4fd98231-02ab-4321-ac57-d9dc96fa6d01
Content-Type: application/json

###

DELETE http://localhost:3080/api/v1/downloads/83bdac3a-e5de-4783-a9b9-dabdcae2a1d2
DELETE https://localhost:8443/api/v1/downloads/83bdac3a-e5de-4783-a9b9-dabdcae2a1d2
Content-Type: application/json
2 changes: 1 addition & 1 deletion apis/paios/options.http
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
OPTIONS http://localhost:3080/api/v1/users
OPTIONS https://localhost:8443/api/v1/users
Origin: http://localhost
Access-Control-Request-Method: GET
8 changes: 4 additions & 4 deletions apis/paios/personas.http
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# API testing with Visual Studio Code - REST Client Extention

POST http://localhost:3080/api/v1/personas
POST https://localhost:8443/api/v1/personas
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

Expand All @@ -13,7 +13,7 @@ Content-Type: application/json

###

PUT http://localhost:3080/api/v1/personas/1cbb0bc5-bae2-4b9d-9555-f2282f767047
PUT https://localhost:8443/api/v1/personas/1cbb0bc5-bae2-4b9d-9555-f2282f767047
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

Expand All @@ -26,12 +26,12 @@ Content-Type: application/json

###

GET http://localhost:3080/api/v1/personas/1cbb0bc5-bae2-4b9d-9555-f2282f767047
GET https://localhost:8443/api/v1/personas/1cbb0bc5-bae2-4b9d-9555-f2282f767047
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

###

DELETE http://localhost:3080/api/v1/personas/1cbb0bc5-bae2-4b9d-9555-f2282f767047
DELETE https://localhost:8443/api/v1/personas/1cbb0bc5-bae2-4b9d-9555-f2282f767047
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json
16 changes: 8 additions & 8 deletions apis/paios/resource.http
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# API testing with Visual Studio Code - REST Client Extention

POST http://localhost:3080/api/v1/resources
POST https://localhost:8443/api/v1/resources
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

{
"name": "My Resource",
"uri": "http://localhost:3080/resources/my-resource"
"uri": "https://localhost:8443/resources/my-resource"
}

###
PUT http://localhost:3080/api/v1/resources/llm-api
PUT https://localhost:8443/api/v1/resources/llm-api
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

{
"id": "llm-api",
"name": "LLM API",
"uri": "http://localhost:3080/resources/llm-api"
"uri": "https://localhost:8443/resources/llm-api"
}

###
PUT http://localhost:3080/api/v1/resources/imap-sync
PUT https://localhost:8443/api/v1/resources/imap-sync
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

Expand All @@ -33,18 +33,18 @@ Content-Type: application/json

###

DELETE http://localhost:3080/api/v1/resources/llm-api
DELETE https://localhost:8443/api/v1/resources/llm-api
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

###

GET http://localhost:3080/api/v1/resources/llm-api
GET https://localhost:8443/api/v1/resources/llm-api
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

###

GET http://localhost:3080/api/v1/resources
GET https://localhost:8443/api/v1/resources
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json
16 changes: 8 additions & 8 deletions apis/paios/users.http
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# API testing with Visual Studio Code - REST Client Extention

POST http://localhost:3080/api/v1/users
POST https://localhost:8443/api/v1/users
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

Expand All @@ -10,7 +10,7 @@ Content-Type: application/json
}

###
PUT http://localhost:3080/api/v1/users/5bae4a90-ce69-4483-86ef-d723258f21e5
PUT https://localhost:8443/api/v1/users/5bae4a90-ce69-4483-86ef-d723258f21e5
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

Expand All @@ -21,7 +21,7 @@ Content-Type: application/json
}

###
PUT http://localhost:3080/api/v1/users/1cbb0bc5-bae2-4b9d-9555-f2282f767047
PUT https://localhost:8443/api/v1/users/1cbb0bc5-bae2-4b9d-9555-f2282f767047
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

Expand All @@ -33,30 +33,30 @@ Content-Type: application/json

###

DELETE http://localhost:3080/api/v1/users/5bae4a90-ce69-4483-86ef-d723258f21e5
DELETE https://localhost:8443/api/v1/users/5bae4a90-ce69-4483-86ef-d723258f21e5
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

###

DELETE http://localhost:3080/api/v1/users/1cbb0bc5-bae2-4b9d-9555-f2282f767047
DELETE https://localhost:8443/api/v1/users/1cbb0bc5-bae2-4b9d-9555-f2282f767047
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

###

GET http://localhost:3080/api/v1/users/5bae4a90-ce69-4483-86ef-d723258f21e5
GET https://localhost:8443/api/v1/users/5bae4a90-ce69-4483-86ef-d723258f21e5
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

###

GET http://localhost:3080/api/v1/users/1cbb0bc5-bae2-4b9d-9555-f2282f767047
GET https://localhost:8443/api/v1/users/1cbb0bc5-bae2-4b9d-9555-f2282f767047
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json

###

GET http://localhost:3080/api/v1/users
GET https://localhost:8443/api/v1/users
Authorization: Bearer {{PAIOS_BEARER_TOKEN}}
Content-Type: application/json
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def add_frontend_app(app):
app.add_url_rule(
'/{path:path}',
endpoint='frontend',
view_func=StaticFiles(directory=static_dir, html=True)
view_func=StaticFiles(directory=static_dir, check_dir=False, html=True)
)
else:
logger.info(f"Skipping serving frontend: {static_dir} directory not found. Options:")
Expand Down
1 change: 0 additions & 1 deletion backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
for directory in required_directories:
if not os.path.exists(directory):
os.makedirs(directory)

Loading

0 comments on commit 72ef184

Please sign in to comment.