From f8658b80828262b5356f086f6c6ea69b706dde06 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Wed, 16 Jul 2014 20:18:09 -0700 Subject: Introduce osc_compat so multi org can still use osc_compat --- lib/chef_zero/data_store/default_facade.rb | 10 ++++---- lib/chef_zero/server.rb | 40 ++++++++++++++++-------------- spec/run.rb | 2 +- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/lib/chef_zero/data_store/default_facade.rb b/lib/chef_zero/data_store/default_facade.rb index 2285576..1512422 100644 --- a/lib/chef_zero/data_store/default_facade.rb +++ b/lib/chef_zero/data_store/default_facade.rb @@ -3,14 +3,14 @@ require 'chef_zero/data_store/interface_v2' module ChefZero module DataStore class DefaultFacade < ChefZero::DataStore::InterfaceV2 - def initialize(real_store, single_org) + def initialize(real_store, osc_compat) @real_store = real_store - @single_org = single_org + @osc_compat = osc_compat clear end attr_reader :real_store - attr_reader :single_org + attr_reader :osc_compat def default(path, name=nil) value = @defaults @@ -72,7 +72,7 @@ module ChefZero 'organizations' => {}, 'acls' => {} } - if !single_org + if !osc_compat @defaults['users'] = { 'pivotal' => '{}' } @@ -302,7 +302,7 @@ module ChefZero 'association_requests' => {}, } - if single_org + if osc_compat result['users']['admin'] = '{ "admin": "true" }' end diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index c3447f8..41b4c8f 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -92,6 +92,9 @@ module ChefZero def initialize(options = {}) @options = DEFAULT_OPTIONS.merge(options) + if @options[:single_org] && !@options.has_key?(:osc_compat) + @options[:osc_compat] = true + end @options.freeze ChefZero::Log.level = @options[:log_level].to_sym @@ -139,13 +142,13 @@ module ChefZero # def data_store @data_store ||= begin - result = @options[:data_store] || DataStore::DefaultFacade.new(DataStore::MemoryStoreV2.new, options[:single_org]) + result = @options[:data_store] || DataStore::DefaultFacade.new(DataStore::MemoryStoreV2.new, options[:osc_compat]) if options[:single_org] if result.respond_to?(:interface_version) && result.interface_version >= 2 && result.interface_version < 3 result.create_dir([ 'organizations' ], options[:single_org]) else result = ChefZero::DataStore::V1ToV2Adapter.new(result, options[:single_org]) - result = ChefZero::DataStore::DefaultFacade.new(result, options[:single_org]) + result = ChefZero::DataStore::DefaultFacade.new(result, options[:osc_compat]) end else if !(result.respond_to?(:interface_version) && result.interface_version >= 2 && result.interface_version < 3) @@ -405,7 +408,7 @@ module ChefZero private def open_source_endpoints - result = if options[:single_org] + result = if options[:osc_compat] # OSC-only [ [ "/organizations/*/users", ActorsEndpoint.new(self) ], @@ -426,27 +429,26 @@ module ChefZero [ "/users/*/association_requests/*", UserAssociationRequestEndpoint.new(self) ], [ "/users/*/organizations", UserOrganizationsEndpoint.new(self) ], [ "/authenticate_user", AuthenticateUserEndpoint.new(self) ], - [ "/system_recovery", SystemRecoveryEndpoint.new(self) ] + [ "/system_recovery", SystemRecoveryEndpoint.new(self) ], + + [ "/organizations", OrganizationsEndpoint.new(self) ], + [ "/organizations/*", OrganizationEndpoint.new(self) ], + [ "/organizations/*/_validator_key", OrganizationValidatorKeyEndpoint.new(self) ], + [ "/organizations/*/association_requests", OrganizationAssociationRequestsEndpoint.new(self) ], + [ "/organizations/*/association_requests/*", OrganizationAssociationRequestEndpoint.new(self) ], + [ "/organizations/*/containers", ContainersEndpoint.new(self) ], + [ "/organizations/*/containers/*", ContainerEndpoint.new(self) ], + [ "/organizations/*/groups", GroupsEndpoint.new(self) ], + [ "/organizations/*/groups/*", GroupEndpoint.new(self) ], + [ "/organizations/*/organization/_acl", AclsEndpoint.new(self) ], + [ "/organizations/*/*/*/_acl", AclsEndpoint.new(self) ], + [ "/organizations/*/organization/_acl/*", AclEndpoint.new(self) ], + [ "/organizations/*/*/*/_acl/*", AclEndpoint.new(self) ] ] end result + [ # Both - [ "/organizations", OrganizationsEndpoint.new(self) ], - [ "/organizations/*", OrganizationEndpoint.new(self) ], - [ "/organizations/*/_validator_key", OrganizationValidatorKeyEndpoint.new(self) ], - [ "/organizations/*/association_requests", OrganizationAssociationRequestsEndpoint.new(self) ], - [ "/organizations/*/association_requests/*", OrganizationAssociationRequestEndpoint.new(self) ], - - [ "/organizations/*/containers", ContainersEndpoint.new(self) ], - [ "/organizations/*/containers/*", ContainerEndpoint.new(self) ], - [ "/organizations/*/groups", GroupsEndpoint.new(self) ], - [ "/organizations/*/groups/*", GroupEndpoint.new(self) ], - [ "/organizations/*/organization/_acl", AclsEndpoint.new(self) ], - [ "/organizations/*/*/*/_acl", AclsEndpoint.new(self) ], - [ "/organizations/*/organization/_acl/*", AclEndpoint.new(self) ], - [ "/organizations/*/*/*/_acl/*", AclEndpoint.new(self) ], - [ "/organizations/*/clients", ActorsEndpoint.new(self) ], [ "/organizations/*/clients/*", ActorEndpoint.new(self) ], [ "/organizations/*/cookbooks", CookbooksEndpoint.new(self) ], diff --git a/spec/run.rb b/spec/run.rb index 0403059..a0aaf40 100644 --- a/spec/run.rb +++ b/spec/run.rb @@ -50,7 +50,7 @@ begin server.start_background else - server = ChefZero::Server.new(:port => 8889, :single_org => false) + server = ChefZero::Server.new(:port => 8889, :single_org => false, :osc_compat => true) server.data_store.create_dir([ 'organizations' ], 'pedant') server.start_background end -- cgit v1.2.1