Skip to content

Instantly share code, notes, and snippets.

@paulmooring
Last active December 10, 2015 21:28
Show Gist options
  • Save paulmooring/4495364 to your computer and use it in GitHub Desktop.
Save paulmooring/4495364 to your computer and use it in GitHub Desktop.
run orgmapper scripts
#!/usr/bin/env ruby
require 'rubygems'
require "bundler/setup"
$:.unshift(File.dirname(__FILE__) + '/../lib/')
require 'orgmapper'
require 'orgmapper/config'
config_file = ARGV.first
if ARGV.length == 2
config_file = ARGV[0]
om_script = ARGV[1]
elsif ARGV.length == 1
config_file = '/etc/opscode/orgmapper.conf'
om_script = ARGV[0]
else
puts "usage: #{$0} [orgmapper conf] script"
exit 1
end
Kernel.load(File.expand_path(config_file))
raise ArgumentError, "CouchDB URL need to begin with http://" unless OrgMapper::Config.instance.couchdb_uri.include?("http://")
raise ArgumentError, "AuthZ URL needs to begin with http://" unless OrgMapper::Config.instance.auth_uri.include?("http://")
PLATFORM_BACKEND = OrgMapper::Backend.new(*OrgMapper::Config.instance.to_ary)
ORGS = OrgMapper::Organizations.new
USERS = OrgMapper::Users.new
GLOBAL_GROUPS = OrgMapper::GlobalGroups.new
GLOBAL_CONTAINERS = OrgMapper::GlobalContainers.new
module Opscode
class OrgMapperScript
def run(script)
eval ::File.read(script)
end
end
end
if __FILE__ == $0
Opscode::OrgMapperScript.new.run(om_script)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment