Example #1
0
def main():
    identity, password, admin_group_id = setup.load_identity()
    group_source_id = setup.GROUP_SOURCE_ID + identity

    print 'Synchronizing groups from Google ...'
    groups_json = setup.sync()

    print 'Pushing groups to Mitro ...'
    args = ('--gid', str(admin_group_id), 'upload_groups', group_source_id)
    output, success = setup.mitro(identity,
                                  password,
                                  args,
                                  stdin_data=groups_json)
    if not success:
        sys.stderr.write('Failed to push groups\n')
        return 1

    print 'Updating groups to reflect changes ...'
    args = ('--gid', str(admin_group_id), 'sync_groups', group_source_id)
    output, success = setup.mitro(identity, password, args)
    if not success:
        sys.stderr.write('Failed to synchronize groups\n')
        return 1
    print 'SUCCESS'
    return 0
Example #2
0
def main(sync_password):
    db_connection = psycopg2.connect(POSTGRES_CONNECTION)

    # Tell the server to sync all domains
    print 'synchronizing with google ...'
    response = request_json('/api/groups/sync', {})

    # For every domain, push the groups to mitro
    success = True
    for domain, admin_emails in response.iteritems():
        if len(admin_emails) == 0:
            print 'warning: domain %s has no administrators; skipping' % (
                domain)
            continue

        # Get the group ID for the first admin user, sorted alphabetically
        admin_emails.sort()
        admin = admin_emails[0]
        group_source_scope = 'gapps://' + urllib.quote(domain)
        print 'pushing data for domain %s with admin user %s' % (domain, admin)

        # Find this user's private group
        # TODO: This is a HORRIBLY UGLY HACK; make an API?
        admin_group_id = get_private_group_id(db_connection, admin)

        # Get the groups for this domain
        args = {'domain': domain}
        try:
            groups = request_json('/api/groups/dictionary?' +
                                  urllib.urlencode(args))
        except urllib2.HTTPError, e:
            if e.code == 404 and e.reason == 'no groups for domain':
                # No groups were selected for this domain; skip it
                print 'warning: domain %s has no groups; skipping' % (domain)
                continue
            # Any other exception: crash
            raise

        # Push to mitro
        print 'pushing %d pending groups to Mitro ...' % (len(groups))
        args = ('--gid', str(admin_group_id), 'upload_groups',
                group_source_scope)
        output, success = setup.mitro(SYNC_ID,
                                      sync_password,
                                      args,
                                      stdin_data=json.dumps(groups))
        if not success:
            sys.stderr.write('Failed to push groups for domain %s admin %s\n' %
                             (domain, admin))
            print 'Command error output:', output
            print
            success = False
Example #3
0
def main():
    identity, password, admin_group_id = setup.load_identity()
    group_source_id = setup.GROUP_SOURCE_ID + identity

    print 'Synchronizing groups from Google ...'
    groups_json = setup.sync()

    print 'Pushing groups to Mitro ...'
    args = ('--gid', str(admin_group_id), 'upload_groups', group_source_id)
    output, success = setup.mitro(identity, password, args, stdin_data=groups_json)
    if not success:
        sys.stderr.write('Failed to push groups\n')
        return 1

    print 'Updating groups to reflect changes ...'
    args = ('--gid', str(admin_group_id), 'sync_groups', group_source_id)
    output, success = setup.mitro(identity, password, args)
    if not success:
        sys.stderr.write('Failed to synchronize groups\n')
        return 1
    print 'SUCCESS'
    return 0