diff options
author | snehaldwivedi <sdwivedi@msystechnologies.com> | 2021-02-11 04:24:01 -0800 |
---|---|---|
committer | snehaldwivedi <sdwivedi@msystechnologies.com> | 2021-02-16 02:45:13 -0800 |
commit | 8f32723295c4ef04724270a4d6e4b77e5caf7b3a (patch) | |
tree | 49746969dc2ac35f84f442fff5623aafe3923b49 | |
parent | 3c1bf664db5c20b02aa5d2f0b1a1f4b18d19d750 (diff) | |
download | chef-8f32723295c4ef04724270a4d6e4b77e5caf7b3a.tar.gz |
Updated rest object URL and removed api_version 1
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
-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, 58 insertions, 67 deletions
diff --git a/lib/chef/knife.rb b/lib/chef/knife.rb index a5ed415fee..318aad27a7 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_url]) + Chef::ServerAPI.new(Chef::Config[:chef_server_root]) end end @@ -662,11 +662,5 @@ 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 340f6c529a..c5599c59f7 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 root_rest.delete("organizations/#{org_name}") + ui.output 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 1d684ca0b4..8e832378b7 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 = root_rest.get("organizations/#{org_name}") + original_org = 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 - root_rest.put("organizations/#{org_name}", edited_org) + 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 85a49ee4c5..1d6af0d54f 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 = root_rest.get("organizations") + results = 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 a8bb207c1d..11a90def51 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 root_rest.get("organizations/#{org_name}") + ui.output 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 aa1d4d54f2..cd61a79b6d 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 = root_rest.post("users/", user_hash) + final_user = rest.post("users/", user_hash) if config[:orgname] request_body = { user: user.username } - response = root_rest.post("organizations/#{config[:orgname]}/association_requests", request_body) + response = rest.post("organizations/#{config[:orgname]}/association_requests", request_body) association_id = response["uri"].split("/").last - root_rest.put("users/#{user.username}/association_requests/#{association_id}", { response: "accept" }) + 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 64d729c951..2740c31745 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 = root_rest.get("users/#{username}/organizations") + org_data = 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}." - root_rest.delete("users/#{username}") + 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 fff8c6b70f..4c392603a6 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 = root_rest.get("users/#{@user_name}") + original_user = rest.get("users/#{@user_name}") edited_user = get_updated_user(original_user) if original_user != edited_user - result = root_rest.put("users/#{@user_name}", edited_user) + result = 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 3284964a47..5c26351cef 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 = root_rest.get("users") + results = 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 2da3c3e285..63b48c10cb 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 = root_rest.get("users/#{user_name}") + result = 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 - root_rest.put("users/#{user_name}", result) + 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 ea2b06b753..6dc1d8955a 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 = root_rest.get("users/#{@user_name}") + results = rest.get("users/#{@user_name}") if config[:with_orgs] - orgs = root_rest.get("users/#{@user_name}/organizations") + orgs = 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 94c224f1e6..b82c144116 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(:root_rest) { double("Chef::ServerAPI") } + let(: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_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) expect(@knife.ui).to receive(:confirm).with("Do you want to delete the organization #{@org_name}") - expect(root_rest).to receive(:delete).with("organizations/#{@org_name}") + expect(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 3badaf5168..7a99f1355a 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(:root_rest) { double("Chef::ServerAPI") } + let(: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_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) original_data = { "org_name" => "my_org" } data = { "org_name" => "my_org1" } - expect(root_rest).to receive(:get).with("organizations/foobar").and_return(original_data) + expect(rest).to receive(:get).with("organizations/foobar").and_return(original_data) expect(knife).to receive(:edit_hash).with(original_data).and_return(data) - expect(root_rest).to receive(:put).with("organizations/foobar", data) + expect(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 1c6fb956af..05fb289e6b 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(:root_rest) { double("Chef::ServerAPI") } + let(: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_url], { api_version: "1" }).and_return(root_rest) - allow(root_rest).to receive(:get).with("organizations").and_return(orgs) + 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) 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 6a6260273f..033bf6f14e 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(:root_rest) { double("Chef::ServerAPI") } + let(: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_url], { api_version: "1" }).and_return(root_rest) - allow(@org).to receive(:root_rest).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) + allow(@org).to receive(:rest).and_return(rest) end it "should load the organisation" do - expect(root_rest).to receive(:get).with("organizations/#{@org_name}") + expect(rest).to receive(:get).with("organizations/#{@org_name}") @knife.run end it "should pretty print the output organisation" do - expect(root_rest).to receive(:get).with("organizations/#{@org_name}") + expect(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 ec221fb8c0..d763debad1 100644 --- a/spec/unit/knife/user_create_spec.rb +++ b/spec/unit/knife/user_create_spec.rb @@ -40,8 +40,6 @@ 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 @@ -86,7 +84,7 @@ describe Chef::Knife::UserCreate do end it "creates an user" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).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 @@ -102,7 +100,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_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.username).to eq("some_user") @@ -135,7 +133,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_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.create_key).to be_falsey @@ -144,7 +142,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_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.create_key).to be_truthy @@ -159,7 +157,7 @@ describe Chef::Knife::UserCreate do end it "sets user.public_key" do - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.public_key).to eq("some_key") @@ -168,7 +166,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_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).and_return(root_rest) expect(root_rest).to receive(:post).and_return(@user) knife.run expect(knife.user.public_key).to be_nil @@ -180,7 +178,7 @@ describe Chef::Knife::UserCreate do before :each do @user = double("Chef::User") - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root ]).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 1467d05af3..17f2e2e2d3 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(:root_rest) { double("Chef::ServerAPI") } + let(: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_url], { api_version: "1" }).and_return(root_rest) - expect(root_rest).to receive(:get).with("users/my_user2").and_return(data) + 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(knife).to receive(:get_updated_user).with(data).and_return(edited_data) - expect(root_rest).to receive(:put).with("users/my_user2", edited_data).and_return(result) + expect(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 853e21cd6d..3994ef57cb 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(:root_rest) { double("Chef::ServerAPI") } + let(: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(:root_rest).and_return(root_rest) + allow(@user).to receive(:rest).and_return(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_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(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(@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 941592cb56..9780b6a340 100644 --- a/spec/unit/knife/user_show_spec.rb +++ b/spec/unit/knife/user_show_spec.rb @@ -24,14 +24,13 @@ Chef::Knife::UserShow.load_deps describe Chef::Knife::UserShow do let(:knife) { Chef::Knife::UserShow.new } let(:user_mock) { double("user_mock") } - let(:root_rest) { double("Chef::ServerAPI") } + let(:rest) { double("Chef::ServerAPI") } before :each do @user_name = "foobar" @password = "abc123" @user = double("Chef::User") - allow(@user).to receive(:root_rest).and_return(root_rest) - # allow(Chef::User).to receive(:new).and_return(@user) + allow(@user).to receive(:rest).and_return(rest) @key = "You don't come into cooking to get rich - Ramsay" end @@ -42,14 +41,14 @@ describe Chef::Knife::UserShow do end it "should load the user" do - 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(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) + expect(@user.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_url], { api_version: "1" }).and_return(root_rest) - expect(@user.root_rest).to receive(:get).with("users/my_user") + 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(knife).to receive(:format_for_display) knife.run end @@ -81,10 +80,10 @@ describe Chef::Knife::UserShow do result = { "organizations" => [] } knife.config[:with_orgs] = true - expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_url], { api_version: "1" }).and_return(root_rest) + expect(Chef::ServerAPI).to receive(:new).with(Chef::Config[:chef_server_root]).and_return(rest) allow(@org).to receive(:[]).with("organization").and_return({ "name" => "test" }) - 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) + 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) knife.run end end |