generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged main into update-validation schemas, finish SignUp tests next
- Loading branch information
Showing
62 changed files
with
2,879 additions
and
830 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# The development configuration uses 3rd party service | ||
# API mocking, and enables debugging and server hot reloading | ||
# by default. No additional environment variables are required, | ||
# but see DevelopmentHUUConfig for the full range of options. | ||
ENV='development' |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Production configuration does not allow mocking, debugging | ||
# or testing. Configuration values are strictly validated where possible. | ||
# The following values are required for staging config. | ||
# See ProductionHUUConfig for all options. | ||
ENV='production' | ||
COGNITO_CLIENT_ID= | ||
COGNITO_CLIENT_SECRET= | ||
COGNITO_REGION= | ||
COGNITO_REDIRECT_URI=http://localhost:4040/signin | ||
COGNITO_USER_POOL_ID= | ||
SECRET_KEY= | ||
COGNITO_ACCESS_ID= | ||
COGNITO_ACCESS_KEY= | ||
DATABASE_URL= | ||
ROOT_URL=https://homeunite.us |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Staging configuration does not allow mocking, but | ||
# does allow debugging and testing. | ||
# The following values are required for staging config. | ||
# See StagingHUUConfig for all options. | ||
ENV='staging' | ||
COGNITO_CLIENT_ID= | ||
COGNITO_CLIENT_SECRET= | ||
COGNITO_REGION= | ||
COGNITO_REDIRECT_URI=http://localhost:4040/signin | ||
COGNITO_USER_POOL_ID= | ||
SECRET_KEY= | ||
COGNITO_ACCESS_ID= | ||
COGNITO_ACCESS_KEY= | ||
DATABASE_URL= | ||
ROOT_URL=https://dev.homeunite.us |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,15 @@ | ||
# Standard Lib | ||
from os import environ as env | ||
from pathlib import Path | ||
from typing import Dict, Any | ||
|
||
# Third Party | ||
import connexion | ||
from dotenv import load_dotenv, find_dotenv, get_key | ||
import prance | ||
|
||
# Local | ||
from openapi_server import encoder | ||
from openapi_server.models.database import DataAccessLayer | ||
from openapi_server.exceptions import AuthError, handle_auth_error | ||
from configs.configs import compile_config | ||
from configs.config_properties import ConfigProperties as cp | ||
|
||
|
||
DataAccessLayer.db_init() | ||
|
||
|
||
def get_bundled_specs(main_file: Path) -> Dict[str, Any]: | ||
''' | ||
Prance is able to resolve references to local *.yaml files. | ||
Use prance to parse the api specification document. Connexion's | ||
default parser is not able to handle local file references, but | ||
our api specification is split across multiple files for readability. | ||
Args: | ||
main_file (Path): Path to a api specification .yaml file | ||
Returns: | ||
Dict[str, Any]: Parsed specification file, stored in a dict | ||
''' | ||
parser = prance.ResolvingParser(str(main_file.absolute()), lazy=True, strict=True) | ||
parser.parse() | ||
|
||
return parser.specification | ||
|
||
def get_version(): | ||
from importlib.metadata import version, PackageNotFoundError | ||
|
||
try: | ||
return version("homeuniteus-api") | ||
except PackageNotFoundError: | ||
# package is not installed | ||
return "0.1.0.dev0" | ||
|
||
def create_app(): | ||
''' | ||
Creates a configured application that is ready to be run. | ||
The application is configured from external environment variables stored | ||
in either a local `.env` in a development environment or from environment | ||
variables that are configured prior to running the application. | ||
This function is made available at the module level so that it can | ||
be loaded by a WSGI server in a production-like environment with | ||
`openapi_server.__main__:create_app()`. | ||
''' | ||
|
||
# `connexion.App` is aliased to `connexion.FlaskApp` (as of connexion v2.13.1) | ||
# which is the connexion layer built on top of Flask. So we think of it as | ||
# the connexion application. | ||
connexion_app = connexion.App(__name__) | ||
api_spec_path = connexion_app.get_root_path() / Path('./openapi/openapi.yaml') | ||
parsed_specs = get_bundled_specs(api_spec_path) | ||
|
||
parsed_specs['info']['version'] = get_version() | ||
|
||
connexion_app.add_api(parsed_specs, pythonic_params=True) | ||
connexion_app.add_error_handler(AuthError, handle_auth_error) | ||
|
||
ENV_FILE = find_dotenv() | ||
if ENV_FILE: | ||
load_dotenv(ENV_FILE) | ||
SECRET_KEY = env.get("SECRET_KEY") | ||
env_config_profile = get_key(find_dotenv(), "CONFIG_PROFILE") | ||
|
||
# The underlying instance of Flask is stored in `connexion_app.app`. | ||
# This is an instance of `flask.Flask`. | ||
flask_app = connexion_app.app | ||
flask_app.json_encoder = encoder.JSONEncoder | ||
flask_app.secret_key = SECRET_KEY | ||
|
||
# Below, the Flask configuration handler is loaded with the | ||
# application configuration settings | ||
flask_app.config.from_object(compile_config(env_config_profile)) | ||
|
||
return connexion_app | ||
|
||
from openapi_server.app import create_app | ||
|
||
if __name__ == "__main__": | ||
# This will/should be only run in a development environment | ||
|
||
connexion_app = create_app() | ||
flask_app = connexion_app.app | ||
|
||
if flask_app.environment == "production": | ||
raise EnvironmentError("The production configuration must be run on a " | ||
"production server. Connexion's app.run() method " | ||
"starts a development server that should be used " | ||
"for testing purposes only.") | ||
connexion_app.run( | ||
host=flask_app.config[cp.HOST.name], | ||
port=flask_app.config[cp.PORT.name], | ||
debug=flask_app.config[cp.DEBUG.name], | ||
use_reloader=flask_app.config[cp.USE_RELOADER.name], | ||
host=flask_app.config["HOST"], | ||
port=flask_app.config["PORT"], | ||
load_dotenv=False | ||
) |
Oops, something went wrong.