MCPcopy
hub / github.com/spacecloud-io/space-cloud / matchRule

Method matchRule

gateway/modules/auth/match.go:28–80  ·  view source on GitHub ↗
(ctx context.Context, project string, rule *config.Rule, args, auth map[string]interface{}, returnWhere model.ReturnWhereStub)

Source from the content-addressed store, hash-verified

26}
27
28func (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
82func (m *Module) matchFunc(ctx context.Context, rule *config.Rule, MakeHTTPRequest utils.TypeMakeHTTPRequest, args map[string]interface{}) error {
83 newArgs := args["args"].(map[string]interface{})

Callers 15

AuthorizeRequestMethod · 0.95
MatchRuleMethod · 0.95
matchQueryMethod · 0.95
matchAndMethod · 0.95
matchOrMethod · 0.95
matchForceMethod · 0.95
matchRemoveMethod · 0.95
matchEncryptMethod · 0.95
matchDecryptMethod · 0.95
matchHashMethod · 0.95
IsCreateOpAuthorisedMethod · 0.95
IsReadOpAuthorisedMethod · 0.95

Calls 11

matchAndMethod · 0.95
matchOrMethod · 0.95
matchFuncMethod · 0.95
matchQueryMethod · 0.95
matchForceMethod · 0.95
matchRemoveMethod · 0.95
matchEncryptMethod · 0.95
matchDecryptMethod · 0.95
matchHashMethod · 0.95
formatErrorFunction · 0.85
matchFunction · 0.85

Tested by 1

TestMatch_RuleFunction · 0.64