Select Git revision
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
Program.cs 3.49 KiB
using Consul;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace ConfigurationUpdater
{
class Program
{
static void Main(string[] args)
{
try
{
if (args.Length > 0)
{
switch (args[0])
{
case "SetValue":
if (args.Length == 3)
{
Console.WriteLine(Consul.TaskRetriever(Consul.SetValue(args[1], args[2])));
}
else
{
Console.WriteLine("Please call \"SetValue\" with \"Key\" and \"Value\"");
}
break;
case "GetValue":
if (args.Length == 2)
{
Console.WriteLine(Consul.TaskRetriever(Consul.GetValue(args[1])));
}
else
{
Console.WriteLine("Please call \"GetValue\" with \"Key\"");
}
break;
case "SetValueOnConfiguration":
if (args.Length == 4)
{
string value = Consul.TaskRetriever(Consul.GetValue(args[1]));
string text = File.ReadAllText(args[2]);
text = text.Replace(args[3], value);
File.WriteAllText(args[2], text);
Console.WriteLine("Replaced \"" + args[3] + "\" with \"" + value + "\" in \"" + args[2] + "\"");
}
else
{
Console.WriteLine("Please call \"SetValueOnConfiguration\" with \"Key\", \"ConfigurationFile\" and \"ReplaceKey\"");
}
break;
case "RestartNomadJob":
// Currently there is no Nomad .NET API
if (args.Length == 2)
{
string jobId = args[1];
Console.WriteLine(Nomad.UpdateJob(jobId));
}
else
{
Console.WriteLine("Please call \"RestartNomadJob\" with the \"JobId\"");
}
break;
default:
Console.WriteLine("Please call this program with the method \"SetValue\", \"GetValue\", \"SetValueOnConfiguration\" or \"RestartNomadJob\"");
break;
}
}
else
{
Console.WriteLine("Please call this program with the method \"SetValue\", \"GetValue\", \"SetValueOnConfiguration\" or \"RestartNomadJob\"");
}
}
catch (Exception e)
{
Console.WriteLine("An error occurred during execution: " + e.Message);
}
Console.ReadLine();
}
}
}