-
Notifications
You must be signed in to change notification settings - Fork 20
/
config.py
133 lines (124 loc) · 5.25 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
"""configuration module for MPContribs Flask API"""
import os
import datetime
import json
import gzip
from semantic_version import Version
formulae_path = os.path.join(
os.path.dirname(__file__), "contributions", "formulae.json.gz"
)
with gzip.open(formulae_path) as f:
FORMULAE = json.load(f)
now = datetime.datetime.now()
VERSION = Version(
major=now.year, minor=now.month, patch=now.day,
prerelease=(str(now.hour), str(now.minute))
)
JSON_SORT_KEYS = False
JSON_ADD_STATUS = False
SECRET_KEY = "super-secret" # TODO in local prod config
MAIL_DEFAULT_SENDER = os.environ.get("MAIL_DEFAULT_SENDER")
MPCONTRIBS_DB = os.environ.get("MPCONTRIBS_DB_NAME", "mpcontribs")
MPCONTRIBS_MONGO_HOST = os.environ.get("MPCONTRIBS_MONGO_HOST")
MONGODB_SETTINGS = {
# Changed in version 3.9: retryWrites now defaults to True.
"host": f"mongodb+srv://{MPCONTRIBS_MONGO_HOST}/{MPCONTRIBS_DB}",
"connect": False,
"db": MPCONTRIBS_DB,
"compressors": ["snappy", "zstd", "zlib"],
}
REDIS_ADDRESS = os.environ.get("REDIS_ADDRESS", "redis")
REDIS_URL = RQ_REDIS_URL = RQ_DASHBOARD_REDIS_URL = f"redis://{REDIS_ADDRESS}"
DOC_DIR = os.path.join(os.path.dirname(__file__), f"swagger-{MPCONTRIBS_DB}")
SWAGGER = {
"swagger_ui_bundle_js": "//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js",
"swagger_ui_standalone_preset_js": "//unpkg.com/swagger-ui-dist@3/swagger-ui-standalone-preset.js",
"jquery_js": "//unpkg.com/jquery@2.2.4/dist/jquery.min.js",
"swagger_ui_css": "//unpkg.com/swagger-ui-dist@3/swagger-ui.css",
"uiversion": 3,
"hide_top_bar": True,
"doc_expansion": "none",
"doc_dir": DOC_DIR,
"specs": [
{
"endpoint": "apispec",
"route": "/apispec.json",
"rule_filter": lambda rule: True, # all in
"model_filter": lambda tag: True, # all in
}
],
"specs_route": "/",
}
TEMPLATE = {
"swagger": "2.0",
"info": {
"title": "MPContribs API",
"description": "Operations to contribute, update and retrieve materials data on Materials Project",
"termsOfService": "https://materialsproject.org/terms",
"version": VERSION,
"contact": {
"name": "MPContribs",
"email": "contribs@materialsproject.org",
"url": "https://mpcontribs.org",
},
"license": {
"name": "Creative Commons Attribution 4.0 International License",
"url": "https://creativecommons.org/licenses/by/4.0/",
},
},
"tags": [
{
"name": "projects",
"description": f'contain provenance information about contributed datasets. \
Deleting projects will also delete all contributions including tables, structures, attachments, notebooks \
and cards for the project. Only users who have been added to a project can update its contents. While \
unpublished, only users on the project can retrieve its data or view it on the \
Portal. Making a project public does not automatically publish all \
its contributions, tables, attachments, and structures. These are separately set to public individually or in bulk.'
"",
},
{
"name": "contributions",
"description": f'contain simple hierarchical data which will show up as cards on the MP details \
page for MP material(s). Tables (rows and columns), structures, and attachments can be added to a \
contribution. Each contribution uses `mp-id` or composition as identifier to associate its data with the \
according entries on MP. Only admins or users on the project can create, update or delete contributions, and \
while unpublished, retrieve its data or view it on the Portal. \
Contribution components (tables, structures, and attachments) are deleted along with a contribution.',
},
{
"name": "structures",
"description": 'are \
<a href="https://pymatgen.org/_modules/pymatgen/core/structure.html#Structure">pymatgen structures</a> which \
can be added to a contribution.',
},
{
"name": "tables",
"description": 'are simple spreadsheet-type tables with columns and rows saved as Pandas \
<a href="https://pandas.pydata.org/pandas-docs/stable/getting_started/dsintro.html#dataframe">DataFrames</a> \
which can be added to a contribution.',
},
{
"name": "attachments",
"description": 'are files saved as objects in AWS S3 and not accessible for querying (only retrieval) \
which can be added to a contribution.',
},
{
"name": "notebooks",
"description": f'are Jupyter \
<a href="https://jupyter-notebook.readthedocs.io/en/stable/notebook.html#notebook-documents">notebook</a> \
documents generated and saved when a contribution is saved. They form the basis for Contribution \
Details Pages on the Portal.',
},
],
"securityDefinitions": {
"ApiKeyAuth": {
"description": "MP API key to authorize requests",
"name": "X-API-KEY",
"in": "header",
"type": "apiKey",
}
},
"security": [{"ApiKeyAuth": []}],
}