Skip to main content
Any Framework

Manage Jinaga replicators. Deploy authorization and distribution rules.

Published
Feb 9, 2024
2y ago
Total Downloads
2.0K
2,008

Install

dotnet add package Jinaga.Tool --version 0.9.0

No framework information available.

README

Jinaga command line tool

Manage Jinaga replicators. Deploy authorization and distribution rules.

Installation

Install the global tool via dotnet.

dotnet tool install -g Jinaga.Tool

Usage

Run the tool during continuous deployment to deploy authorization and distribution rules.

dotnet jinaga deploy authorization <assembly> <endpoint> <secret>
dotnet jinaga deploy distribution <assembly> <endpoint> <secret>

You can find the endpoint and secret in the Jinaga replicator portal.

This tool is to be used with a Jinaga application. Install the Jinaga NuGet package and create a model. For example:

[FactType("Blog.Site")]
public record Site(User creator, string identifier) { }

[FactType("Blog.GuestBlogger")]
public record GuestBlogger(Site site, User guest) { }

[FactType("Blog.Content")]
public record Content(Site site, string path) { }

Create a public static class called JinagaConfig. This will typically be the class that creates the JinagaClient. For example:

public static class JinagaConfig
{
  public static JinagaClient j = JinagaClient.Create(opt =>
  {
    var settings = new Settings();
    settings.Verify();
    opt.HttpEndpoint = new Uri(settings.ReplicatorUrl);
  });
}

Add your authorization and distribution rules to this class. Use the AuthorizationRules class to build and describe your rules. For example:

  public static string Authorization() => AuthorizationRules.Describe(Authorization);

  private static AuthorizationRules Authorization(AuthorizationRules r) => r
    // Anyone can create a user
    .Any<User>()
    // A site can only be created by its creator
    .Type<Site>(site => site.creator)
    // A guest blogger can only be created by the site's creator
    .Type<GuestBlogger>(guestBlogger => guestBlogger.site.creator)
    // A content item can be created by the site's creator
    .Type<Content>(content => content.site.creator)
    // A content item can also be created by a guest blogger
    .Type<Content>((content, facts) =>
      from guestBlogger in facts.OfType<GuestBlogger>()
      where guestBlogger.site == content.site
      from user in facts.OfType<User>()
      where user == guestBlogger.guest
      select user
    )
    ;

Use the DistributionRules class to build and describe your rules. For example:

  public static string Distribution() => DistributionRules.Describe(Distribution);

  private static DistributionRules Distribution(DistributionRules r) => r
    // Everyone can see published posts
    .Share(Given<Model.Site>.Match((site, facts) =>
      from content in facts.OfType<Model.Content>()
      where content.site == site &&
        facts.Any<Model.Publish>(publish => publish.content == content)
      select content
    ))
    .WithEveryone()
    // The creator can see all posts
    .Share(Given<Model.Site>.Match((site, facts) =>
      from content in facts.OfType<Model.Content>()
      where content.site == site
      select content
    ))
    .With(site => site.creator)
    ;

Run the tool to deploy the rules to the replicator. The replicator will then enforce the rules.

Build and Test

dotnet build .\Jinaga.Tool -c Release
dotnet pack .\Jinaga.Tool -c Release
dotnet tool install --global --add-source .\Jinaga.Tool\bin\Release Jinaga.Tool

After testing, uninstall the tool

dotnet tool uninstall --global Jinaga.Tool

Changes from Previous Version

No structural changes between v0.6.1 and v0.9.0.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

No target framework metadata is available. Confirm compatibility in a representative project before standardising on this package.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.