Пример #1
0
        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));
        }
Пример #2
0
        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));
        }
Пример #3
0
 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();
 }
Пример #4
0
        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));
        }