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

Config framework implementation #17545

Merged
merged 10 commits into from
May 12, 2022
Merged

Config framework implementation #17545

merged 10 commits into from
May 12, 2022

Conversation

isra-fel
Copy link
Member

@isra-fel isra-fel commented Mar 22, 2022

This PR implements the abstractions defined in Azure/azure-powershell-common#313

You can review this PR by commits:

  1. 8efa0f9 brought in the code of Microsoft.Extensions.Configuration library we use as the storage layer, with some modification that allows us to update the configuration; to read environment variables from different targets (user/system) etc.
  2. e54b3cb is the main implementation of the interfaces, the core types being ConfigManager which provides all the CRUD APIs to the config; and ConfigInitializer which initializes the config file and config manager. This commit also includes helper classes and abstract config definitions.
  3. 3f59938 is about the PowerShell cmdlets, for example, Get-AzConfig.
  4. c1e967f is tests.

Description

Checklist

  • I have read the Submitting Changes section of CONTRIBUTING.md
  • The title of the PR is clear and informative
  • The appropriate ChangeLog.md file(s) has been updated:
    • For any service, the ChangeLog.md file can be found at src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md
    • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header -- no new version header should be added
  • The PR does not introduce breaking changes
  • If applicable, the changes made in the PR have proper test coverage
  • For public API changes to cmdlets:

src/Accounts/.editorconfig Outdated Show resolved Hide resolved
src/Accounts/Accounts.sln Outdated Show resolved Hide resolved
src/Accounts/Accounts/Az.Accounts.psd1 Outdated Show resolved Hide resolved
src/Accounts/Accounts/Config/ClearConfigCommand.cs Outdated Show resolved Hide resolved
src/Accounts/Accounts/Config/ConfigCommandBase.cs Outdated Show resolved Hide resolved
src/Accounts/Authentication/Config/ConfigInitializer.cs Outdated Show resolved Hide resolved
src/Accounts/Authentication/Config/ConfigInitializer.cs Outdated Show resolved Hide resolved
src/Accounts/Authentication/Config/ConfigInitializer.cs Outdated Show resolved Hide resolved
src/Accounts/Authentication/Config/ConfigInitializer.cs Outdated Show resolved Hide resolved
```

## DESCRIPTION
{{ Fill in the Description }}
Copy link
Member Author

Choose a reason for hiding this comment

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

Docs will be updated in a following PR.
I merely included them for CI.

}
}

// todo: tests initializes configs in a different way. Maybe there should be an abstraction IConfigInitializer and two concrete classes ConfigInitializer + TestConfigInitializer
Copy link
Member Author

Choose a reason for hiding this comment

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

This refactoring is low priority

configManager.BuildConfig();
}

private void RegisterConfigs(IConfigManager configManager)
Copy link
Member Author

Choose a reason for hiding this comment

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

This method will be implemented in a follow up PR

Copy link
Member

Choose a reason for hiding this comment

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

It is great that those code can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed

src/Accounts/Accounts/Config/ConfigCommandBase.cs Outdated Show resolved Hide resolved
@isra-fel isra-fel marked this pull request as ready for review March 24, 2022 08:53
public static class AppliesToHelper
{
internal static readonly Regex ModulePattern = new Regex(@"^az\.[a-z]+$", RegexOptions.IgnoreCase);
internal static readonly Regex CmdletPattern = new Regex(@"^[a-z]+-[a-z]+$", RegexOptions.IgnoreCase);
Copy link
Member

@dingmeng-xue dingmeng-xue Apr 12, 2022

Choose a reason for hiding this comment

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

Cmdlet may contains digital number. such as Get-AzDataFactoryV2 I recommend that module supports digital number too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added numbers to the regex and moved the logic of handling regex into a new PSNamingUtilities class.

@@ -30,4 +30,8 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this part? it seems it is not required.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed

@isra-fel isra-fel self-assigned this Apr 12, 2022
Comment on lines +58 to +61
private bool IsMultiContent(object value)
{
return value is Array;
}
Copy link
Member

Choose a reason for hiding this comment

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

seems not required. nice to have.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, nice to have.

@dingmeng-xue
Copy link
Member

A general question. If class is defined as interface, why is its namespace internal?

@isra-fel
Copy link
Member Author

A general question. If class is defined as interface, why is its namespace internal?

The code in the internal namespace works as the data layer of the config framework. It is not supposed to be exposed as public API, so I made it explicit by the namespace.

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