public async Task <int> Execute() { try { KongConfiguration = await KongReader.GetConfiguration(); } catch (Exception e) when(e is KongException || e is HttpRequestException) { return(ExitWithCode.Return(ExitCode.HostUnreachable, e.Message)); } var versionSubStr = KongConfiguration.Version.Substring(0, 4); var version = double.Parse(versionSubStr[3] == '.' ? versionSubStr.Substring(0, 3) : versionSubStr); if (KongConfiguration.Version.Contains("enterprise-edition")) { const double lowestSupportedVersion = 0.36; if (version < lowestSupportedVersion) { return(ExitWithCode.Return(ExitCode.HostVersionNotSupported, $"This version of Kongverge can only support Kong enterprise from version {lowestSupportedVersion}-x")); } } else { const double lowestSupportedVersion = 1.4; if (version < lowestSupportedVersion) { return(ExitWithCode.Return(ExitCode.HostVersionNotSupported, $"This version of Kongverge can only support Kong from version {lowestSupportedVersion}.x")); } } return(await DoExecute()); }
public override async Task <int> DoExecute() { KongvergeConfiguration targetConfiguration; try { targetConfiguration = await _configReader.ReadConfiguration(Configuration.InputFolder); } catch (DirectoryNotFoundException ex) { return(ExitWithCode.Return(ExitCode.InputFolderUnreachable, ex.Message)); } catch (InvalidConfigurationFileException ex) { return(ExitWithCode.Return(ExitCode.InvalidConfigurationFile, $"Invalid configuration file {ex.Path}{Environment.NewLine}{ex.Message}")); } var existingConfiguration = await _configBuilder.FromKong(KongReader); await ConvergeObjects( existingConfiguration.Services, targetConfiguration.Services, x => _kongWriter.DeleteService(x.Id), x => _kongWriter.AddService(x), x => _kongWriter.UpdateService(x), ConvergeServiceChildren); await ConvergeChildrenPlugins(existingConfiguration.GlobalConfig, targetConfiguration.GlobalConfig); return(ExitWithCode.Return(ExitCode.Success)); }
public override async Task <int> DoExecute() { var existingConfiguration = await _configBuilder.FromKong(KongReader); await _configWriter.WriteConfiguration(existingConfiguration, _arguments.OutputFolder); return(ExitWithCode.Return(ExitCode.Success)); }
public async Task <int> Execute() { var reachable = await KongReader.KongIsReachable(); if (!reachable) { return(ExitWithCode.Return(ExitCode.HostUnreachable)); } return(await DoExecute()); }
public async Task <int> Execute() { try { KongConfiguration = await KongReader.GetConfiguration(); } catch { return(ExitWithCode.Return(ExitCode.HostUnreachable)); } return(await DoExecute()); }
public async Task<int> Execute() { try { KongConfiguration = await KongReader.GetConfiguration(); } catch (Exception e) when (e is KongException || e is HttpRequestException) { return ExitWithCode.Return(ExitCode.HostUnreachable, e.Message); } return await DoExecute(); }
public static int Main(string[] args) { var app = new CommandLineApplication { Name = "Kongverge", Description = "Kong configuration convergence." }; var options = new Options(app); app.OnExecute(async() => { ServiceRegistration.CreateConsoleLogger(); var exitCode = options.Validate(); if (exitCode.HasValue) { return(ExitWithCode.Return(exitCode.Value)); } var serviceProvider = new ServiceCollection().ConfigureServices().BuildServiceProvider(); options.Apply(serviceProvider); var workflow = serviceProvider.GetService <Workflow.Workflow>(); Log.Information($"************** {app.Name} **************"); return(await workflow.Execute()); }); try { return(app.Execute(args)); } catch (Exception ex) { Log.Error(ex, "Error running program: {message}", ex.Message); return((int)ExitCode.UnspecifiedError); } }
public override async Task <int> DoExecute() { _availablePlugins = KongConfiguration.Plugins.Available .Where(x => x.Value) .Select(x => x.Key) .ToDictionary(x => x, x => new AsyncLazy <KongPluginSchema>(() => KongReader.GetPluginSchema(x))); KongvergeConfiguration targetConfiguration; try { targetConfiguration = await _configReader.ReadConfiguration(_arguments.InputFolder, _availablePlugins); } catch (DirectoryNotFoundException ex) { return(ExitWithCode.Return(ExitCode.InputFolderUnreachable, ex.Message)); } catch (InvalidConfigurationFilesException ex) { return(ExitWithCode.Return(ExitCode.InvalidConfigurationFiles, ex.Message)); } var existingConfiguration = await _configBuilder.FromKong(KongReader); try { await ConvergeConfiguration(existingConfiguration, targetConfiguration); } catch (KongException e) when(e.StatusCode == HttpStatusCode.BadRequest) { Log.Error(e, $"Error converging target configuration: {e}"); Log.Information("Attempting rollback to previous configuration..."); var currentConfiguration = await _configBuilder.FromKong(KongReader); await ConvergeConfiguration(currentConfiguration, existingConfiguration); return(ExitWithCode.Return(ExitCode.UnspecifiedError, "An error occurred while attempting to converge target configuration. Rollback was successful.")); } return(ExitWithCode.Return(ExitCode.Success)); }
public override async Task <int> DoExecute() { var schemas = KongConfiguration.GetSchemas(KongReader); KongvergeConfiguration targetConfiguration; try { targetConfiguration = await _configReader.ReadConfiguration(_arguments.InputFolder, schemas); } catch (DirectoryNotFoundException ex) { return(ExitWithCode.Return(ExitCode.InputFolderUnreachable, ex.Message)); } catch (InvalidConfigurationFilesException ex) { return(ExitWithCode.Return(ExitCode.InvalidConfigurationFiles, ex.Message)); } var existingConfiguration = await _configBuilder.FromKong(KongReader); try { await ConvergeConfiguration(existingConfiguration, targetConfiguration); } catch (KongException e) when(e.StatusCode == HttpStatusCode.BadRequest) { Log.Error(e, $"Error converging target configuration: {e}"); var currentConfiguration = await _configBuilder.FromKong(KongReader); Log.Information($"Attempting rollback to previous configuration: {existingConfiguration}"); await ConvergeConfiguration(currentConfiguration, existingConfiguration); return(ExitWithCode.Return(ExitCode.UnspecifiedError, "An error occurred while attempting to converge target configuration. Rollback was successful.")); } return(ExitWithCode.Return(ExitCode.Success)); }
public override Task <int> DoExecute() => Task.FromResult(ExitWithCode.Return(ExitCode.Success));