init: server workds with tls, needs database models
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
commit
2c17903012
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
server.crt
|
||||||
|
server.csr
|
||||||
|
server.key
|
||||||
|
server.orig.key
|
||||||
|
__pycache__
|
||||||
|
venv/
|
25
echo_server.py
Executable file
25
echo_server.py
Executable file
@ -0,0 +1,25 @@
|
|||||||
|
#/bin/python
|
||||||
|
|
||||||
|
import uvicorn
|
||||||
|
from typing import Optional
|
||||||
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
class EchoType(BaseModel):
|
||||||
|
val: str
|
||||||
|
|
||||||
|
@app.post("/echo")
|
||||||
|
def get_echo(echo: EchoType):
|
||||||
|
return echo
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
#uvicorn server:app --port 8000 --ssl-certfile server.crt --ssl-keyfile server.key
|
||||||
|
uvicorn.run(
|
||||||
|
'echo_server:app', port=8000, host='localhost',
|
||||||
|
reload=False,
|
||||||
|
ssl_keyfile='server.key',
|
||||||
|
ssl_certfile='server.crt')
|
10
genssl.sh
Normal file
10
genssl.sh
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#/bin/env bash
|
||||||
|
|
||||||
|
openssl genrsa -des3 -out server.orig.key 2048
|
||||||
|
|
||||||
|
openssl rsa -in server.orig.key -out server.key
|
||||||
|
|
||||||
|
openssl req -new -key server.key -out server.csr
|
||||||
|
|
||||||
|
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
|
||||||
|
|
26
mkdb.sh
Executable file
26
mkdb.sh
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Make a new database
|
||||||
|
# Mar 3, 2022 - H.B.
|
||||||
|
|
||||||
|
if [ -z ${1} ]
|
||||||
|
then
|
||||||
|
echo "Enter a databse name to use this"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
sqlite3 ${1} << EOF
|
||||||
|
CREATE TABLE user_accounts(
|
||||||
|
id INTEGER(512) PRIMARY KEY NOT NULL,
|
||||||
|
username TEXT(64) NOT NULL,
|
||||||
|
date_created datetime ,
|
||||||
|
digest TEXT NOT NULL,
|
||||||
|
salt TEXT
|
||||||
|
);
|
||||||
|
CREATE TABLE iot_entity(
|
||||||
|
id INTEGER(512) PRIMARY KEY NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
last_connection datetime,
|
||||||
|
);
|
||||||
|
EOF
|
||||||
|
|
4
run-tls
Executable file
4
run-tls
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
uvicorn server:app --ssl-certfile server.crt --ssl-keyfile server.key --port 4433 --host 0.0.0.0 --no-server-header --reload
|
||||||
|
|
8
schema.sql
Normal file
8
schema.sql
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
CREATE TABLE user_accounts(
|
||||||
|
user_id UNSIGHNED INT PRIMARY KEY NOT NULL,
|
||||||
|
username NCHAR(64) NOT NULL,
|
||||||
|
email NCHAR(64) NOT NULL,
|
||||||
|
date_created DATETIME,
|
||||||
|
digest NCHAR(512) NOT NULL,
|
||||||
|
salt NCHAR(64) NOT NULL
|
||||||
|
);
|
26
server.py
Executable file
26
server.py
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
#/bin/python
|
||||||
|
|
||||||
|
import uvicorn
|
||||||
|
from typing import Optional
|
||||||
|
from fastapi import FastAPI
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
class UserAuthForEntity(BaseModel):
|
||||||
|
username: str
|
||||||
|
passwd: str
|
||||||
|
entitiy: int
|
||||||
|
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
@app.post("/isauth")
|
||||||
|
def is_auth(user_auth_for_entity: UserAuthForEntity):
|
||||||
|
return user_auth_for_entity
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
#uvicorn server:app --port 8000 --ssl-certfile server.crt --ssl-keyfile server.key
|
||||||
|
uvicorn.run(
|
||||||
|
'server:app', port=4433, host='0.0.0.0',
|
||||||
|
reload=False,
|
||||||
|
ssl_keyfile='server.key',
|
||||||
|
ssl_certfile='server.crt')
|
Loading…
Reference in New Issue
Block a user