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

win_chocolatey_feature: new module #42848

Merged
merged 2 commits into from Jul 18, 2018

Conversation

jborean93
Copy link
Contributor

SUMMARY

In continuing with the work of completing https://chocolatey.org/docs/features-infrastructure-automation#chocolatey-integration-implementation-with-common-configuration-managers

Manages Chocolatey features https://chocolatey.org/docs/commands-feature.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

win_chocolatey_feature

ANSIBLE VERSION
devel

@ansibot
Copy link
Contributor

ansibot commented Jul 16, 2018

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. windows Windows community labels Jul 16, 2018
@ansibot
Copy link
Contributor

ansibot commented Jul 16, 2018

@Daniel-Sanchez-Fabregas @LiranNis @SamLiu79 @timothyvandenbrande @andrewsaraceni @ar7z1 @blakfeld @brianlloyd @chrishoffman @daBONDi @elventear @erwanquelin @henrikwallstrom @if-meaton @joshludwig @marqelme @nwchandler @nwsparks @petemounce @ptemplier @riponbanik @rndmh3ro @schwartzmx @smadam813 @themiwi @tksarah

As a maintainer of a module in the same namespace this new module has been submitted to, your vote counts for shipits. Please review this module and add shipit if you would like to see it merged.

click here for bot help

@@ -0,0 +1,75 @@
#!powershell
# This file is part of Ansible
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is a minor nitpick, but I am looking at making the Windows modules more consistent. Does the addition of # This file is part of Ansible has any useful meaning ?

Also, we tend to have # -*- coding: utf-8 -*- as the second line.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW I see you are doing this for the .py file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The # This file is part of Ansible isn't needed IMO, I'm just copying pasting from another module and happy to have it removed. I don't think we should have # -*- coding: utf-8 -* as that is not a Windows/PowerShell-ism. There's no benefit for having that in the PowerShell modules.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright, I always asumed # -*- coding: utf-8 -*- was an editor/IDE feature, but it does seem to be tight to Python specifically. Let me get rid of those then.

Copy link
Contributor

Choose a reason for hiding this comment

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

#!powershell
# This file is part of Ansible

# Copyright (c) 2018 Ansible Project
Copy link
Contributor

Choose a reason for hiding this comment

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

Another minor nitpick is that the syntax for copyright lines used to be:

# Copyright: (c) 2018, Ansible Project

I know people have been adding other stuff since, but this was originally documented and automated by @abadger and I have been updating at least my modules like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW I see you are doing this for the .py file.

@dagwieers
Copy link
Contributor

cc @gep13 @ferventcoder

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Jul 16, 2018
Copy link

@gep13 gep13 left a comment

Choose a reason for hiding this comment

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

Just a minor nit pick

} else {
$state_string = "disable"
}
$res = Run-Command -command "`"$($choco_app.Path)`" feature $state_string --name `"$name`""
Copy link

Choose a reason for hiding this comment

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

The recommended command here would be:

choco feature enable --name="'<name>'"

Copy link

Choose a reason for hiding this comment

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

While the command you have will work, it is not best practice.

Copy link
Contributor Author

@jborean93 jborean93 Jul 17, 2018

Choose a reason for hiding this comment

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

I have a few questions

  • Why the double quoting " and ' of the value, surely having separate arguments (that are correctly escaped) is a better option
  • Is it a preference from Chocolatey from a docs and ensuring user's escape correctly or is the parser expecting this format

This is calling CreateProcessW directly so cmd shell quotes don't take effect here, only " is used in this layer when being parsed by Windows.

While in this module it isn't as important, other modules we have a special function that takes in an array of args and correctly escapes them so the program receive those args as written (without the user escaping them themselves). The Chocolatey preferred format --key="'value'" won't work well with the function we have while the --key value format is a lot easier.

Copy link

Choose a reason for hiding this comment

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

Due to the myriad of escaping, and quote removal, and potential for spaces in paths/names, etc. that happens when interacting between cmd and powershell, etc. our guidance/best practice is always to use the equivalent of this:

choco feature enable --name="'<featureName>'"

for each Chocolatey command. We have found that this is the most resilient way to correctly pass the intended parameters into Chocolatey, and have them be recognised.

Arguably, this isn't needed here, since feature names will never have spaces, etc. However, if someone were to look at this command, and how it is doing something, and then apply the same to another Chocolatey command, it might not work as intended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, so sounds like it's more getting users to escape their args correctly. From a maintainability perspective I feel like keeping the existing format is better for us. If a user copies and paste what we are doing then the onus is on them to figure out what is going wrong then just blindly copying it. There are plenty of docs in Chocolatey to cover these scenarios as well.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Jul 17, 2018
@jborean93 jborean93 merged commit 7ae5912 into ansible:devel Jul 18, 2018
@jborean93 jborean93 deleted the win_chocolatey_feature-module branch July 18, 2018 00:36
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. windows Windows community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants