/// <summary> /// Force the SDK to load and apply the given endpoints details /// (eg: an updated endpoints.json file). /// Service clients created after this call will be set up with /// endpoints based on this information. /// /// This function should only be used at application startup, before /// creating service clients. /// /// Known Caveats: /// * static readonly fields (eg: <see cref="RegionEndpoint.USEast1"/>) are not updated. /// If you use this function, you should use <see cref="RegionEndpoint.GetEndpoint"/> with /// explicit region system names to ensure you work with RegionEndpoint objects containing /// the reloaded data. RegionEndpoint objects returned from GetEndpoint will generally /// fail Equality comparisons against the static fields. /// * Service clients created before calling Reload have no guarantee around /// which endpoint data will be used. /// </summary> /// <param name="stream">Stream containing an Endpoints manifest to reload in the SDK. /// Pass null in to reset the SDK, so that it uses its built-in manifest instead.</param> public static void Reload(Stream stream) { if (stream == null) { _regionEndpointProvider = null; } else { JsonData rootData = null; using (StreamReader reader = new StreamReader(stream)) { rootData = JsonMapper.ToObject(reader); } var manifestVersion = rootData?["version"]?.ToString(); if (manifestVersion == "3") { _regionEndpointProvider = new RegionEndpointProviderV3(rootData); } else { throw new NotSupportedException("Endpoints data format is not supported by reload"); } } // Reset static lookup maps that may contain objects relating to old endpoint data lock (_hashBySystemName) { _hashBySystemName.Clear(); } ResetRegionEndpointOverride(); }
internal RegionFinder() { _regionEndpointProviderV3 = new RegionEndpointProviderV3(); _regionEndpoints = BuildRegionEndpoints(); _root = BuildRoot(); _logger = Logger.GetLogger(typeof(RegionFinder)); }