Skip to content
Snippets Groups Projects
Select Git revision
  • 47a5d5f30f1cc9b65a1184ca48a910f5c89eba29
  • main default protected
  • gitkeep
  • dev protected
  • Issue/xxxx-configurableApiHostname
  • Issue/2732-updatedApiClient
  • APIv2
  • Issue/2518-docs
  • Hotfix/2427-adminTrouble
  • Issue/1910-MigrationtoNET6.0
  • Issue/1833-newLogin
  • Sprint/2022-01
  • Sprint/2021-23
  • Issue/1745-coscineConnection
  • x/setup
15 results

CoscineCodeGenerator.cs

Blame
  • 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();
    
            }
    
            
        }
    }