add gitignore mongo_data_dir

add requirements pillow
create dockerfile and docker compose
fix privkey file path
add flask admin for developments.
autogenerate_flutter
Mustafa Yontar 4 years ago
parent 923df90014
commit e886e4e95c
  1. 1
      .gitignore
  2. 17
      Dockerfile
  3. 29
      docker-compose.yaml
  4. 6
      internal_lib/EncryptedField.py
  5. 30
      main.py
  6. 3
      models/EmbededDocuments.py
  7. 3
      models/Union.py
  8. 0
      mongo_data_dir/.gitkeep
  9. 2
      requirements.txt

1
.gitignore vendored

@ -23,3 +23,4 @@ var/
*.pem *.pem
*test.py *test.py
trash trash
mongo_data_dir/*

@ -0,0 +1,17 @@
FROM python:3.9.1-buster
WORKDIR /code
ENV FLASK_APP=main.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apt install gcc
RUN apt-get update && apt-get install -y \
python-dev python-pip python-setuptools \
libffi-dev libxml2-dev libxslt1-dev \
libtiff-dev libjpeg-dev zlib1g-dev \
liblcms2-dev libwebp-dev python-tk
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD ["flask", "run"]

@ -0,0 +1,29 @@
version: "3.3"
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: xcoder
MONGO_INITDB_ROOT_PASSWORD: 4dun4710
volumes:
- ./mongo_data_dir/:/data/db/
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: xcoder
ME_CONFIG_MONGODB_ADMINPASSWORD: 4dun4710
ME_CONFIG_OPTIONS_EDITORTHEME: ambiance
ME_CONFIG_BASICAUTH_USERNAME: xcoder
ME_CONFIG_BASICAUTH_PASSWORD: 4dun4710
web:
build: .
ports:
- "5000:5000"
environment:
ADUNATIO_PRIV_KEY: /code/privkey.pem
volumes:
- .:/code

@ -1,6 +1,5 @@
import re import re
from flask import current_app
from mongoengine.base import BaseField from mongoengine.base import BaseField
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP from Crypto.Cipher import PKCS1_OAEP
@ -11,8 +10,9 @@ class EncryptedStringField(BaseField):
keyPair = None keyPair = None
def __init__(self, **kwargs): def __init__(self, **kwargs):
import os
self.keyPair = RSA.importKey(open(current_app.config.get('priv_key_path')).read()) priv_key = os.environ.get('ADUNATIO_PRIV_KEY')
self.keyPair = RSA.importKey(open(priv_key).read())
super().__init__(**kwargs) super().__init__(**kwargs)

@ -1,16 +1,24 @@
# This is a sample Python script. from flask import Flask
from flask_admin.contrib.mongoengine import ModelView
from mongoengine import connect
# Press Shift+F10 to execute it or replace it with your code. from models.Union import Union
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. from models.User import User
from restapi import MongoApi
from flask_admin import Admin
"""
Mongodb connection string
"""
connect('adunatio', host='mongo',username="xcoder",password="4dun4710", authentication_source='admin')
def print_hi(name): app = Flask(__name__)
# Use a breakpoint in the code line below to debug your script. app.secret_key = "secret_key+secret_key"
print(f'Hi, {name}') # Press Ctrl+8 to toggle the breakpoint. api = MongoApi(app)
api.register_model(User,uri="/api/user")
adm = Admin(app)
adm.add_view(ModelView(User))
adm.add_view(ModelView(Union))
# Press the green button in the gutter to run the script.
if __name__ == '__main__': if __name__ == '__main__':
print_hi('PyCharm') app.run(host="0.0.0.0",port=5000,debug=True)
# See PyCharm help at https://www.jetbrains.com/help/pycharm/

@ -2,7 +2,6 @@ from mongoengine import *
class Descriptions(EmbeddedDocument): class Descriptions(EmbeddedDocument):
from models.User import User
text = StringField() text = StringField()
user = ReferenceField(User) user = ReferenceField("User")
date = DateTimeField() date = DateTimeField()

@ -19,13 +19,14 @@ class Union(Document):
group = Group() group = Group()
group.union = self group.union = self
group.name = 'Root' group.name = 'Root'
group.rights = ["*::*::{}}/*".format(self.id)] group.rights = ["*::*::{}/*".format(self.id)]
group.save() group.save()
user = User() user = User()
user.username = "{}@root".format(self.legal_registration_number) user.username = "{}@root".format(self.legal_registration_number)
user.user_group = group user.user_group = group
user.union = self user.union = self
password = ''.join(choices(ascii_letters+digits, k=10)) password = ''.join(choices(ascii_letters+digits, k=10))
print("New union password : {}".format(password))
user.password = generate_password_hash(password) user.password = generate_password_hash(password)
# TODO: send password via mail or sms or nothing # TODO: send password via mail or sms or nothing
user.save() user.save()

@ -5,3 +5,5 @@ pycryptodome
flask_jwt_extended flask_jwt_extended
flask_views flask_views
flask_login flask_login
pillow
flask-admin
Loading…
Cancel
Save