()
| 218 | func (p *MetadataAccessPolicy) schemaPredicate(schemaExpression string) string { |
| 219 | if p == nil { |
| 220 | return "TRUE" |
| 221 | } |
| 222 | values := append([]string(nil), p.AllowedSchemas...) |
| 223 | for _, relation := range p.AllowedRelations { |
| 224 | if schema, _, ok := strings.Cut(relation, "."); ok { |
| 225 | values = append(values, schema) |
| 226 | } |
| 227 | } |
| 228 | values = normalizedSQLValues(values) |
| 229 | if len(values) == 0 { |
| 230 | return "FALSE" |
| 231 | } |
| 232 | return fmt.Sprintf("lower(%s) IN (%s)", schemaExpression, quotedSQLValues(values)) |
| 233 | } |
| 234 | |
| 235 | func normalizedSQLValues(values []string) []string { |
| 236 | seen := make(map[string]struct{}, len(values)) |
| 237 | for _, value := range values { |
| 238 | value = strings.ToLower(strings.TrimSpace(value)) |
| 239 | if value != "" { |
| 240 | seen[value] = struct{}{} |
| 241 | } |
no outgoing calls
no test coverage detected