internal DynamoDBContextConfig() { this.TableNamePrefix = AWSConfigs.GetConfig(AWSConfigsDynamoDB.DynamoDBContextTableNamePrefixKey); TableAliases = new Dictionary <string, string>(StringComparer.Ordinal); TypeMappings = new Dictionary <Type, TypeMapping>(); }
private bool IsClockskew(IExecutionContext executionContext, Exception exception) { var clientConfig = executionContext.RequestContext.ClientConfig; var ase = exception as AmazonServiceException; var isHead = executionContext.RequestContext.Request != null && string.Equals(executionContext.RequestContext.Request.HttpMethod, "HEAD", StringComparison.Ordinal); var isClockskewErrorCode = ase != null && (ase.ErrorCode == null || clockSkewErrorCodes.Contains(ase.ErrorCode)); if (isHead || isClockskewErrorCode) { var endpoint = executionContext.RequestContext.Request.Endpoint.ToString(); var realNow = AWSConfigs.utcNowSource(); var correctedNow = CorrectClockSkew.GetCorrectedUtcNowForEndpoint(endpoint); DateTime serverTime; // Try getting server time from the headers bool serverTimeDetermined = TryParseDateHeader(ase, out serverTime); // If that fails, try to parse it from the exception message if (!serverTimeDetermined) { serverTimeDetermined = TryParseExceptionMessage(ase, out serverTime); } if (serverTimeDetermined) { // using accurate server time, calculate correction if local time is off serverTime = serverTime.ToUniversalTime(); var diff = correctedNow - serverTime; var absDiff = diff.Ticks < 0 ? -diff : diff; if (absDiff > clockSkewMaxThreshold) { var newCorrection = serverTime - realNow; Logger.InfoFormat(clockSkewMessageFormat, realNow, correctedNow, clientConfig.ClockOffset, serverTime, endpoint); // Always set the correction, for informational purposes CorrectClockSkew.SetClockCorrectionForEndpoint(endpoint, newCorrection); var shouldRetry = AWSConfigs.CorrectForClockSkew && !AWSConfigs.ManualClockCorrection.HasValue; // Only retry if clock skew correction is not disabled if (shouldRetry) { // Set clock skew correction Logger.InfoFormat(clockSkewUpdatedFormat, newCorrection, endpoint); executionContext.RequestContext.IsSigned = false; return(true); } } } } return(false); }
internal RootConfig() { Logging = new LoggingConfig(); DynamoDB = new DynamoDBConfig(); S3 = new S3Config(); EC2 = new EC2Config(); Proxy = new ProxyConfig(); EndpointDefinition = AWSConfigs._endpointDefinition; Region = AWSConfigs._awsRegion; ProfileName = AWSConfigs._awsProfileName; ProfilesLocation = AWSConfigs._awsAccountsLocation; #if !WIN_RT && !WINDOWS_PHONE var root = AWSConfigs.GetSection <AWSSection>(_rootAwsSectionName); Logging.Configure(root.Logging); DynamoDB.Configure(root.DynamoDB); S3.Configure(root.S3); EC2.Configure(root.EC2); Proxy.Configure(root.Proxy); EndpointDefinition = Choose(EndpointDefinition, root.EndpointDefinition); Region = Choose(Region, root.Region); ProfileName = Choose(ProfileName, root.ProfileName); ProfilesLocation = Choose(ProfilesLocation, root.ProfilesLocation); #endif }
/// <summary> /// Get clock skew corrected UTC now value. If ManualClockCorrection is set, /// use ManualClockCorrection instead of endpoint specific clock correction value. /// </summary> /// <param name="endpoint"></param> /// <returns></returns> public static DateTime GetCorrectedUtcNowForEndpoint(string endpoint) { TimeSpan adjustment = TimeSpan.Zero; manualClockCorrectionLock.EnterReadLock(); try { if (manualClockCorrection != null) { adjustment = manualClockCorrection.Value; } } finally { manualClockCorrectionLock.ExitReadLock(); } if (AWSConfigs.CorrectForClockSkew && (adjustment == TimeSpan.Zero)) { adjustment = GetClockCorrectionForEndpoint(endpoint); } return(AWSConfigs.utcNowSource() + adjustment); }
private void RemoveOldItems_Locked() { if (LastCacheClean + CacheClearPeriod > AWSConfigs.utcNowSource().ToLocalTime()) { return; } // Remove all items that were not accessed since the cutoff. // Using a cutoff is more optimal than item.Age, as we only need // to do DateTime calculation once, not for each item. var cutoff = GetCorrectedLocalTime() - MaximumItemLifespan; var keysToRemove = new List <TKey>(); foreach (var kvp in Contents) { var key = kvp.Key; var item = kvp.Value; if (item == null || item.LastUseTime < cutoff) { keysToRemove.Add(key); } } foreach (var key in keysToRemove) { Contents.Remove(key); } LastCacheClean = GetCorrectedLocalTime(); }
public RootConfig() { Logging = new LoggingConfig(); Proxy = new ProxyConfig(); EndpointDefinition = AWSConfigs._endpointDefinition; Region = AWSConfigs._awsRegion; ProfileName = AWSConfigs._awsProfileName; ProfilesLocation = AWSConfigs._awsAccountsLocation; UseSdkCache = AWSConfigs._useSdkCache; CorrectForClockSkew = true; AWSSection section = AWSConfigs.GetSection <AWSSection>("aws"); Logging.Configure(section.Logging); Proxy.Configure(section.Proxy); ServiceSections = section.ServiceSections; if (section.UseSdkCache.HasValue) { UseSdkCache = section.UseSdkCache.Value; } EndpointDefinition = Choose(EndpointDefinition, section.EndpointDefinition); Region = Choose(Region, section.Region); ProfileName = Choose(ProfileName, section.ProfileName); ProfilesLocation = Choose(ProfilesLocation, section.ProfilesLocation); ApplicationName = Choose(ApplicationName, section.ApplicationName); if (section.CorrectForClockSkew.HasValue) { CorrectForClockSkew = section.CorrectForClockSkew.Value; } }
public RootConfig() { Logging = new LoggingConfig(); Proxy = new ProxyConfig(); EndpointDefinition = AWSConfigs._endpointDefinition; Region = AWSConfigs._awsRegion; ProfileName = AWSConfigs._awsProfileName; ProfilesLocation = AWSConfigs._awsAccountsLocation; UseSdkCache = AWSConfigs._useSdkCache; CorrectForClockSkew = true; #if !WIN_RT && !WINDOWS_PHONE var root = AWSConfigs.GetSection <AWSSection>(_rootAwsSectionName); Logging.Configure(root.Logging); Proxy.Configure(root.Proxy); ServiceSections = root.ServiceSections; if (root.UseSdkCache.HasValue) { UseSdkCache = root.UseSdkCache.Value; } EndpointDefinition = Choose(EndpointDefinition, root.EndpointDefinition); Region = Choose(Region, root.Region); ProfileName = Choose(ProfileName, root.ProfileName); ProfilesLocation = Choose(ProfilesLocation, root.ProfilesLocation); if (root.CorrectForClockSkew.HasValue) { CorrectForClockSkew = root.CorrectForClockSkew.Value; } #endif }
// Gets the name of the closest "parent" TraceRoute that has listeners, or null otherwise. private static TraceSource GetTraceSourceWithListeners(string name, SourceLevels sourceLevels) { string[] parts = name.Split(new char[] { '.' }, StringSplitOptions.None); List <string> namesToTest = new List <string>(); StringBuilder sb = new StringBuilder(); foreach (var part in parts) { if (sb.Length > 0) { sb.Append("."); } sb.Append(part); string partialName = sb.ToString(); namesToTest.Add(partialName); } namesToTest.Reverse(); foreach (var testName in namesToTest) { TraceSource ts = new TraceSource(testName); //bug in unity .NET 35 subset version. //constructor defaults the source level to always off. ts.Switch.Level = sourceLevels; ts.Listeners.AddRange(AWSConfigs.TraceListeners(testName)); // no listeners? skip if (ts.Listeners == null || ts.Listeners.Count == 0) { ts.Close(); continue; } // more than one listener? use this TraceSource if (ts.Listeners.Count > 1) { return(ts); } TraceListener listener = ts.Listeners[0]; // single listener isn't DefaultTraceListener? use this TraceRoute if (!(listener is DefaultTraceListener)) { return(ts); } // single listener is DefaultTraceListener but isn't named Default? use this TraceRoute if (!string.Equals(listener.Name, "Default", StringComparison.Ordinal)) { return(ts); } // not the TraceSource we're looking for, close it ts.Close(); } // nothing found? no listeners are configured for any of the names, even the original, // so return null to signify failure return(null); }
public MobileAnalyticsManagerConfigSectionRoot(XElement section) { if (section == null) { return; } this.SectionConfig = AWSConfigs.GetObject <MobileAnalyticsManagerConfigSection>(section, mobileAnalyticsKey); }
protected override void ProcessRecord() { var listener = this.ParameterSetName.Equals(ParamSet_SimpleListener, StringComparison.OrdinalIgnoreCase) ? new TextWriterTraceListener(LogFilePath, Name) : TraceListener; AWSConfigs.AddTraceListener(Source ?? "Amazon", listener); AWSConfigs.LoggingConfig.LogTo |= LoggingOptions.SystemDiagnostics; Trace.AutoFlush = true; // bump the logging level up to OnError at least. Might already be configured higher. if (AWSConfigs.LoggingConfig.LogResponses == ResponseLoggingOption.Never) { AWSConfigs.LoggingConfig.LogResponses = ResponseLoggingOption.OnError; } }
public void AddAWSSimpleEmailService(IServiceCollection services, AWSConfigs options) { var config = new AmazonSimpleEmailServiceV2Config(); if (options.Region != null) { config.RegionEndpoint = options.Region; } else { config.ServiceURL = options.DefaultClientConfig.ServiceURL; } if (!string.IsNullOrEmpty(options.Profile)) { var chain = new CredentialProfileStoreChain(options.ProfilesLocation); chain.TryGetAWSCredentials(options.Profile, out AWSCredentials awsCredential); var client = new AmazonSimpleEmailServiceV2Client(awsCredential, config); services.AddSingleton <IAmazonSimpleEmailServiceV2>(se => { return(client); }); } else { var client = new AmazonSimpleEmailServiceV2Client(config.AccessKey, config.SerectKey, config); services.AddSingleton <IAmazonSimpleEmailServiceV2>(se => { return(client); }); } }
public DynamoDBSectionRoot(XElement section) { this.DynamoDB = AWSConfigs.GetObject <DynamoDBSection>(section, dynamoDBKey); }
/// <summary> /// This should be a one time call to use reflection to find all the types and methods /// needed for the logging API. /// </summary> private static void loadStatics() { lock (InternalLog4netLogger.LOCK) { if (loadState != LoadState.Uninitialized) { return; } loadState = LoadState.Loading; try { loggerType = Type.GetType("Amazon.Runtime.Internal.Util.Logger"); // The LogManager and its methods logMangerType = Type.GetType("log4net.Core.LoggerManager, log4net"); logMangerTypeInfo = TypeFactory.GetTypeInfo(logMangerType); if (logMangerType == null) { loadState = LoadState.Failed; return; } getLoggerWithTypeMethod = logMangerTypeInfo.GetMethod("GetLogger", new ITypeInfo[] { TypeFactory.GetTypeInfo(typeof(Assembly)), TypeFactory.GetTypeInfo(typeof(Type)) }); // The ILog and its methdods logType = Type.GetType("log4net.Core.ILogger, log4net"); logTypeInfo = TypeFactory.GetTypeInfo(logType); levelType = Type.GetType("log4net.Core.Level, log4net"); levelTypeInfo = TypeFactory.GetTypeInfo(levelType); debugLevelPropertyValue = levelTypeInfo.GetField("Debug").GetValue(null); infoLevelPropertyValue = levelTypeInfo.GetField("Info").GetValue(null); errorLevelPropertyValue = levelTypeInfo.GetField("Error").GetValue(null); systemStringFormatType = Type.GetType("log4net.Util.SystemStringFormat, log4net"); logMethod = logTypeInfo.GetMethod("Log", new ITypeInfo[] { TypeFactory.GetTypeInfo(typeof(Type)), levelTypeInfo, TypeFactory.GetTypeInfo(typeof(object)), TypeFactory.GetTypeInfo(typeof(Exception)) }); isEnabledForMethod = logTypeInfo.GetMethod("IsEnabledFor", new ITypeInfo[] { levelTypeInfo }); if (getLoggerWithTypeMethod == null || isEnabledForMethod == null || logType == null || levelType == null || logMethod == null) { loadState = LoadState.Failed; return; } var log4netSectionPresent = AWSConfigs.XmlSectionExists("log4net"); // If log4net section exists and log4net logging is enabled, we attempt to activate // log4net by calling XmlConfigurator.Configure() if (log4netSectionPresent && (AWSConfigs.LoggingConfig.LogTo & LoggingOptions.Log4Net) == LoggingOptions.Log4Net) { ITypeInfo xmlConfiguratorType = TypeFactory.GetTypeInfo(Type.GetType("log4net.Config.XmlConfigurator, log4net")); if (xmlConfiguratorType != null) { MethodInfo configureMethod = xmlConfiguratorType.GetMethod("Configure", new ITypeInfo[0]); if (configureMethod != null) { configureMethod.Invoke(null, null); } } } loadState = LoadState.Success; } catch { // Mark as failed so no attempted will be made on the logging methods. loadState = LoadState.Failed; } } }
private static void loadStatics() { lock (LOCK) { if (loadState == LoadState.Uninitialized) { loadState = LoadState.Loading; try { loggerType = Type.GetType("Amazon.Runtime.Internal.Util.Logger"); logMangerType = Type.GetType("log4net.Core.LoggerManager, log4net"); logMangerTypeInfo = TypeFactory.GetTypeInfo(logMangerType); if (logMangerType == null) { loadState = LoadState.Failed; } else { getLoggerWithTypeMethod = logMangerTypeInfo.GetMethod("GetLogger", new ITypeInfo[2] { TypeFactory.GetTypeInfo(typeof(Assembly)), TypeFactory.GetTypeInfo(typeof(Type)) }); logType = Type.GetType("log4net.Core.ILogger, log4net"); logTypeInfo = TypeFactory.GetTypeInfo(logType); levelType = Type.GetType("log4net.Core.Level, log4net"); levelTypeInfo = TypeFactory.GetTypeInfo(levelType); debugLevelPropertyValue = levelTypeInfo.GetField("Debug").GetValue(null); infoLevelPropertyValue = levelTypeInfo.GetField("Info").GetValue(null); errorLevelPropertyValue = levelTypeInfo.GetField("Error").GetValue(null); systemStringFormatType = Type.GetType("log4net.Util.SystemStringFormat, log4net"); logMethod = logTypeInfo.GetMethod("Log", new ITypeInfo[4] { TypeFactory.GetTypeInfo(typeof(Type)), levelTypeInfo, TypeFactory.GetTypeInfo(typeof(object)), TypeFactory.GetTypeInfo(typeof(Exception)) }); isEnabledForMethod = logTypeInfo.GetMethod("IsEnabledFor", new ITypeInfo[1] { levelTypeInfo }); if (getLoggerWithTypeMethod == null || isEnabledForMethod == null || logType == null || levelType == null || logMethod == null) { loadState = LoadState.Failed; } else { if (AWSConfigs.XmlSectionExists("log4net") && (AWSConfigs.LoggingConfig.LogTo & LoggingOptions.Log4Net) == LoggingOptions.Log4Net) { TypeFactory.GetTypeInfo(Type.GetType("log4net.Config.XmlConfigurator, log4net"))?.GetMethod("Configure", new ITypeInfo[0])?.Invoke(null, null); } loadState = LoadState.Success; } } } catch { loadState = LoadState.Failed; } } } }
protected override void ProcessRecord() { AWSConfigs.RemoveTraceListener(Source, Name); }