in sources/src/main/java/com/google/solutions/jitaccess/catalog/policy/IamRoleBinding.java [42:92]
public record IamRoleBinding(
@NotNull ResourceId resource,
@NotNull IamRole role,
@Nullable String description,
@Nullable String condition
) implements Privilege {
@Override
public @NotNull String name() {
return this.role.name();
}
@Override
public @NotNull String resourceName() {
return this.resource.path();
}
@Override
public boolean hasResourceCondition() {
return this.condition != null;
}
@Override
public String toString() {
return Coalesce.nonEmpty(
this.description,
String.format("%s on %s",
this.role,
this.resource.path()));
}
public IamRoleBinding(
@NotNull ResourceId resource,
@NotNull IamRole role
) {
this(resource, role, null, null);
}
/**
* Create a checksum that doesn't depend on the current
* JRE version's implementation of String.hashCode().
*/
public int checksum() {
var hash = Hashing.crc32().newHasher();
hash.putString(this.resource.id(), Charset.defaultCharset());
hash.putString(this.role.name(), Charset.defaultCharset());
hash.putString(Strings.nullToEmpty(this.condition), Charset.defaultCharset());
hash.putString(Strings.nullToEmpty(this.description), Charset.defaultCharset());
return hash.hash().asInt();
}
}