Skip to content

Commit 4ae3580

Browse files
authored
Add warning message for -DefaultProfile (Azure#1128)
* Add warning message for -DefaultProfile and clean model cmdlet folder when regenerate * Use PSVersionTable.PSVersion for PowerShell versio
1 parent fa5578c commit 4ae3580

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

docs/samples/xkcd/xkcd.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ info:
1010
x-apisguru-categories:
1111
- media
1212
x-logo:
13-
url: 'https: //api.apis.guru/v2/cache/logo/http_imgs.xkcd.com_static_terrible_small_logo.png'
13+
url: 'https://api.apis.guru/v2/cache/logo/http_imgs.xkcd.com_static_terrible_small_logo.png'
1414
x-origin:
1515
- format: swagger
16-
url: 'https: //raw.githubusercontent.com/APIs-guru/unofficial_openapi_specs/master/xkcd.com/1.0.0/swagger.yaml'
16+
url: 'https://raw.githubusercontent.com/APIs-guru/unofficial_openapi_specs/master/xkcd.com/1.0.0/swagger.yaml'
1717
version: '2.0'
1818
x-preferred: true
1919
x-providerName: xkcd.com
@@ -22,7 +22,7 @@ info:
2222
- comics
2323
x-unofficialSpec: true
2424
externalDocs:
25-
url: 'https: //xkcd.com/json.html'
25+
url: 'https://xkcd.com/json.html'
2626
securityDefinitions: {}
2727
produces:
2828
- application/json

powershell/cmdlets/class.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ export class CmdletClass extends Class {
519519
proxyUri.add(new Attribute(CategoryAttribute, { parameters: [`${ParameterCategory}.Runtime`] }));
520520

521521
if (this.state.project.azure) {
522-
this.defaultProfile = this.add(new Property('DefaultProfile', PSObject, { description: 'The credentials, account, tenant, and subscription used for communication with Azure' }));
523-
this.defaultProfile.add(new Attribute(ParameterAttribute, { parameters: ['Mandatory = false', 'HelpMessage = "The credentials, account, tenant, and subscription used for communication with Azure."'] }));
522+
this.defaultProfile = this.add(new Property('DefaultProfile', PSObject, { description: 'The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription' }));
523+
this.defaultProfile.add(new Attribute(ParameterAttribute, { parameters: ['Mandatory = false', 'HelpMessage = "The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription."'] }));
524524
this.defaultProfile.add(new Attribute(ValidateNotNull));
525525
this.defaultProfile.add(new Attribute(Alias, { parameters: ['"AzureRMContext"', '"AzureCredential"'] }));
526526
this.defaultProfile.add(new Attribute(CategoryAttribute, { parameters: [`${ParameterCategory}.Azure`] }));

powershell/generators/script-cmdlet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ ${command.link || ''}
112112
[Alias('AzureRMContext', 'AzureCredential')]
113113
[ValidateNotNull()]
114114
[System.Management.Automation.PSObject]
115-
# The credentials, account, tenant, and subscription used for communication with Azure.
115+
# The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
116116
$\{DefaultProfile\},`);
117117
yield '';
118118
}
@@ -253,7 +253,7 @@ $\{ProxyUseDefaultCredentials\}
253253
[Alias('AzureRMContext', 'AzureCredential')]
254254
[ValidateNotNull()]
255255
[System.Management.Automation.PSObject]
256-
# The credentials, account, tenant, and subscription used for communication with Azure.
256+
# The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
257257
${DefaultProfile},
258258
259259
[Parameter()]

powershell/resources/assets/build-module.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ $null = New-Item -ItemType Directory -Force -Path $examplesFolder
112112

113113
Write-Host -ForegroundColor Green 'Creating cmdlets for specified models...'
114114
$modelCmdlets = @(${$project.modelCmdlets.map(each => `'` + each + `'`).join(', ')})
115+
$modelCmdletFolder = Join-Path (Join-Path $PSScriptRoot '${$project.customFolder}') 'autogen-model-cmdlets'
116+
if (Test-Path $modelCmdletFolder) {
117+
$null = Remove-Item -Force -Recurse -Path $modelCmdletFolder
118+
}
115119
if ($modelCmdlets.Count -gt 0) {
116120
. (Join-Path $PSScriptRoot 'create-model-cmdlets.ps1')
117121
CreateModelCmdlet($modelCmdlets)

powershell/resources/assets/tools/Resources/custom/New-AzDeployment.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ function New-AzDeployment {
116116
# The location to store the deployment data.
117117
${Location},
118118

119-
[Parameter(HelpMessage='The credentials, account, tenant, and subscription used for communication with Azure.')]
119+
[Parameter(HelpMessage='The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.')]
120120
[Alias('AzureRMContext', 'AzureCredential')]
121121
[ValidateNotNull()]
122122
[Microsoft.Azure.PowerShell.Cmdlets.Resources.Category('Azure')]
123123
[System.Management.Automation.PSObject]
124-
# The credentials, account, tenant, and subscription used for communication with Azure.
124+
# The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
125125
${DefaultProfile},
126126

127127
[Parameter(HelpMessage='Run the command as a job')]

powershell/resources/psruntime/BuildTime/Models/PsProxyOutputs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private string GetTelemetry()
199199
{
200200
return $@"
201201
{Indent}{Indent}if ($null -eq [Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet]::PowerShellVersion) {{
202-
{Indent}{Indent}{Indent}[Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet]::PowerShellVersion = $Host.Version.ToString()
202+
{Indent}{Indent}{Indent}[Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet]::PowerShellVersion = $PSVersionTable.PSVersion.ToString()
203203
{Indent}{Indent}}}
204204
{Indent}{Indent}$preTelemetryId = [Microsoft.WindowsAzure.Commands.Common.MetricHelper]::TelemetryId
205205
{Indent}{Indent}if ($preTelemetryId -eq '') {{

powershell/resources/psruntime/MessageAttributeHelper.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace Microsoft.Message.ClientRuntime
2323
using System.Threading.Tasks;
2424
public class MessageAttributeHelper
2525
{
26+
private static readonly bool IsAzure = Convert.ToBoolean(@"${$project.azure}");
2627
public const string BREAKING_CHANGE_ATTRIBUTE_INFORMATION_LINK = "https://aka.ms/azps-changewarnings";
2728
public const string SUPPRESS_ERROR_OR_WARNING_MESSAGE_ENV_VARIABLE_NAME = "SuppressAzurePowerShellBreakingChangeWarnings";
2829

@@ -52,7 +53,10 @@ public static void ProcessCustomAttributesAtRuntime(CommandInfo commandInfo, Inv
5253
//Do not process the attributes at runtime... The env variable to override the warning messages is set
5354
return;
5455
}
55-
56+
if (IsAzure && invocationInfo.BoundParameters.ContainsKey("DefaultProfile"))
57+
{
58+
psCmdlet.WriteWarning("The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.");
59+
}
5660
List<GenericBreakingChangeAttribute> attributes = new List<GenericBreakingChangeAttribute>(GetAllBreakingChangeAttributesInType(commandInfo, invocationInfo, parameterSet));
5761
StringBuilder sb = new StringBuilder();
5862
Action<string> appendBreakingChangeInfo = (string s) => sb.Append(s);

0 commit comments

Comments
 (0)