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));

  await _client
      .declare($p.ResourceDeclareRequest(policy: policy, id: policyResource));

  await ClientChannelSingleton.instance.release();
}