| 170 | } |
| 171 | |
| 172 | func CheckDatabaseGroupMatch(ctx context.Context, expression string, database *store.DatabaseMessage) (bool, error) { |
| 173 | prog, err := common.ValidateGroupCELExpr(expression) |
| 174 | if err != nil { |
| 175 | return false, err |
| 176 | } |
| 177 | |
| 178 | effectiveEnvironmentID := "" |
| 179 | if database.EffectiveEnvironmentID != nil { |
| 180 | effectiveEnvironmentID = *database.EffectiveEnvironmentID |
| 181 | } |
| 182 | res, _, err := prog.ContextEval(ctx, map[string]any{ |
| 183 | common.CELAttributeResourceDatabaseName: database.DatabaseName, |
| 184 | common.CELAttributeResourceEnvironmentID: effectiveEnvironmentID, |
| 185 | common.CELAttributeResourceInstanceID: database.InstanceID, |
| 186 | common.CELAttributeResourceDatabaseLabels: database.Metadata.Labels, |
| 187 | }) |
| 188 | if err != nil { |
| 189 | return false, connect.NewError(connect.CodeInternal, err) |
| 190 | } |
| 191 | |
| 192 | val, err := res.ConvertToNative(reflect.TypeFor[bool]()) |
| 193 | if err != nil { |
| 194 | return false, connect.NewError(connect.CodeInternal, errors.New("expect bool result")) |
| 195 | } |
| 196 | if boolVal, ok := val.(bool); ok && boolVal { |
| 197 | return true, nil |
| 198 | } |
| 199 | return false, nil |
| 200 | } |
| 201 | |
| 202 | // IsSpaceOrSemicolon checks if the rune is a space or a semicolon. |
| 203 | func IsSpaceOrSemicolon(r rune) bool { |