registerPolicy method

Future<void> registerPolicy(
  1. List<T> permissions
)

Register a policy with the Nitric server to secure the resource with least-privilege. Handles shutting down the channel.

Implementation

Future<void> registerPolicy(List<T> permissions) async {
  var resourceIdentifier = await _registrationCompletion.future;

  var policyResource = $p.ResourceIdentifier(type: $p.ResourceType.Policy);

  var policy = $p.PolicyResource(
      principals: [$p.ResourceIdentifier(type: $p.ResourceType.Service)],
      resources: [resourceIdentifier],
      actions: permissionsToActions(permissions));

  var req = $p.ResourceDeclareRequest(policy: policy, id: policyResource);

  await ClientChannelSingleton.useClient($p.ResourcesClient.new,
      (client) async {
    await client.declare(req);
  });
}