internal static WindowsConfiguration DeserializeWindowsConfiguration(JsonElement element) { OSType osType = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("osType")) { osType = new OSType(property.Value.GetString()); continue; } } return(new WindowsConfiguration(osType)); }
internal static LinuxConfiguration DeserializeLinuxConfiguration(JsonElement element) { Optional <bool> disablePasswordAuthentication = default; Optional <SshConfiguration> ssh = default; Optional <SshKeyPair> sshKeyPair = default; OSType osType = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("disablePasswordAuthentication")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } disablePasswordAuthentication = property.Value.GetBoolean(); continue; } if (property.NameEquals("ssh")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } ssh = SshConfiguration.DeserializeSshConfiguration(property.Value); continue; } if (property.NameEquals("sshKeyPair")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } sshKeyPair = SshKeyPair.DeserializeSshKeyPair(property.Value); continue; } if (property.NameEquals("osType")) { osType = new OSType(property.Value.GetString()); continue; } } return(new LinuxConfiguration(osType, Optional.ToNullable(disablePasswordAuthentication), ssh.Value, sshKeyPair.Value)); }
void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteStartObject(); if (Optional.IsDefined(DisablePasswordAuthentication)) { writer.WritePropertyName("disablePasswordAuthentication"); writer.WriteBooleanValue(DisablePasswordAuthentication.Value); } if (Optional.IsDefined(Ssh)) { writer.WritePropertyName("ssh"); writer.WriteObjectValue(Ssh); } if (Optional.IsDefined(SshKeyPair)) { writer.WritePropertyName("sshKeyPair"); writer.WriteObjectValue(SshKeyPair); } writer.WritePropertyName("osType"); writer.WriteStringValue(OSType.ToString()); writer.WriteEndObject(); }
internal static OSConfiguration DeserializeOSConfiguration(JsonElement element) { if (element.TryGetProperty("osType", out JsonElement discriminator)) { switch (discriminator.GetString()) { case "Linux": return(LinuxConfiguration.DeserializeLinuxConfiguration(element)); case "Windows": return(WindowsConfiguration.DeserializeWindowsConfiguration(element)); } } OSType osType = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("osType")) { osType = new OSType(property.Value.GetString()); continue; } } return(new OSConfiguration(osType)); }