-
Notifications
You must be signed in to change notification settings - Fork 395
Modifications to UsePSCredentialType and AvoidUsernameAndPasswordParams rules. #455
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
Conversation
…ttribute in UsePSCredentialType rule.
I'm opposed to this change. Why are you removing the ordering enforcement. It is mandatory if you want a Credential parameter to work properly. The only way you can have a -Credential parameter that accepts both string and PSCredential types as input is if you define it as follows: [Parameter()] I added the default value to highlight that best practice as well; however, PSCredential must be defined above/before the Credential converter attribute so that the value passed in can be converted (from string) before PowerShell checks to make sure it is of type PSCredential. |
I Agree with @KirkMunro as this would be essentially reverting work done in #391 |
@KirkMunro In #391, you mention that a function will return error if CredentialAttribute precedes PSCredential, but I am not able to reproduce the error. Consider the following.
Since the order doesn't seem to make any difference why should we enforce it? |
Have you tried that in downlevel versions of Windows running PowerShell 2, 3 and/or 4? In those versions of PowerShell, order matters. In PowerShell 5+, conversion attributes are processed before type attributes, so order doesn't matter. Since downlevel versions are still around and in use, it's better for the community if order is enforced on this rule, regardless of the version of PowerShell that is being used. Once PowerShell version 5 becomes the minimum supported version for PSScriptAnalyser, then the order enforcement can be removed without issue. |
@KirkMunro You are right. On versions 3 and 4, Get-Credential1 -Credential "someuser" indeed gives an error. As the rule is applicable to v3 and v4 but not to v5, I agree that we shouldn't remove the ordering enforcement. However, given that the rule is not applicable to v5 it will only cause noise within v5 context. My suggestion then would be to keep the ordering but change the error message stating that the warning is applicable only to v3 and v4. |
Changing the error message is fine with me. I just didn't want the ordering enforcement work to be undone. |
Closing the pull request as the issue we were addressing was not completely examined. |
No description provided.