diff options
author | snehaldwivedi <sdwivedi@msystechnologies.com> | 2021-02-15 21:30:28 -0800 |
---|---|---|
committer | snehaldwivedi <sdwivedi@msystechnologies.com> | 2021-02-16 02:45:13 -0800 |
commit | 6a3587867d17b9d8d5d8ea0f9279c3e522f0ea71 (patch) | |
tree | 5117e08efc39ac07c1adcf19e6161c0947ee9711 | |
parent | 8f32723295c4ef04724270a4d6e4b77e5caf7b3a (diff) | |
download | chef-6a3587867d17b9d8d5d8ea0f9279c3e522f0ea71.tar.gz |
Revert "Updated rest object URL and removed api_version 1"
This reverts commit 182d83672e231c470e0b33ed777306a72a6bd76a.
-rw-r--r-- | lib/chef/knife.rb | 8 | ||||
-rw-r--r-- | lib/chef/knife/org_delete.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/org_edit.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/org_list.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/org_show.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/user_create.rb | 6 | ||||
-rw-r--r-- | lib/chef/knife/user_delete.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/user_edit.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/user_list.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/user_password.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/user_show.rb | 4 | ||||
-rw-r--r-- | spec/unit/knife/org_delete_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/org_edit_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/knife/org_list_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/knife/org_show_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/knife/user_create_spec.rb | 16 | ||||
-rw-r--r-- | spec/unit/knife/user_edit_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/knife/user_password_spec.rb | 10 | ||||
-rw-r--r-- | spec/unit/knife/user_show_spec.rb | 19 |
19 files changed, 67 insertions, 58 deletions
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index 318aad27a7..a5ed415fee 100644 --- a/lib/chef/knife.rb +++ b/lib/chef/knife.rb @@ -640,7 +640,7 @@ class Chef def rest @rest ||= begin require_relative "server_api" - Chef::ServerAPI.new(Chef::Config[:chef_server_root]) + Chef::ServerAPI.new(Chef::Config[:chef_server_url]) end end @@ -662,5 +662,11 @@ class Chef Chef::Config.init_openssl end + def root_rest + @root_rest ||= begin + require_relative "server_api" + Chef::ServerAPI.new(Chef::Config[:chef_server_root], { api_version: "1" }) + end + end end end diff --git a/lib/chef/knife/org_delete.rb b/lib/chef/knife/org_delete.rb index c5599c59f7..340f6c529a 100644 --- a/lib/chef/knife/org_delete.rb +++ b/lib/chef/knife/org_delete.rb @@ -25,7 +25,7 @@ class Chef def run org_name = @name_args[0] ui.confirm "Do you want to delete the organization #{org_name}" - ui.output rest.delete("organizations/#{org_name}") + ui.output root_rest.delete("organizations/#{org_name}") end end end diff --git a/lib/chef/knife/org_edit.rb b/lib/chef/knife/org_edit.rb index 8e832378b7..1d684ca0b4 100644 --- a/lib/chef/knife/org_edit.rb +++ b/lib/chef/knife/org_edit.rb @@ -31,7 +31,7 @@ class Chef exit 1 end - original_org = rest.get("organizations/#{org_name}") + original_org = root_rest.get("organizations/#{org_name}") edited_org = edit_hash(original_org) if original_org == edited_org @@ -40,7 +40,7 @@ class Chef end ui.msg edited_org - rest.put("organizations/#{org_name}", edited_org) + root_rest.put("organizations/#{org_name}", edited_org) ui.msg("Saved #{org_name}.") end end diff --git a/lib/chef/knife/org_list.rb b/lib/chef/knife/org_list.rb index 1d6af0d54f..85a49ee4c5 100644 --- a/lib/chef/knife/org_list.rb +++ b/lib/chef/knife/org_list.rb @@ -33,7 +33,7 @@ class Chef description: "Show auto-generated hidden orgs in output" def run - results = rest.get("organizations") + results = root_rest.get("organizations") unless config[:all_orgs] results = results.select { |k, v| !(k.length == 20 && k =~ /^[a-z]+$/) } end diff --git a/lib/chef/knife/org_show.rb b/lib/chef/knife/org_show.rb index 11a90def51..a8bb207c1d 100644 --- a/lib/chef/knife/org_show.rb +++ b/lib/chef/knife/org_show.rb @@ -24,7 +24,7 @@ class Chef def run org_name = @name_args[0] - ui.output rest.get("organizations/#{org_name}") + ui.output root_rest.get("organizations/#{org_name}") end end end diff --git a/lib/chef/knife/user_create.rb b/lib/chef/knife/user_create.rb index cd61a79b6d..aa1d4d54f2 100644 --- a/lib/chef/knife/user_create.rb +++ b/lib/chef/knife/user_create.rb @@ -114,13 +114,13 @@ class Chef end end - final_user = rest.post("users/", user_hash) + final_user = root_rest.post("users/", user_hash) if config[:orgname] request_body = { user: user.username } - response = rest.post("organizations/#{config[:orgname]}/association_requests", request_body) + response = root_rest.post("organizations/#{config[:orgname]}/association_requests", request_body) association_id = response["uri"].split("/").last - rest.put("users/#{user.username}/association_requests/#{association_id}", { response: "accept" }) + root_rest.put("users/#{user.username}/association_requests/#{association_id}", { response: "accept" }) end ui.info("Created #{user.username}") diff --git a/lib/chef/knife/user_delete.rb b/lib/chef/knife/user_delete.rb index 2740c31745..64d729c951 100644 --- a/lib/chef/knife/user_delete.rb +++ b/lib/chef/knife/user_delete.rb @@ -82,7 +82,7 @@ class Chef end def org_memberships(username) - org_data = rest.get("users/#{username}/organizations") + org_data = root_rest.get("users/#{username}/organizations") org_data.map { |org| Chef::Org.new(org["organization"]["name"]) } end @@ -109,7 +109,7 @@ class Chef def delete_user(username) ui.stderr.puts "Deleting user #{username}." - rest.delete("users/#{username}") + root_rest.delete("users/#{username}") end # Error message that says how to removed from org diff --git a/lib/chef/knife/user_edit.rb b/lib/chef/knife/user_edit.rb index 4c392603a6..fff8c6b70f 100644 --- a/lib/chef/knife/user_edit.rb +++ b/lib/chef/knife/user_edit.rb @@ -42,10 +42,10 @@ class Chef ui.fatal("You must specify a user name") exit 1 end - original_user = rest.get("users/#{@user_name}") + original_user = root_rest.get("users/#{@user_name}") edited_user = get_updated_user(original_user) if original_user != edited_user - result = rest.put("users/#{@user_name}", edited_user) + result = root_rest.put("users/#{@user_name}", edited_user) ui.msg("Saved #{@user_name}.") unless result["private_key"].nil? if config[:filename] diff --git a/lib/chef/knife/user_list.rb b/lib/chef/knife/user_list.rb index 5c26351cef..3284964a47 100644 --- a/lib/chef/knife/user_list.rb +++ b/lib/chef/knife/user_list.rb @@ -30,7 +30,7 @@ class Chef description: "Show corresponding URIs." def run - results = rest.get("users") + results = root_rest.get("users") output(format_list_for_display(results)) end end diff --git a/lib/chef/knife/user_password.rb b/lib/chef/knife/user_password.rb index 63b48c10cb..2da3c3e285 100644 --- a/lib/chef/knife/user_password.rb +++ b/lib/chef/knife/user_password.rb @@ -47,7 +47,7 @@ class Chef # true or false, there is no way of knowing if the user is using ldap or not, # so we will update the user every time, instead of checking if we are actually # changing anything before we PUT. - result = rest.get("users/#{user_name}") + result = root_rest.get("users/#{user_name}") result["password"] = password unless password.nil? @@ -58,7 +58,7 @@ class Chef result["recovery_authentication_enabled"] = !config[:enable_external_auth] begin - rest.put("users/#{user_name}", result) + root_rest.put("users/#{user_name}", result) rescue => e raise e end diff --git a/lib/chef/knife/user_show.rb b/lib/chef/knife/user_show.rb index 6dc1d8955a..ea2b06b753 100644 --- a/lib/chef/knife/user_show.rb +++ b/lib/chef/knife/user_show.rb @@ -39,9 +39,9 @@ class Chef exit 1 end - results = rest.get("users/#{@user_name}") + results = root_rest.get("users/#{@user_name}") if config[:with_orgs] - orgs = rest.get("users/#{@user_name}/organizations") + orgs = root_rest.get("users/#{@user_name}/organizations") results["organizations"] = orgs.map { |o| o["organization"]["name"] } end output(format_for_display(results)) diff --git a/spec/unit/knife/org_delete_spec.rb b/spec/unit/knife/org_delete_spec.rb index b82c144116..94c224f1e6 100644 --- a/spec/unit/knife/org_delete_spec.rb +++ b/spec/unit/knife/org_delete_spec.rb @@ -21,7 +21,7 @@ require "chef/org" describe Chef::Knife::OrgDelete do - let(:rest) { double("Chef::ServerAPI") } + let(:root_rest) { double("Chef::ServerAPI") } before :each do @knife = Chef::Knife::OrgDelete.new @@ -32,9 +32,9 @@ describe Chef::Knife::OrgDelete do end it "should confirm that you want to delete and then delete organizations" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) expect(@knife.ui).to receive(:confirm).with("Do you want to delete the organization #{@org_name}") - expect(rest).to receive(:delete).with("organizations/#{@org_name}") + expect(root_rest).to receive(:delete).with("organizations/#{@org_name}") expect(@knife.ui).to receive(:output) @knife.run end diff --git a/spec/unit/knife/org_edit_spec.rb b/spec/unit/knife/org_edit_spec.rb index 7a99f1355a..3badaf5168 100644 --- a/spec/unit/knife/org_edit_spec.rb +++ b/spec/unit/knife/org_edit_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Chef::Knife::OrgEdit do let(:knife) { Chef::Knife::OrgEdit.new } - let(:rest) { double("Chef::ServerAPI") } + let(:root_rest) { double("Chef::ServerAPI") } before :each do Chef::Knife::OrgEdit.load_deps @@ -31,12 +31,12 @@ describe Chef::Knife::OrgEdit do end it "loads and edits the organisation" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) original_data = { "org_name" => "my_org" } data = { "org_name" => "my_org1" } - expect(rest).to receive(:get).with("organizations/foobar").and_return(original_data) + expect(root_rest).to receive(:get).with("organizations/foobar").and_return(original_data) expect(knife).to receive(:edit_hash).with(original_data).and_return(data) - expect(rest).to receive(:put).with("organizations/foobar", data) + expect(root_rest).to receive(:put).with("organizations/foobar", data) knife.run end diff --git a/spec/unit/knife/org_list_spec.rb b/spec/unit/knife/org_list_spec.rb index 05fb289e6b..1c6fb956af 100644 --- a/spec/unit/knife/org_list_spec.rb +++ b/spec/unit/knife/org_list_spec.rb @@ -20,7 +20,7 @@ require "chef/org" describe Chef::Knife::OrgList do - let(:rest) { double("Chef::ServerAPI") } + let(:root_rest) { double("Chef::ServerAPI") } let(:orgs) do { @@ -33,8 +33,8 @@ describe Chef::Knife::OrgList do before :each do @org = double("Chef::Org") @knife = Chef::Knife::OrgList.new - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) - allow(rest).to receive(:get).with("organizations").and_return(orgs) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + allow(root_rest).to receive(:get).with("organizations").and_return(orgs) end describe "with no arguments" do diff --git a/spec/unit/knife/org_show_spec.rb b/spec/unit/knife/org_show_spec.rb index 033bf6f14e..6a6260273f 100644 --- a/spec/unit/knife/org_show_spec.rb +++ b/spec/unit/knife/org_show_spec.rb @@ -21,24 +21,24 @@ require "chef/org" describe Chef::Knife::OrgShow do - let(:rest) { double("Chef::ServerAPI") } + let(:root_rest) { double("Chef::ServerAPI") } before :each do @knife = Chef::Knife::OrgShow.new @org_name = "foobar" @knife.name_args << @org_name @org = double("Chef::Org") - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) - allow(@org).to receive(:rest).and_return(rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + allow(@org).to receive(:root_rest).and_return(root_rest) end it "should load the organisation" do - expect(rest).to receive(:get).with("organizations/#{@org_name}") + expect(root_rest).to receive(:get).with("organizations/#{@org_name}") @knife.run end it "should pretty print the output organisation" do - expect(rest).to receive(:get).with("organizations/#{@org_name}") + expect(root_rest).to receive(:get).with("organizations/#{@org_name}") expect(@knife.ui).to receive(:output) @knife.run end diff --git a/spec/unit/knife/user_create_spec.rb b/spec/unit/knife/user_create_spec.rb index d763debad1..ec221fb8c0 100644 --- a/spec/unit/knife/user_create_spec.rb +++ b/spec/unit/knife/user_create_spec.rb @@ -40,6 +40,8 @@ describe Chef::Knife::UserCreate do allow(knife.ui).to receive(:warn) end + let(:chef_root_rest_v0) { double("Chef::ServerAPI") } + context "when USERNAME isn't specified" do # from spec/support/shared/unit/knife_shared.rb it_should_behave_like "mandatory field missing" do @@ -84,7 +86,7 @@ describe Chef::Knife::UserCreate do end it "creates an user" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) expect(knife.ui).to receive(:ask).with("Please enter the user's password: ", echo: false).and_return("password") knife.run @@ -100,7 +102,7 @@ describe Chef::Knife::UserCreate do end it "sets all the mandatory fields" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.username).to eq("some_user") @@ -133,7 +135,7 @@ describe Chef::Knife::UserCreate do end it "does not set user.create_key" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.create_key).to be_falsey @@ -142,7 +144,7 @@ describe Chef::Knife::UserCreate do context "when --prevent-keygen is not passed" do it "sets user.create_key to true" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.create_key).to be_truthy @@ -157,7 +159,7 @@ describe Chef::Knife::UserCreate do end it "sets user.public_key" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.public_key).to eq("some_key") @@ -166,7 +168,7 @@ describe Chef::Knife::UserCreate do context "when --user-key is not passed" do it "does not set user.public_key" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.public_key).to be_nil @@ -178,7 +180,7 @@ describe Chef::Knife::UserCreate do before :each do @user = double("Chef::User") - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) @key = "You don't come into cooking to get rich - Ramsay" allow(@user).to receive(:[]).with("private_key").and_return(@key) diff --git a/spec/unit/knife/user_edit_spec.rb b/spec/unit/knife/user_edit_spec.rb index 17f2e2e2d3..1467d05af3 100644 --- a/spec/unit/knife/user_edit_spec.rb +++ b/spec/unit/knife/user_edit_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Chef::Knife::UserEdit do let(:knife) { Chef::Knife::UserEdit.new } - let(:rest) { double("Chef::ServerAPI") } + let(:root_rest) { double("Chef::ServerAPI") } before(:each) do @stderr = StringIO.new @@ -38,10 +38,10 @@ describe Chef::Knife::UserEdit do @key = "You don't come into cooking to get rich - Ramsay" allow(result).to receive(:[]).with("private_key").and_return(@key) - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) - expect(rest).to receive(:get).with("users/my_user2").and_return(data) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(root_rest).to receive(:get).with("users/my_user2").and_return(data) expect(knife).to receive(:get_updated_user).with(data).and_return(edited_data) - expect(rest).to receive(:put).with("users/my_user2", edited_data).and_return(result) + expect(root_rest).to receive(:put).with("users/my_user2", edited_data).and_return(result) knife.run end diff --git a/spec/unit/knife/user_password_spec.rb b/spec/unit/knife/user_password_spec.rb index 3994ef57cb..853e21cd6d 100644 --- a/spec/unit/knife/user_password_spec.rb +++ b/spec/unit/knife/user_password_spec.rb @@ -23,14 +23,14 @@ Chef::Knife::UserDelete.load_deps describe Chef::Knife::UserPassword do - let(:rest) { double("Chef::ServerAPI") } + let(:root_rest) { double("Chef::ServerAPI") } before :each do @knife = Chef::Knife::UserPassword.new @user_name = "foobar" @password = "abc123" @user = double("Chef::User") - allow(@user).to receive(:rest).and_return(rest) + allow(@user).to receive(:root_rest).and_return(root_rest) @key = "You don't come into cooking to get rich - Ramsay" end @@ -43,9 +43,9 @@ describe Chef::Knife::UserPassword do result = { "password" => [], "recovery_authentication_enabled" => true } allow(@user).to receive(:[]).with("organization") - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) - expect(@user.rest).to receive(:get).with("users/#{@user_name}").and_return(result) - expect(@user.rest).to receive(:put).with("users/#{@user_name}", result) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(@user.root_rest).to receive(:get).with("users/#{@user_name}").and_return(result) + expect(@user.root_rest).to receive(:put).with("users/#{@user_name}", result) expect(@knife.ui).to receive(:msg).with("Authentication info updated for #{@user_name}.") @knife.run diff --git a/spec/unit/knife/user_show_spec.rb b/spec/unit/knife/user_show_spec.rb index 9780b6a340..941592cb56 100644 --- a/spec/unit/knife/user_show_spec.rb +++ b/spec/unit/knife/user_show_spec.rb @@ -24,13 +24,14 @@ Chef::Knife::UserShow.load_deps describe Chef::Knife::UserShow do let(:knife) { Chef::Knife::UserShow.new } let(:user_mock) { double("user_mock") } - let(:rest) { double("Chef::ServerAPI") } + let(:root_rest) { double("Chef::ServerAPI") } before :each do @user_name = "foobar" @password = "abc123" @user = double("Chef::User") - allow(@user).to receive(:rest).and_return(rest) + allow(@user).to receive(:root_rest).and_return(root_rest) + # allow(Chef::User).to receive(:new).and_return(@user) @key = "You don't come into cooking to get rich - Ramsay" end @@ -41,14 +42,14 @@ describe Chef::Knife::UserShow do end it "should load the user" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) - expect(@user.rest).to receive(:get).with("users/my_user") + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(@user.root_rest).to receive(:get).with("users/my_user") knife.run end it "loads and displays the user" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) - expect(@user.rest).to receive(:get).with("users/my_user") + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(@user.root_rest).to receive(:get).with("users/my_user") expect(knife).to receive(:format_for_display) knife.run end @@ -80,10 +81,10 @@ describe Chef::Knife::UserShow do result = { "organizations" => [] } knife.config[:with_orgs] = true - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) allow(@org).to receive(:[]).with("organization").and_return({ "name" => "test" }) - expect(@user.rest).to receive(:get).with("users/#{@user_name}").and_return(result) - expect(@user.rest).to receive(:get).with("users/#{@user_name}/organizations").and_return(orgs) + expect(@user.root_rest).to receive(:get).with("users/#{@user_name}").and_return(result) + expect(@user.root_rest).to receive(:get).with("users/#{@user_name}/organizations").and_return(orgs) knife.run end end |