forked from man-group/dapr-sidekick-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDaprProcessOptions.cs
169 lines (145 loc) · 7.56 KB
/
DaprProcessOptions.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
using System;
using Man.Dapr.Sidekick.Security;
namespace Man.Dapr.Sidekick.Options
{
public abstract class DaprProcessOptions
{
/// <summary>
/// Gets or sets the full path to the directory containing the process binary.
/// If specified and the binary cannot be found in this directory and <see cref="CopyProcessFile"/> is <c>true</c>, the process binary
/// will be copied to this directory from <see cref="RuntimeDirectory"/>/bin.
/// Defaults to <see cref="RuntimeDirectory"/>/bin if not specified.
/// </summary>
public string BinDirectory { get; set; }
/// <summary>
/// Gets or sets a value that determines if the Dapr process binary is copied to <see cref="BinDirectory"/> from <see cref="InitialDirectory"/> when different.
/// This allows new versions of binaries to be deployed to <see cref="InitialDirectory"/> while an application is running, such that on restart the application picks up the new version.
/// Default is <c>false</c>.
/// </summary>
public bool? CopyProcessFile { get; set; }
/// <summary>
/// Gets or sets a value that determines if the Dapr process is enabled. If <c>false</c> the Dapr process binary will not be launched or managed on startup.
/// This allows an application to use Dapr Sidekick for development but leverage standard Dapr runtime mechanisms for deployments.
/// Defaults to <c>true</c>.
/// </summary>
public bool? Enabled { get; set; }
/// <summary>
/// Gets or sets the full path to the initial directory containing the Dapr components.
/// Typically this is the directory created by the "dapr init" command containing
/// the config.yaml file and the bin, components and certs subdirectories.
/// Defaults to %USERPROFILE%/.dapr ($HOME/.dapr on Linux) if not specified.
/// </summary>
public string InitialDirectory { get; set; }
/// <summary>
/// Gets or sets the issuer certificate used for mTLS encryption.
/// </summary>
public SensitiveString IssuerCertificate { get; set; }
/// <summary>
/// Gets or sets the issuer private key used for mTLS certificates.
/// </summary>
public SensitiveString IssuerKey { get; set; }
/// <summary>
/// Gets or sets the log level. Options are debug, info, warning, error, or fatal (default "info").
/// </summary>
public string LogLevel { get; set; }
/// <summary>
/// Gets or sets the options for managing and encriching the metrics exposed by the Dapr binary.
/// </summary>
public DaprMetricsOptions Metrics { get; set; }
/// <summary>
/// Gets or sets the full path to the filename of the Dapr process binary.
/// Defaults to <see cref="BinDirectory"/>/<see cref="ProcessName"/>.exe (<see cref="BinDirectory"/>/<see cref="ProcessName"/> on Linux) if not specified.
/// </summary>
public string ProcessFile { get; set; }
/// <summary>
/// Gets or sets the name of the process used to detemine <see cref="ProcessFile"/> and identify duplicate/attachable instances.
/// If not specified the appropriate default value for the process will be used.
/// </summary>
public string ProcessName { get; set; }
/// <summary>
/// Gets or sets the interval after which a restart will be attempted for the Dapr sidecar should it fail to start up or exit unexpectedly.
/// Set this to any negative number to prevent restart attempts. Defaults to 5000 (5 seconds) if not defined.
/// </summary>
public int? RestartAfterMillseconds { get; set; }
/// <summary>
/// Gets or sets a value that determines if any automatically assigned ports are retained on restart.
/// If <c>false</c> the port assignments will be updated to use the next available set of ports as reported by the operating system.
/// Defaults to <c>true</c> if not specified to ensure existing port assignments are retained on restart.
/// </summary>
public bool? RetainPortsOnRestart { get; set; }
/// <summary>
/// Gets or sets the full path to the runtime directory of the Dapr components.
/// Defaults to <see cref="InitialDirectory"/> if not specified.
/// </summary>
public string RuntimeDirectory { get; set; }
/// <summary>
/// Gets or sets a value that determines the number of seconds to wait for the process to shut down gracefully before it is force killed.
/// If not specified the process will be force killed immediately.
/// </summary>
public int? WaitForShutdownSeconds { get; set; }
/// <summary>
/// Gets or sets the trust anchor certificate used for mTLS encryption.
/// </summary>
public SensitiveString TrustAnchorsCertificate { get; set; }
/// <summary>
/// Creates a deep clone of this instance.
/// </summary>
/// <returns>A deep clone of this insteance.</returns>
public DaprProcessOptions Clone()
{
var clone = (DaprProcessOptions)MemberwiseClone();
clone.Metrics = Metrics?.Clone();
return clone;
}
/// <summary>
/// Updates any undefined properties in this instance with the values in <paramref name="source"/> where specified.
/// </summary>
/// <param name="source">A source options instance.</param>
public void EnrichFrom(DaprProcessOptions source)
{
if (source == null)
{
return;
}
BinDirectory ??= source.BinDirectory;
CopyProcessFile ??= source.CopyProcessFile;
Enabled ??= source.Enabled;
InitialDirectory ??= source.InitialDirectory;
IssuerCertificate ??= source.IssuerCertificate;
IssuerKey ??= source.IssuerKey;
LogLevel ??= source.LogLevel;
ProcessFile ??= source.ProcessFile;
ProcessName ??= source.ProcessName;
RestartAfterMillseconds ??= source.RestartAfterMillseconds;
RetainPortsOnRestart ??= source.RetainPortsOnRestart;
RuntimeDirectory ??= source.RuntimeDirectory;
WaitForShutdownSeconds ??= source.WaitForShutdownSeconds;
TrustAnchorsCertificate ??= source.TrustAnchorsCertificate;
(Metrics ??= new DaprMetricsOptions()).EnrichFrom(source.Metrics);
}
/// <summary>
/// Gets the address of the health endpoint, such as http://127.0.0.1:3500/v1.0/health.
/// </summary>
/// <returns>The health endpoint address.</returns>
public Uri GetHealthUri() => GetLocalUri(builder => AddHealthUri(builder));
/// <summary>
/// Gets the address of the metrics endpoint, such as http://127.0.0.1:9090.
/// </summary>
/// <returns>The metrics endpoint address.</returns>
public Uri GetMetricsUri() => GetLocalUri(builder => AddMetricsUri(builder));
protected virtual bool AddHealthUri(UriBuilder builder) => false;
protected virtual bool AddMetricsUri(UriBuilder builder) => false;
protected Uri GetLocalUri(Func<UriBuilder, bool> configure)
{
var builder = new UriBuilder("http", DaprConstants.LocalhostAddress);
if (configure(builder))
{
return builder.Uri;
}
else
{
return null;
}
}
}
}