Exemplo n.º 1
0
def run(opts, **kw):

    # parse paths
    if not '/' in opts.module_name:
        root_dir = here('.')
        _slug = slug(opts.module_name)
    else:
        parts = opts.module_name.split('/')
        root_dir = "/".join(parts[:1])
        _slug = slug(parts[-1])

    kw.update({
        'root_dir': root_dir,
        'name': _slug.replace('-', '_'),
        'slug': _slug,
        'description': opts.description,
        'github_user': opts.github_user,
        'author': opts.author,
        'update': opts.update
    })
    if opts.template:
        kw['tmpl_dir'] = opts.template
    log.info(
        'Creating Sous Chef Module: {}'.format(opts.module_name))
    sc_module.create(**kw)
Exemplo n.º 2
0
 def __init__(self, **kw):
     self.org_id = kw.get('org_id')
     self.name = kw.get('name')
     self.slug = kw.get('slug', slug(kw.get('name')))
     self.template = kw.get('template')
     self.format = kw.get('format')
     self.data = kw.get('data')
Exemplo n.º 3
0
 def __init__(self, **kw):
     self.org_id = kw.get('org_id')
     self.name = kw.get('name')
     self.slug = kw.get('slug', slug(kw.get('name')))
     self.template = kw.get('template')
     self.format = kw.get('format')
     self.data = kw.get('data')
Exemplo n.º 4
0
 def __init__(self, **kw):
     self.org_id = kw.get('org_id')
     self.name = kw.get('name')
     self.slug = slug(kw.get('slug', kw['name']))
     self.type = kw.get('type')
     self.color = kw.get('color')
     self.category = kw.get('category')
     self.level = kw.get('level')
Exemplo n.º 5
0
 def __init__(self, **kw):
     self.org_id = kw.get("org_id")
     self.name = kw.get("name")
     self.slug = slug(kw.get("slug", kw["name"]))
     self.type = kw.get("type")
     self.color = kw.get("color")
     self.category = kw.get("category")
     self.level = kw.get("level")
Exemplo n.º 6
0
def run(opts, **kw):

    # parse paths
    if not '/' in opts.module_name:
        root_dir = here('.')
        _slug = slug(opts.module_name)
    else:
        parts = opts.module_name.split('/')
        root_dir = "/".join(parts[:1])
        _slug = slug(parts[-1])

    kw.update({
        'root_dir': root_dir,
        'name': _slug.replace('-', '_'),
        'slug': _slug,
        'description': opts.description,
        'github_user': opts.github_user,
        'author': opts.author,
        'update': opts.update
    })
    if opts.template:
        kw['tmpl_dir'] = opts.template
    log.info('Creating Sous Chef Module: {}'.format(opts.module_name))
    sc_module.create(**kw)
Exemplo n.º 7
0
def gen_org(users):

    # create the org and super user
    org = Org.query.filter_by(name=settings.SUPER_USER_ORG).first()
    if not org:
        org = Org(name=settings.SUPER_USER_ORG,
                  timezone=settings.SUPER_USER_ORG_TIMEZONE)
    else:
        org.timezone = settings.SUPER_USER_ORG_TIMEZONE
        org.name = settings.SUPER_USER_ORG
        org.slug = slug(settings.SUPER_USER_ORG)
    for u in users:
        if u.id not in org.user_ids:
            org.users.append(u)
    db.session.add(org)
    db.session.commit()
    return org
Exemplo n.º 8
0
def gen_org(users):

    # create the org and super user
    org = Org.query.filter_by(name=settings.SUPER_USER_ORG).first()
    if not org:
        org = Org(name=settings.SUPER_USER_ORG,
                  timezone=settings.SUPER_USER_ORG_TIMEZONE)
    else:
        org.timezone = settings.SUPER_USER_ORG_TIMEZONE
        org.name = settings.SUPER_USER_ORG
        org.slug = slug(settings.SUPER_USER_ORG)
    for u in users:
        if u.id not in org.user_ids:
            org.users.append(u)
    db.session.add(org)
    db.session.commit()
    return org
Exemplo n.º 9
0
def org_update(user, org_id):

    req_data = request_data()

    # fetch org
    org = fetch_by_id_or_field(Org, 'slug', org_id)

    # if the org doesnt exist, create it.
    if not org:
        raise NotFoundError(
            'Org {} does not exist.'.format(org_id))

    if user.id not in org.user_ids:
        raise ForbiddenError(
            "You are not allowed to access this Org.")

    # localize
    localize(org)

    # update the requesting user to the org
    if 'name' in req_data:
        org.name = req_data['name']

    if 'slug' in req_data:
        org.slug = req_data['slug']

    elif 'name' in req_data:
        org.slug = slug(req_data['name'])

    if 'timezone' in req_data:
        org.timezone = req_data['timezone']

    try:
        db.session.add(org)
        db.session.commit()

    except Exception as e:
        raise RequestError(
            "An error occurred while updating this Org '{}'. "
            "Here's the error message: {}"
            .format(org.name, e.message))

    return jsonify(org)
Exemplo n.º 10
0
    def __init__(self, **kw):

        # set columns
        self.org_id = kw.get('org_id')
        self.name = kw.get('name')
        self.slug = slug(kw.get('slug', kw['name']))
        self.description = kw.get('description')
        self.runs = kw.get('runs')
        self.filepath = kw.get('filepath')
        self.is_command = kw.get('is_command')
        if self.is_command:
            self.filepath = kw.get('runs')
        self.creates = kw.get('creates', 'null')
        if not self.creates:
            self.creates = 'null'
        self.required_auths = kw.get('requires_auths', [])
        self.required_settings = kw.get('requires_settings', [])
        self.option_order = kw.get('option_order', [])
        self.options = kw.get('options', {})
        self.metrics = kw.get('metrics', {})
Exemplo n.º 11
0
    def __init__(self, **kw):

        # set columns
        self.org_id = kw.get('org_id')
        self.name = kw.get('name')
        self.slug = slug(kw.get('slug', kw['name']))
        self.description = kw.get('description')
        self.runs = kw.get('runs')
        self.filepath = kw.get('filepath')
        self.is_command = kw.get('is_command')
        if self.is_command:
            self.filepath = kw.get('runs')
        self.creates = kw.get('creates', 'null')
        if not self.creates:
            self.creates = 'null'
        self.required_auths = kw.get('requires_auths', [])
        self.required_settings = kw.get('requires_settings', [])
        self.option_order = kw.get('option_order', [])
        self.options = kw.get('options', {})
        self.metrics = kw.get('metrics', {})
Exemplo n.º 12
0
def org(
        name=settings.SUPER_USER_ORG,
        timezone=settings.SUPER_USER_ORG_TIMEZONE,
        email=settings.SUPER_USER_EMAIL):

    # create the org and super user
    org = Org.query.filter_by(name=name).first()
    if not org:
        log.info('Creating org: "{}"'.format(name))
        org = Org(name=name, timezone=timezone)
    else:
        log.warning('Updating org: "{}"'.format(name))
        org.timezone = timezone
        org.name = name
        org.slug = slug(unicode(name))

    # create the super user and add to the org.
    u = User.query.filter_by(email=email).first()
    if not u:
        log.info('Creating super user: "******"'.format(email))
        u = User(name=settings.SUPER_USER,
                 email=settings.SUPER_USER_EMAIL,
                 password=settings.SUPER_USER_PASSWORD,
                 admin=True,
                 super_user=True)
        u.apikey = settings.SUPER_USER_APIKEY

    else:
        log.warning('Updating super user: "******"'.format(email))
        u.apikey = settings.SUPER_USER_APIKEY
        u.email = settings.SUPER_USER_EMAIL
        u.password = settings.SUPER_USER_PASSWORD
        u.admin = True
        u.super_user = True
    org.users.append(u)
    db.session.add(org)
    db.session.commit()
    tags(org)
    sous_chefs(org)
    recipes(org)
    return org
Exemplo n.º 13
0
def org_update(user, org_id):

    req_data = request_data()

    # fetch org
    org = fetch_by_id_or_field(Org, 'slug', org_id)

    # if the org doesnt exist, create it.
    if not org:
        raise NotFoundError('Org {} does not exist.'.format(org_id))

    if user.id not in org.user_ids:
        raise ForbiddenError("You are not allowed to access this Org.")

    # localize
    localize(org)

    # update the requesting user to the org
    if 'name' in req_data:
        org.name = req_data['name']

    if 'slug' in req_data:
        org.slug = req_data['slug']

    elif 'name' in req_data:
        org.slug = slug(req_data['name'])

    if 'timezone' in req_data:
        org.timezone = req_data['timezone']

    try:
        db.session.add(org)
        db.session.commit()

    except Exception as e:
        raise RequestError("An error occurred while updating this Org '{}'. "
                           "Here's the error message: {}".format(
                               org.name, e.message))

    return jsonify(org)
Exemplo n.º 14
0
def org(name=settings.SUPER_USER_ORG,
        timezone=settings.SUPER_USER_ORG_TIMEZONE,
        email=settings.SUPER_USER_EMAIL):

    # create the org and super user
    org = Org.query.filter_by(name=name).first()
    if not org:
        log.info('Creating org: "{}"'.format(name))
        org = Org(name=name, timezone=timezone)
    else:
        log.warning('Updating org: "{}"'.format(name))
        org.timezone = timezone
        org.name = name
        org.slug = slug(unicode(name))

    # create the super user and add to the org.
    u = User.query.filter_by(email=email).first()
    if not u:
        log.info('Creating super user: "******"'.format(email))
        u = User(name=settings.SUPER_USER,
                 email=settings.SUPER_USER_EMAIL,
                 password=settings.SUPER_USER_PASSWORD,
                 admin=True,
                 super_user=True)
        u.apikey = settings.SUPER_USER_APIKEY

    else:
        log.warning('Updating super user: "******"'.format(email))
        u.apikey = settings.SUPER_USER_APIKEY
        u.email = settings.SUPER_USER_EMAIL
        u.password = settings.SUPER_USER_PASSWORD
        u.admin = True
        u.super_user = True
    org.users.append(u)
    db.session.add(org)
    db.session.commit()
    tags(org)
    sous_chefs(org)
    recipes(org)
    return org
Exemplo n.º 15
0
    def __init__(self, sous_chef, **kw):
        """
        A recipe must be initialized with an existing sous chef.
        """
        # core fields
        self.name = kw.get('name')
        self.slug = slug(kw.get('slug', kw['name']))
        self.description = kw.get('description')
        self.schedule_by = kw.get('schedule_by', 'unscheduled')
        self.crontab = kw.get('crontab')
        self.time_of_day = kw.get('time_of_day')
        self.minutes = kw.get('minutes')
        self.status = kw.get('status', 'stable')
        self.traceback = kw.get('traceback')
        self.set_options(kw.get('options', {}))

        # internal fields
        self.sous_chef_id = sous_chef.id
        self.user_id = kw.get('user_id')
        self.org_id = kw.get('org_id')
        self.last_run = kw.get('last_run', None)
        self.last_job = kw.get('last_job', {})
Exemplo n.º 16
0
def update_template(user, org, slug_id):

    t = fetch_by_id_or_field(Template, 'slug', slug_id, org_id=org.id)
    if not t:
        raise NotFoundError(
            'Template "{}" does not yet exist for Org "{}"'.format(
                slug_id, org.name))

    # get the request data
    req_data = request_data()

    name = req_data.get('name')
    slug = req_data.get('slug')
    template = req_data.get('template')
    format = req_data.get('format')
    if name:
        t.name = name
    if slug:
        t.slug = slug
    elif name:
        t.slug = slug(name)
    if template:
        try:
            tmpl = Tmpl(template)
        except Exception as e:
            raise RequestError('This template is invalid: {}'.format(
                e.message))
        t.template = template
    if format:
        t.format = format

    # no duplicates.
    try:
        db.session.add(t)
        db.session.commit()
    except Exception as e:
        raise RequestError(e.message)
    return jsonify(t)
Exemplo n.º 17
0
def update_template(user, org,slug_id):

    t = fetch_by_id_or_field(Template, 'slug', slug_id, org_id=org.id)
    if not t:
        raise NotFoundError(
            'Template "{}" does not yet exist for Org "{}"'
            .format(slug_id, org.name))

    # get the request data
    req_data = request_data()

    name = req_data.get('name')
    slug = req_data.get('slug')
    template = req_data.get('template')
    format = req_data.get('format')
    if name:
        t.name = name
    if slug:
        t.slug = slug
    elif name:
        t.slug = slug(name)
    if template:
        try:
            tmpl = Tmpl(template)
        except Exception as e:
            raise RequestError('This template is invalid: {}'.format(e.message))
        t.template = template
    if format:
        t.format = format

    # no duplicates.
    try:
        db.session.add(t)
        db.session.commit()
    except Exception as e:
        raise RequestError(e.message)
    return jsonify(t)
Exemplo n.º 18
0
 def __init__(self, **kw):
     self.name = kw.get('name')
     self.timezone = kw.get('timezone', 'UTC')
     self.slug = kw.get('slug', slug(kw['name']))
Exemplo n.º 19
0
 def __init__(self, **kw):
     self.name = kw.get('name')
     self.timezone = kw.get('timezone', 'UTC')
     self.slug = kw.get('slug', slug(kw['name']))
Exemplo n.º 20
0
 def get_tags(self, entry):
     """
     Get all tags.
     """
     tags = self.get_candidates(entry, TAG_CANDIDATE_JSONPATH)
     return uniq([slug(t) for t in tags if t and t.strip() != ""])