private static void ConfigureInternalDependencies(IProfileRegistry registry, StartupParameters parameters) { registry.For <ISnsTopicCreator>().Use <SnsTopicCreator>(); registry.For <ISnsSubscriptionCreator>().Use <SnsSubscriptionCreator>(); registry.For <ITableAlarmCreator>().Use <TableAlarmCreator>(); registry.For <IIndexAlarmCreator>().Use <IndexAlarmCreator>(); registry.For <IAlarmFinder>().Use <AlarmFinder>(); registry.For <IConfigLoader>().Use <ConfigLoader>(); registry.For <IQueueAlarmCreator>().Use <QueueAlarmCreator>(); var s3Location = GetS3Location(parameters); registry .For <ICloudformationStackDeployer>() .Use(ctx => new CloudformationStackDeployer( ctx.GetInstance <IAlarmLogger>(), ctx.GetInstance <IAmazonCloudFormation>(), ctx.GetInstance <IAmazonS3>(), s3Location )); registry.For <IAlarmCreator>().Use <CloudFormationAlarmCreator>(); }
private static void ConfigureLoggers(IProfileRegistry registry, StartupParameters parameters) { var fileSettings = new FileSettings(parameters.ConfigFolderLocation); var alarmLogger = new ConsoleAlarmLogger(parameters.Verbose); var loadLogger = new ConsoleConfigLoadLogger(parameters.Verbose); registry.For <FileSettings>().Use(fileSettings); registry.For <IAlarmLogger>().Use(alarmLogger); registry.For <IConfigLoadLogger>().Use(loadLogger); }
public IContainer ConfigureContainer(StartupParameters parameters) { var container = new Container(); container.Configure(ctx => AwsBootstrapper.Configure(ctx, parameters)); container.Configure(AwsServiceBootstrapper.Configure); container.Configure(ctx => ConfigureLoggers(ctx, parameters)); container.Configure(ConfigureResourceSources); container.Configure(ctx => ConfigureInternalDependencies(ctx, parameters)); return(container); }
private static S3Location GetS3Location(StartupParameters parameters) { if (string.IsNullOrWhiteSpace(parameters.TemplateS3Path)) { return(null); } var regex = new Regex("^s3://([^/]+)/(.*)", RegexOptions.IgnoreCase); var match = regex.Match(parameters.TemplateS3Path); if (!match.Success) { throw new Exception("Parameter TemplateS3Path does not match format s3://bucket/path"); } return(new S3Location(match.Groups[1].Value, match.Groups[2].Value)); }
private static async Task <int> GenerateAlarms(StartupParameters startParams) { try { var container = new IocBootstrapper().ConfigureContainer(startParams); var alarmGenerator = container.GetInstance <AlarmLoaderAndGenerator>(); await alarmGenerator.LoadAndGenerateAlarms(startParams.RunMode); return(ExitCode.Success); } catch (Exception ex) { Console.Error.WriteLine($"Run failed: {ex.Message}"); return(ExitCode.RunFailed); } }
private static void ConfigureInternalDependencies(IProfileRegistry registry, StartupParameters parameters) { registry.For <ISnsTopicCreator>().Use <SnsTopicCreator>(); registry.For <ISnsSubscriptionCreator>().Use <SnsSubscriptionCreator>(); registry.For <ITableAlarmCreator>().Use <TableAlarmCreator>(); registry.For <IIndexAlarmCreator>().Use <IndexAlarmCreator>(); registry.For <IAlarmFinder>().Use <AlarmFinder>(); registry.For <IConfigLoader>().Use <ConfigLoader>(); registry.For <IQueueAlarmCreator>().Use <QueueAlarmCreator>(); registry.For <IDynamoAlarmGenerator>().Use <DynamoAlarmGenerator>(); registry.For <IOrphanTablesReporter>().Use <OrphanTablesReporter>(); registry.For <IOrphanQueuesReporter>().Use <OrphanQueuesReporter>(); registry.For <ISqsAlarmGenerator>().Use <SqsAlarmGenerator>(); registry.For <ICurrentTimeProvider>().Use <CurrentTimeProvider>(); if (!string.IsNullOrWhiteSpace(parameters.WriteCloudFormationTemplatesToDirectory)) { registry .For <ICloudformationStackDeployer>() .Use( ctx => new DummyCloudFormationStackDeployer( parameters.WriteCloudFormationTemplatesToDirectory, ctx.GetInstance <IAlarmLogger>())); } else { var s3Location = GetS3Location(parameters); registry .For <ICloudformationStackDeployer>() .Use(ctx => new CloudformationStackDeployer( ctx.GetInstance <IAlarmLogger>(), ctx.GetInstance <IAmazonCloudFormation>(), ctx.GetInstance <IAmazonS3>(), s3Location )); } registry.For <IAlarmCreator>().Use <CloudFormationAlarmCreator>(); }
public static StartupParameters ToParameters(string[] args) { var startupParams = new StartupParameters(); if (!Parser.Default.ParseArguments(args, startupParams)) { Console.WriteLine("Missing required arguments, exiting..."); return(null); } switch (startupParams.RunMode) { case RunMode.DryRun: case RunMode.GenerateAlarms: case RunMode.TestConfig: break; default: Console.WriteLine("RunMode not recognised, exiting..."); return(null); } return(startupParams); }