Rocketmakers.Environment.Generation.Cli 0.4.0

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global Rocketmakers.Environment.Generation.Cli --version 0.4.0                
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local Rocketmakers.Environment.Generation.Cli --version 0.4.0                
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=Rocketmakers.Environment.Generation.Cli&version=0.4.0                
nuke :add-package Rocketmakers.Environment.Generation.Cli --version 0.4.0                

Rocketmakers.Environment

These set of packages are used to describe the contract your application has to its running environment, and make this contract available to other downstream consumers of your application.

Definition

You can define a (machine readable) JSON/YAML file, that will be used to generate a C# Environment class for consumption in your application

{
  "$schema": "./node_modules/@rocketmakers/environment/schema/environment-schema.json",
  "version": 1,
  "name": "Authentication",
  "prefix": "AUTH",
  "variables": [
    { "kind": "string", "name": "TOKEN", "secret": true },
    { "kind": "string", "name": "NAME", "optional": true },
    { "kind": "string", "name": "CONTACTS", "optional": true, "array": true },
    { "kind": "number", "name": "RATE" },
    { "kind": "integer", "name": "PORT" },
    { "kind": "file-path", "name": "RSA_FILE", "secret": true }
  ]
}

Note: secret is purely advisory for any consumers, and not directly used within this package!

You can then use the CLI tool to generate a .NET implementation matching the contract for your application. This will have a dependency on our supporting library Rocketmakers.Environment.

Packages

Rocketmakers.Environment.Generation

Nuget

This contains the main logic for generating a consumable C# class which matches the contract of a given environment schema. The main entry point for this is via the Generator class.

var generator = new Generator();
var inputFilePath = 'path/to/environment/definition.json';

var content = await generator.GenerateAsync(inputFilePath, new GeneratorOptions('MyApplicationNamespace'));

...which for the example definition above would produce something like...

/// <summary>
/// DO NOT EDIT! This class is automatically generated using Rocketmakers.Environment.Generation.
/// </summary>

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Rocketmakers.Environment;

namespace MyApplicationNamespace;

public partial record AuthenticationDefaults
{
    public string Token { get; set; }

    public string Name { get; set; }

    public IEnumerable<string> Contacts { get; set; }

    public decimal? rate { get; set; }

    public int? Port { get; set; }

    public string RsaFile { get; set; }
}

public partial class Authentication
{
    public string Token { get; init; }

    public string Name { get; init; }

    public IEnumerable<string> Contacts { get; init; }

    public decimal rate { get; init; }

    public int Port { get; init; }

    public string RsaFile { get; init; }


    public static async Task<Authentication> ConfigureAsync(IEnvironmentProvider provider, AuthenticationDefaults defaults)
    {
        // Generated code is here, but removed for demonstration purposes //
    }

    public static Authentication Configure(IEnvironmentProvider provider, AuthenticationDefaults defaults)
    {
        // Generated code is here, but removed for demonstration purposes //
    }

    public static Task<Authentication> ConfigureAsync(IEnvironmentProvider provider, Action<AuthenticationDefaults> constructDefaults)
    {
        // Generated code is here, but removed for demonstration purposes //
    }

    public static Authentication Configure(IEnvironmentProvider provider, Action<AuthenticationDefaults> constructDefaults)
    {
        // Generated code is here, but removed for demonstration purposes //
    }

    public static Task<Authentication> ConfigureAsync(IEnvironmentProvider provider)
    {
        // Generated code is here, but removed for demonstration purposes //
    }

    public static Authentication Configure(IEnvironmentProvider provider)
    {
        // Generated code is here, but removed for demonstration purposes //
    }
}

...which would then be consumed something like...

var config = Authentication.Load
(
    new EnvironmentVariableProvider(),
    new AuthenticationDefaults()
    {
      Name = "Default Name"
    }
);

Rocketmakers.Environment.Generation.Cli

Nuget

This package contains a .NET CLI tool for exposing Rocketmakers.Environment.Generation functionality via the command line.

Please note, at the present time the CLI tool only supports JSON files.

Installation

Before you install, it is suggested you create a dotnet tool manifest. This ensures that all developers working on your code base use the same version of the tool. This can be done by running the following command

dotnet new tool-manifest

You can then install the tool with the following command to install the latest version.

dotnet tool install Rocketmakers.Environment.Generation.Cli
Running The Tool

You can then run the tool with the following command

dotnet tool run rocketmakers-environment-cli -i /path/to/environment/definition.json -o /path/to/output/generated/code.cs -n MyNamespace

Rocketmakers.Environment

Nuget

This is a supporting package required by the code generated by Rocketmakers.Environment.Generation. It provides interfaces and default implementations that the generated code relies upon. This includes a default provider for retrieving the environment data from environment variables, but also the interface for the contract if you want to retrieve them from somewhere else (e.g. cloud secret manager).

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
2.1.2 3,607 11/4/2024
2.1.1 9,556 5/13/2024
2.1.0 4,485 4/3/2024
2.0.0 3,382 3/19/2024
1.0.0 10,040 11/15/2023
0.5.1 8,465 5/15/2023
0.5.0 8,616 12/16/2022
0.4.2 1,495 12/5/2022
0.4.1 4,481 8/8/2022
0.4.0 3,218 7/29/2022
0.3.1 765 5/19/2022 0.3.1 is deprecated because it is no longer maintained.
0.3.0 503 5/19/2022 0.3.0 is deprecated because it is no longer maintained.
0.2.0 477 5/19/2022 0.2.0 is deprecated because it is no longer maintained.
0.1.0 505 5/13/2022 0.1.0 is deprecated because it is no longer maintained.

# Changelog: dotnet  Generated using [standard-version](https://github.com/conventional-changelog/standard-version/tree/v9.5.0)  ## 0.4.0 (2022-07-13)  ### Features  - **dotnet:** Updated generator to perform schema validation on loaded schema and report errors ([0222f25](https://gitlab.com/rocketmakers/core/environment/commit/0222f25678cdbe0d22a2b6e95ff8ebed3f903954)) - **dotnet:** Added project to generate c# classes from schema ([cfbe96d](https://gitlab.com/rocketmakers/core/environment/commit/cfbe96d305c2ba837e0881d595f92cdf0a528fbb)) - **dotnet:** Refactored EnvironmentVariableProvider to have less repeatable code ([9ece8f9](https://gitlab.com/rocketmakers/core/environment/commit/9ece8f9933eecc6d82d46f94a23e839b0e865b58)) - **dotnet:** Renamed EnvironmentConfigProvider to EnvironmentVariableProvider ([ab9f0e2](https://gitlab.com/rocketmakers/core/environment/commit/ab9f0e283a039a7da84bf1c14149ea3390d3913f)) - **dotnet:** Updated Load functions to throw an exception on error instead of a result object ([f87034f](https://gitlab.com/rocketmakers/core/environment/commit/f87034f6102e800fb4526d7bbbfdceaad0206ef8))  ### Bug Fixes  - **dotnet:** Fixed issue with array based environment variables using incorrect key ([755343a](https://gitlab.com/rocketmakers/core/environment/commit/755343af023579ec7c0c1de1bd7e9cb414881a33)) - **dotnet:** Fixed issue with keys when a prefix is used. ([38ac354](https://gitlab.com/rocketmakers/core/environment/commit/38ac35459e9eeeb6776e6e38b388715c0a3c2416)) - **dotnet:** Fixed spelling mistake in mandatory string ([7040457](https://gitlab.com/rocketmakers/core/environment/commit/70404579cf6c582856433f4e92c730528032ded9)) - **dotnet:** Fixed generated loading to adhere to optional properties correctly ([faab940](https://gitlab.com/rocketmakers/core/environment/commit/faab94062a60a0a17312160e66aa193fc9d24629)) - **dotnet:** Updated cli to create parent dir of output if it doesn't exist ([c7e96cb](https://gitlab.com/rocketmakers/core/environment/commit/c7e96cb603d8f2bbeb4c8bba18a30890a8d615fb)) - **dotnet:** Fixed template issue with EnvironmentVariableProvider rename ([0117a37](https://gitlab.com/rocketmakers/core/environment/commit/0117a37d0f6aa69bc64d4fee269e6b93a7b90c49))  ### Tests  - **dotnet-environment:** Added unit tests around Rocketmakers.Environment package ([c10c83d](https://gitlab.com/rocketmakers/core/environment/commit/c10c83dbc96b40a5cf91d19ee99821b4f88c194f)) - **dotnet:** Added unit tests around invalid schemas ([24415bf](https://gitlab.com/rocketmakers/core/environment/commit/24415bfc1fdcfecaf778ff52cd35fff9e9297c89)) - **dotnet:** Fixed unit tests ([0f657ba](https://gitlab.com/rocketmakers/core/environment/commit/0f657baee2c425f07c001f471fb21f6e546ec232)) - **dotnet:** Fixed integration tests to include copy of generated code ([3d0193e](https://gitlab.com/rocketmakers/core/environment/commit/3d0193ef16ffe4217a3be244d8508bbc4ff9cfb2)) - **dotnet:** Fixed tests ([5f65d38](https://gitlab.com/rocketmakers/core/environment/commit/5f65d38fa425b68138bc5b71a965c533534d7a01)) - **dotnet:** Updated unit tests to reflect changes and include some integration tests ([76cfb42](https://gitlab.com/rocketmakers/core/environment/commit/76cfb4239cf39ba7e0b13bb6e9b5f1251afae043)) - **dotnet:** Updated tests around generation for expected inputs ([4e00581](https://gitlab.com/rocketmakers/core/environment/commit/4e005816a6762b5cc3ee00c4dbdd18ac48ecf29c))  ### CI  - Added CI jobs for building and testing dotnet implementation ([1c676e8](https://gitlab.com/rocketmakers/core/environment/commit/1c676e8db1397d73217c1a93591e2d0eb4445eab)) - Updated unit tests to export reports ([b76c3d8](https://gitlab.com/rocketmakers/core/environment/commit/b76c3d8b7000db6f7f11db9ed7329960894585e8))