Skip to content

Commit

Permalink
Fix limit mode metadata blocking (#4489)
Browse files Browse the repository at this point in the history
## Change
The serialization code should not be modifying the object that it is
operating on. Move it to instead skip the output of some values rather
than removing them.

When the remoting server is operating in limited mode, the metadata must
match between the initial limitation set and the incoming unit. This
removal was also breaking that, as the entry was now missing.

## Validation
Manual confirmation that the limit mode works after the change.
  • Loading branch information
JohnMcPMS committed May 18, 2024
1 parent 4bfc7cb commit 6e35ddf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
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 });
}
}

0 comments on commit 6e35ddf

Please sign in to comment.