| 26 | } |
| 27 | |
| 28 | func (m *Module) matchRule(ctx context.Context, project string, rule *config.Rule, args, auth map[string]interface{}, returnWhere model.ReturnWhereStub) (*model.PostProcess, error) { |
| 29 | if project != m.project { |
| 30 | return nil, formatError(ctx, rule, errors.New("invalid project details provided")) |
| 31 | } |
| 32 | |
| 33 | if rule.Rule == "allow" || rule.Rule == "authenticated" { |
| 34 | return nil, nil |
| 35 | } |
| 36 | |
| 37 | if idTemp, p := auth["id"]; p { |
| 38 | if id, ok := idTemp.(string); ok && id == utils.InternalUserID { |
| 39 | return nil, nil |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | switch rule.Rule { |
| 44 | case "deny": |
| 45 | return nil, formatError(ctx, rule, errors.New("the operation being performed is denied")) |
| 46 | |
| 47 | case "match": |
| 48 | return nil, match(ctx, rule, args, returnWhere) |
| 49 | |
| 50 | case "and": |
| 51 | return m.matchAnd(ctx, project, rule, args, auth, returnWhere) |
| 52 | |
| 53 | case "or": |
| 54 | return m.matchOr(ctx, project, rule, args, auth, returnWhere) |
| 55 | |
| 56 | case "webhook": |
| 57 | return nil, m.matchFunc(ctx, rule, m.makeHTTPRequest, args) |
| 58 | |
| 59 | case "query": |
| 60 | return m.matchQuery(ctx, project, rule, m.crud, args, auth, returnWhere) |
| 61 | |
| 62 | case "force": |
| 63 | return m.matchForce(ctx, project, rule, args, auth) |
| 64 | |
| 65 | case "remove": |
| 66 | return m.matchRemove(ctx, project, rule, args, auth) |
| 67 | |
| 68 | case "encrypt": |
| 69 | return m.matchEncrypt(ctx, project, rule, args, auth) |
| 70 | |
| 71 | case "decrypt": |
| 72 | return m.matchDecrypt(ctx, project, rule, args, auth) |
| 73 | |
| 74 | case "hash": |
| 75 | return m.matchHash(ctx, project, rule, args, auth) |
| 76 | |
| 77 | default: |
| 78 | return nil, formatError(ctx, rule, fmt.Errorf("invalid rule type (%s) provided", rule.Rule)) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | func (m *Module) matchFunc(ctx context.Context, rule *config.Rule, MakeHTTPRequest utils.TypeMakeHTTPRequest, args map[string]interface{}) error { |
| 83 | newArgs := args["args"].(map[string]interface{}) |