insertOwner method

void insertOwner(
  1. PolicySubject owner
)

Adds the given owner to the special group owner.

If PolicySubject._id is already a member of the group, the old value gets overwritten. If there is no owner group present, this method will create one.

Implementation

void insertOwner(PolicySubject owner) {
  if (!_groups.containsKey(ownerGroupKey)) {
    final Map<String, PolicyResource> resource = <String, PolicyResource>{
      'thing:/': PolicyResource('thing:/', grants: <PermissionType>{
        PermissionType.read,
        PermissionType.write
      }),
      'policy:/': PolicyResource('policy:/', grants: <PermissionType>{
        PermissionType.read,
        PermissionType.write
      }),
      'message:/': PolicyResource('message:/',
          grants: <PermissionType>{PermissionType.read, PermissionType.write})
    };
    // TODO(poq): add s3i admin entry?
    insertGroup(PolicyGroup(ownerGroupKey,
        policySubjects: <String, PolicySubject>{owner.id: owner},
        policyResources: resource));
  } else {
    _groups[ownerGroupKey]!.subjects[owner.id] = owner;
  }
}