Skip to content

Commit 799cb80

Browse files
committed
add other CEL validations
1 parent 7b09729 commit 799cb80

6 files changed

Lines changed: 47 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ users:
9393

9494
### 2. Create PostgreSQL Connection and Secret
9595

96-
For the `postgresql` Dev Service, you can generate the necessary Custom Resources to test the operator:
96+
For the `postgresql` Dev Service, you can generate the necessary Custom Resources to test the Operator:
9797

9898
1. From the Dev UI, get the `postgresql` Dev Service properties (username, password, host, port).
9999
2. Convert the `postgresql` Dev Service properties to a **Basic Auth Secret** and a **ClusterConnection** CR instance.

operator/src/main/java/it/aboutbits/postgresql/core/ClusterReference.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package it.aboutbits.postgresql.core;
22

33
import io.fabric8.generator.annotation.Required;
4+
import io.fabric8.generator.annotation.ValidationRule;
45
import lombok.Getter;
56
import lombok.Setter;
67
import org.jspecify.annotations.NullMarked;
@@ -11,6 +12,10 @@
1112
@Setter
1213
public class ClusterReference {
1314
@Required
15+
@ValidationRule(
16+
value = "self.size() > 0",
17+
message = "The ClusterReference name must not be empty."
18+
)
1419
private String name = "";
1520

1621
@Nullable

operator/src/main/java/it/aboutbits/postgresql/core/SecretRef.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package it.aboutbits.postgresql.core;
22

33
import io.fabric8.generator.annotation.Required;
4+
import io.fabric8.generator.annotation.ValidationRule;
45
import lombok.Getter;
56
import lombok.Setter;
67
import org.jspecify.annotations.NullMarked;
@@ -11,6 +12,10 @@
1112
@Setter
1213
public class SecretRef {
1314
@Required
15+
@ValidationRule(
16+
value = "self.size() > 0",
17+
message = "The SecretRef name must not be empty."
18+
)
1419
private String name = "";
1520

1621
/**

operator/src/main/java/it/aboutbits/postgresql/crd/clusterconnection/ClusterConnectionSpec.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package it.aboutbits.postgresql.crd.clusterconnection;
22

3+
import io.fabric8.generator.annotation.Max;
4+
import io.fabric8.generator.annotation.Min;
35
import io.fabric8.generator.annotation.Required;
6+
import io.fabric8.generator.annotation.ValidationRule;
47
import it.aboutbits.postgresql.core.SecretRef;
58
import lombok.Getter;
69
import lombok.Setter;
@@ -14,12 +17,22 @@
1417
@Setter
1518
public class ClusterConnectionSpec {
1619
@Required
20+
@ValidationRule(
21+
value = "self.size() > 0",
22+
message = "The ClusterConnection host must not be empty."
23+
)
1724
private String host = "";
1825

1926
@Required
20-
private Integer port = -1;
27+
@Min(1)
28+
@Max(65535)
29+
private int port = -1;
2130

2231
@Required
32+
@ValidationRule(
33+
value = "self.size() > 0",
34+
message = "The ClusterConnection maintenanceDatabase must not be empty."
35+
)
2336
private String maintenanceDatabase = "postgres";
2437

2538
@Required

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
@NullMarked
1515
@Getter
1616
@Setter
17+
@ValidationRule(
18+
value = "self.objectType == 'database' || (has(self.schema) && self.schema.size() > 0)",
19+
message = "The Grant schema is required to be set, except if objectType is 'database'."
20+
)
1721
public class GrantSpec {
1822
@Required
1923
private ClusterReference clusterRef = new ClusterReference();
@@ -24,6 +28,10 @@ public class GrantSpec {
2428
value = "self == oldSelf",
2529
message = "The Grant database is immutable. Changing it would require revoking permissions from the old database before granting them in the new one."
2630
)
31+
@ValidationRule(
32+
value = "self.size() > 0",
33+
message = "The Grant database must not be empty."
34+
)
2735
private String database = "";
2836

2937
/// The name of the role to grant privileges on.
@@ -32,14 +40,21 @@ public class GrantSpec {
3240
value = "self == oldSelf",
3341
message = "The Grant role is immutable. Changing it would require revoking permissions from the old role before granting them to the new one."
3442
)
43+
@ValidationRule(
44+
value = "self.size() > 0",
45+
message = "The Grant role must not be empty."
46+
)
3547
private String role = "";
3648

3749
/// The database schema to grant privileges on for this role (required except if objectType is "database")
38-
@Required
3950
@ValidationRule(
4051
value = "self == oldSelf",
4152
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."
4253
)
54+
@ValidationRule(
55+
value = "self.size() > 0",
56+
message = "The Grant schema must not be empty."
57+
)
4358
private String schema = "";
4459

4560
/// The PostgreSQL object type to grant the privileges on.
@@ -72,7 +87,7 @@ public class GrantSpec {
7287
private List<String> objects = new ArrayList<>();
7388

7489
/// The privileges to grant on the PostgreSQL objects.
75-
/// The operator also validates if the objectType supports the privileges.
90+
/// The Operator also validates if the objectType supports the privileges.
7691
///
7792
/// There are different kinds of privileges:
7893
/// - `select`

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ public class RoleSpec {
2121
@Required
2222
@ValidationRule(
2323
value = "self == oldSelf",
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."
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."
25+
)
26+
@ValidationRule(
27+
value = "self.size() > 0",
28+
message = "The Role name must not be empty."
2529
)
2630
private String name = "";
2731

0 commit comments

Comments
 (0)