Skip to content

Commit

Permalink
Support native YAML for fodder content (#87)
Browse files Browse the repository at this point in the history
* Bump ConfigModel packages
* Fix breaking changes
  • Loading branch information
ChristopherMann authored Oct 31, 2024
1 parent 99de852 commit 9268f08
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 49 deletions.
13 changes: 3 additions & 10 deletions src/Eryph.ComputeClient.Commands/Catlets/CatletConfigCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,10 @@ protected static CatletConfig DeserializeConfigString(string configString)
configString = configString.Replace("\r\n", "\n");

if (configString.StartsWith("{") && configString.EndsWith("}"))
return CatletConfigDictionaryConverter.Convert(ConfigModelJsonSerializer.DeserializeToDictionary(configString));
return CatletConfigJsonSerializer.Deserialize(configString);

//YAML
try
{
return CatletConfigYamlSerializer.Deserialize(configString);
}
catch (YamlException ex)
{
throw ex;
}

return CatletConfigYamlSerializer.Deserialize(configString);

}

Expand Down
4 changes: 2 additions & 2 deletions src/Eryph.ComputeClient.Commands/Catlets/GetCatletCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ protected override void ProcessRecord()

private void WriteConfig(CatletConfiguration config)
{
var catletConfig = CatletConfigDictionaryConverter.Convert(
ConfigModelJsonSerializer.DeserializeToDictionary(config.Configuration));
var catletConfig = CatletConfigJsonSerializer.Deserialize(
config.Configuration);

var yaml = CatletConfigYamlSerializer.Serialize(catletConfig);
WriteObject(yaml);
Expand Down
4 changes: 1 addition & 3 deletions src/Eryph.ComputeClient.Commands/Catlets/NewCatletCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using System.Collections;
using System.Management.Automation;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using Eryph.ComputeClient.Models;
using Eryph.ConfigModel.Catlets;
using Eryph.ConfigModel.Json;
Expand Down Expand Up @@ -105,7 +103,7 @@ protected override void EndProcessing()
if (!PopulateVariables(config, Variables, SkipVariablesPrompt))
return;

var serializedConfig = JsonSerializer.SerializeToElement(config, ConfigModelJsonSerializer.DefaultOptions);
var serializedConfig = CatletConfigJsonSerializer.SerializeToElement(config);

WaitForOperation(
Factory.CreateCatletsClient().Create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

<ItemGroup>
<PackageReference Include="Eryph.ClientRuntime.Powershell" Version="0.7.0" />
<PackageReference Include="Eryph.ConfigModel.Catlets.Yaml" Version="0.6.0" />
<PackageReference Include="Eryph.ConfigModel.Networks.Yaml" Version="0.6.0" />
<PackageReference Include="Eryph.ConfigModel.System.Json" Version="0.6.0" />
<PackageReference Include="Eryph.ConfigModel.Catlets.Json" Version="0.7.0" />
<PackageReference Include="Eryph.ConfigModel.Catlets.Yaml" Version="0.7.0" />
<PackageReference Include="Eryph.ConfigModel.Networks.Json" Version="0.7.0" />
<PackageReference Include="Eryph.ConfigModel.Networks.Yaml" Version="0.7.0" />
<PackageReference Include="GitVersion.MsBuild" Version="5.12.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ protected override void ProcessRecord()

private void WriteConfig(VirtualNetworkConfiguration config)
{
var networkConfig = ProjectNetworksConfigJsonSerializer.Deserialize(
config.Configuration);

var catletConfig = ProjectNetworksConfigDictionaryConverter.Convert(
ConfigModelJsonSerializer.DeserializeToDictionary(config.Configuration));

var yaml = ProjectNetworkConfigYamlSerializer.Serialize(catletConfig);
var yaml = ProjectNetworksConfigYamlSerializer.Serialize(networkConfig);
WriteObject(yaml);

}

}
Expand Down
34 changes: 11 additions & 23 deletions src/Eryph.ComputeClient.Commands/Networks/NetworkConfigCmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,20 @@
using Eryph.ConfigModel.Yaml;
using YamlDotNet.Core;

namespace Eryph.ComputeClient.Commands.Networks
{
public class NetworkConfigCmdlet : NetworkCmdLet
{
namespace Eryph.ComputeClient.Commands.Networks;

protected static ProjectNetworksConfig DeserializeConfigString(string configString)
{
configString = configString.Trim();
configString = configString.Replace("\r\n", "\n");
public class NetworkConfigCmdlet : NetworkCmdLet
{

if (configString.StartsWith("{") && configString.EndsWith("}"))
return ProjectNetworksConfigDictionaryConverter.Convert(
ConfigModelJsonSerializer.DeserializeToDictionary(configString));
protected static ProjectNetworksConfig DeserializeConfigString(string configString)
{
configString = configString.Trim();
configString = configString.Replace("\r\n", "\n");


//YAML
try
{
return ProjectNetworkConfigYamlSerializer.Deserialize(configString);
}
catch (YamlException ex)
{
throw ex;
}
if (configString.StartsWith("{") && configString.EndsWith("}"))
return ProjectNetworksConfigJsonSerializer.Deserialize(configString);

}

return ProjectNetworksConfigYamlSerializer.Deserialize(configString);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Management.Automation;
using System.Text;
using System.Text.Json;
using Eryph.ComputeClient.Models;
using Eryph.ConfigModel.Json;
using Eryph.ConfigModel.Networks;
using JetBrains.Annotations;

namespace Eryph.ComputeClient.Commands.Networks
Expand Down Expand Up @@ -77,7 +75,7 @@ protected override void EndProcessing()
}

config.Project = ProjectName;
var configJson = JsonSerializer.SerializeToElement(config, ConfigModelJsonSerializer.DefaultOptions);
var configJson = ProjectNetworksConfigJsonSerializer.SerializeToElement(config);

WaitForOperation(
Factory.CreateVirtualNetworksClient().UpdateConfig(
Expand Down

0 comments on commit 9268f08

Please sign in to comment.