Giter Club home page Giter Club logo

consul-hashicorp-clone-tree's Introduction

Using Console with Consul

This is a C# code example that interacts with Consul to export, import, and clone configurations.

Requirements

  • .NET Core SDK
  • NuGet Package: Consul

How to Use

  1. Clone this repository.
  2. Navigate to the project directory.
  3. Build the project using the command dotnet build.
  4. Run the program using the command dotnet run.

Features

The program offers the following options:

Export Configurations

Exports configurations from Consul to a JSON file.

Console.WriteLine("Enter the settings prefix to export: ");
var prefixToExport = Console.ReadLine();

Console.WriteLine("Enter the file path to save the settings. ex: c:/temp/my-export.json ");
var exportFilePath = Console.ReadLine();

await ExportConfigurations(consulClient, prefixToExport, exportFilePath);

Import Configurations

Imports configurations from a JSON file to Consul.

Console.WriteLine("Enter the file path of the settings to import.  ex: c:/temp/my-export.json");
var importFilePath = Console.ReadLine();

Console.WriteLine("Enter the new prefix for the imported settings: ");
var newPrefixForImport = Console.ReadLine();

await ImportConfigurations(consulClient, importFilePath, newPrefixForImport);

Clone Structure

Clones the configuration structure from one prefix to another.

Console.WriteLine("Enter the prefix you want to clone: ");
var prefix = Console.ReadLine();
var keysEValues = await FindKeys(consulClient, prefix);

Console.WriteLine("Enter the NEW prefix where you want to create the clone: ");
var newPrefix = Console.ReadLine();

foreach (var par in keysEValues)
{
    await CreateKey(consulClient, $"{newPrefix}/{par.Key}", par.Value);
}

Notes

  • Make sure you have the proper permissions to access Consul.
  • Make sure you have a running instance of Consul before using this program.
  • Replace the default Consul address and token values as needed in the CreateConsulClient() method.

Developed by Meigston.

For testing purposes, there's a docker-compose file that will spin up a Consul instance with predefined configuration. This allows testing the application by performing an export or importing a new configuration.

consul-hashicorp-clone-tree's People

Contributors

meigston avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.