Skip to content

Commit 7b09729

Browse files
committed
add immutable Grant CRD CEL validation rules
1 parent ff8cc0c commit 7b09729

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

operator/src/main/java/it/aboutbits/postgresql/crd/grant/GrantSpec.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.fasterxml.jackson.annotation.JsonFormat;
44
import io.fabric8.generator.annotation.Required;
5+
import io.fabric8.generator.annotation.ValidationRule;
56
import it.aboutbits.postgresql.core.ClusterReference;
67
import lombok.Getter;
78
import lombok.Setter;
@@ -19,14 +20,26 @@ public class GrantSpec {
1920

2021
/// The database to grant privileges on for this role.
2122
@Required
23+
@ValidationRule(
24+
value = "self == oldSelf",
25+
message = "The Grant database is immutable. Changing it would require revoking permissions from the old database before granting them in the new one."
26+
)
2227
private String database = "";
2328

2429
/// The name of the role to grant privileges on.
2530
@Required
31+
@ValidationRule(
32+
value = "self == oldSelf",
33+
message = "The Grant role is immutable. Changing it would require revoking permissions from the old role before granting them to the new one."
34+
)
2635
private String role = "";
2736

2837
/// The database schema to grant privileges on for this role (required except if objectType is "database")
2938
@Required
39+
@ValidationRule(
40+
value = "self == oldSelf",
41+
message = "The Grant schema is immutable. Changing it would require revoking permissions from the old schema before granting them to objects in the new schema."
42+
)
3043
private String schema = "";
3144

3245
/// The PostgreSQL object type to grant the privileges on.
@@ -46,6 +59,10 @@ public class GrantSpec {
4659
/// - `type`
4760
@Required
4861
@JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_VALUES)
62+
@ValidationRule(
63+
value = "self == oldSelf",
64+
message = "The Grant objectType is immutable. Changing it would require revoking permissions and generating a completely different SQL statement."
65+
)
4966
private GrantObjectType objectType = GrantObjectType.DATABASE;
5067

5168
/// The PostgreSQL objects to grant privileges on.

operator/src/main/java/it/aboutbits/postgresql/crd/role/RoleSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class RoleSpec {
2121
@Required
2222
@ValidationRule(
2323
value = "self == oldSelf",
24-
message = "The Role name must not be changed once it is created"
24+
message = "The Role name is immutable. Allowing to rename the Role name using 'alter role <old_name> rename to <new_name>' would add unwanted side-effects to the operator."
2525
)
2626
private String name = "";
2727

0 commit comments

Comments
 (0)