@@ -14,8 +14,6 @@ public sealed class LowkeyVaultBuilder : ContainerBuilder<LowkeyVaultBuilder, Lo
14
14
15
15
private const string LowKeyVaultEnvVarKey = "LOWKEY_ARGS" ;
16
16
17
- private readonly HashSet < string > NoAutoRegistration = [ "-" ] ;
18
-
19
17
/// <summary>
20
18
/// Initializes a new instance of the <see cref="LowkeyVaultBuilder" /> class.
21
19
/// </summary>
@@ -39,115 +37,6 @@ private LowkeyVaultBuilder(LowkeyVaultConfiguration dockerResourceConfiguration)
39
37
protected override LowkeyVaultConfiguration DockerResourceConfiguration { get ; }
40
38
41
39
42
- /// <summary>
43
- /// Sets the vault names.
44
- /// </summary>
45
- /// <param name="vaultNames">The vault names.</param>
46
- /// <returns>A configured instance of <see cref="LowkeyVaultBuilder" />.</returns>
47
- public LowkeyVaultBuilder WithVaultNames ( HashSet < string > vaultNames )
48
- {
49
- return Merge ( DockerResourceConfiguration , new LowkeyVaultConfiguration ( vaultNames : vaultNames ) )
50
- . WithEnvironment ( LowKeyVaultEnvVarKey , AddOrAppend ( $ "--LOWKEY_VAULT_NAMES={ string . Join ( "," , vaultNames ) } ") ) ;
51
- }
52
-
53
- /// <summary>
54
- /// Sets the vault aliases.
55
- /// </summary>
56
- /// <param name="aliasMap">The vault aliases.</param>
57
- /// <returns>A configured instance of <see cref="LowkeyVaultBuilder" />.</returns>
58
- public LowkeyVaultBuilder WithVaultAliases ( Dictionary < string , HashSet < string > > aliasMap )
59
- {
60
- return Merge ( DockerResourceConfiguration , new LowkeyVaultConfiguration ( aliasMap : aliasMap ) )
61
- . WithEnvironment ( LowKeyVaultEnvVarKey , AddOrAppend ( $ "--LOWKEY_VAULT_ALIASES={ ProcessVaultAliases ( aliasMap ) } ") ) ;
62
- }
63
-
64
- /// <summary>
65
- /// Sets No Auto Registration.
66
- /// </summary>
67
- /// <returns>A configured instance of <see cref="LowkeyVaultBuilder" />.</returns>
68
- public LowkeyVaultBuilder WithNoAutoRegistration ( )
69
- {
70
- return WithVaultNames ( NoAutoRegistration ) ;
71
- }
72
-
73
- /// <summary>
74
- /// Sets Import file.
75
- /// </summary>
76
- /// <param name="importFilePath">The import file path.</param>
77
- /// <returns>A configured instance of <see cref="LowkeyVaultBuilder" />.</returns>
78
- public LowkeyVaultBuilder WithImportFile ( string importFilePath )
79
- {
80
- return WithEnvironment ( LowKeyVaultEnvVarKey , AddOrAppend ( $ "--LOWKEY_IMPORT_LOCATION={ importFilePath } ") )
81
- . WithResourceMapping ( new FileInfo ( importFilePath ) , new FileInfo ( "/import/vaults.json" ) ) ;
82
- }
83
-
84
- /// <summary>
85
- /// Sets External config file.
86
- /// </summary>
87
- /// <param name="externalConfigFilePath">The external config file path.</param>
88
- /// <returns>A configured instance of <see cref="LowkeyVaultBuilder" />.</returns>
89
- public LowkeyVaultBuilder WithExternalConfigFile ( string externalConfigFilePath )
90
- {
91
- return Merge ( DockerResourceConfiguration , new LowkeyVaultConfiguration ( externalConfigFilePath : externalConfigFilePath ) )
92
- . WithResourceMapping ( new FileInfo ( externalConfigFilePath ) , new FileInfo ( "/config/application.properties" ) ) ;
93
- }
94
-
95
- /// <summary>
96
- /// Sets Custom Ssl Certificate file.
97
- /// </summary>
98
- /// <param name="keyStoreFilePath">The keyStore (custom Ssl Certificate) file path.</param>
99
- /// <param name="keyStorePassword">The keyStore password.</param>
100
- /// <param name="keyStoreType">The keyStore Type.</param>
101
- /// <returns>A configured instance of <see cref="LowkeyVaultBuilder" />.</returns>
102
- public LowkeyVaultBuilder WithCustomSslCertificate ( string keyStoreFilePath , string keyStorePassword , StoreType keyStoreType = StoreType . PKCS12 )
103
- {
104
- return WithEnvironment ( LowKeyVaultEnvVarKey , AddOrAppend ( $ "--server.ssl.key-store={ keyStoreFilePath } "
105
- + $ "--server.ssl.key-store-type={ keyStoreType } "
106
- + $ "--server.ssl.key-store-password={ keyStorePassword ?? string . Empty } ") )
107
- . WithResourceMapping ( new FileInfo ( keyStoreFilePath ) , new FileInfo ( "/config/cert.store" ) ) ;
108
- }
109
-
110
- /// <summary>
111
- /// Enable Or Disable Debug.
112
- /// </summary>
113
- /// <param name="debug">The flag to enable or disable debug.</param>
114
- /// <returns>A configured instance of <see cref="LowkeyVaultBuilder" />.</returns>
115
- public LowkeyVaultBuilder WithDebug ( bool debug )
116
- {
117
- return WithEnvironment ( LowKeyVaultEnvVarKey , AddOrAppend ( $ "--LOWKEY_DEBUG_REQUEST_LOG={ debug } ") ) ;
118
- }
119
-
120
- /// <summary>
121
- /// Enable Or Disable Relaxed Ports.
122
- /// </summary>
123
- /// <param name="relaxedPorts">The flag to enable or disable relaxed ports.</param>
124
- /// <returns>A configured instance of <see cref="LowkeyVaultBuilder" />.</returns>
125
- public LowkeyVaultBuilder WithRelaxedPorts ( bool relaxedPorts )
126
- {
127
- return WithEnvironment ( LowKeyVaultEnvVarKey , AddOrAppend ( $ "--LOWKEY_VAULT_RELAXED_PORTS={ relaxedPorts } ") ) ;
128
- }
129
-
130
- /// <summary>
131
- /// Sets The host used to replace host placeholder in import template.
132
- /// </summary>
133
- /// <param name="logicalHost">The logical host.</param>
134
- /// <returns>A configured instance of <see cref="LowkeyVaultBuilder" />.</returns>
135
- public LowkeyVaultBuilder WithLogicalHost ( string logicalHost )
136
- {
137
- return WithEnvironment ( LowKeyVaultEnvVarKey , AddOrAppend ( $ "--LOWKEY_IMPORT_TEMPLATE_HOST={ logicalHost } ") ) ;
138
- }
139
-
140
- /// <summary>
141
- /// Sets The port used to replace host placeholder in import template.
142
- /// </summary>
143
- /// <param name="logicalPort">The logical port.</param>
144
- /// <returns>A configured instance of <see cref="LowkeyVaultBuilder" />.</returns>
145
- public LowkeyVaultBuilder WithLogicalPort ( ushort logicalPort )
146
- {
147
- return WithEnvironment ( LowKeyVaultEnvVarKey , AddOrAppend ( $ "--LOWKEY_IMPORT_TEMPLATE_PORT={ logicalPort } ") ) ;
148
- }
149
-
150
-
151
40
/// <summary>
152
41
/// Sets Additional Arguments.
153
42
/// </summary>
@@ -163,12 +52,7 @@ public LowkeyVaultBuilder WithAdditionalArguments(List<string> additionalArgumen
163
52
public override LowkeyVaultContainer Build ( )
164
53
{
165
54
Validate ( ) ;
166
-
167
- var waitStrategy = Wait . ForUnixContainer ( ) . UntilMessageIsLogged ( "(?s).*Started LowkeyVaultApp.*$" ) ;
168
-
169
- var lowkeyVaultBuilder = DockerResourceConfiguration . WaitStrategies . Count ( ) > 1 ? this : WithWaitStrategy ( waitStrategy ) ;
170
-
171
- return new LowkeyVaultContainer ( lowkeyVaultBuilder . DockerResourceConfiguration ) ;
55
+ return new LowkeyVaultContainer ( DockerResourceConfiguration ) ;
172
56
}
173
57
174
58
/// <inheritdoc />
@@ -178,28 +62,15 @@ protected override LowkeyVaultBuilder Init()
178
62
. WithImage ( LowkeyVaultImage )
179
63
. WithPortBinding ( LowkeyVaultPort , true )
180
64
. WithPortBinding ( LowkeyVaultTokenPort , true )
181
- . WithRelaxedPorts ( true ) ;
65
+ . WithAdditionalArguments ( [ $ "--LOWKEY_VAULT_RELAXED_PORTS={ true } "] )
66
+ . WithWaitStrategy ( Wait . ForUnixContainer ( ) . UntilMessageIsLogged ( "(?s).*Started LowkeyVaultApp.*$" ) ) ;
182
67
}
183
68
184
69
/// <inheritdoc />
185
70
protected override void Validate ( )
186
71
{
187
72
base . Validate ( ) ;
188
-
189
- _ = Guard . Argument ( DockerResourceConfiguration . VaultNames , nameof ( DockerResourceConfiguration . VaultNames ) ) . NotNull ( ) ;
190
- _ = Guard . Argument ( DockerResourceConfiguration . AliasMap , nameof ( DockerResourceConfiguration . AliasMap ) ) . NotNull ( ) ;
191
73
_ = Guard . Argument ( DockerResourceConfiguration . AdditionalArguments , nameof ( DockerResourceConfiguration . AdditionalArguments ) ) . NotNull ( ) ;
192
- _ = Guard . Argument ( DockerResourceConfiguration , nameof ( DockerResourceConfiguration . ExternalConfigFilePath ) )
193
- . ThrowIf ( argument =>
194
- {
195
- var externalConfigFilePath = argument . Value . ExternalConfigFilePath ;
196
- var fileName = Path . GetFileName ( externalConfigFilePath ) ;
197
- return ! string . IsNullOrEmpty ( externalConfigFilePath ) && ! Path . GetFileName ( fileName ) . EndsWith ( ".properties" , StringComparison . Ordinal ) ;
198
- } , argument => throw new ArgumentException ( "External configuration file must be a *.properties file." ) ) ;
199
-
200
- ValidateVaultNames ( DockerResourceConfiguration . VaultNames ) ;
201
-
202
- ValidateAliasMap ( DockerResourceConfiguration . AliasMap ) ;
203
74
}
204
75
205
76
/// <inheritdoc />
@@ -282,53 +153,4 @@ static Dictionary<string, string> ParseToDictionary(string input)
282
153
return dictionary ;
283
154
}
284
155
}
285
-
286
- private void ValidateVaultNames ( HashSet < string > vaultNames )
287
- {
288
- if ( ! NoAutoRegistration . SetEquals ( vaultNames ) )
289
- {
290
- var invalid = vaultNames . Where ( s => ! Regex . IsMatch ( s ?? string . Empty , "^[0-9a-zA-Z-]+$" , RegexOptions . Compiled ) ) . ToList ( ) ;
291
-
292
- if ( invalid . Count != 0 )
293
- {
294
- throw new ArgumentException ( "VaultNames contains invalid values: " + string . Join ( ", " , invalid ) ) ;
295
- }
296
- }
297
- }
298
-
299
- private static void ValidateAliasMap ( Dictionary < string , HashSet < string > > aliasMap )
300
- {
301
- foreach ( var host in aliasMap . Keys )
302
- {
303
- if ( ! Regex . IsMatch ( host , "^[0-9a-z\\ -_.]+$" ) )
304
- {
305
- throw new ArgumentException ( $ "Vault host names must match '^[0-9a-z\\ -_.]+$'. Found: { host } ") ;
306
- }
307
- }
308
-
309
- foreach ( var alias in aliasMap . Values )
310
- {
311
- foreach ( var host in alias )
312
- {
313
- if ( ! Regex . IsMatch ( host , "^[0-9a-z\\ -_.]+(:[0-9]+|:<port>)?$" ) )
314
- {
315
- throw new ArgumentException ( $ "Vault aliases must match '^[0-9a-z\\ -_.]+(:[0-9]+|:<port>)?$'. Found: { host } ") ;
316
- }
317
- }
318
- }
319
- }
320
-
321
- private static string ProcessVaultAliases ( Dictionary < string , HashSet < string > > aliasMap )
322
- {
323
- return aliasMap . OrderBy ( pair => pair . Key ) // Sort keys
324
- . SelectMany ( pair => pair . Value . OrderBy ( alias => alias ) // Sort values
325
- . Select ( alias => $ "{ pair . Key } ={ alias } ") )
326
- . Aggregate ( ( current , next ) => $ "{ current } ,{ next } ") ; // Join the pairs into a single string with commas
327
- }
328
-
329
- public enum StoreType
330
- {
331
- JKS ,
332
- PKCS12
333
- }
334
156
}
0 commit comments