Marnen Laibow-Koser wrote:
> Josh Stevenson wrote:
> [...]
>> On that line is this:
>> proivisioner = GAppsProvisioning::ProvisioningAPI.new(p_domain, 
>> p_username, p_password)
> 
> And are those classes defined anywhere?
> 
> Best,
> --
> Marnen Laibow-Koser
> http://www.marnen.org
> marnen / marnen.org

Yes.
Here is the entire script.
ENV['RAILS_ENV'] = 'production'
require '/usr/home/admin/rails/nusers/config/environment'
require 'gappsprovisioning/provisioningapi'
include GAppsProvisioning

dual = ARGV.first == '--dual'

# don't waste time with syncing password changes
CONFIG["auth_plugins"]["enable"] = 'f'

# dup'd from auth_plugins.rb
p_domain   = CONFIG['auth_plugins']['google']['domain']
p_username = CONFIG['auth_plugins']['google']['username']
p_password = CONFIG['auth_plugins']['google']['password']

proivisioner = GAppsProvisioning::ProvisioningAPI.new(p_domain, 
p_username, p_password)

while username = $stdin.gets
  username.chomp!
  user = User.find_by_uname(username)

  unless user
    $stderr.puts "#{username} not found"
    next
  end

  # if their password doesn't meet requirements, gen a temp one
  # and use that to create the google account if necessary.
  # once the google account is created, the user can change their
  # password with the new reqs and their google account will update
  if user.pass.blank? || user.pass.length < 6
    $stderr.puts "#{username} needs to change their password"
    google_pass = Password.phonemic(8,Password::ONE_DIGIT)
  else
    # otherwise just use their normal password
    google_pass = user.pass
  end

  # where to send mail so it lands in the user's google account
  google_destination = "#{user.uname}@extmail.yumaed.org"

  # where to send mail so it lands in both the user's google account
  # and their IMAP account
  dual_destination   = [google_destination, user.mail].join(',')

  # if user is already set up to have their mail sent to google,
  # skip them. this lets us run this script multiple times with
  # the same usernames.
  next if user.mail_destination == google_destination

  # create an account if necessary
  begin
    unless proivisioner.retrieve_user(user.uname)
      proivisioner.create_user(user.fname, user.lname, google_pass, 
user.uname)
    end
  rescue => e
    $stderr.puts "#{username} trouble creating google account: #{e}"
    next
  end

  # unless the --dual argument was given, send the user's mail
  # just to google. otherwise, do dual delivery.
  unless dual
    destination = google_destination
  else
    destination = dual_destination
  end

  # set their destination to what we decided on
  user.mail_destination = destination

  if user.save
    puts "#{username} updated (#{user.mail_destination})"
  else
    $stderr.puts "#{username} problem saving: 
#{user.errors.full_messages.join(' / ')}"
  end
end
-- 
Posted via http://www.ruby-forum.com/.