GetQueryExportFactors is used to get risk factors from query and export expressions.
(expression string)
| 215 | |
| 216 | // GetQueryExportFactors is used to get risk factors from query and export expressions. |
| 217 | func GetQueryExportFactors(expression string) (*QueryExportFactors, error) { |
| 218 | // If the expression is empty, return an empty struct. |
| 219 | if expression == "" { |
| 220 | return &QueryExportFactors{}, nil |
| 221 | } |
| 222 | |
| 223 | factors := &QueryExportFactors{} |
| 224 | e, err := cel.NewEnv(IAMPolicyConditionCELAttributes...) |
| 225 | if err != nil { |
| 226 | return nil, err |
| 227 | } |
| 228 | ast, issues := e.Compile(expression) |
| 229 | if issues != nil { |
| 230 | return nil, errors.Errorf("found issue %v", issues) |
| 231 | } |
| 232 | parsedExpr, err := cel.AstToParsedExpr(ast) |
| 233 | if err != nil { |
| 234 | return nil, err |
| 235 | } |
| 236 | callExpr := parsedExpr.Expr.GetCallExpr() |
| 237 | findField(callExpr, factors) |
| 238 | return factors, nil |
| 239 | } |
| 240 | |
| 241 | func findField(callExpr *exprproto.Expr_Call, factors *QueryExportFactors) { |
| 242 | if callExpr == nil { |