def cloudFoundryfyConfig(config: FlaskConfig): """ Optionale Anpassung der Flask-Konfiguration mit CF-Umgebung. """ cfenv = AppEnv() if len(cfenv.app) > 0: logger.info("app %s %d services: %s", cfenv.name, len(cfenv.services), cfenv.app) for service in cfenv.services: logger.info("bound service '%s': %s", service.name, service.env) {% if cookiecutter.use_reldb.startswith('y') -%} vcapdb = cfenv.get_service(label='p-mysql') if vcapdb: logger.info("%s", vcapdb) config['SQLALCHEMY_DATABASE_URI'] = 'mysql://{username}:{password}@{hostname}:{port}/{name}'.format( **vcapdb.credentials) logger.info("MySQL Service %s konfiguriert", vcapdb.credentials['hostname']) elif 'SQLALCHEMY_DATABASE_URI' not in config: logger.critical("Kein Datenbank-Service gebunden!") {%- endif -%} else: cfenv = None return cfenv
def scp_connect(dest_name, dest_uri, dest_client): ###################################################################### ############### Step 1: Read the environment variables ############### ###################################################################### env = AppEnv() uaa_service = env.get_service(name='uaa_service') dest_service = env.get_service(name='destination_service') sUaaCredentials = dest_service.credentials[ "clientid"] + ':' + dest_service.credentials["clientsecret"] ####################################################################### ##### Step 2: Request a JWT token to access the destination service ### ####################################################################### headers = { 'Authorization': 'Basic ' + base64.b64encode(sUaaCredentials), 'content-type': 'application/x-www-form-urlencoded' } form = [('client_id', dest_service.credentials["clientid"]), ('grant_type', 'client_credentials')] r = requests.post(uaa_service.credentials["url"] + '/oauth/token', data=form, headers=headers) ####################################################################### ###### Step 3: Search your destination in the destination service ##### ####################################################################### token = r.json()["access_token"] headers = {'Authorization': 'Bearer ' + token} r = requests.get(dest_service.credentials["uri"] + '/destination-configuration/v1/destinations/' + dest_name, headers=headers) ####################################################################### ############### Step 4: Access the destination securely ############### ####################################################################### destination = r.json() token = destination["authTokens"][0] headers = { 'Authorization': token["type"] + ' ' + token["value"], 'Accept': 'application/json' } if dest_client: dest_client = '?sap-client=' + dest_client else: #Read sap-client from Destinations configuration dest_client = '?sap-client=' + destination["destinationConfiguration"][ "sap-client"] r = requests.get(destination["destinationConfiguration"]["URL"] + dest_uri + dest_client, headers=headers) return r
def get_connection_string(): env = AppEnv() mssql = env.get_service(name='mssql-service') server = 'tcp:' + mssql.credentials['server'] database = mssql.credentials['database'] username = mssql.credentials['username'] password = mssql.credentials['password'] return 'DRIVER={ODBC Driver 17 for SQL Server};SERVER=' + server + ';DATABASE=' + database + ';UID=' + username + ';PWD=' + password
def credhub_secret(key): ''' Read the VCAP_SERVICES env variable & extract the "demo-certificate" value :return: parsed credhub value as a dict ''' cf_env = AppEnv() credhub_env = cf_env.get_service(label="credhub").get_url(key) return credhub_env
def __init__(self): if os.getenv('VCAP_SERVICES') is None: os.environ['VCAP_SERVICES'] = get_services_from_file( os.getenv('SERVICES_PATH'), 'env/services.yml') env = AppEnv() self.APIALCHEMY_BINDS = {} self.apialchemy_binds = api_helper.parse_services_for_binds( service_prefix['APIALCHEMY'], env.services) self.SQLALCHEMY_BINDS = {} self.sqlalchemy_binds = sqlalchemy_helper.parse_services_for_binds( service_prefix['SQLALCHEMY'], env.services) self.SCHEDULER_JOBS = [] if os.getenv('JOBS_SOURCE_SERVICE') is not None: self.JOBS_SOURCE_REFRESH_INTERVAL = os.getenv( 'JOBS_SOURCE_REFRESH_INTERVAL', '60') self.service_jobs = apscheduler_helper.get_jobs_from_services( job_prefix, template_prefix, env.services) self.source_jobs = {} self.jobs = self.service_jobs
def handle(self, *args, **options): env = AppEnv() if env.index is None or env.index == 0: management.call_command('migrate', fake_initial=True) management.call_command('rebuild_index', interactive=False, remove=True)
def __init__(self): self.env_parser = Env() self.cf_env_parser = AppEnv() self.ENV = self.env_parser("ENV") self.SEMAPHORE = "cloud-gov-migration-ready" # this is a well-known constant # https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html self.CLOUDFRONT_HOSTED_ZONE_ID = "Z2FDTNDATAQYW2"
def create_app() -> Flask: app = Flask(__name__) app_env = AppEnv() @app.route("/") def index(): return jsonify(app_env.app) @app.route("/services") def services(): return jsonify([s.__dict__ for s in app_env.services]) return app
def down_dir(): dest = request.args.get("destination") path = request.args.get("path") if (dest == None or path == None): return "Please provide paramenters" download_directory(dest, path, AppEnv()) dir_list = [] for root, dirs, files in os.walk('.'): for d in dirs: dir_list.append(os.path.join(root, d)) for f in files: dir_list.append(os.path.join(root, f)) return str(''.join(list(os.popen("ls -lh 124M/run1"))))
def start_job(): service = AppEnv().get_service(name='redeployer-creds') token = service.credentials.get('API_TOKEN') branch = os.environ.get('CIRCLE_BRANCH', 'master') job = os.environ.get('CIRLCE_JOBNAME', 'build') org = os.environ.get('CIRCLE_ORGNAME') repo = os.environ.get('CIRCLE_REPONAME') vcs = os.environ.get('CIRCLE_VCS', 'github') url = f"https://{token}:@circleci.com/api/v1.1/project/{vcs}/{org}/{repo}" url += f"/tree/{branch}" result = requests.post(url, data={'build_parameters[CIRCLE_JOB]': job}) result.raise_for_status()
def hello(): env = AppEnv() app_name = env.name app_uris = env.uris space_name = env.space index = env.index vcap_app_env = json.loads(os.getenv('VCAP_APPLICATION', '{}')) app_mem_limit = str(vcap_app_env["limits"].get('mem')) app_disk_limit = str(vcap_app_env["limits"].get('disk')) #return render_template('index1.html', app_name=app_name, app_uris=app_uris) return render_template('index.html', app_name=app_name, app_uris=app_uris, space_name=space_name, index=index, app_mem_limit=app_mem_limit, app_disk_limit=app_disk_limit)
def __init__(self): self.env = Env() self.cfenv = AppEnv() self.FLASK_ENV = self.env("FLASK_ENV") self.TMPDIR = self.env("TMPDIR", "/app/tmp/") self.DNS_PROPAGATION_SLEEP_TIME = self.env( "DNS_PROPAGATION_SLEEP_TIME", "300") self.CLOUDFRONT_PROPAGATION_SLEEP_TIME = 60 # Seconds self.SQLALCHEMY_TRACK_MODIFICATIONS = False self.TESTING = True self.DEBUG = True self.ACME_POLL_TIMEOUT_IN_SECONDS = self.env( "ACME_POLL_TIMEOUT_IN_SECONDS", 90) self.AWS_POLL_WAIT_TIME_IN_SECONDS = 60 self.AWS_POLL_MAX_ATTEMPTS = 120 # https://docs.aws.amazon.com/Route53/latest/APIReference/API_AliasTarget.html self.CLOUDFRONT_HOSTED_ZONE_ID = "Z2FDTNDATAQYW2"
def download_directory(destination, directory_path, env=AppEnv()): responseText = call_destination(destination, directory_path, env) print(responseText) directory = json.loads(responseText) for item in directory: if (item["type"] == "file"): if item["size"] // 1024 >= 1024: response_stream = call_destination( destination, '/' + '/'.join( item["download_url"].strip("https://").split('/')[1:]), stream=True) print(response_stream) with open(item["name"], 'wb') as fp: for chunk in response_stream.iter_content(chunk_size=1024): fp.write(chunk) else: responseObject = json.loads( call_destination(destination, directory_path + "/" + item["name"])) if "raw_lfs" in responseObject["download_url"]: thread = Thread(target=download_large_file, args=( destination, responseObject, )) thread.start() else: with open(responseObject["name"], 'wb') as fp: fp.write( base64.standard_b64decode( responseObject["content"])) elif (item["type"] == "dir"): os.mkdir(item["name"]) os.chdir(item["name"]) download_directory(destination, directory_path + "/" + item["name"], env) os.chdir('..')
import json import os import dj_database_url from cfenv import AppEnv from .base import * # noqa env = AppEnv() DEBUG = False ANALYTICS = { 'DAP': { 'AGENCY': 'GSA' } } DATABASES = { 'default': dj_database_url.config() } vcap_app = json.loads(os.environ.get('VCAP_APPLICATION', '{}')) ALLOWED_HOSTS = ['localhost'] + vcap_app.get('application_uris', []) vcap_services = json.loads(os.environ.get('VCAP_SERVICES', '{}')) es_config = vcap_services.get('elasticsearch-swarm-1.7.1', []) if es_config: HAYSTACK_CONNECTIONS['default'] = { 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', 'URL': es_config[0]['credentials']['uri'],
"django.template.context_processors.request", "django.contrib.auth.context_processors.auth", ], }, }, ] WSGI_APPLICATION = "idemia.wsgi.application" # The VCAP_APPLICATION environment variable is set by cloud.gov and # populated with service information needed to connect to the database. VCAP_ENV_VAR = "VCAP_APPLICATION" if VCAP_ENV_VAR in os.environ: # Deployment to Cloud.gov -- Set DB to RDS ENV = AppEnv() RDS_VARS = ENV.get_service(label="aws-rds") DB_INFO = RDS_VARS.credentials DB_DICT = { "ENGINE": "django.db.backends.postgresql", "NAME": DB_INFO["db_name"], "USER": DB_INFO["username"], "PASSWORD": DB_INFO["password"], "HOST": DB_INFO["host"], "PORT": DB_INFO["port"], } else: # Local development -- use local DB info # See README for setting up postgres container DB_DICT = {
import os import re import cv2 import numpy as np import imutils from cfenv import AppEnv env = AppEnv() statusService = env.get_service(name='status-topic') if statusService is None: statusKafka = "localhost:9092" statusTopic = "opencv-kafka-demo-status" else: statusKafka = statusService.credentials.get("hostname") statusTopic = statusService.credentials.get("topicName") inImagesService = env.get_service(name=re.compile('raw')) if inImagesService is None: if not os.environ.get('DEVICE_ID'): print("Must provide $DEVICE_ID when not running on Cloud Foundry") exit(1) inImagesKafka = "localhost:9092" inImagesTopic = "opencv-kafka-demo-raw-" + os.environ['DEVICE_ID'] else: inImagesKafka = inImagesService.credentials.get("hostname") inImagesTopic = inImagesService.credentials.get("topicName") print("Found inbound Cloud Foundry service", inImagesService.name) outImagesService = env.get_service(name=re.compile('edgedetector'))
# app server from flask import Flask app = Flask(__name__) import os port = int(os.environ.get('PORT', 3000)) # Cloud Foundry from cfenv import AppEnv env = AppEnv() hana_service = 'hana' hana = env.get_service(label=hana_service) # SAP HANA Client from hdbcli import dbapi # SQL statement sql = "select * from SYS.M_DATABASE" # home page @app.route('/') def hello(): return "Hello World" @app.route('/hana') def db(): if hana is None:
""" migrations.py implements the 'Migrate Frequently' section of https://docs.huihoo.com/cloudfoundry/documentation/devguide/services/migrate-db.html """ import logging import os from cfenv import AppEnv from django.core.management import execute_from_command_line os.environ.setdefault("DJANGO_SETTINGS_MODULE", "idemia.settings") ENV = AppEnv() # Only allow the 0th instance of the application to run the migration scripts on the # database. When deploying there will always be at least 1 application instance. if ENV.index == 0: logging.warning("Instance index 0 started -- running migrations script") execute_from_command_line(["manage.py", "migrate"]) logging.warning("Migrations complete")
import json import logging import os import sys import dj_database_url from cfenv import AppEnv from .base import * logging.basicConfig(level=logging.INFO, stream=sys.stdout) env = AppEnv() DEBUG = False TEMPLATE_DEBUG = False ANALYTICS = { 'GOOGLE': { 'GA_SITE_ID': 'UA-48605964-22', }, 'DAP': { 'AGENCY': 'FEC', }, } DATABASES = {'default': dj_database_url.config()} vcap_app = json.loads(os.environ.get('VCAP_APPLICATION', '{}')) ALLOWED_HOSTS = ['localhost'] + vcap_app.get('application_uris', []) vcap_services = json.loads(os.environ.get('VCAP_SERVICES', '{}'))
def handle(self, *args, **options): env = AppEnv() if env.index is None or env.index == 0: management.call_command('migrate', '--noinput')
import logging from cfenv import AppEnv from hdbcli import dbapi from cf_logging import flask_logging from sap import xssec from flask import * from flask_socketio import SocketIO from flask_socketio import send, emit, Namespace #create instance of flask app app = Flask(__name__) socketio = SocketIO(app) app_port = int(os.environ.get('PORT', 3000)) #connection with services env = AppEnv() hana = env.get_service(name='spatial-db') uaa_service = env.get_service(name='myuaa').credentials #logging flask_logging.init(app, logging.INFO) logger = logging.getLogger('route.logger') #used to establish connection with HANA DB def connectDB(serviceName): service = env.get_service(name=serviceName) conn = dbapi.connect(address=service.credentials['host'], port= int(service.credentials['port']), user = service.credentials['user'], password = service.credentials['password'], CURRENTSCHEMA=service.credentials['schema'])
import tempfile from .base import * DEBUG = False TEMPLATE_DEBUG = False ALLOWED_HOSTS = [ '.everykidinapark.gov', # Allow domain and subdomains 'kids-prod.18f.gov', 'ekip-prod.app.cloud.gov', # Internal URL for production instance 'kids.18f.gov', 'ekip-staging.app.cloud.gov', # Allow staging URL 'kids-dev.18f.gov', 'ekip-dev.app.cloud.gov' # Allow development URL ] database_url = os.getenv('DATABASE_URL') env = AppEnv() cf_db = env.get_service(name=re.compile('ekip-db')) if cf_db: database_url = cf_db.credentials['uri'] DATABASES = {} DATABASES['default'] = dj_database_url.parse(database_url) DATABASES['default']['CONN_MAX_AGE'] = 60 AWS_S3_REGION_NAME = os.getenv('EKIP_AWS_REGION') AWS_ACCESS_KEY_ID = os.getenv('EKIP_AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = os.getenv('EKIP_AWS_SECRET_ACCESS_KEY') AWS_STORAGE_BUCKET_NAME = os.getenv('EKIP_STATIC_BUCKET_NAME') cf_s3 = env.get_service(name=re.compile('ekip-s3')) if cf_s3: AWS_STORAGE_BUCKET_NAME = cf_s3.credentials['bucket'] AWS_S3_REGION_NAME = cf_s3.credentials['region']
import os import newrelic.agent from cfenv import AppEnv from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "atf_eregs.settings") # important that the whitenoise import is after the line above from whitenoise.django import DjangoWhiteNoise env = AppEnv() settings = newrelic.agent.global_settings() settings.app_name = env.get_credential('NEW_RELIC_APP_NAME') settings.license_key = env.get_credential('NEW_RELIC_LICENSE_KEY') newrelic.agent.initialize() application = DjangoWhiteNoise(get_wsgi_application())
from .base import * import os import re import dj_database_url from cfenv import AppEnv database_url = os.getenv("DATABASE_URL") env = AppEnv() cf_foia_db = env.get_service(name=re.compile('foia-db')) if cf_foia_db: database_url = cf_foia_db.credentials['uri'] # See env.example for an explanation of these settings. SECRET_KEY = os.getenv("FOIA_SECRET_SESSION_KEY") DATABASES = {'default': dj_database_url.parse(database_url)} SHOW_WEBFORM = (os.getenv("FOIA_SHOW_WEBFORM") == "true") ANALYTICS_ID = os.getenv("FOIA_ANALYTICS_ID")
from flask import Flask, render_template from cfenv import AppEnv import os import requests import base64 import json #create an app using flask lib and also get the port info for later use app = Flask(__name__) app.config["DEBUG"] = True cf_port = os.getenv("PORT") ###################################################################### ############### Step 1: Read the environment variables ############### ###################################################################### env = AppEnv() #read all the xsuaa service key values from the env variables uaa_service = env.get_service(name='xsuaa-demo') #read all the connectivity service key values from the env variables conn_service = env.get_service(name='connectivity-demo-lite') # read the client ID and secret for the connectivity service conn_sUaaCredentials = conn_service.credentials[ "clientid"] + ':' + conn_service.credentials["clientsecret"] # read the On premise proxy host and on premise proxy port for the connectivity service proxy_url = conn_service.credentials[ "onpremise_proxy_host"] + ':' + conn_service.credentials[ "onpremise_proxy_port"] ###################################################################### ##### Step 2: Request a JWT token to access the connectivity service## ###################################################################### #create authorization with basic authentication using connectivity credentials as base64 format headers = {
from .base import HAYSTACK_CONNECTIONS # explicitly referenced below DEBUG = False TEMPLATE_DEBUG = False ANALYTICS = { 'GOOGLE': { 'GTM_SITE_ID': '', 'GA_SITE_ID': 'UA-48605964-38', }, 'DAP': { 'AGENCY': 'DOJ', 'SUBAGENCY': 'ATF', }, } env = AppEnv() HTTP_AUTH_USER = env.get_credential('HTTP_AUTH_USER') HTTP_AUTH_PASSWORD = env.get_credential('HTTP_AUTH_PASSWORD') ALLOWED_HOSTS = ['localhost'] + env.uris # Service name may well change in the future. Fuzzy match elastic_service = env.get_service(name=re.compile('search')) if elastic_service: HAYSTACK_CONNECTIONS['default'] = { 'ENGINE': ('haystack.backends.elasticsearch_backend.' 'ElasticsearchSearchEngine'), 'URL': elastic_service.credentials['uri'], 'INDEX_NAME': 'eregs', }
app = Flask(__name__) from app import views views.register(app) from app import helpers helpers.register(app) port = int(os.getenv("PORT", 5000)) environment = os.getenv("PULSE_ENV", "development") if environment == "development": app.debug = True # Configure newrelic env = AppEnv() app_name = os.environ.get('NEW_RELIC_APP_NAME') license_key = env.get_credential('NEW_RELIC_LICENSE_KEY') if app_name and license_key: nr_settings = newrelic.agent.global_settings() nr_settings.app_name = app_name nr_settings.license_key = license_key newrelic.agent.initialize() if __name__ == "__main__": if environment == "development": app.run(port=port) else: serve(app, port=port)
import os from cfenv import AppEnv env = AppEnv() with open(os.path.dirname(os.path.realpath(__file__)) + "/development.ini", "a") as config: print env.uris config.write('\n') config.write('ckan.site_url = https://' + env.uris[0] + '\n') postgres = env.get_service(label='postgres') config.write("sqlalchemy.url = " + postgres.credentials['uri'] + '\n') # config.write( "ckan.datastore.write_url = "+postgres.credentials['uri']) # echo 'ckan.datastore.write_url = $DATABASE_URL' > development.ini # ckan.datastore.read_url redis = env.get_service(label='redis32').credentials redis_url = "redis://:{}@{}:{}/0".format(redis['password'], redis['host'], redis['port']) config.write('ckan.redis.url = ' + redis_url + '\n') config.write('\n')
def call_destination( destination: "name of the destination item on the SAP Cloud Platform Cockpit Destinations" = '', path: "endpoint path for accessing the data" = None, env: "CF App Environment Variable" = AppEnv(), requestContentType: "Content type of the request -> Default is always everything" = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3', stream: "To stream a large file" = False): """ Function to call the on-prem service via destination, connectivity, and Cloud Connector. Destination to be fetched can be informed on the call. If no destination could be defined, it will return a 400. :param destination: name of the destination item on the SAP Cloud Platform Cockpit Destinations :param path: endpoint path for accessing the data :param request: request object from flask :param env: CF environment object :param requestContentType: Content type of the request -> Default is always everything :return: data from the end point """ if destination == '': return ("Destination not found", 400) elif path is None: return ("Path not found", 400) elif env is None: return ("Environment object is not forwarded", 400) try: vs_uaa_service_credentials = env.get_service( name=xsuaa_service).credentials vs_connectivity_credentials = env.get_service( name=connectivity_service).credentials vs_destination_credentials = env.get_service( name=destination_service).credentials except Exception as err: msg = 'Required services not found! Without services / credentials it will be impossible to succeed!' + \ ' Exception:' + str(err) return (msg, 503) # ------------------------------------------------------------------------------------------------------------------ uaa_url = vs_uaa_service_credentials["url"] + \ '/oauth/token?grant_type=client_credentials' try: response = requests.post( uaa_url, headers={'Accept': 'application/json'}, auth=(vs_destination_credentials['clientid'], vs_destination_credentials['clientsecret'])) jwt_destination = response.json()['access_token'] except Exception as err: msg = "Something wrong getting JWT from xsuaa service for the destination service. Exception: " + \ str(err) return (msg, 500) # ------------------------------------------------------------------------------------------------------------------ destination_url = vs_destination_credentials['uri'] + '/destination-configuration/v1/destinations/' + \ destination try: response = requests.get(destination_url, headers={ 'Accept': 'application/json', 'Authorization': 'Bearer ' + jwt_destination, }) destination = response.json()['destinationConfiguration'] print_version = deepcopy(destination) print_version['Password'] = '******' except Exception as e: msg = "Something wrong reading data from the destination service: " + \ str(e) return (msg, 500) # ------------------------------------------------------------------------------------------------------------------ connectivity_url = vs_uaa_service_credentials["url"] + \ '/oauth/token?grant_type=client_credentials' try: response = requests.post( connectivity_url, headers={'Accept': 'application/json'}, auth=(vs_connectivity_credentials['clientid'], vs_connectivity_credentials['clientsecret'])) jwt_connectivity = response.json()['access_token'] except Exception as e: msg = "Something wrong posting data for the connectivity service. Exception: " + \ str(e) return msg, 500 # ------------------------------------------------------------------------------------------------------------------ proxies = { 'http': "http://" + vs_connectivity_credentials['onpremise_proxy_host'] + ':' + vs_connectivity_credentials['onpremise_proxy_port'], } request_url = destination['URL'] + path # ------------------------------------------------------------------------------------------------------------------ try: if stream: response_stream = requests.get( request_url, proxies=proxies, headers={ 'Accept': requestContentType, # 'SAP-Connectivity-Authentication': 'Bearer ' + jwt_user_auth, 'Proxy-Authorization': 'Bearer ' + jwt_connectivity, "SAP-Connectivity-SCC-Location_ID": destination["CloudConnectorLocationId"] }, auth=(destination['User'], destination['Password']), stream=True) return response_stream else: response = requests.get( request_url, proxies=proxies, headers={ 'Accept': requestContentType, # 'SAP-Connectivity-Authentication': 'Bearer ' + jwt_user_auth, 'Proxy-Authorization': 'Bearer ' + jwt_connectivity, "SAP-Connectivity-SCC-Location_ID": destination["CloudConnectorLocationId"] }, auth=(destination['User'], destination['Password'])) return response.content except Exception as e: msg = "Something wrong when accessing on-premise resource. Exception: " + \ str(e) return (msg, 500)
import json import os from cfenv import AppEnv env = AppEnv() from regcore.settings.base import * REGCORE_APPS = tuple(INSTALLED_APPS) REGCORE_DATABASES = dict(DATABASES) from regulations.settings.base import * REGSITE_APPS = tuple(INSTALLED_APPS) INSTALLED_APPS = ('overextends', 'fec_eregs',) + REGCORE_APPS + REGSITE_APPS BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) NOSE_ARGS = [ '--with-coverage', '--cover-package=regcore,regulations', '--tests=regulations.tests,regcore.tests,fec_eregs/tests/', '--verbosity=3' ] TEMPLATES[0]['OPTIONS']['context_processors'] += ( 'fec_eregs.context_processors.app_urls', ) TEST_RUNNER = 'django_nose.runner.NoseTestSuiteRunner' ROOT_URLCONF = 'fec_eregs.urls'
def process_file(): dest = request.args.get("destination") path = request.args.get("path") responseText = call_destination(dest, path, AppEnv()) return responseText
""" WSGI config for ticketer project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/ """ from cfenv import AppEnv import newrelic.agent import os from django.core.wsgi import get_wsgi_application env = AppEnv() # Initialize New Relic monitoring if on Cloud Foundry ekip_creds = env.get_service(name='ekip-newrelic') if ekip_creds is not None: new_relic_license = ekip_creds.credentials['NEW_RELIC_LICENSE_KEY'] new_relic_app_name = os.environ.get('NEW_RELIC_APP_NAME') if new_relic_license and new_relic_app_name: new_relic_settings = newrelic.agent.global_settings() new_relic_settings.license_key = new_relic_license new_relic_settings.app_name = new_relic_app_name print('Initializing New Relic monitoring') newrelic.agent.initialize() os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production") application = get_wsgi_application()
# Author: Michael Akayan import os import boto import redis from flask import Flask, render_template, request, redirect, url_for, send_from_directory from time import time from werkzeug import secure_filename import json from cfenv import AppEnv # Setup ECS variables locally if not runing in CF ##ecs_access_key_id = '<Insert your key>@ecstestdrive.emc.com' ##ecs_secret_key = '<Insert your key>' env = AppEnv() ecs_access_key_id = env.get_credential('ECS_access_key') ecs_secret_key = env.get_credential('ECS_secret') ecs_host = env.get_credential('ECS_host') # Set bucket name bname = 'images' namespace = ecs_access_key_id.split('@')[0] http_url = 'http://{ns}.{host}/{bucket}/'.format( ns=namespace, host='public.ecstestdrive.com', bucket=bname) if 'VCAP_SERVICES' in os.environ: VCAP_SERVICES = json.loads(os.environ['VCAP_SERVICES']) CREDENTIALS = VCAP_SERVICES["rediscloud"][0]["credentials"] r = redis.Redis(host=CREDENTIALS["hostname"],
import json import logging import os import sys import dj_database_url from cfenv import AppEnv from .base import * logging.basicConfig(level=logging.INFO, stream=sys.stdout) env = AppEnv() DEBUG = False TEMPLATE_DEBUG = False ANALYTICS = { } DATABASES = { 'default': dj_database_url.config() } vcap_app = json.loads(os.environ.get('VCAP_APPLICATION', '{}')) ALLOWED_HOSTS = ['localhost'] + vcap_app.get('application_uris', []) vcap_services = json.loads(os.environ.get('VCAP_SERVICES', '{}')) es_config = vcap_services.get('elasticsearch-swarm-1.7.1', []) if es_config: HAYSTACK_CONNECTIONS['default'] = {
""" WSGI config for omb_eregs project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ """ import os import newrelic.agent from cfenv import AppEnv from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "omb_eregs.settings") env = AppEnv() app_name = os.environ.get('NEW_RELIC_APP_NAME') license_key = env.get_credential('NEW_RELIC_LICENSE_KEY') if app_name and license: nr_settings = newrelic.agent.global_settings() nr_settings.app_name = app_name nr_settings.license_key = license_key newrelic.agent.initialize() application = get_wsgi_application()
SHOW_WEBFORM = False CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'LOCATION': os.getenv('TMPDIR', '/tmp'), 'TIMEOUT': 1440, 'OPTIONS': { 'MAX_ENTRIES': 1000 }, } } AWS_STORAGE_BUCKET_NAME = os.getenv('FOIA_S3_STATIC_BUCKET_NAME') AWS_REGION = '' env = AppEnv() cf_s3_bucket = env.get_service(name=re.compile('foia-public-bucket')) if cf_s3_bucket: AWS_STORAGE_BUCKET_NAME = cf_s3_bucket.credentials['bucket'] AWS_REGION = '-%s' % cf_s3_bucket.credentials['region'] AWS_S3_REGION_NAME = cf_s3_bucket.credentials['region'] AWS_ACCESS_KEY_ID = cf_s3_bucket.credentials['access_key_id'] AWS_SECRET_ACCESS_KEY = cf_s3_bucket.credentials['secret_access_key'] AWS_S3_CUSTOM_DOMAIN = 's3%s.amazonaws.com/%s' % (AWS_REGION, AWS_STORAGE_BUCKET_NAME) STATIC_URL = 'https://%s/' % AWS_S3_CUSTOM_DOMAIN STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
from cfenv import AppEnv import os env = AppEnv() kavskdb = env.get_service(label='aws-rds-postgresql') basedir = os.path.abspath(os.path.dirname(__file__)) SQLALCHEMY_ECHO = False SQLALCHEMY_TRACK_MODIFICATIONS = True SQLALCHEMY_DATABASE_URI = kavskdb.credentials['uri']
import os from cfenv import AppEnv env = AppEnv() with open( os.path.dirname(os.path.realpath(__file__)) + "/development.ini", "a") as config: print env.uris config.write('\n') config.write('ckan.site_url = https://' + env.uris[0] + '\n') postgres = env.get_service(label='postgres') config.write("sqlalchemy.url = " + postgres.credentials['uri'] + '\n') # config.write( "ckan.datastore.write_url = "+postgres.credentials['uri']) # echo 'ckan.datastore.write_url = $DATABASE_URL' > development.ini # ckan.datastore.read_url redis = env.get_service(label='redis32').credentials redis_url = "redis://:{}@{}:{}/0".format(redis['password'], redis['host'], redis['port']) config.write('ckan.redis.url = ' + redis_url + '\n') config.write('\n')
import keras import tensorflow as tf import time import datetime from json import JSONEncoder from tensorflow.python.keras.backend import set_session from json import dumps from json import loads from keras.models import model_from_yaml from cfenv import AppEnv app = Flask(__name__) port = int(os.getenv("PORT")) env = AppEnv() global graph global out_prob global non_out_prob global d_timestamp global sess @app.route('/') def started(): return 'Hello from python!!!' tasks = { 'id': 1, 'title': u'created a new event',
import os import logging from flask import Flask from cfenv import AppEnv from flask import request from flask import abort from sap import xssec from hdbcli import dbapi from cf_logging import flask_logging app = Flask(__name__) env = AppEnv() flask_logging.init(app, logging.INFO) port = int(os.environ.get('PORT', 3000)) hana = env.get_service(label='hana') uaa_service = env.get_service(name='myuaa').credentials @app.route('/') def hello(): logger = logging.getLogger('route.logger') logger.info('Someone accessed us') if 'authorization' not in request.headers: abort(403) access_token = request.headers.get('authorization')[7:] security_context = xssec.create_security_context(access_token, uaa_service) isAuthorized = security_context.check_scope('openid') if not isAuthorized: abort(403)
from flask import request from flask import Response from flask import send_from_directory # import os import json import datetime from cfenv import AppEnv from hdbcli import dbapi import platform app = Flask(__name__) env = AppEnv() # Get port from environment variable or choose 9099 as local default # If you are testing locally (i.e. not with xs or cf deployments, # Be sure to pull all the python modules locally # with pip using XS_PYTHON unzipped to /tmp # mkdir -p local # pip install -t local -r requirements.txt -f /tmp port = int(os.getenv("PORT", 9099)) hana = env.get_service(label='hana') # This module's Flask webserver will respond to these three routes (URL paths) # If there is no path then just return Hello World and this module's instance number # Requests passed through the app-router will never hit this route. @app.route('/')
import json import os import dj_database_url from cfenv import AppEnv from .base import * env = AppEnv() DEBUG = False TEMPLATE_DEBUG = False ANALYTICS = { } DATABASES = { 'default': dj_database_url.config() } vcap_app = json.loads(os.environ.get('VCAP_APPLICATION', '{}')) ALLOWED_HOSTS = ['localhost'] + vcap_app.get('application_uris', []) vcap_services = json.loads(os.environ.get('VCAP_SERVICES', '{}')) es_config = vcap_services.get('elasticsearch-swarm-1.7.1', []) if es_config: HAYSTACK_CONNECTIONS['default'] = { 'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', 'URL': es_config[0]['credentials']['uri'], 'INDEX_NAME': 'eregs', }