Permalink
Browse files

Merge branch 'services-r7' into fileservice

Change-Id: Ie7e02d2f54eb8047dada15035af4f76fe6c14356
  • Loading branch information...
2 parents 3254211 + ed73c6b commit 8b43963f03553aecb311ec9ea6591eba748da4b6 Tang Rui committed Dec 2, 2011
Showing with 3,845 additions and 74 deletions.
  1. +2 −2 README.md
  2. +1 −1 cloud_controller/Gemfile
  3. +3 −3 cloud_controller/Gemfile.lock
  4. +1 −1 cloud_controller/app/controllers/apps_controller.rb
  5. +2 −1 cloud_controller/app/controllers/users_controller.rb
  6. +10 −0 cloud_controller/app/models/user.rb
  7. +44 −1 cloud_controller/config/appconfig.rb
  8. +2 −2 cloud_controller/config/cloud_controller.yml
  9. +1 −0 cloud_controller/config/final_stage/activate.rb
  10. +9 −0 cloud_controller/config/final_stage/bootstrap_users.rb
  11. +44 −0 cloud_controller/spec/controllers/users_controller_spec.rb
  12. +27 −0 cloud_controller/spec/models/user_spec.rb
  13. BIN cloud_controller/vendor/cache/eventmachine-0.12.11.cloudfoundry.2.gem
  14. +84 −0 common/bin/pool_tool
  15. +48 −0 common/lib/vcap/close_fds
  16. +61 −0 common/lib/vcap/em_run.rb
  17. +47 −0 common/lib/vcap/user_pools/user_ops.rb
  18. +46 −0 common/lib/vcap/user_pools/user_pool.rb
  19. +107 −0 common/lib/vcap/user_pools/user_pool_util.rb
  20. +8 −0 common/spec/spec_helper.rb
  21. +14 −0 common/spec/unit/em_fiber_wrap.rb
  22. +27 −0 common/spec/unit/user_ops_spec.rb
  23. +32 −0 common/spec/unit/user_pool_spec.rb
  24. +31 −0 common/spec/unit/user_pool_util_spec.rb
  25. +1 −1 dea/Gemfile
  26. +3 −3 dea/Gemfile.lock
  27. BIN dea/vendor/cache/eventmachine-0.12.11.cloudfoundry.2.gem
  28. +1 −0 dev_setup/bin/vcap_dev
  29. +1 −0 dev_setup/cookbooks/ccdb/attributes/default.rb
  30. +8 −0 dev_setup/cookbooks/cloud_controller/attributes/default.rb
  31. +7 −7 dev_setup/cookbooks/cloud_controller/templates/default/cloud_controller.yml.erb
  32. +22 −0 dev_setup/cookbooks/cloud_controller/templates/default/php.yml.erb
  33. +5 −1 dev_setup/cookbooks/dea/attributes/default.rb
  34. +13 −6 dev_setup/cookbooks/dea/templates/default/dea.yml.erb
  35. +2 −2 dev_setup/cookbooks/health_manager/templates/default/health_manager.yml.erb
  36. +7 −0 dev_setup/cookbooks/php/README.rdoc
  37. +3 −0 dev_setup/cookbooks/php/attributes/default.rb
  38. +6 −0 dev_setup/cookbooks/php/metadata.rb
  39. +70 −0 dev_setup/cookbooks/php/recipes/default.rb
  40. +5 −0 dev_setup/cookbooks/php/templates/default/apache2.cnf.erb
  41. +1 −1 health_manager/Gemfile
  42. +3 −3 health_manager/Gemfile.lock
  43. BIN health_manager/vendor/cache/eventmachine-0.12.11.cloudfoundry.2.gem
  44. BIN health_manager/vendor/cache/vcap_logging-0.1.0.gem
  45. BIN health_manager/vendor/cache/vcap_logging-0.1.3.gem
  46. +15 −0 package_cache/Gemfile
  47. +70 −0 package_cache/README
  48. +55 −0 package_cache/TODO
  49. +48 −0 package_cache/bin/close_fds
  50. +21 −0 package_cache/bin/package_cache
  51. +7 −0 package_cache/config/dev.yml
  52. +100 −0 package_cache/lib/vcap/package_cache.rb
  53. +42 −0 package_cache/lib/vcap/package_cache/builder.rb
  54. +68 −0 package_cache/lib/vcap/package_cache/cache.rb
  55. +27 −0 package_cache/lib/vcap/package_cache/cache_client.rb
  56. +69 −0 package_cache/lib/vcap/package_cache/client.rb
  57. +53 −0 package_cache/lib/vcap/package_cache/config.rb
  58. +22 −0 package_cache/lib/vcap/package_cache/debug_formatter.rb
  59. +14 −0 package_cache/lib/vcap/package_cache/em_fiber_wrap.rb
  60. +7 −0 package_cache/lib/vcap/package_cache/errors.rb
  61. +85 −0 package_cache/lib/vcap/package_cache/gem_builder.rb
  62. +119 −0 package_cache/lib/vcap/package_cache/inbox.rb
  63. +12 −0 package_cache/lib/vcap/package_cache/pkg_util.rb
  64. +102 −0 package_cache/lib/vcap/package_cache/server.rb
  65. +16 −0 package_cache/spec/Rakefile
  66. BIN package_cache/spec/fixtures/fluentxml-0.1.1.pip
  67. BIN package_cache/spec/fixtures/yajl-ruby-0.8.2.gem
  68. +10 −0 package_cache/spec/functional/10_valid.txt
  69. +42 −0 package_cache/spec/functional/e2e_test
  70. +10 −0 package_cache/spec/functional/first_10.txt
  71. +40 −0 package_cache/spec/functional/gem_list.txt
  72. +75 −0 package_cache/spec/functional/load_test
  73. +31 −0 package_cache/spec/spec_helper.rb
  74. +30 −0 package_cache/spec/unit/cache_spec.rb
  75. +12 −0 package_cache/spec/unit/config_spec.rb
  76. +52 −0 package_cache/spec/unit/gem_builder_spec.rb
  77. +42 −0 package_cache/spec/unit/inbox_spec.rb
  78. +8 −0 package_cache/spec/unit/spec_helper.rb
  79. BIN package_cache/vendor/cache/addressable-2.2.6.gem
  80. BIN package_cache/vendor/cache/async_sinatra-0.5.0.gem
  81. BIN package_cache/vendor/cache/daemons-1.1.4.gem
  82. BIN package_cache/vendor/cache/diff-lcs-1.1.3.gem
  83. BIN package_cache/vendor/cache/em-http-request-1.0.0.beta.3.gem
  84. BIN package_cache/vendor/cache/em-socksify-0.1.0.gem
  85. BIN package_cache/vendor/cache/eventmachine-0.12.10.gem
  86. BIN package_cache/vendor/cache/eventmachine-0.12.11.cloudfoundry.1.gem
  87. BIN package_cache/vendor/cache/http_parser.rb-0.5.1.gem
  88. BIN package_cache/vendor/cache/http_parser.rb-0.5.3.gem
  89. BIN package_cache/vendor/cache/json_pure-1.5.3.gem
  90. BIN package_cache/vendor/cache/json_pure-1.6.1.gem
  91. BIN package_cache/vendor/cache/little-plugger-1.1.2.gem
  92. BIN package_cache/vendor/cache/little-plugger-1.1.3.gem
  93. BIN package_cache/vendor/cache/logging-1.6.0.gem
  94. BIN package_cache/vendor/cache/logging-1.6.1.gem
  95. BIN package_cache/vendor/cache/mime-types-1.16.gem
  96. BIN package_cache/vendor/cache/mime-types-1.17.2.gem
  97. BIN package_cache/vendor/cache/nats-0.4.10.gem
  98. BIN package_cache/vendor/cache/posix-spawn-0.3.6.gem
  99. BIN package_cache/vendor/cache/rack-1.3.2.gem
  100. BIN package_cache/vendor/cache/rack-1.3.5.gem
  101. BIN package_cache/vendor/cache/rack-fiber_pool-0.9.2.gem
  102. BIN package_cache/vendor/cache/rack-protection-1.1.4.gem
  103. BIN package_cache/vendor/cache/rake-0.9.2.2.gem
  104. BIN package_cache/vendor/cache/rake-0.9.2.gem
  105. BIN package_cache/vendor/cache/rest-client-1.6.3.gem
  106. BIN package_cache/vendor/cache/rspec-2.6.0.gem
  107. BIN package_cache/vendor/cache/rspec-2.7.0.gem
  108. BIN package_cache/vendor/cache/rspec-core-2.6.4.gem
  109. BIN package_cache/vendor/cache/rspec-core-2.7.1.gem
  110. BIN package_cache/vendor/cache/rspec-expectations-2.6.0.gem
  111. BIN package_cache/vendor/cache/rspec-expectations-2.7.0.gem
  112. BIN package_cache/vendor/cache/rspec-mocks-2.6.0.gem
  113. BIN package_cache/vendor/cache/rspec-mocks-2.7.0.gem
  114. BIN package_cache/vendor/cache/sinatra-1.2.6.gem
  115. BIN package_cache/vendor/cache/sinatra-1.3.1.gem
  116. BIN package_cache/vendor/cache/thin-1.2.11.gem
  117. BIN package_cache/vendor/cache/thin-1.3.1.gem
  118. BIN package_cache/vendor/cache/tilt-1.3.3.gem
  119. BIN package_cache/vendor/cache/vcap_logging-0.1.1.gem
  120. BIN package_cache/vendor/cache/vcap_logging-0.1.3.gem
  121. BIN package_cache/vendor/cache/yajl-ruby-0.8.3.gem
  122. BIN package_cache/vendor/cache/yajl-ruby-1.1.0.gem
  123. +1 −1 router/Gemfile
  124. +3 −3 router/Gemfile.lock
  125. BIN router/vendor/cache/eventmachine-0.12.11.cloudfoundry.2.gem
  126. +1 −1 services
  127. +2 −3 setup/install
  128. +34 −31 setup/vcap_setup
  129. +5 −0 warden/.gitignore
  130. +9 −0 warden/Gemfile
  131. +138 −0 warden/README.md
  132. +16 −0 warden/Rakefile
  133. +18 −0 warden/TODO.md
  134. +28 −0 warden/bin/warden-repl
  135. +5 −0 warden/lib/warden.rb
  136. +117 −0 warden/lib/warden/client.rb
  137. +32 −0 warden/lib/warden/event_emitter.rb
  138. +99 −0 warden/lib/warden/network.rb
  139. +536 −0 warden/lib/warden/server.rb
  140. +3 −0 warden/lib/warden/version.rb
  141. +4 −0 warden/root/.gitignore
  142. +31 −0 warden/root/.instance-skeleton/config.erb
  143. +87 −0 warden/root/.instance-skeleton/setup.rb
  144. +26 −0 warden/root/.instance-skeleton/start.sh.erb
  145. +14 −0 warden/root/.instance-skeleton/stop.sh.erb
  146. +50 −0 warden/root/.lib/global.rb
  147. +48 −0 warden/root/.lib/mount_union.rb
  148. +22 −0 warden/root/000-base/setup.rb
  149. +31 −0 warden/root/001-apt/setup.rb
  150. +31 −0 warden/root/010-misc/setup.rb
  151. +12 −0 warden/root/chroot.rb
  152. +12 −0 warden/root/create.sh
  153. +7 −0 warden/root/setup.rb
  154. +43 −0 warden/spec/client_spec.rb
  155. +61 −0 warden/spec/network_spec.rb
  156. +102 −0 warden/spec/server_spec.rb
  157. +81 −0 warden/spec/spec_helper.rb
  158. +23 −0 warden/warden.gemspec
View
@@ -52,9 +52,9 @@ server VM.
* setup a VM with a pristine Ubuntu 10.04.2 server 64bit image,
[download here](http://www.ubuntu.com/download/ubuntu/download)
-* you may wish to snapshot your VM now in case things go pear shaped.
* setup your VM with 1G or more of memory
-* great snapshot spots are here and after step 4
+* you may wish to snapshot your VM now in case things go pear shaped
+ (great snapshot spots are here and after step 4)
* to enable remote access (more fun than using the console), install ssh.
To install ssh:
View
@@ -34,7 +34,7 @@ group :production do
end
# EventMachine and async support
-gem 'eventmachine', '~> 0.12.11.cloudfoundry.1'
+gem 'eventmachine', '~> 0.12.11.cloudfoundry.2'
gem 'thin', '> 1.2'
gem 'em-http-request', '~> 1.0.0.beta.3', :require => 'em-http'
gem 'em-redis', :require => nil
@@ -2,7 +2,7 @@ PATH
remote: ../common
specs:
vcap_common (0.99)
- eventmachine (~> 0.12.11.cloudfoundry.1)
+ eventmachine (~> 0.12.11.cloudfoundry.2)
logging (>= 1.5.0)
nats
posix-spawn
@@ -64,7 +64,7 @@ GEM
eventmachine
erubis (2.6.6)
abstract (>= 1.0.0)
- eventmachine (0.12.11.cloudfoundry.1)
+ eventmachine (0.12.11.cloudfoundry.2)
hiredis (0.3.2)
http_parser.rb (0.5.1)
i18n (0.5.0)
@@ -160,7 +160,7 @@ DEPENDENCIES
em-hiredis
em-http-request (~> 1.0.0.beta.3)
em-redis
- eventmachine (~> 0.12.11.cloudfoundry.1)
+ eventmachine (~> 0.12.11.cloudfoundry.2)
logging (>= 1.5.0)
mocha
mysql2 (>= 0.2.6)
@@ -49,7 +49,7 @@ def delete
end
def valid_upload_path?(path)
- File.join(CloudController.uploads_dir, File.basename(path)) == path
+ path.starts_with?(CloudController.uploads_dir)
end
def get_uploaded_file
@@ -76,7 +76,8 @@ def grab_event_user
def enforce_registration_policy
return if user && user.admin?
- if AppConfig[:local_register_only] && remote_request?
+ unless AppConfig[:allow_registration]
+ CloudController.logger.info("User registration is disabled but someone from #{request.remote_ip} is attempting to register the email '#{body_params[:email]}'.")
raise CloudError.new(CloudError::FORBIDDEN)
end
end
@@ -48,6 +48,16 @@ def from_token(user_token)
def all_email_addresses
connection.select_values "select email from users"
end
+
+ # Called at startup to seed the database with initial users
+ # if they do not yet exist.
+ def create_bootstrap_user(email, password, is_admin=false)
+ user = User.find_or_create_by_email(email)
+ user.set_and_encrypt_password(password)
+ user.save!
+ admins << email if is_admin
+ user
+ end
end
def set_and_encrypt_password(val)
@@ -34,7 +34,6 @@
:support_address => 'http://support.cloudfoundry.com',
:rails_environment => 'development',
:local_route => '127.0.0.1',
- :local_register_only => true,
:allow_external_app_uris => false,
:staging => { :max_concurrent_stagers => 10,
:max_staging_runtime => 60 },
@@ -187,3 +186,47 @@
$stderr.puts "You must supply a redis config to use the new stager"
exit 1
end
+
+if AppConfig[:bootstrap_users]
+ unless AppConfig[:bootstrap_users].kind_of?(Array)
+ $stderr.puts "List of bootstrap users must be an array"
+ exit 1
+ end
+
+ for user in AppConfig[:bootstrap_users]
+ unless user.kind_of?(Hash)
+ $stderr.puts "List elements of bootstrap users must be a hash"
+ exit 1
+ end
+
+ unless user.has_key?('email')
+ $stderr.puts "#{user.inspect} is missing an email address"
+ exit 1
+ end
+
+ unless user['email'].kind_of?(String)
+ $stderr.puts "Email for #{user.inspect} must be a string"
+ exit 1
+ end
+
+ unless user.has_key?('password')
+ $stderr.puts "#{user.inspect} is missing a password"
+ exit 1
+ end
+
+ unless user['password'].kind_of?(String)
+ $stderr.puts "Password for #{user.inspect} must be a string"
+ exit 1
+ end
+
+ if user['is_admin'] && !(user['is_admin'].kind_of?(TrueClass) || user['password'].kind_of?(FalseClass))
+ $stderr.puts "#{user.inspect} should have a bool for is_admin"
+ exit 1
+ end
+ end
+end
+
+unless AppConfig.has_key?(:allow_registration)
+ $stderr.puts "Allow registration not set, defaulting to true"
+ AppConfig[:allow_registration] = true
+end
@@ -10,8 +10,8 @@ support_address: http://support.cloudfoundry.com
# value of nil, should work in most cases.
local_route: 127.0.0.1
-# Specifies if new users can register only from the host that is running the cloud controller
-local_register_only: false
+# Specifies if new users are allowed to register via VMC
+allow_registration: true
# Allow applications to register URIs that are outside your domain.
# Legacy (FIXME REMOVE)
@@ -4,6 +4,7 @@
require dir.join('descriptor_table_size')
require dir.join('event_log')
require dir.join('check_database')
+require dir.join('bootstrap_users')
require dir.join('message_bus')
require dir.join('redis')
require dir.join('log_boot_completion')
@@ -0,0 +1,9 @@
+# Not sure if this is the correct place to be creating what are essentially seed users.
+# It seems like the right place for this is during 'rake db:seed', but this provides
+# a much nicer user experience.
+if AppConfig[:bootstrap_users]
+ for user in AppConfig[:bootstrap_users]
+ User.create_bootstrap_user(user['email'], user['password'], user['is_admin'])
+ CloudController.logger.info("Created user #{user['email']}")
+ end
+end
@@ -55,6 +55,44 @@
end
end
+ describe '#create' do
+ it 'should return 403 if the user is not an admin and registration is disabled' do
+ AppConfig[:allow_registration] = false
+ post_with_body :create do
+ { :email => 'foo@bar.com',
+ :password => 'testpass',
+ }
+ end
+ response.status.should == 403
+ end
+
+ it 'should create users if the user is an admin and registration is disabled' do
+ AppConfig[:allow_registration] = false
+ User.find_by_email('foo@bar.com').should be_nil
+ @admin.admin?.should be_true
+ @admin_headers.each {|key, value| request.env[key] = value}
+ post_with_body :create do
+ { :email => 'foo@bar.com',
+ :password => 'testpass',
+ }
+ end
+ response.status.should == 204
+ User.find_by_email('foo@bar.com').should_not be_nil
+ end
+
+ it 'should create users if the user is not an admin and registration is allowed' do
+ AppConfig[:allow_registration] = true
+ User.find_by_email('foo@bar.com').should be_nil
+ post_with_body :create do
+ { :email => 'foo@bar.com',
+ :password => 'testpass',
+ }
+ end
+ response.status.should == 204
+ User.find_by_email('foo@bar.com').should_not be_nil
+ end
+ end
+
describe "#list" do
it 'should return 200 as an admin' do
@admin.admin?.should be_true
@@ -101,4 +139,10 @@
User.find_by_email(@user.email).should_not be_nil
end
end
+
+ def post_with_body(*args, &blk)
+ body = yield
+ request.env['RAW_POST_DATA'] = Yajl::Encoder.encode(body)
+ post(*args)
+ end
end
@@ -127,6 +127,33 @@
end
end
+ describe '#create_bootstrap_user' do
+ before :each do
+ @email = 'foo@bar.com'
+ @pass = 'test'
+ end
+
+ it 'should create users if they do not exist' do
+ User.find_by_email(@email).should be_nil
+ User.create_bootstrap_user(@email, @pass).should_not be_nil
+ User.find_by_email(@email).should_not be_nil
+ end
+
+ it 'should update existing users' do
+ oldpass = 'test1'
+ newpass = 'test2'
+ create_user(@email, oldpass)
+ User.create_bootstrap_user(@email, newpass).should_not be_nil
+ User.valid_login?(@email, newpass).should be_true
+ end
+
+ it 'should update User.admins if the user is an admin' do
+ User.admins.include?(@email).should_not be_true
+ User.create_bootstrap_user(@email, @pass, true)
+ User.admins.include?(@email).should be_true
+ end
+ end
+
def create_user(email, pw)
u = User.new(:email => email)
u.set_and_encrypt_password(pw)
View
@@ -0,0 +1,84 @@
+#!/usr/bin/env ruby
+$:.unshift(File.join(File.dirname(__FILE__), '../lib/vcap/user_pools'))
+require 'optparse'
+require 'user_pool_util'
+
+module PoolTool
+ USAGE = 'usage: pool_tool [OPTIONS], try -h for more options'
+
+ class << self
+ def require_root
+ if Process.uid != 0
+ puts "This operation requires root privileges."
+ exit 1
+ end
+ end
+
+ def install_pool(name, size)
+ require_root
+ if not VCAP::UserPoolUtil.pool_exists?(name)
+ VCAP::UserPoolUtil.install_pool(name, size.to_i)
+ else
+ puts "Pool with name #{name} already exists, can't install."
+ exit 1
+ end
+ end
+
+ def remove_pool(name)
+ require_root
+ if VCAP::UserPoolUtil.pool_exists?(name)
+ VCAP::UserPoolUtil.remove_pool(name)
+ else
+ puts "No pool with name #{name}, can't do remove."
+ exit 1
+ end
+ end
+
+ def list_pools
+ list = VCAP::UserPoolUtil.pool_list
+ if list.size > 0
+ puts list
+ else
+ puts "No user pools found."
+ end
+ end
+
+ def parse_options
+ options = OptionParser.new do |opts|
+ opts.banner = USAGE
+
+ opts.on("-c", "--create NAME,SIZE", "Create pool NAME with SIZE users.") do |opt|
+ name, size = opt.split(',')
+ if size == nil
+ puts "Invalid input to create, see ./pool_tool -h."
+ exit 1
+ end
+ install_pool(name, size)
+ end
+
+ opts.on("-d", "--delete NAME", "Delete pool NAME.") do |opt|
+ remove_pool(opt)
+ end
+
+ opts.on("-l", "--list", "List current pools.") do
+ list_pools
+ end
+
+ opts.on("-h", "--help", "Help") do
+ puts opts
+ exit
+ end
+ end
+ options.parse!(ARGV)
+ end
+ end
+
+ logger = Logger.new(STDOUT)
+ logger.level = Logger::INFO
+ VCAP::UserPoolUtil.init(logger)
+ if ARGV.length == 0
+ puts USAGE
+ exit
+ end
+ parse_options
+end
View
@@ -0,0 +1,48 @@
+#!/usr/bin/env ruby
+# Copyright (c) 2009-2011 VMware, Inc.
+
+require "fileutils"
+
+def close_fds
+ 3.upto(get_max_open_fd) do |fd|
+ begin
+ IO.for_fd(fd, "r").close
+ rescue
+ end
+ end
+end
+
+def get_max_open_fd
+ max = 0
+
+ dir = nil
+ if File.directory?("/proc/self/fd/") # Linux
+ dir = "/proc/self/fd/"
+ elsif File.directory?("/dev/fd/") # Mac
+ dir = "/dev/fd/"
+ end
+
+ if dir
+ Dir.foreach(dir) do |entry|
+ begin
+ pid = Integer(entry)
+ max = pid if pid > max
+ rescue
+ end
+ end
+ else
+ max = 65535
+ end
+
+ max
+end
+
+close_fds
+
+# deletes itself when run by the DEA
+delete_script = ARGV.shift
+if delete_script == "true"
+ FileUtils.rm(__FILE__)
+end
+
+exec(*ARGV)
Oops, something went wrong.

0 comments on commit 8b43963

Please sign in to comment.