Example #1
0
def library_import(args, l, config):
    import json
    from ambry.library.config import LibraryConfigSyncProxy
    from ambry.orm import Account
    from simplecrypt import encrypt, decrypt, DecryptionException

    try:
        jsn = decrypt(args.password, args.config_file.read().decode('base64'))
    except DecryptionException as e:
        fatal(e)
    finally:
        args.config_file.close()

    args.config_file.close()

    d = json.loads(jsn)

    for k, v in d['accounts'].items():
        if v.get('major_type') != 'user' and 'encrypted_secret' in v:
            v['secret'] = Account.sym_decrypt(args.password,
                                              v['encrypted_secret'])

    if args.list:
        prt_no_format(json.dumps(d, indent=4))
    else:
        lcsp = LibraryConfigSyncProxy(l)

        lcsp.sync_remotes(d['remotes'], cb=l.logger.info)
        lcsp.sync_accounts(d['accounts'], cb=l.logger.info)

        for vid, v in d['bundles'].items():
            l.logger.info("Check in remote bundle {}, {}".format(
                vid, v['vname']))
            l.checkin_remote_bundle(vid)
Example #2
0
def library_import(args, l, config):
    import json
    from ambry.library.config import LibraryConfigSyncProxy
    from ambry.orm import Account
    from simplecrypt import encrypt, decrypt, DecryptionException

    try:
        jsn = decrypt(args.password, args.config_file.read().decode('base64'))
    except DecryptionException as e:
        fatal(e)
    finally:
        args.config_file.close()

    args.config_file.close()

    d = json.loads(jsn)

    for k, v in d['accounts'].items():
        if v.get('major_type') != 'user' and 'encrypted_secret' in v:
            v['secret'] = Account.sym_decrypt(args.password, v['encrypted_secret'])

    if args.list:
        prt_no_format(json.dumps(d, indent=4))
    else:
        lcsp = LibraryConfigSyncProxy(l)

        lcsp.sync_remotes(d['remotes'], cb=l.logger.info)
        lcsp.sync_accounts(d['accounts'], cb=l.logger.info)

        for vid, v in d['bundles'].items():
            l.logger.info("Check in remote bundle {}, {}".format(vid, v['vname']))
            l.checkin_remote_bundle(vid)
Example #3
0
def admin_remotes():
    import yaml

    from ambry.library.config import LibraryConfigSyncProxy

    if not current_user.is_admin:
        abort(403)

    if request.method == "POST":

        if request.form['config']:
            try:

                d = yaml.load(request.form['config'])

                if 'remotes' in d:
                    d = d['remotes']

                lcsp = LibraryConfigSyncProxy(aac.library)
                lcsp.sync_remotes(d)

                flash('Loaded {} remotes'.format(len(d)), 'success')

            except Exception as e:
                flash(str(e), 'error')

        if request.form.get('delete'):
            aac.library.delete_remote(request.form['delete'])

        if request.form.get('update'):
            from ambry.orm.remote import RemoteAccessError
            if request.form['update'] == 'all':
                for r in aac.library.remotes:
                    try:
                        r.update()
                        aac.library.commit()
                    except RemoteAccessError as e:
                        flash("Update Error: {}".format(e), 'error')

            else:
                r = aac.library.remote(request.form['update'])
                try:
                    r.update()
                    aac.library.commit()
                except RemoteAccessError as e:
                    flash("Update Error: {}".format(e), 'error')

        if request.form.get('install'):
            aac.library.checkin_remote_bundle(request.form['install'])
            b = aac.library.bundle(request.form['install'])
            flash("Installed bundle {}".format(b.identity.vname), 'success')

    cxt = dict(
        remotes=[r for r in aac.library.remotes],
        **aac.cc
    )

    return aac.render('admin/remotes.html', **cxt)
Example #4
0
def admin_remotes():
    import yaml

    from ambry.library.config import LibraryConfigSyncProxy

    if not current_user.is_admin:
        abort(403)

    if request.method == "POST":

        if request.form['config']:
            try:

                d = yaml.load(request.form['config'])

                if 'remotes' in d:
                    d = d['remotes']

                lcsp = LibraryConfigSyncProxy(aac.library)
                lcsp.sync_remotes(d)

                flash('Loaded {} remotes'.format(len(d)), 'success')

            except Exception as e:
                flash(str(e), 'error')

        if request.form.get('delete'):
            aac.library.delete_remote(request.form['delete'])

        if request.form.get('update'):
            from ambry.orm.remote import RemoteAccessError
            if request.form['update'] == 'all':
                for r in aac.library.remotes:
                    try:
                        r.update()
                        aac.library.commit()
                    except RemoteAccessError as e:
                        flash("Update Error: {}".format(e), 'error')

            else:
                r = aac.library.remote(request.form['update'])
                try:
                    r.update()
                    aac.library.commit()
                except RemoteAccessError as e:
                    flash("Update Error: {}".format(e), 'error')

        if request.form.get('install'):
            aac.library.checkin_remote_bundle(request.form['install'])
            b = aac.library.bundle(request.form['install'])
            flash("Installed bundle {}".format(b.identity.vname), 'success')

    cxt = dict(remotes=[r for r in aac.library.remotes], **aac.cc)

    return aac.render('admin/remotes.html', **cxt)