@@ -0,0 +1,2460 @@
+%22%22%22%0AEB-DOCKER-FLASK-MSSQL%0Aby Jeric Macalintal %0A%0AA Flask Application for deployment in AWS Elastic Beanstalk Preconfigured with Docker%0A%0AJuly 23, 2017%0A%22%22%22%0A%0A#region Imports%0Aimport os%0Aimport logging%0Aimport sys%0Aimport json%0Aimport flask%0Afrom flask import request, Response,make_response,render_template%0Aimport pyodbc%0Afrom flask_basicauth import BasicAuth%0A%0A#endregion%0A%0A# Create the Flask app%0Aapplication = flask.Flask(__name__)%0A%0A#region Environment Variables%0A# Default config vals%0ATHEME = 'default' if os.environ.get('THEME') is None else os.environ.get('THEME')%0AFLASK_DEBUG = 'false' if os.environ.get('FLASK_DEBUG') is None else os.environ.get('FLASK_DEBUG')%0ABASIC_AUTH_USERNAME = '' if os.environ.get('BASIC_AUTH_USERNAME') is None else os.environ.get('BASIC_AUTH_USERNAME')%0ABASIC_AUTH_PASSWORD = '' if os.environ.get('BASIC_AUTH_PASSWORD') is None else os.environ.get('BASIC_AUTH_PASSWORD')%0ACONNECTION_STRING = '' if os.environ.get('CONNECTION_STRING') is None else os.environ.get('CONNECTION_STRING')%0A%0Aapplication.config.from_object(__name__)%0Aapplication.config.from_envvar('APP_CONFIG', silent=True)%0Aapplication.config%5B'BASIC_AUTH_USERNAME'%5D = BASIC_AUTH_USERNAME%0Aapplication.config%5B'BASIC_AUTH_PASSWORD'%5D = BASIC_AUTH_PASSWORD%0A# application.config%5B'BASIC_AUTH_FORCE'%5D = True%0Abasic_auth = BasicAuth(application)%0A#endregion%0A%0A#region Application Functions%0A%0A# SQL Query Function%0Adef sql_query(sql,arguments):%0A    %22%22%22%0A        Args:%0A            sql         (str): SQL Statement.%0A            arguments   (list of str): List of arguments for the sql Statement.%0A%0A        Returns:%0A            results     List of Dictionaries.%0A    %22%22%22%0A    cnxn = pyodbc.connect(CONNECTION_STRING)%0A%0A    cursor = cnxn.cursor()%0A    _sqlString = sql%0A    cursor.execute(_sqlString,arguments)%0A%0A    columns = %5Bcolumn%5B0%5D for column in cursor.description%5D%0A    results = %5B%5D%0A%0A    for row in cursor:%0A        results.append(dict(zip(columns, row)))%0A    cursor.close()%0A    del cursor%0A%0A    return results%0A%0A#endregion%0A%0A#region Main Web Pages%0A#Homepage%0A@application.route('/')%0Adef welcome():%0A    return render_template(%22home.html%22)%0A%0A#endregion%0A%0A#region Error Logging%0A%0A@application.before_first_request%0Adef setup_logging():%0A        if not application.debug:%0A            application.logger.addHandler(logging.StreamHandler())%0A            application.logger.setLevel(logging.INFO)%0A#endregion%0A%0Aif __name__ == '__main__':%0A    application.run(host='0.0.0.0')%0A    application.debug = True%0A    application.run()%0A

Create application.py