Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrated knife-opc into Chef #10187

Merged
merged 14 commits into from
Feb 22, 2021

Conversation

snehaldwivedi
Copy link
Contributor

@snehaldwivedi snehaldwivedi commented Jul 22, 2020

Signed-off-by: snehaldwivedi sdwivedi@msystechnologies.com

Description

  • Merge this knife plugin into Chef.
  • Moved user password command to core chef

Related Issue

chef-boneyard/knife-opc#48
chef-boneyard/knife-opc#57
#3517
#3514 (covers knife user create should check file permissions), #3515, #3516

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

@snehaldwivedi snehaldwivedi requested review from a team as code owners July 22, 2020 09:18
@snehaldwivedi snehaldwivedi changed the title Merge this knife plugin into Chef directly Integrated knife-opc into Chef Jul 22, 2020
Copy link
Contributor

@stevendanna stevendanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting this started!

module Opc
class OpcOrgCreate < Chef::Knife
category "CHEF ORGANIZATION MANAGEMENT"
banner "knife opc org create ORG_SHORT_NAME ORG_FULL_NAME (options)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider removing the opc prefix from all of these commands.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

def run
results = root_rest.get("organizations")
unless config[:all_orgs]
results = results.select { |k, v| !(k.length == 20 && k =~ /^[a-z]+$/) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this filter is from when we used to pre-generate organizations because organization took a long time. I believe this is no longer the default so perhaps it would be best to turn this filtering off by default and it can end up filtering out legit organizations.


class Chef
class Org
module GroupOperations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we really need a separate module for this. It was structured this way in the plugin because we lived outside the Chef codebase, but we could probably add these features directly to the Chef::Org class or create a new Chef::Group class that would abstract away some of these features.

module Opc
class OpcUserCreate < Chef::Knife
category "CHEF ORGANIZATION MANAGEMENT"
banner "knife opc user create USERNAME FIRST_NAME [MIDDLE_NAME] LAST_NAME EMAIL PASSWORD"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a set of knife user commands that I think should cover most of the user-related commands in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see one or the other, but not both user commands. Since every chef server is a server with an org at this point we should just make any missing functionality part of the existing knife user operations.

# Rather than upgrade all of this code to move to v1, the goal is to remove the
# need for this plugin. See
# https://github.com/chef/chef/issues/3517
@root_rest ||= Chef::ServerAPI.new(Chef::Config[:chef_server_root], { api_version: "0" })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the existing user plugins were converted to v1 and that none of the other APIs here really care about the API version so we can probably don't need to specify the api_version if we end up removing the user-related commands from this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this should go away and we should not be using v0 here.

@snehaldwivedi
Copy link
Contributor Author

snehaldwivedi commented Jul 22, 2020

NOTE: This test is failing due to changes in gem chef/.bundle/ruby/2.7.0/gems/tty-prompt-0.21.0/lib/tty/prompt/question.rb
attr_accessor :echo need to be added here

@tas50 tas50 added the Status: Waiting on Contributor A pull request that has unresolved requested actions from the author. label Jul 27, 2020
@snehaldwivedi
Copy link
Contributor Author

snehaldwivedi commented Jul 29, 2020

I am working on all review comments also I found that both knife user and knife opc user commands don't match completely, like for example knife opc user list also provide list of user associated with organisations which is not available in knife user list command. So I think we can merge that too and started working on this as well.

@snehaldwivedi snehaldwivedi force-pushed the snehal/Merge_knife_plugin_into_Chef branch from d8deb15 to 76ffdf5 Compare July 31, 2020 11:47
# See the License for the specific language governing permissions and
# limitations under the License.
#
require_relative "../mixin/root_rest"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this mixin still needs to go away

@@ -1,6 +1,6 @@
#
# Author:: Steven Danna (<steve@chef.io>)
# Copyright:: Copyright (c) Chef Software Inc.
# Copyright:: Copyright 2011-2016 Chef Software, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these copyrights need to get updated

end
end
end

def prompt_for_password
ui.ask("Please enter the user's password: ") { |q| q.echo = false }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ui.ask("Please enter the user's password: ") { |q| q.echo = false }
ui.ask("Please enter the user's password: ", echo: false)

@snehaldwivedi snehaldwivedi force-pushed the snehal/Merge_knife_plugin_into_Chef branch from 6146928 to 30cde90 Compare August 7, 2020 05:01
@btm
Copy link
Contributor

btm commented Aug 7, 2020

@snehaldwivedi if knife org edit survives into core, please test it to see that it opens the editor? chef-boneyard/knife-opc#57

@snehaldwivedi snehaldwivedi force-pushed the snehal/Merge_knife_plugin_into_Chef branch from c9d41dc to 3842097 Compare August 10, 2020 13:43

def run
org_name = @name_args[0]
ui.output root_rest.get("organizations/#{org_name}")
org = Chef::Org.from_hash({ "name" => org_name })
ui.output org.chef_rest.get("organizations/#{org_name}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like this should be pushed into the Chef::Org object.

I haven't looked but we should be able to do something to get a Chef::Org object for the org_name directly rather than going in through from_hash and then the get call should be hidden from the caller. That could be combined into one static method if necessary like Chef::Org.load(org_name) (unless that collides with an existing method name but something like that)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay I will look into that

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lamont-granquist I would prefer to add root_rest method to knife.rb similar to rest so that it will be available to all subclasses as we have more root level operations into chef core.

    def root_rest
      @root_rest ||= begin
        require_relative "server_api"
        Chef::ServerAPI.new(Chef::Config[:chef_server_root])
      end
    end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the point here though is that AFAIK we should not be using protocol v0, and I don't understand why this PR is spreading it everywhere.

The chef/user.rb that defines the chef_rest_v0 object has a large banner at the top of it that Chef::User should be replaced by Chef::UserV1 in Chef 13 (that didn't happen) but AFAIK it should all go away. I have no idea why knife-opc was using v0, that may have been due to some kind of backwards compatibility with now-ancient chef-servers. Without knowing what breaks, my position is that it should be removed and we should be using our normal v2 rest objects consistently.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

knife-opc was using v0 simply because we needed it to work ASAP and that was the smallest possible change, so 👍 to doing it right this time around.

@btm btm linked an issue Aug 13, 2020 that may be closed by this pull request
8 tasks
option :no_disassociate_user,
long: "--no-disassociate-user",
short: "-d",
description: "Don't disassociate the user first"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disassociate from what? This description isn't very helpful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for disassociate user I will update once this is merge chef-boneyard/knife-opc#36 as it has changes related to it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tas50 can you please confirm if chef-boneyard/knife-opc#56 is good to add changes in this PR?

@snehaldwivedi
Copy link
Contributor Author

snehaldwivedi commented Oct 9, 2020

I have removed abstract_user as we are not covering cleanup #10458 on this PR. Updated API version back to 1 and used user_v1 for commands that require any helper methods else used directly rest objects.

Please let me know if require any changes

@snehaldwivedi
Copy link
Contributor Author

@tas50 Can you please have a look into the PR for merge or if any more changes required form my side?

@lamont-granquist
Copy link
Contributor

You should be able to eliminate the @root_rest API object entirely and just use the default knife rest object. That is a v2 REST object but it should work fine with the users_v1 object. They don't have to match the rest object just needs to be a higher version, which it should be. It would break with users_v0 which is deprecated at this point.

@snehaldwivedi
Copy link
Contributor Author

snehaldwivedi commented Feb 4, 2021

Hi @lamont-granquist

As per my analysis, I cannot use the default rest object as its uses chef_server_url which will not provide us the exact result required for the opc commands. Because chef_server_url is URL for the specific organizations which will not provide the proper result like if we need a list of all organization, global user requirement in this ticket.

If we can change chef_server_url to chef_server_root in rest object then we can use it. Please let me know if you have any suggestions on this or any other way to do this?

@lamont-granquist
Copy link
Contributor

Okay the communication failure is now a bit more obvious. You can do that, but you need to remove { api_version: "1" } off of the arguments, that's the problem that I'm having with it.

@snehaldwivedi snehaldwivedi force-pushed the snehal/Merge_knife_plugin_into_Chef branch 2 times, most recently from 3a7e23b to 182d836 Compare February 11, 2021 12:27
@@ -640,7 +640,7 @@ def test_mandatory_field(field, fieldname)
def rest
@rest ||= begin
require_relative "server_api"
Chef::ServerAPI.new(Chef::Config[:chef_server_url])
Chef::ServerAPI.new(Chef::Config[:chef_server_root])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this change the rest API for all the rest of the knife commands though?

i was okay with the root_rest object but just didn't want it v1.

Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
Signed-off-by: snehaldwivedi <sdwivedi@msystechnologies.com>
@snehaldwivedi snehaldwivedi force-pushed the snehal/Merge_knife_plugin_into_Chef branch from 182d836 to 0570757 Compare February 16, 2021 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Waiting on Contributor A pull request that has unresolved requested actions from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Merge knife-opc into core Chef
7 participants