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 admin_accounts():

    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 'accounts' in d:
                    d = d['accounts']

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

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

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

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

    cxt = dict(
        accounts=[ a for a in aac.library.accounts.values() if a['major_type'] != 'user'],
        **aac.cc
    )

    return aac.render('admin/accounts.html',  **cxt)
Example #3
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 #4
0
def admin_accounts():

    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 'accounts' in d:
                    d = d['accounts']

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

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

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

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

    cxt = dict(accounts=[
        a for a in aac.library.accounts.values() if a['major_type'] != 'user'
    ],
               **aac.cc)

    return aac.render('admin/accounts.html', **cxt)
Example #5
0
def config_accounts_put():
    from ambry.orm.account import AccountDecryptionError, MissingPasswordError

    from ambry.library.config import LibraryConfigSyncProxy

    l = aac.library

    lsp = LibraryConfigSyncProxy(aac.library)

    try:

        lsp.sync_accounts(request.get_json())
    except MissingPasswordError:
        print 'Missing Password'
        abort(400)
    except AccountDecryptionError:
        print "Decryption Failed"
        abort(400)

    return aac.json(
        accounts={k: proc_account(a)
                  for k, a in aac.library.accounts.items()})
Example #6
0
def config_accounts_put():
    from ambry.orm.account import AccountDecryptionError, MissingPasswordError

    from ambry.library.config import LibraryConfigSyncProxy

    l = aac.library

    lsp = LibraryConfigSyncProxy(aac.library)

    try:

        lsp.sync_accounts(request.get_json())
    except MissingPasswordError:
        print 'Missing Password'
        abort(400)
    except AccountDecryptionError:
        print "Decryption Failed"
        abort(400)


    return aac.json(
        accounts={k: proc_account(a) for k, a in aac.library.accounts.items()}
    )