Rocketmakers.Environment.Generation.Cli
2.1.2
dotnet tool install --global Rocketmakers.Environment.Generation.Cli --version 2.1.2
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local Rocketmakers.Environment.Generation.Cli --version 2.1.2
#tool dotnet:?package=Rocketmakers.Environment.Generation.Cli&version=2.1.2
nuke :add-package Rocketmakers.Environment.Generation.Cli --version 2.1.2
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": "https://docs.rocketmakers.club/environment/schema/v1.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
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...
//<autogenerated />
// DO NOT EDIT! This class is automatically generated using Rocketmakers.Environment.Generation.
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
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
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 providers for retrieving the environment data from environment variables or dotenv
files, but also the interface for the contract if you want to retrieve them from somewhere else (e.g. cloud secret manager).
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
This package has no dependencies.
Version | Downloads | Last updated | |
---|---|---|---|
2.1.2 | 3,545 | 11/4/2024 | |
2.1.1 | 9,549 | 5/13/2024 | |
2.1.0 | 4,483 | 4/3/2024 | |
2.0.0 | 3,378 | 3/19/2024 | |
1.0.0 | 10,038 | 11/15/2023 | |
0.5.1 | 8,463 | 5/15/2023 | |
0.5.0 | 8,614 | 12/16/2022 | |
0.4.2 | 1,491 | 12/5/2022 | |
0.4.1 | 4,477 | 8/8/2022 | |
0.4.0 | 3,214 | 7/29/2022 | |
0.3.1 | 761 | 5/19/2022 | |
0.3.0 | 499 | 5/19/2022 | |
0.2.0 | 473 | 5/19/2022 | |
0.1.0 | 501 | 5/13/2022 |