11namespace SecureStore . Contrib . Configuration
22{
33 using System ;
4- using System . IO ;
54 using Microsoft . Extensions . Configuration ;
65 using Microsoft . Extensions . FileProviders ;
76
87 /// <summary>
9- /// Extension methods for adding <see cref="SecureStoreConfigurationProvider"/>.
8+ /// Extension methods for adding <see cref="SecureStoreConfigurationProvider" />.
109 /// </summary>
1110 public static class SecureStoreConfigurationExtensions
1211 {
1312 /// <summary>
14- /// Adds the SecureStore configuration provider at <paramref name="path"/> to <paramref name="builder"/>.
13+ /// Adds the SecureStore configuration provider at <paramref name="path" /> to <paramref name="builder" />.
1514 /// </summary>
16- /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
17- /// <param name="path">Path relative to the base path stored in
18- /// <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>.</param>
15+ /// <param name="builder">The <see cref="IConfigurationBuilder" /> to add to.</param>
16+ /// <param name="path">
17+ /// Path relative to the base path stored in
18+ /// <see cref="IConfigurationBuilder.Properties" /> of <paramref name="builder" />.
19+ /// </param>
1920 /// <param name="key">The SecureStore key.</param>
2021 /// <param name="keyType">The key type.</param>
21- /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
22+ /// <returns>The <see cref="IConfigurationBuilder" />.</returns>
2223 public static IConfigurationBuilder AddSecureStoreFile ( this IConfigurationBuilder builder , string path ,
2324 string key , KeyType keyType )
2425 {
25- return AddSecureStoreFile ( builder , path , key , keyType , false ) ;
26+ return AddSecureStoreFile ( builder , null , path , key , keyType , false , false ) ;
2627 }
2728
2829 /// <summary>
29- /// Adds the SecureStore configuration provider at <paramref name="path"/> to <paramref name="builder"/>.
30+ /// Adds the SecureStore configuration provider at <paramref name="path" /> to <paramref name="builder" />.
3031 /// </summary>
31- /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
32- /// <param name="path">Path relative to the base path stored in
33- /// <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>.</param>
32+ /// <param name="builder">The <see cref="IConfigurationBuilder" /> to add to.</param>
33+ /// <param name="path">
34+ /// Path relative to the base path stored in
35+ /// <see cref="IConfigurationBuilder.Properties" /> of <paramref name="builder" />.
36+ /// </param>
3437 /// <param name="key">The SecureStore key.</param>
3538 /// <param name="keyType">The key type.</param>
3639 /// <param name="optional">Whether the file is optional.</param>
37- /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
40+ /// <returns>The <see cref="IConfigurationBuilder" />.</returns>
3841 public static IConfigurationBuilder AddSecureStoreFile ( this IConfigurationBuilder builder , string path ,
3942 string key , KeyType keyType , bool optional )
4043 {
41- return AddSecureStoreFile ( builder , path , key , keyType , optional , false ) ;
44+ return AddSecureStoreFile ( builder , null , path , key , keyType , optional , false ) ;
4245 }
4346
4447 /// <summary>
45- /// Adds the SecureStore configuration provider at <paramref name="path"/> to <paramref name="builder"/>.
48+ /// Adds the SecureStore configuration provider at <paramref name="path" /> to <paramref name="builder" />.
4649 /// </summary>
47- /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
48- /// <param name="path">Path relative to the base path stored in
49- /// <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>.</param>
50+ /// <param name="builder">The <see cref="IConfigurationBuilder" /> to add to.</param>
51+ /// <param name="path">
52+ /// Path relative to the base path stored in
53+ /// <see cref="IConfigurationBuilder.Properties" /> of <paramref name="builder" />.
54+ /// </param>
5055 /// <param name="key">The SecureStore key.</param>
5156 /// <param name="keyType">The key type.</param>
5257 /// <param name="optional">Whether the file is optional.</param>
5358 /// <param name="reloadOnChange">Whether the configuration should be reloaded if the file changes.</param>
54- /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
59+ /// <returns>The <see cref="IConfigurationBuilder" />.</returns>
5560 public static IConfigurationBuilder AddSecureStoreFile ( this IConfigurationBuilder builder , string path ,
5661 string key , KeyType keyType , bool optional ,
5762 bool reloadOnChange )
@@ -60,17 +65,19 @@ public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilde
6065 }
6166
6267 /// <summary>
63- /// Adds a SecureStore configuration source to <paramref name="builder"/>.
68+ /// Adds a SecureStore configuration source to <paramref name="builder" />.
6469 /// </summary>
65- /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
66- /// <param name="provider">The <see cref="IFileProvider"/> to use to access the file.</param>
67- /// <param name="path">Path relative to the base path stored in
68- /// <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>.</param>
70+ /// <param name="builder">The <see cref="IConfigurationBuilder" /> to add to.</param>
71+ /// <param name="provider">The <see cref="IFileProvider" /> to use to access the file.</param>
72+ /// <param name="path">
73+ /// Path relative to the base path stored in
74+ /// <see cref="IConfigurationBuilder.Properties" /> of <paramref name="builder" />.
75+ /// </param>
6976 /// <param name="key">The SecureStore key.</param>
7077 /// <param name="keyType">The key type.</param>
7178 /// <param name="optional">Whether the file is optional.</param>
7279 /// <param name="reloadOnChange">Whether the configuration should be reloaded if the file changes.</param>
73- /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
80+ /// <returns>The <see cref="IConfigurationBuilder" />.</returns>
7481 public static IConfigurationBuilder AddSecureStoreFile ( this IConfigurationBuilder builder ,
7582 IFileProvider provider ,
7683 string path , string key , KeyType keyType , bool optional , bool reloadOnChange )
@@ -90,12 +97,6 @@ public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilde
9097 throw new ArgumentException ( "File key/path must be a non-empty string." , nameof ( key ) ) ;
9198 }
9299
93- if ( provider == null && Path . IsPathRooted ( path ) )
94- {
95- provider = new PhysicalFileProvider ( Path . GetDirectoryName ( path ) ) ;
96- path = Path . GetFileName ( path ) ;
97- }
98-
99100 return builder . AddSecureStoreFile ( source =>
100101 {
101102 source . FileProvider = provider ;
@@ -104,16 +105,21 @@ public static IConfigurationBuilder AddSecureStoreFile(this IConfigurationBuilde
104105 source . KeyType = keyType ;
105106 source . Optional = optional ;
106107 source . ReloadOnChange = reloadOnChange ;
108+ source . ResolveFileProvider ( ) ;
109+ source . ResolveKeyFileProvider ( ) ;
107110 } ) ;
108111 }
109112
110113 /// <summary>
111- /// Adds a SecureStore configuration source to <paramref name="builder"/>.
114+ /// Adds a SecureStore configuration source to <paramref name="builder" />.
112115 /// </summary>
113- /// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
116+ /// <param name="builder">The <see cref="IConfigurationBuilder" /> to add to.</param>
114117 /// <param name="configureSource">Configures the source.</param>
115- /// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
116- public static IConfigurationBuilder AddSecureStoreFile ( this IConfigurationBuilder builder , Action < SecureStoreConfigurationSource > configureSource )
117- => builder . Add ( configureSource ) ;
118+ /// <returns>The <see cref="IConfigurationBuilder" />.</returns>
119+ public static IConfigurationBuilder AddSecureStoreFile ( this IConfigurationBuilder builder ,
120+ Action < SecureStoreConfigurationSource > configureSource )
121+ {
122+ return builder . Add ( configureSource ) ;
123+ }
118124 }
119125}
0 commit comments