GetMatchedDatabasesInDatabaseGroup returns the matched databases in the given database group.
(ctx context.Context, databaseGroup *store.DatabaseGroupMessage, allDatabases []*store.DatabaseMessage)
| 153 | |
| 154 | // GetMatchedDatabasesInDatabaseGroup returns the matched databases in the given database group. |
| 155 | func GetMatchedDatabasesInDatabaseGroup(ctx context.Context, databaseGroup *store.DatabaseGroupMessage, allDatabases []*store.DatabaseMessage) ([]*store.DatabaseMessage, error) { |
| 156 | var matches []*store.DatabaseMessage |
| 157 | |
| 158 | // DONOT check bb.feature.database-grouping for instance. The API here is read-only in the frontend, we need to show if the instance is matched but missing required license. |
| 159 | // The feature guard will works during issue creation. |
| 160 | for _, database := range allDatabases { |
| 161 | matched, err := CheckDatabaseGroupMatch(ctx, databaseGroup.Expression.Expression, database) |
| 162 | if err != nil { |
| 163 | return nil, err |
| 164 | } |
| 165 | if matched { |
| 166 | matches = append(matches, database) |
| 167 | } |
| 168 | } |
| 169 | return matches, nil |
| 170 | } |
| 171 | |
| 172 | func CheckDatabaseGroupMatch(ctx context.Context, expression string, database *store.DatabaseMessage) (bool, error) { |
| 173 | prog, err := common.ValidateGroupCELExpr(expression) |
no test coverage detected