MCPcopy Index your code
hub / github.com/bytebase/bytebase / CheckDatabaseGroupMatch

Function CheckDatabaseGroupMatch

backend/utils/utils.go:172–200  ·  view source on GitHub ↗
(ctx context.Context, expression string, database *store.DatabaseMessage)

Source from the content-addressed store, hash-verified

170}
171
172func 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.
203func IsSpaceOrSemicolon(r rune) bool {

Callers 2

Calls 1

ValidateGroupCELExprFunction · 0.92

Tested by 1