예제 #1
0
def main():
    reporting_cf = common.get_template(TEMPLATE_BASE).replace(
        "{{import_config_rule_status}}",
        get_checksum_zip.get_checksum_zip("import_config_rule_status"))

    common.generate_file(TEMPLATE_DESTINATION,
                         reporting_cf)  # Creates the deployable CF file
예제 #2
0
def main():
    """Main function."""
    template = common.get_template(TEMPLATE_SOURCE).replace(
        "{{bakery_account}}",
        BAKERY_VARS.BakeryAccount).replace("{{access_type_roles}}",
                                           get_access_type_roles())

    common.generate_file(TEMPLATE_DESTINATION, template)
예제 #3
0
def main():
    """Main function."""
    template = common.get_template(TEMPLATE_SOURCE).replace(
        "{{groups_policies}}",
        get_groups_policies()
    )

    common.generate_file(TEMPLATE_DESTINATION, template)
예제 #4
0
def handle(start_response, route):

    template = common.get_template('graph.html')

    response = template.render().encode("utf-8")

    start_response('200 OK', [('Content-Type', 'text/html')])

    return [response]
예제 #5
0
def main():
    """Main function"""
    template = common.get_template(RULE_TEMPLATE_BASE).replace(
        "{{proxy_lambda_zip}}",
        get_checksum_zip.get_checksum_zip("proxy_lambda")).replace(
            "{{proxy_lambda_permissions}}",
            get_accounts_permissions(get_accounts.get_accounts()))

    common.generate_file(TEMPLATE_DESTINATION, template)
예제 #6
0
def main():
    """Main function."""
    template = common.get_template(TEMPLATE_SOURCE).replace(
        "{{bakery_account}}",
        BAKERY_VARS.BakeryAccount
    ).replace(
        "{{access_type_roles}}",
        get_access_type_roles()
    )

    common.generate_file(TEMPLATE_DESTINATION, template)
예제 #7
0
def main():
    """Main function"""
    template = common.get_template(RULE_TEMPLATE_BASE).replace(
        "{{notifications_slack}}",
        get_notifications.get_notification_slack()).replace(
            "{{slack_channel_hook_url}}",
            get_notifications.get_slack_channel_hook_url()).replace(
                "{{notifications_email}}",
                get_notifications.get_notification_email())

    common.generate_file(TEMPLATE_DESTINATION, template)
예제 #8
0
def main():
    citizen_update_cf = common.get_template(TEMPLATE_BASE).replace(
        "{{bucket_policy_accounts}}",
        get_bucket_policy_cf(get_accounts.get_accounts())).replace(
            "{{update_citizen_stacks}}",
            get_checksum_zip.get_checksum_zip(
                "update_citizen_stacks")).replace(
                    "{{external_cidr}}", get_external_cidr.get_external_cidr())

    common.generate_file(TEMPLATE_DESTINATION,
                         citizen_update_cf)  # Creates the deployable CF file
예제 #9
0
def main(args):
    # If no parameters were passed in
    if len(args) == 1:
        rules = get_verification_rules.get_rules()
    else:
        # Parameter contains paths, e.g. ./verification_rules,./folder1/verification_rules
        rules = get_verification_rules.get_rules(args[1].split(","))

    citizen_rules_cfn = common.get_template(RULES_TEMPLATE_BASE).replace(
        "{{citizen_rules}}", get_rules_cf(rules))

    common.generate_file(TEMPLATE_DESTINATION, citizen_rules_cfn)
예제 #10
0
def main(args):
    """Main function"""
    # If no parameters were passed in
    if len(args) == 1:
        cloud_formation_snippet = get_cloud_formation_snippet()
    else:
        # Parameter contains paths, e.g. ./verification_rules,./folder1/verification_rules
        cloud_formation_snippet = get_cloud_formation_snippet(
            args[1].split(","))

    template = common.get_template(RULE_TEMPLATE_BASE).replace(
        "{{proxy_rules}}", cloud_formation_snippet)

    common.generate_file(TEMPLATE_DESTINATION, template)
예제 #11
0
def handle(start_response, route):
    """
    We pass in the function "start_response" which when called triggers the start of the response.
    """

    if 'num' in route:

        num = int(route['num'])

        if num <= 0:        # Invalid number requested by user
            return error.handle(start_response, '400 Bad Request', "<i>num</i> should be greater than 0.")

    else:
        num = 12            # The default value of num when none is specified


    db = common.get_db()
    conn = sqlite3.connect(db)
    cursor = conn.cursor()

    records = []        # Construct a list of tuples with each tuple of the format (time, buy, sell)

    for values in cursor.execute('''SELECT "time", "buy", "sell" FROM "prices" ORDER BY "time" DESC LIMIT ?''', (num,)):

        t = values[0]
        buy = values[1]
        sell = values[2]

        ts = common.format_time(t)

        records.append({'time': ts, 'buy': buy, 'sell': sell})

    bi, si = maxima(records)          # get the indices of the maxima

    records[bi]['min_buy'] = True           # Append boolean values to the records corresponding to the maxima
    records[si]['max_sell'] = True

    template = common.get_template('recent.html')

    response = template.render({'rows': records}).encode("utf-8")

    conn.close()

    start_response('200 OK', [('Content-Type', 'text/html')])

    return [response]
예제 #12
0
def handle(start_response, route):
    """
    We pass in the function "start_response" which when called triggers the start of the response.
    """

    t, buy, sell = fetch_current()

    ts = common.format_time(t)          # Convert time integer to string

    template = common.get_template('current.html')

    data = {"time": ts, "buy": buy, "sell": sell}       # Create dictionary of variables to be substituted

    response = template.render(data).encode("utf-8")          # jinja2 template renderer returns unicode so we explicitly encode it as utf-8 before returning it so that the browser can read it.

    start_response('200 OK', [('Content-Type', 'text/html')])

    return [response]
예제 #13
0
def setup():
    print("Creating student schema ldif, slaptest output follows:\n")
    # Read in slaptest configuration file template
    conf = get_template('conf')
    # Format placeholder with the schema file path
    conf = conf.format_map({'pwd': os.getcwd()})
    # Create a temporary directory for slaptest output
    mkdir_p('tmpdir')
    # Write slaptest configuration file
    with open('tmpdir/student.conf', 'w') as f:
        f.write(conf)
    # Let slaptest create a ldif
    run("slaptest -f tmpdir/student.conf -F tmpdir/", shell=True)

    print("\nInstalling schema")
    # Read schema ldif and remove unnecessary lines
    with open('tmpdir/cn=config/cn=schema/cn={3}student.ldif', 'r') as f:
        ldif = f.read().splitlines()[5:-7]
    # Add some required lines
    ldif = ["dn: cn=student,cn=schema,cn=config",
            "objectClass: olcSchemaConfig",
            "cn: student"] + ldif
    # Write ldif file
    with open('tmpdir/add_student_schema.ldif', 'w') as f:
        f.write('\n'.join(ldif) + '\n')
    # Add schema to configuration
    run("ldapadd -Y EXTERNAL -H ldapi:/// -D \"cn=config\" -f tmpdir/add_student_schema.ldif", shell=True)
    # add_ldif("tmpdir/add_student_schema.ldif")

    print("Adding organizational units")
    for ou in ['Students', 'Praktikum']:
        filename = 'tmpdir/add_{}_org_unit.ldif'.format(ou)
        format_dict = {'ou': ou, 'in_ou_complete': ''}
        create_ldif('organizational_unit', format_dict, filename)
        add_ldif(filename)
    for i in range(1, 12):
        filename = 'tmpdir/add_Praktikum_Team{}_org_unit.ldif'.format(i)
        format_dict = {'ou': 'Team' + str(i),
                       'in_ou_complete': 'ou=Praktikum,'}
        create_ldif('organizational_unit', format_dict, filename)
        add_ldif(filename)
예제 #14
0
def main(args):
    """Opens a "template" file, substitutes values into it and then writes
    the contents to a new file.
    """
    # If no parameters were passed in
    if len(args) == 1:
        rules = get_verification_rules.get_rules()
    else:
        # Parameter contains paths, e.g. ./verification_rules,./folder1/verification_rules
        rules = get_verification_rules.get_rules(args[1].split(","))

    elasticsearch_cf = common.get_template(RULES_TEMPLATE_BASE).replace(
        "{{logs_to_elastic_search}}",
        get_checksum_zip.get_checksum_zip("logs_to_elastic_search")).replace(
            "{{roll_indexes}}",
            get_checksum_zip.get_checksum_zip("roll_indexes")).replace(
                "{{external_cidr}}",
                get_external_cidr.get_external_cidr()).replace(
                    "{{rules-subscriptions}}", get_subscriptions_cf(rules))

    common.generate_file(TEMPLATE_DESTINATION, elasticsearch_cf)
예제 #15
0
def main():
    """Main function."""
    template = common.get_template(TEMPLATE_SOURCE).replace(
        "{{groups_policies}}", get_groups_policies())

    common.generate_file(TEMPLATE_DESTINATION, template)
예제 #16
0
#!/usr/bin/env python
import io
import os
import sys
import uuid
import time
import json

import common

# 1. fetch variables
if 'SCRIPT' in os.environ:
    template = common.get_template(os.environ['SCRIPT'])
    deref, vars_ = common.get_script_variables()
    deref = common.deref_block(deref)
    script = io.StringIO(template.render(**vars_, **deref))
    job_name = os.environ['SCRIPT']
else:
    q2_vars = common.get_q2_environment_variables()

    if 'plugin' in q2_vars:
        # 2. Dereference reference.link inputs into artifact FPs and metadata
        #    FPs
        dereferenced = {}
        dereferenced['inputs'] = common.deref_block(q2_vars['inputs'])
        dereferenced['metadata'] = common.deref_block(q2_vars['metadata'])
        dereferenced['columns'] = {
            k: [common.deref(md), c]
            for k, (md, c) in q2_vars['columns'].items()
        }
        dereferenced['params'] = q2_vars['params']
예제 #17
0
def main():
    common.generate_file(TEMPLATE_DESTINATION,
                         common.get_template(RULES_TEMPLATE_BASE))
예제 #18
0
def main():
    roles_cf = common.get_template(TEMPLATE_BASE)
    common.generate_file(TEMPLATE_DESTINATION,
                         roles_cf)  # Creates the deployable CF file