Beispiel #1
0
    def is_anonymous(self):
        return False

    def get_id(self):
        return unicode(self.identifier)

    def __repr__(self):
        return '<User %r>' % (self.username)


if __name__ == '__main__':
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == 'create':
            print('Creating database objects')
            DB.create_all()

            print('Creating superuser account')
            username = raw_input('Enter your username: '******'Enter your password: '******'Enter your password again: ').strip()
            if password1 != password2:
                raise ValueError('Passwords must match')
            email1 = raw_input('Enter your email: ').strip()
            email2 = raw_input('Enter your email again: ').strip()
            if email1 != email2:
                raise ValueError('Emails must match')

            user_to_add = User(username, password1, email1, role='admin')
            DB.session.add(user_to_add)
            try:
Beispiel #2
0
    return [
        DB.session.query(mrt, func.count(mrt)).group_by(mrt),
        DB.session.query(mrt).count()
    ]


if __name__ == '__main__':
    import sys
    from flask import Flask
    APP = Flask(__name__)
    APP.config.from_pyfile('config.py')
    APP.config.from_pyfile('../instance/config.py')
    if len(sys.argv) > 1:
        if sys.argv[1] == 'create':
            print('Creating database objects')
            DB.create_all()

            print('Creating superuser account')
            username = raw_input('Enter your username: '******'Enter your password: '******'Enter your password again: ').strip()
            if password1 != password2:
                raise ValueError('Passwords must match')
            email1 = raw_input('Enter your email: ').strip()
            email2 = raw_input('Enter your email again: ').strip()
            if email1 != email2:
                raise ValueError('Emails must match')

            user_to_add = User(username, password1, email1, role='admin')
            DB.session.add(user_to_add)
        elif sys.argv[1] == 'drop':
Beispiel #3
0
def load_data(file_path):
    # Beware!
    DB.drop_all()
    db_commit()

    # In particular for Postgres to drop connections
    DB.session.close()

    DB.create_all()

    with open(file_path) as ff:
        objects = json.load(ff)

    # add users, keeping track of DB objects
    users = {}
    for user_name in objects['users']:
        user = objects['users'][user_name]
        user = User(user['username'], user['password'], user['email'],
                    user['role'])
        users[user_name] = user
        DB.session.add(user)

    # add tags, keeping track of DB objects
    tags = {}
    for tag_str in objects['tags']:
        tag = objects['tags'][tag_str]

        tag = Tag(tag)
        tags[tag_str] = tag
        DB.session.add(tag)

    # add Resources, keeping track of DB objects
    resources = {}
    for resource_name in objects['resources']:
        resource = objects['resources'][resource_name]

        resource_tags = []
        for tag_str in resource['tags']:
            resource_tags.append(tags[tag_str])

        resource = Resource(users[resource['owner']],
                            resource['resource_type'], resource['title'],
                            resource['url'], resource_tags)

        resources[resource_name] = resource
        DB.session.add(resource)

    # add Probes, keeping track of DB objects
    probes = {}
    for probe_name in objects['probe_vars']:
        probe = objects['probe_vars'][probe_name]

        probe = ProbeVars(
            resources[probe['resource']],
            probe['probe_class'],
            probe['parameters'],
        )

        probes[probe_name] = probe
        DB.session.add(probe)

    # add Checks, keeping track of DB objects
    checks = {}
    for check_name in objects['check_vars']:
        check = objects['check_vars'][check_name]

        check = CheckVars(
            probes[check['probe_vars']],
            check['check_class'],
            check['parameters'],
        )

        checks[check_name] = check
        DB.session.add(check)

    db_commit()
    DB.session.close()