Skip to content

Commit f26e381

Browse files
authored
Fix all style issues in src/Cli/func (#4380)
* Fix style in Common/ (#4370) * Fix style in Actions/ (part 1) (#4371) * Fix style in Actions/ (part 2) (#4372) * Fix style in Arm/ (#4373) * Fix style in Helpers/ (#4374) * Fix style in Exceptions/, Extensions/ and Interfaces/ (#4375) * Fix style in Telemetry/ (#4377) * Fix style in Models, ContainerApps, Diagnostics and misc (#4378) * Fix style in func root, broken tests, and errors in host (#4379) * Fix style in Kubernetes/ (#4376)
1 parent 72918ee commit f26e381

File tree

281 files changed

+3603
-2848
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

281 files changed

+3603
-2848
lines changed

src/Cli/func/ActionAttribute.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using System;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
23

34
namespace Azure.Functions.Cli
45
{
56
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
6-
sealed class ActionAttribute : Attribute
7+
internal sealed class ActionAttribute : Attribute
78
{
89
public Context Context { get; set; }
910

src/Cli/func/ActionType.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
using System;
2-
using System.Collections.Generic;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
namespace Azure.Functions.Cli
55
{
66
internal class ActionType
77
{
88
public Type Type { get; set; }
9+
910
public IEnumerable<Context> Contexts { get; set; }
11+
1012
public IEnumerable<Context> SubContexts { get; set; }
13+
1114
public IEnumerable<string> Names { get; set; }
1215
}
13-
}
16+
}

src/Cli/func/Actions/AzureActions/AddStorageAccountSettingAction.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
using System;
2-
using System.Linq;
3-
using System.Threading.Tasks;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Azure.Functions.Cli.Common;
5+
using Azure.Functions.Cli.Helpers;
6+
using Azure.Functions.Cli.Interfaces;
47
using Colors.Net;
58
using Fclp;
6-
using Azure.Functions.Cli.Arm;
7-
using Azure.Functions.Cli.Interfaces;
89
using static Azure.Functions.Cli.Common.OutputTheme;
9-
using Azure.Functions.Cli.Common;
10-
using Azure.Functions.Cli.Helpers;
1110

1211
namespace Azure.Functions.Cli.Actions.AzureActions
1312
{
@@ -17,14 +16,14 @@ internal class AddStorageAccountSettingAction : BaseAzureAction
1716
private readonly ISettings _settings;
1817
private readonly ISecretsManager _secretsManager;
1918

20-
public string StorageAccountName { get; set; }
21-
2219
public AddStorageAccountSettingAction(ISettings settings, ISecretsManager secretsManager)
2320
{
2421
_settings = settings;
2522
_secretsManager = secretsManager;
2623
}
2724

25+
public string StorageAccountName { get; set; }
26+
2827
public override ICommandLineParserResult ParseArgs(string[] args)
2928
{
3029
if (args.Any())
@@ -33,7 +32,8 @@ public override ICommandLineParserResult ParseArgs(string[] args)
3332
}
3433
else
3534
{
36-
throw new CliArgumentsException("Must specify storage account name.",
35+
throw new CliArgumentsException(
36+
"Must specify storage account name.",
3737
new CliArgument { Name = nameof(StorageAccountName), Description = "Storage Account Name" });
3838
}
3939

src/Cli/func/Actions/AzureActions/BaseAzureAction.cs

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
using System;
2-
using System.IO;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
34
using System.Runtime.InteropServices;
45
using System.Text;
5-
using System.Threading.Tasks;
6-
using Azure.Functions.Cli.Arm;
76
using Azure.Functions.Cli.Common;
8-
using static Azure.Functions.Cli.Common.OutputTheme;
97
using Azure.Functions.Cli.Interfaces;
108
using Colors.Net;
119
using Fclp;
1210
using Newtonsoft.Json;
1311
using Newtonsoft.Json.Linq;
14-
using static Colors.Net.StringStaticMethods;
15-
using Azure.Functions.Cli.Helpers;
12+
using static Azure.Functions.Cli.Common.OutputTheme;
1613

1714
namespace Azure.Functions.Cli.Actions.AzureActions
1815
{
19-
abstract class BaseAzureAction : BaseAction, IInitializableAction
16+
internal abstract class BaseAzureAction : BaseAction, IInitializableAction
2017
{
2118
// Az is the Azure PowerShell module that works in both PowerShell Core and Windows PowerShell
22-
private const string _azProfileModuleName = "Az.Accounts";
19+
private const string AzProfileModuleName = "Az.Accounts";
2320

2421
// AzureRm is the Azure PowerShell module that only works on Windows PowerShell
25-
private const string _azureRmProfileModuleName = "AzureRM.Profile";
22+
private const string AzureRmProfileModuleName = "AzureRM.Profile";
2623

2724
// PowerShell Core is version 6.0 and higher that is cross-platform
28-
private const string _powerShellCoreExecutable = "pwsh";
25+
private const string PowerShellCoreExecutable = "pwsh";
2926

3027
// Windows PowerShell is PowerShell version 5.1 and lower that only works on Windows
31-
private const string _windowsPowerShellExecutable = "powershell";
28+
private const string WindowsPowerShellExecutable = "powershell";
3229

33-
private const string _defaultManagementURL = Constants.DefaultManagementURL;
30+
private const string DefaultManagementURL = Constants.DefaultManagementURL;
3431

3532
public string AccessToken { get; set; }
33+
3634
public bool ReadStdin { get; set; }
35+
3736
public string ManagementURL { get; set; }
37+
3838
public string Subscription { get; private set; }
3939

4040
public override ICommandLineParserResult ParseArgs(string[] args)
@@ -73,6 +73,7 @@ public async Task Initialize()
7373
{
7474
AccessToken = accessToken;
7575
}
76+
7677
if (string.IsNullOrEmpty(AccessToken))
7778
{
7879
throw new CliException("Unable to set access token from stdin.");
@@ -101,14 +102,15 @@ private async Task<string> GetManagementURL()
101102
{
102103
// TODO: Try with Poweshell if az is non-existent or if the call fails
103104
// For now, let's default this out
104-
managementURL = _defaultManagementURL;
105+
managementURL = DefaultManagementURL;
105106
}
107+
106108
// Having a trailing slash could cause issues later when we attach it to function IDs
107109
// It's easier to remove now, than to do that before every ARM call.
108-
return managementURL.EndsWith("/") ? managementURL.Substring(0, managementURL.Length - 1) : managementURL;
110+
return managementURL.EndsWith("/") ? managementURL[..^1] : managementURL;
109111
}
110112

111-
private async Task<(bool, string)> TryGetAzCLIManagementURL()
113+
private async Task<(bool AzCliSucceeded, string ManagementURL)> TryGetAzCLIManagementURL()
112114
{
113115
try
114116
{
@@ -120,24 +122,33 @@ private async Task<string> GetManagementURL()
120122
{
121123
ColoredConsole.WriteLine(WarningColor("Unable to retrieve the resource manager URL from az CLI"));
122124
}
125+
123126
return (false, null);
124127
}
125128
}
126129

127130
private async Task<string> GetAccessToken()
128131
{
129132
(bool cliSucceeded, string cliToken) = await TryGetAzCliToken();
130-
if (cliSucceeded) return cliToken;
133+
134+
if (cliSucceeded)
135+
{
136+
return cliToken;
137+
}
131138

132139
(bool powershellSucceeded, string psToken) = await TryGetAzPowerShellToken();
133-
if (powershellSucceeded) return psToken;
140+
141+
if (powershellSucceeded)
142+
{
143+
return psToken;
144+
}
134145

135146
if (TryGetTokenFromTestEnvironment(out string envToken))
136147
{
137148
return envToken;
138149
}
139150

140-
throw new CliException($"Unable to connect to Azure. Make sure you have the `az` CLI or `{_azProfileModuleName}` PowerShell module installed and logged in and try again");
151+
throw new CliException($"Unable to connect to Azure. Make sure you have the `az` CLI or `{AzProfileModuleName}` PowerShell module installed and logged in and try again");
141152
}
142153

143154
private bool TryGetTokenFromTestEnvironment(out string token)
@@ -146,7 +157,7 @@ private bool TryGetTokenFromTestEnvironment(out string token)
146157
return !string.IsNullOrEmpty(token);
147158
}
148159

149-
private async Task<(bool succeeded, string token)> TryGetAzCliToken()
160+
private async Task<(bool Succeeded, string Token)> TryGetAzCliToken()
150161
{
151162
try
152163
{
@@ -158,6 +169,7 @@ private bool TryGetTokenFromTestEnvironment(out string token)
158169
{
159170
ColoredConsole.WriteLine(WarningColor("Unable to fetch access token from az CLI"));
160171
}
172+
161173
return (false, null);
162174
}
163175
}
@@ -168,13 +180,15 @@ private async Task<string> RunAzCLICommand(string param)
168180
{
169181
throw new CliException("az CLI not found");
170182
}
183+
171184
var az = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
172185
? new Executable("cmd", $"/c az {param}")
173186
: new Executable("az", param);
174187

175188
var stdout = new StringBuilder();
176189
var stderr = new StringBuilder();
177190
var exitCode = await az.RunAsync(o => stdout.AppendLine(o), e => stderr.AppendLine(e));
191+
178192
if (exitCode == 0)
179193
{
180194
return stdout.ToString().Trim(' ', '\n', '\r', '"');
@@ -185,18 +199,18 @@ private async Task<string> RunAzCLICommand(string param)
185199
{
186200
ColoredConsole.WriteLine(VerboseColor($"Unable to run az CLI command `az {param}`. Error: {stderr.ToString().Trim(' ', '\n', '\r')}"));
187201
}
202+
188203
throw new CliException("Error running Az CLI command");
189204
}
190205
}
191206

192-
private async Task<(bool succeeded, string token)> TryGetAzPowerShellToken()
207+
private async Task<(bool Succeeded, string Token)> TryGetAzPowerShellToken()
193208
{
194209
// PowerShell Core can only use Az so we can check that it exists and that the Az module exists
195-
if (CommandChecker.CommandExists(_powerShellCoreExecutable) &&
196-
await CommandChecker.PowerShellModuleExistsAsync(_powerShellCoreExecutable, _azProfileModuleName))
210+
if (CommandChecker.CommandExists(PowerShellCoreExecutable) &&
211+
await CommandChecker.PowerShellModuleExistsAsync(PowerShellCoreExecutable, AzProfileModuleName))
197212
{
198-
var az = new Executable(_powerShellCoreExecutable,
199-
$"-NonInteractive -o Text -NoProfile -c {GetPowerShellAccessTokenScript(_azProfileModuleName)}");
213+
var az = new Executable(PowerShellCoreExecutable, $"-NonInteractive -o Text -NoProfile -c {GetPowerShellAccessTokenScript(AzProfileModuleName)}");
200214

201215
var stdout = new StringBuilder();
202216
var stderr = new StringBuilder();
@@ -215,18 +229,18 @@ await CommandChecker.PowerShellModuleExistsAsync(_powerShellCoreExecutable, _azP
215229
}
216230

217231
// Windows PowerShell can use Az or AzureRM so first we check if powershell.exe is available
218-
if (CommandChecker.CommandExists(_windowsPowerShellExecutable))
232+
if (CommandChecker.CommandExists(WindowsPowerShellExecutable))
219233
{
220234
string moduleToUse;
221235

222236
// depending on if Az.Profile or AzureRM.Profile is available, we need to change the prefix
223-
if (await CommandChecker.PowerShellModuleExistsAsync(_windowsPowerShellExecutable, _azProfileModuleName))
237+
if (await CommandChecker.PowerShellModuleExistsAsync(WindowsPowerShellExecutable, AzProfileModuleName))
224238
{
225-
moduleToUse = _azProfileModuleName;
239+
moduleToUse = AzProfileModuleName;
226240
}
227-
else if (await CommandChecker.PowerShellModuleExistsAsync(_windowsPowerShellExecutable, _azureRmProfileModuleName))
241+
else if (await CommandChecker.PowerShellModuleExistsAsync(WindowsPowerShellExecutable, AzureRmProfileModuleName))
228242
{
229-
moduleToUse = _azureRmProfileModuleName;
243+
moduleToUse = AzureRmProfileModuleName;
230244
}
231245
else
232246
{
@@ -235,6 +249,7 @@ await CommandChecker.PowerShellModuleExistsAsync(_powerShellCoreExecutable, _azP
235249
{
236250
ColoredConsole.WriteLine(VerboseColor("Unable to find Az.Profile or AzureRM.Profile."));
237251
}
252+
238253
return (false, null);
239254
}
240255

@@ -255,24 +270,25 @@ await CommandChecker.PowerShellModuleExistsAsync(_powerShellCoreExecutable, _azP
255270
}
256271
}
257272
}
273+
258274
return (false, null);
259275
}
260276

261277
// Sets the prefix of the script in case they have Az.Profile or AzureRM.Profile
262278
private static string GetPowerShellAccessTokenScript(string module)
263279
{
264280
string prefix;
265-
if (module == _azProfileModuleName)
281+
if (module == AzProfileModuleName)
266282
{
267283
prefix = "Az";
268284
}
269-
else if (module == _azureRmProfileModuleName)
285+
else if (module == AzureRmProfileModuleName)
270286
{
271287
prefix = "AzureRM";
272288
}
273289
else
274290
{
275-
throw new ArgumentException($"Expected module to be '{_azProfileModuleName}' or '{_azureRmProfileModuleName}'");
291+
throw new ArgumentException($"Expected module to be '{AzProfileModuleName}' or '{AzureRmProfileModuleName}'");
276292
}
277293

278294
// This PowerShell script first grabs the Azure context, fetches the profile client and requests an accesstoken.

src/Cli/func/Actions/AzureActions/BaseFunctionAppAction.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System.Linq;
2-
using Azure.Functions.Cli.Arm;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
34
using Azure.Functions.Cli.Common;
45
using Fclp;
56

67
namespace Azure.Functions.Cli.Actions.AzureActions
78
{
8-
abstract class BaseFunctionAppAction : BaseAzureAction
9+
internal abstract class BaseFunctionAppAction : BaseAzureAction
910
{
1011
public string FunctionAppName { get; set; }
1112

@@ -25,7 +26,9 @@ public override ICommandLineParserResult ParseArgs(string[] args)
2526
}
2627
else
2728
{
28-
throw new CliArgumentsException("Must specify functionApp name.", base.ParseArgs(args),
29+
throw new CliArgumentsException(
30+
"Must specify functionApp name.",
31+
base.ParseArgs(args),
2932
new CliArgument { Name = nameof(FunctionAppName), Description = "Function App name" });
3033
}
3134

src/Cli/func/Actions/AzureActions/DeprecatedAzureActions.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.Threading.Tasks;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
24
using Azure.Functions.Cli.Common;
35

46
namespace Azure.Functions.Cli.Actions.AzureActions
@@ -22,4 +24,4 @@ public override Task RunAsync()
2224
throw new CliException("This command has been removed. Please use az-cli (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) or Azure Powershell (https://docs.microsoft.com/en-us/powershell/azure/overview) for management commands.");
2325
}
2426
}
25-
}
27+
}

src/Cli/func/Actions/AzureActions/FetchAppSettingsAction.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
using Colors.Net;
4-
using Azure.Functions.Cli.Arm;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Azure.Functions.Cli.Helpers;
55
using Azure.Functions.Cli.Interfaces;
6+
using Colors.Net;
67
using static Azure.Functions.Cli.Common.OutputTheme;
7-
using Azure.Functions.Cli.Helpers;
88

99
namespace Azure.Functions.Cli.Actions.AzureActions
1010
{
1111
[Action(Name = "fetch-app-settings", Context = Context.Azure, SubContext = Context.FunctionApp, HelpText = "Retrieve App Settings from your Azure-hosted Function App and store locally")]
1212
[Action(Name = "fetch", Context = Context.Azure, SubContext = Context.FunctionApp, HelpText = "Retrieve App Settings from your Azure-hosted Function App and store locally")]
1313
internal class FetchAppSettingsAction : BaseFunctionAppAction
1414
{
15-
private ISecretsManager _secretsManager;
15+
private readonly ISecretsManager _secretsManager;
1616

1717
public FetchAppSettingsAction(ISecretsManager secretsManager)
1818
{
@@ -37,9 +37,8 @@ public override async Task RunAsync()
3737
foreach (var connectionString in functionApp.ConnectionStrings)
3838
{
3939
ColoredConsole.WriteLine($"Loading {connectionString.Key} = *****");
40-
_secretsManager.SetConnectionString(connectionString.Key, connectionString.Value.value);
40+
_secretsManager.SetConnectionString(connectionString.Key, connectionString.Value.Value);
4141
}
42-
4342
}
4443
else
4544
{

0 commit comments

Comments
 (0)