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

Fix limit mode metadata blocking #4489

Merged
merged 2 commits into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ jobs:
testSelector: 'testAssemblies'
testAssemblyVer2: '**\Microsoft.Management.Configuration.UnitTests.dll'
searchFolder: '$(buildOutDir)\Microsoft.Management.Configuration.UnitTests'
codeCoverageEnabled: true
codeCoverageEnabled: false
platform: '$(buildPlatform)'
configuration: '$(BuildConfiguration)'
diagnosticsEnabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,39 @@ namespace winrt::Microsoft::Management::Configuration::implementation
// TODO: Consider having the version/uri/type information all together in the future
if (schemaVersion.PartAt(0).Integer == 0 && schemaVersion.PartAt(1).Integer == 1)
{
throw E_NOTIMPL;
THROW_HR(E_NOTIMPL);
}
else if (schemaVersion.PartAt(0).Integer == 0 && schemaVersion.PartAt(1).Integer == 2)
{
return std::make_unique<ConfigurationSetSerializer_0_2>();
}
else if (schemaVersion.PartAt(0).Integer == 0 && schemaVersion.PartAt(1).Integer == 3)
{
throw E_NOTIMPL;
THROW_HR(E_NOTIMPL);
}
else
{
AICLI_LOG(Config, Error, << "Unknown configuration version: " << schemaVersion.ToString());
throw E_UNEXPECTED;
THROW_HR(E_UNEXPECTED);
}
}

void ConfigurationSetSerializer::WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet)
void ConfigurationSetSerializer::WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet, std::initializer_list<ConfigurationField> exclusions)
{
// Create a sorted list of the field names to exclude
std::vector<winrt::hstring> exclusionStrings;
for (ConfigurationField field : exclusions)
{
exclusionStrings.emplace_back(GetConfigurationFieldNameHString(field));
}
std::sort(exclusionStrings.begin(), exclusionStrings.end());

emitter << BeginMap;

for (const auto& [key, value] : valueSet)
{
if (value != nullptr)
if (value != nullptr &&
!std::binary_search(exclusionStrings.begin(), exclusionStrings.end(), key))
{
std::string keyName = winrt::to_string(key);
emitter << Key << keyName << Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the MIT License.
#pragma once
#include "ConfigurationSetSerializer.h"
#include "ConfigurationSetUtilities.h"
#include "ConfigurationSet.h"

#include <winget/Yaml.h>
#include <initializer_list>

namespace winrt::Microsoft::Management::Configuration::implementation
{
Expand All @@ -26,7 +28,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation
ConfigurationSetSerializer() = default;

void WriteYamlConfigurationUnits(AppInstaller::YAML::Emitter& emitter, const std::vector<ConfigurationUnit>& units);
void WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet);
void WriteYamlValueSet(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSet, std::initializer_list<ConfigurationField> exclusions = {});
void WriteYamlValue(AppInstaller::YAML::Emitter& emitter, const winrt::Windows::Foundation::IInspectable& value);
void WriteYamlValueSetAsArray(AppInstaller::YAML::Emitter& emitter, const Windows::Foundation::Collections::ValueSet& valueSetArray);
winrt::hstring GetSchemaVersionComment(winrt::hstring version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,7 @@ namespace winrt::Microsoft::Management::Configuration::implementation

void ConfigurationSetSerializer_0_2::WriteResourceDirectives(AppInstaller::YAML::Emitter& emitter, const ConfigurationUnit& unit)
{
auto metadata = unit.Metadata();

const auto moduleKey = GetConfigurationFieldNameHString(ConfigurationField::ModuleDirective);
if (metadata.HasKey(moduleKey))
{
metadata.Remove(moduleKey);
}

emitter << Key << GetConfigurationFieldName(ConfigurationField::Directives);
WriteYamlValueSet(emitter, metadata);
WriteYamlValueSet(emitter, unit.Metadata(), { ConfigurationField::ModuleDirective });
}
}
Loading