@@ -78,16 +78,24 @@ def create_app(config_override=None, instance_path=None):
7878
7979 """
8080 app = Flask (__name__ , instance_relative_config = True , instance_path = instance_path )
81- app .config .from_mapping (
82- SECRET_KEY = os .urandom (16 ),
83- SQLALCHEMY_DATABASE_URI = 'sqlite+pysqlite:///' + os .path .join (app .instance_path ,
84- 'mrmat-python-api-flask.sqlite' ),
85- SQLALCHEMY_TRACK_MODIFICATIONS = False ,
86- OIDC_RESOURCE_SERVER_ONLY = True )
87- if config_override is None :
88- app .config .from_pyfile ('config.py' , silent = True )
89- else :
81+
82+ #
83+ # Set configuration defaults. If a config file is present then load it. If we have overrides, apply them
84+
85+ app .config .setdefault ('SECRET_KEY' , os .urandom (16 ))
86+ app .config .setdefault ('SQLALCHEMY_DATABASE_URI' ,
87+ 'sqlite+pysqlite:///' + os .path .join (app .instance_path , 'mrmat-python-api-flask.sqlite' ))
88+ app .config .setdefault ('SQLALCHEMY_TRACK_MODIFICATIONS' , False )
89+ app .config .setdefault ('OIDC_USER_INFO_ENABLED' , True )
90+ app .config .setdefault ('OIDC_RESOURCE_SERVER_ONLY' , True )
91+ if 'FLASK_CONFIG' in os .environ and os .path .exists (os .path .expanduser (os .environ ['FLASK_CONFIG' ])):
92+ app .config .from_json (os .path .expanduser (os .environ ['FLASK_CONFIG' ]))
93+ if config_override is not None :
9094 app .config .from_mapping (config_override )
95+
96+ #
97+ # Create the instance folder if it does not exist
98+
9199 try :
92100 if not os .path .exists (app .instance_path ):
93101 app .logger .info (f'Creating new instance path at { app .instance_path } ' )
@@ -105,18 +113,23 @@ def create_app(config_override=None, instance_path=None):
105113 db .init_app (app )
106114 migrate .init_app (app , db )
107115 ma .init_app (app )
108- oidc .init_app (app )
116+ if 'OIDC_CLIENT_SECRETS' in app .config .keys ():
117+ oidc .init_app (app )
118+ else :
119+ app .logger .warning ('Running without any authentication/authorisation' )
109120
110121 #
111122 # Import and register our APIs here
112123
113124 from mrmat_python_api_flask .apis .healthz import bp as api_healthz # pylint: disable=import-outside-toplevel
114125 from mrmat_python_api_flask .apis .greeting .v1 import api_greeting_v1 # pylint: disable=import-outside-toplevel
115126 from mrmat_python_api_flask .apis .greeting .v2 import api_greeting_v2 # pylint: disable=import-outside-toplevel
127+ from mrmat_python_api_flask .apis .greeting .v3 import api_greeting_v3 # pylint: disable=import-outside-toplevel
116128 from mrmat_python_api_flask .apis .resource .v1 import api_resource_v1 # pylint: disable=import-outside-toplevel
117129 app .register_blueprint (api_healthz , url_prefix = '/healthz' )
118130 app .register_blueprint (api_greeting_v1 , url_prefix = '/api/greeting/v1' )
119131 app .register_blueprint (api_greeting_v2 , url_prefix = '/api/greeting/v2' )
132+ app .register_blueprint (api_greeting_v3 , url_prefix = '/api/greeting/v3' )
120133 app .register_blueprint (api_resource_v1 , url_prefix = '/api/resource/v1' )
121134
122135 return app
0 commit comments