-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClusterConfig.cs
82 lines (67 loc) · 2.37 KB
/
ClusterConfig.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using Azure.Core;
using CloudWorker.Client.SDK.ARM;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace CloudWorker.Client.SDK;
public enum ServiceType
{
Custom,
Echo,
CGI,
GRPC
}
public class ServiceTypeJsonConverter : JsonConverter<ServiceType>
{
public override ServiceType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
return Enum.Parse<ServiceType>(value!, true);
}
public override void Write(Utf8JsonWriter writer, ServiceType value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString().ToLower());
}
}
public class AzureLocationJsonConverter : JsonConverter<AzureLocation>
{
public override AzureLocation Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var value = reader.GetString();
return new AzureLocation(value!);
}
public override void Write(Utf8JsonWriter writer, AzureLocation value, JsonSerializerOptions options)
{
writer.WriteStringValue(value);
}
}
//TODO: More options in the config ...
public class ClusterConfig : IValidatable
{
public Guid SubScriptionId { get; set; }
//The location is for both ArmDeploymentContent.Location and an ARM template parameter
[JsonConverter(typeof(AzureLocationJsonConverter))]
public AzureLocation Location { get; set; } = AzureLocation.SoutheastAsia;
[JsonConverter(typeof(ServiceTypeJsonConverter))]
public ServiceType Service { get; set; } = ServiceType.Echo;
[ValidateCollection]
public IEnumerable<SecureEnvironmentVariable>? EnvironmentVariables { get; set; }
[ValidateCollection]
public IEnumerable<FileShareMount>? FileShares { get; set; }
public int? NodeCount { get; set; }
[ValidateObject]
public NodeOptions? NodeOptions { get; set; }
[ValidateObject]
public ServiceBusQueueOptions? ServiceBusQueueOptions { get; set; }
public void Validate()
#pragma warning disable CS8774 // Member must have a non-null value when exiting.
{
IValidatable.Validate(this);
if (Service == ServiceType.Custom)
{
throw new NotImplementedException();
}
}
#pragma warning restore CS8774 // Member must have a non-null value when exiting.
}