Skip to content

Commit

Permalink
Merge pull request #5 from AaltoRSE/saml
Browse files Browse the repository at this point in the history
Saml
  • Loading branch information
tpfau authored Mar 12, 2024
2 parents 7dacd5a + e04dff1 commit a4e8ce4
Show file tree
Hide file tree
Showing 73 changed files with 12,045 additions and 522 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
app/frontend/**/*
!app/frontend/dist/**/*
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,14 @@ pyenv
Vagrantfile

# vscode stuff
.vscode/**/*
.vscode/**/*

# SAML certificates and settings (depend on the actual location)
app/saml/saml_data/certs/*
app/saml/saml_data/settings.json

# dev databases
mongodb/**/*
data/**/*

keyfile.key
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ RUN micromamba create -f /opt/environment.yml -p /opt/env/
ENV PATH="/opt/env/bin:$PATH"

# Change work directory
WORKDIR /

# Copy application contents
COPY ./app .
COPY ./entrypoint.sh .
WORKDIR /app

# run the container as a non-root user
ENV USER=aaltorse
RUN groupadd -r $USER && useradd -r -g $USER $USER
USER $USER

# Copy application contents (this includes the frontend files, and only those)
COPY --chown=aaltorse:aaltorse ./app .
COPY ./entrypoint.sh .

# Entrypoint
ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["./entrypoint.sh"]
Empty file added app/admin/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions app/utils/api_requests.py → app/admin/admin_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ class RemoveModelRequest(BaseModel):

class RemoveKeyRequest(BaseModel):
key: str = Field(description="The key to add.")


class LoginRequest(BaseModel):
key: str = Field(description="The key to add.")
56 changes: 56 additions & 0 deletions app/admin/admin_router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from .admin_requests import *
from fastapi import APIRouter, Request, Security, HTTPException, status
from security.api_keys import get_admin_key, key_handler
from utils.handlers import model_handler
import logging

router = APIRouter(
prefix="/admin", tags=["admin"], dependencies=[Security(get_admin_key)]
)

logger = logging.getLogger("admin")


# Admin endpoints
@router.post("/addmodel", status_code=status.HTTP_201_CREATED)
def addModel(
RequestData: AddAvailableModelRequest, admin_key: str = Security(get_admin_key)
):
try:
model_handler.add_model(model=RequestData.model, owner=RequestData.owner, path=RequestData.target_path)
except KeyError as e:
raise HTTPException(status.HTTP_409_CONFLICT)


@router.post("/removemodel", status_code=status.HTTP_200_OK)
def removemodel(
RequestData: RemoveModelRequest, admin_key: str = Security(get_admin_key)
):
try:
model_handler.remove_model(RequestData.model)
except KeyError as e:
raise HTTPException(status.HTTP_410_GONE)


@router.post("/addapikey", status_code=status.HTTP_201_CREATED)
def addKey(RequestData: AddApiKeyRequest, admin_key: str = Security(get_admin_key)):
if key_handler.add_key(
user=RequestData.user, api_key=RequestData.key, name=RequestData.name
):
pass
else:
raise HTTPException(409, "Key already exists")


@router.post("/removeapikey", status_code=status.HTTP_200_OK)
def removeKey(RequestData: AddApiKeyRequest, admin_key: str = Security(get_admin_key)):
if key_handler.delete_key(key=RequestData.key):
pass
else:
raise HTTPException(409, "Key already exists")


@router.get("/listkeys", status_code=status.HTTP_200_OK)
def listKeys(RequestData: Request, admin_key: str = Security(get_admin_key)):
logger.info("Keys requested")
return key_handler.list_keys()
15 changes: 15 additions & 0 deletions app/frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-env node */
require('@rushstack/eslint-patch/modern-module-resolution')

module.exports = {
root: true,
'extends': [
'plugin:vue/vue3-essential',
'eslint:recommended',
'@vue/eslint-config-typescript',
'@vue/eslint-config-prettier/skip-formatting'
],
parserOptions: {
ecmaVersion: 'latest'
}
}
30 changes: 30 additions & 0 deletions app/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
.DS_Store
dist
dist-ssr
coverage
*.local

/cypress/videos/
/cypress/screenshots/

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

*.tsbuildinfo
8 changes: 8 additions & 0 deletions app/frontend/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}
8 changes: 8 additions & 0 deletions app/frontend/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"Vue.volar",
"Vue.vscode-typescript-vue-plugin",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
52 changes: 52 additions & 0 deletions app/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frontend

This template should help get you started developing with Vue 3 in Vite.

## Recommended IDE Setup

[VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur) + [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin).

## Type Support for `.vue` Imports in TS

TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [TypeScript Vue Plugin (Volar)](https://marketplace.visualstudio.com/items?itemName=Vue.vscode-typescript-vue-plugin) to make the TypeScript language service aware of `.vue` types.

If the standalone TypeScript plugin doesn't feel fast enough to you, Volar has also implemented a [Take Over Mode](https://github.com/johnsoncodehk/volar/discussions/471#discussioncomment-1361669) that is more performant. You can enable it by the following steps:

1. Disable the built-in TypeScript Extension
1) Run `Extensions: Show Built-in Extensions` from VSCode's command palette
2) Find `TypeScript and JavaScript Language Features`, right click and select `Disable (Workspace)`
2. Reload the VSCode window by running `Developer: Reload Window` from the command palette.

## Customize configuration

See [Vite Configuration Reference](https://vitejs.dev/config/).

## Project Setup

```sh
npm install
```

### Compile and Hot-Reload for Development

```sh
npm run dev
```

### Type-Check, Compile and Minify for Production

```sh
npm run build
```

### Run Unit Tests with [Vitest](https://vitest.dev/)

```sh
npm run test:unit
```

### Lint with [ESLint](https://eslint.org/)

```sh
npm run lint
```
1 change: 1 addition & 0 deletions app/frontend/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
13 changes: 13 additions & 0 deletions app/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SciComp LLM Self-Service</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
Loading

0 comments on commit a4e8ce4

Please sign in to comment.