|
28 | 28 | using System.Collections.Generic;
|
29 | 29 | using Amazon.Runtime;
|
30 | 30 | using Amazon.Runtime.Telemetry;
|
| 31 | +using Amazon.Runtime.Credentials; |
31 | 32 |
|
32 | 33 | namespace Amazon
|
33 | 34 | {
|
@@ -72,32 +73,23 @@ public static partial class AWSConfigs
|
72 | 73 | {
|
73 | 74 | #region Private static members
|
74 | 75 |
|
75 |
| - private static char[] validSeparators = new char[] { ' ', ',' }; |
76 |
| - |
77 | 76 | // Tests can override this DateTime source.
|
78 | 77 | internal static Func<DateTime> utcNowSource = GetUtcNow;
|
79 | 78 |
|
80 |
| - // Deprecated configs |
81 | 79 | internal static string _awsRegion = GetConfig(AWSRegionKey);
|
82 | 80 | internal static string _awsProfileName = GetConfig(AWSProfileNameKey);
|
83 | 81 | internal static string _awsAccountsLocation = GetConfig(AWSProfilesLocationKey);
|
84 | 82 | internal static bool _useSdkCache = GetConfigBool(UseSdkCacheKey, defaultValue: true);
|
85 | 83 | internal static bool _initializeCollections = GetConfigBool(InitializeCollectionsKey, defaultValue: false);
|
86 |
| - // for reading from awsconfigs.xml |
87 |
| - private static object _lock = new object(); |
88 |
| - private static List<string> standardConfigs = new List<string>() { "region", "logging", "correctForClockSkew" }; |
89 | 84 | private static TelemetryProvider _telemetryProvider = new DefaultTelemetryProvider();
|
90 | 85 |
|
91 |
| -#pragma warning disable 414 |
92 |
| - private static bool configPresent = true; |
93 |
| -#pragma warning restore 414 |
94 |
| - |
95 | 86 | #if NET8_0_OR_GREATER
|
96 | 87 | internal static bool _disableDangerousDisablePathAndQueryCanonicalization = GetConfigBool(DisableDangerousDisablePathAndQueryCanonicalizationKey, defaultValue: false);
|
97 | 88 | #endif
|
98 | 89 |
|
99 | 90 | // New config section
|
100 |
| - private static RootConfig _rootConfig = new RootConfig(); |
| 91 | + private static readonly RootConfig _rootConfig = new(); |
| 92 | + |
101 | 93 | #endregion
|
102 | 94 |
|
103 | 95 | #region Clock Skew
|
@@ -226,12 +218,12 @@ public static string AWSProfilesLocation
|
226 | 218 |
|
227 | 219 | /// <summary>
|
228 | 220 | /// Key for the StreamingUtf8JsonReaderBufferSize property.
|
229 |
| - /// <seealso cref="Amazon.AWSConfigs.StreamingUtf8JsonReaderBufferSize"/>"/> |
| 221 | + /// <seealso cref="StreamingUtf8JsonReaderBufferSize"/> |
230 | 222 | /// </summary>
|
231 | 223 | public const string StreamingUtf8JsonReaderBufferSizeKey = "StreamingUtf8JsonReaderBufferSize";
|
232 | 224 |
|
233 | 225 | /// <summary>
|
234 |
| - /// Configures the default buffer size for the the StreamingUtf8JsonReader/> |
| 226 | + /// Configures the default buffer size for the the StreamingUtf8JsonReader |
235 | 227 | /// used for buffering data from the stream passed into its constructor. If this isn't set, the SDK will default to 4096 bytes.
|
236 | 228 | ///
|
237 | 229 | /// Setting this property is not thread safe and should only be set at application startup.
|
@@ -324,7 +316,32 @@ public static bool DisableDangerousDisablePathAndQueryCanonicalization
|
324 | 316 | set { _rootConfig.DisableDangerousDisablePathAndQueryCanonicalization = value; }
|
325 | 317 | }
|
326 | 318 | #endif
|
327 |
| -#endregion |
| 319 | + #endregion |
| 320 | + |
| 321 | + #region CredentialsGenerators |
| 322 | + |
| 323 | + /// <summary> |
| 324 | + /// Global configuration option to override the search order for credentials when creating SDK service clients without credentials. |
| 325 | + /// <para /> |
| 326 | + /// This option is equivalent to the <see cref="FallbackCredentialsFactory.CredentialsGenerators"/>, but it should only be used |
| 327 | + /// if the <a href="https://docs.aws.amazon.com/sdk-for-net/v4/developer-guide/creds-assign.html">default order</a> does not meet your application needs. |
| 328 | + /// <para /> |
| 329 | + /// When set, all service clients will use the specified providers so you must guarantee they return valid |
| 330 | + /// credentials for the operations to succeed. |
| 331 | + /// <para /> |
| 332 | + /// Setting this property is not thread safe and should only be set at application startup. |
| 333 | + /// </summary> |
| 334 | + /// <remarks> |
| 335 | + /// This option is only used in the <see cref="DefaultAWSCredentialsIdentityResolver"/>, it's not considered by the |
| 336 | + /// deprecated <see cref="FallbackCredentialsFactory"/> when resolving credentials. |
| 337 | + /// </remarks> |
| 338 | + public static List<DefaultAWSCredentialsIdentityResolver.CredentialsGenerator> AWSCredentialsGenerators |
| 339 | + { |
| 340 | + get { return _rootConfig.AWSCredentialsGenerators; } |
| 341 | + set { _rootConfig.AWSCredentialsGenerators = value; } |
| 342 | + } |
| 343 | + |
| 344 | + #endregion |
328 | 345 |
|
329 | 346 | #region AWS Config Sections
|
330 | 347 |
|
@@ -462,48 +479,6 @@ private static bool GetConfigBool(string name, bool defaultValue = false)
|
462 | 479 | return defaultValue;
|
463 | 480 | }
|
464 | 481 |
|
465 |
| - private static T GetConfigEnum<T>(string name) |
466 |
| - { |
467 |
| - var type = typeof(T); |
468 |
| - if (!type.IsEnum) throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Type {0} must be enum", type.FullName)); |
469 |
| - |
470 |
| - string value = GetConfig(name); |
471 |
| - if (string.IsNullOrEmpty(value)) |
472 |
| - return default(T); |
473 |
| - T result = ParseEnum<T>(value); |
474 |
| - return result; |
475 |
| - } |
476 |
| - |
477 |
| - private static T ParseEnum<T>(string value) |
478 |
| - { |
479 |
| - T t; |
480 |
| - if (TryParseEnum<T>(value, out t)) |
481 |
| - return t; |
482 |
| - Type type = typeof(T); |
483 |
| - string messageFormat = "Unable to parse value {0} as enum of type {1}. Valid values are: {2}"; |
484 |
| - string enumNames = string.Join(", ", Enum.GetNames(type)); |
485 |
| - throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, messageFormat, value, type.FullName, enumNames)); |
486 |
| - } |
487 |
| - |
488 |
| - private static bool TryParseEnum<T>(string value, out T result) |
489 |
| - { |
490 |
| - result = default(T); |
491 |
| - |
492 |
| - if (string.IsNullOrEmpty(value)) |
493 |
| - return false; |
494 |
| - |
495 |
| - try |
496 |
| - { |
497 |
| - T t = (T)Enum.Parse(typeof(T), value, true); |
498 |
| - result = t; |
499 |
| - return true; |
500 |
| - } |
501 |
| - catch (ArgumentException) |
502 |
| - { |
503 |
| - return false; |
504 |
| - } |
505 |
| - } |
506 |
| - |
507 | 482 | /// <summary>
|
508 | 483 | /// This method should never be called directly.
|
509 | 484 | /// Call AWSSDKUtils.CorrectedUtcNow instead.
|
|
0 commit comments