summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-09-03 17:49:37 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-09-03 17:49:37 -0700
commit93dd378c1953aa9355bbbcb7c3ae00deabd35380 (patch)
treef5e74a3ebc09e4a9adb3b96c6565e9a7f5cd9a1f
parenta0b7ca95a44eaf69de1340e14c371a8db560d138 (diff)
downloadchef-93dd378c1953aa9355bbbcb7c3ae00deabd35380.tar.gz
Explicitly set organization when local mode is enabled
-rw-r--r--lib/chef/config.rb11
-rw-r--r--lib/chef/local_mode.rb17
2 files changed, 15 insertions, 13 deletions
diff --git a/lib/chef/config.rb b/lib/chef/config.rb
index d57f398f4d..7aa89a8ce1 100644
--- a/lib/chef/config.rb
+++ b/lib/chef/config.rb
@@ -341,7 +341,7 @@ class Chef
# - otherwise, it is "https://localhost:443".
default :chef_server_url do
if chef_server_root
- if has_key?(:organization)
+ if organization
File.join(chef_server_root, 'organizations', organization)
end
elsif chef_zero.enabled
@@ -372,7 +372,7 @@ class Chef
if has_key?(:chef_server_url)
# https://blah.com/organizations/foo -> https://blah.com
path = Pathname.new(URI.parse(chef_server_url).path).cleanpath
- if !has_key?(:organization) || path.basename.to_s == organization
+ if path.basename.to_s == organization
path = path.dirname
if path.basename.to_s == 'organizations'
URI.join(chef_server_url, path.dirname.to_s).to_s.chomp('/')
@@ -400,12 +400,7 @@ class Chef
# when chef_server_url = https://blah.com/organizations/orgname,
# organization = orgname.
default(:organization) do
- if chef_zero.enabled
- unless chef_zero.chef_11_osc_compat
- 'chef'
- end
-
- elsif has_key?(:chef_server_url)
+ if has_key?(:chef_server_url)
# https://blah.com/organizations/foo -> foo
path = Pathname.new(URI.parse(chef_server_url).path).cleanpath
if path.dirname.basename.to_s == 'organizations'
diff --git a/lib/chef/local_mode.rb b/lib/chef/local_mode.rb
index 8c7cbf2237..5b1e4d43e2 100644
--- a/lib/chef/local_mode.rb
+++ b/lib/chef/local_mode.rb
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
require 'chef/config'
+require 'chef/log'
+require 'chef/server_api'
class Chef
class LocalMode
@@ -100,6 +102,7 @@ class Chef
require 'chef_zero/server'
require 'chef/chef_fs/chef_fs_data_store'
require 'chef/chef_fs/config'
+ require 'chef_zero/data_store/v1_to_v2_adapter'
@saved_config = config.save
@@ -111,12 +114,13 @@ class Chef
data_store = Chef::ChefFS::ChefFSDataStore.new(@chef_fs)
# If the data store already has an org.json, grab an org name
# from that.
+ organization = nil
if !config.has_key?(:organization) && data_store.exists?([ 'org' ])
org = JSON.parse(data_store.get([ 'org' ]), :create_additions => false)
- config[:organization] = org['name'] if org.is_a?(Hash)
+ organization = org['name'] if org.is_a?(Hash)
end
- config[:organization] ||= 'chef'
- data_store = ChefZero::DataStore::V1ToV2Adapter.new(data_store, config[:organization] || 'chef')
+ organization ||= config[:organization] || 'chef'
+ data_store = ChefZero::DataStore::V1ToV2Adapter.new(data_store, organization)
#
# Start the chef-zero server
@@ -128,7 +132,7 @@ class Chef
server_options[:port] = parse_port(config[:chef_zero][:port])
if config[:chef_zero][:chef_11_osc_compat]
server_options[:osc_compat] = true
- server_options[:single_org] = config[:organization]
+ server_options[:single_org] = organization
else
server_options[:osc_compat] = false
server_options[:single_org] = false
@@ -145,6 +149,7 @@ class Chef
config.delete(:organization)
else
config[:chef_server_root] = @chef_zero_server.url
+ config[:organization] = organization
config.delete(:chef_server_url) # Default will do us just fine, thanks.
begin
root.post('/organizations', { 'name' => config[:organization] })
@@ -158,7 +163,9 @@ class Chef
end
def root
- Chef::ServerAPI.new(config[:chef_server_root], :client_name => config[:node_name], :signing_key_filename => config[:client_key])
+ Chef::ServerAPI.new(config[:chef_server_root],
+ :client_name => config[:node_name],
+ :signing_key_filename => config[:client_key])
end
# Return the current chef-zero server set up by start.