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

Tagging #if statements for Az #91

Closed
wants to merge 4 commits into from
Closed

Conversation

MiYanni
Copy link
Contributor

@MiYanni MiYanni commented Oct 31, 2018

This is for: Azure/azure-powershell#6793

Status Name Location Notes
Tagged DiskDataStore.cs C:\Code\azure-powershell-common\src\Authentication.Abstractions\  
Low Risk AzureSessionInitializer.cs C:\Code\azure-powershell-common\src\Authentication\ Primary changes covered in Azure/azure-powershell#6166
Tagged AdalTokenProvider.cs C:\Code\azure-powershell-common\src\Authentication\Authentication\  
Tagged ITokenProvider.cs C:\Code\azure-powershell-common\src\Authentication\Authentication\  
Tagged KeyStoreApplicationCredentialProvider.cs C:\Code\azure-powershell-common\src\Authentication\Authentication\  
Tagged ProtectedFileTokenCache.cs C:\Code\azure-powershell-common\src\Authentication\Authentication\  
Tagged ServicePrincipalTokenProvider.cs C:\Code\azure-powershell-common\src\Authentication\Authentication\  
High Risk AuthenticationFactory.cs C:\Code\azure-powershell-common\src\Authentication\Factories\ No Certificate-based authentication
Tagged AzureDataCmdlet.cs C:\Code\azure-powershell-common\src\Common\  
Tagged AzurePowerShell.cs C:\Code\azure-powershell-common\src\Common\  
Tagged GeneralUtilities.cs C:\Code\azure-powershell-common\src\Common\Utilities\  
Tagged Validate.cs C:\Code\azure-powershell-common\src\Common\Utilities\  
Tagged AzureRMConstants.cs C:\Code\azure-powershell-common\src\ResourceManager\  

Key

  • Tagged: The #if NETSTANDARD was simply tagged with either // TODO: Remove IfDef or // TODO: Remove IfDef code. These changes are unlikely to cause issues and/or won't require any special attention for migration.
  • Low Risk: There are differences between net452 and netstandard. These may need information added to the migration guide. They have minimal/low risk changes.
  • High Risk: There are differences between net452 and netstandard. These likely need information added to the migration guide. The changes may fundamentally alter how the files/cmdlets works.
  • Resolved: The #if NETSTANDARD was removed and not necessary.

# Conflicts:
#	src/Authentication/Authentication/AdalTokenProvider.cs
#	src/Authentication/Authentication/ITokenProvider.cs
#	src/Authentication/Factories/AuthenticationFactory.cs
userId,
password,
credentialType);
return _userTokenProvider.GetAccessToken(config, promptBehavior, promptAction, userId, password, credentialType);
Copy link
Member

Choose a reason for hiding this comment

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

why the two different styles of call? Above you move from a single line, here you move to a single line. Seems like we could just leave this alone altogether, or always use the multi-line call

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 don't remember changing this. It might have happened automatically when I renamed the field with the underscore. This is why I like the idea of having a code style that is applied to the entire codebase automatically. 😉

Copy link
Member

Choose a reason for hiding this comment

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

As a ganeral rule, this is good, but this can run afoul of other engineering best practices (e.g. it is a good idea to make changes to legacy codebases minimal, to prevent introducing regressions)

{
if (_store.FileExists(cacheFileName))
if (!_store.FileExists(cacheFileName)) return;
Copy link
Member

Choose a reason for hiding this comment

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

Always enclose the code block of an if statement in brackets, even if there is only one statement in the block. This future-proofs you in case additional staatements are added to the block in revisions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, that is the purpose of not using brackets. The code's intent is to not add additional code to the if-statement. It is a guard clause. In these instances, I don't even write that code. It is generated by Resharper, and is stylistically correct for the intent. However, I can understand this being confusing if you are not used to C#.

I can't find any specific materials on it, but I've always seen guard clauses as single line statements. However, if we want all if-statements to have brackets, we should enforce it via a style manager.

Copy link
Member

Choose a reason for hiding this comment

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

First of all, none of these modificatiosn are necessary for the purpose of this PR, and they are holding up the PR as we have this discussion.

Secondly, there is a reason why no if statement block should ever lack brackets, and it has to do with engineering best practices for maintenance. If you don't have brackets, it is an easy mistake to place another statement under the if clause withoutadding the brackets ina future revision.

Additionally, this entire pattern adds an additional exit point for the function. It is not necessary for this change, and we should remove it.

{
if (HasStateChanged)
Copy link
Member

Choose a reason for hiding this comment

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

Please revert this to the simple if

{
IAzureTokenCache result = new AuthenticationStoreTokenCache(new AzureTokenCache());
if (autoSaveMode == ContextSaveMode.CurrentUser)
if (autoSaveMode != ContextSaveMode.CurrentUser) return result;
Copy link
Member

Choose a reason for hiding this comment

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

revert this pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comments from Azure/azure-powershell#7712

Copy link
Member

Choose a reason for hiding this comment

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

There are no comments there on this. See above, pleaser rever6t this - it is unrelated to the change that is the subject of this PR.

@@ -34,7 +34,7 @@ public AuthenticationFactory()
{
_getKeyStore = () =>
{
IServicePrincipalKeyStore keyStore = null;
Copy link
Member

Choose a reason for hiding this comment

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

I believe that some versions of CodeAnalysis will show this as uninitialized - let's leave in the explicit initialization

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not uninitialized. See comments from Azure/azure-powershell#7712

Copy link
Member

Choose a reason for hiding this comment

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

I am aware of how the language works, I am talking about earlier versions of CodeAnalysis.

@@ -325,7 +311,7 @@ public ServiceClientCredentials GetServiceClientCredentials(IAzureContext contex
tokenCache = context.TokenCache;
}

ServiceClientCredentials result = null;
Copy link
Member

Choose a reason for hiding this comment

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

same comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not uninitialized. See comments from Azure/azure-powershell#7712

{
// make best effort to remove credentials
}
var cache = tokenCache as TokenCache;
Copy link
Member

Choose a reason for hiding this comment

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

revert this pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comments in Azure/azure-powershell#7712

Copy link
Member

Choose a reason for hiding this comment

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

See comments above, please revert

{
if (cache != null && cache.Count > 0 && account != null && !string.IsNullOrWhiteSpace(account.Id) && !string.IsNullOrWhiteSpace(account.Type))
if (cache == null || cache.Count <= 0 || account == null || string.IsNullOrWhiteSpace(account.Id) ||
Copy link
Member

Choose a reason for hiding this comment

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

revert this pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comments in Azure/azure-powershell#7712

Copy link
Member

Choose a reason for hiding this comment

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

see comments above, please revert

{
bool result = false;
if (account != null && !string.IsNullOrWhiteSpace(account.Type) && item != null)
if (account == null || string.IsNullOrWhiteSpace(account.Type) || item == null) return false;
Copy link
Member

Choose a reason for hiding this comment

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

revert this pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comments in Azure/azure-powershell#7712

Copy link
Member

@markcowl markcowl Nov 19, 2018

Choose a reason for hiding this comment

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

see comments above, please revert

{
msg = exceptionMessage;
}
if (FileUtilities.DataStore.DirectoryExists(directory)) return;
Copy link
Member

Choose a reason for hiding this comment

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

revert this pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See comments in Azure/azure-powershell#7712

Copy link
Member

Choose a reason for hiding this comment

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

see comments above, please revert

@markcowl
Copy link
Member

For this row:

High Risk AuthenticationFactory.cs C:\Code\azure-powershell-common\src\Authentication\Factories\

I don't see an ifdef in this file, what is the high risk change?

@MiYanni
Copy link
Contributor Author

MiYanni commented Nov 19, 2018

@markcowl There used to be #if NETSTANDARD in AuthenticationFactory.cs: 2936235#diff-d1505bde5cceebeeb089715e3d33314cR127

I'm assuming this was removed as part of Cormac's changes in this repo.

@MiYanni MiYanni changed the base branch from dev to master December 5, 2018 00:39
@markcowl
Copy link
Member

markcowl commented Jan 3, 2019

@MiYanni do we still need this PR?

@MiYanni
Copy link
Contributor Author

MiYanni commented Jan 3, 2019

Nope.

@MiYanni MiYanni closed this Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants