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

Method SetFileRule

gateway/managers/syncman/syncman_file.go:52–91  ·  view source on GitHub ↗

SetFileRule sets the rule for file store

(ctx context.Context, project, id string, value *config.FileRule, params model.RequestParams)

Source from the content-addressed store, hash-verified

50
51// SetFileRule sets the rule for file store
52func (s *Manager) SetFileRule(ctx context.Context, project, id string, value *config.FileRule, params model.RequestParams) (int, error) {
53 // Check if the request has been hijacked
54 hookResponse := s.integrationMan.InvokeHook(ctx, params)
55 if hookResponse.CheckResponse() {
56 // Check if an error occurred
57 if err := hookResponse.Error(); err != nil {
58 return hookResponse.Status(), err
59 }
60
61 // Gracefully return
62 return hookResponse.Status(), nil
63 }
64
65 // Acquire a lock
66 s.lock.Lock()
67 defer s.lock.Unlock()
68
69 value.ID = id
70 projectConfig, err := s.getConfigWithoutLock(ctx, project)
71 if err != nil {
72 return http.StatusBadRequest, err
73 }
74
75 resourceID := config.GenerateResourceID(s.clusterID, project, config.ResourceFileStoreRule, id)
76 if projectConfig.FileStoreRules == nil {
77 projectConfig.FileStoreRules = config.FileStoreRules{resourceID: value}
78 } else {
79 projectConfig.FileStoreRules[resourceID] = value
80 }
81
82 if err := s.modules.SetFileStoreSecurityRuleConfig(ctx, project, projectConfig.FileStoreRules); err != nil {
83 return http.StatusInternalServerError, err
84 }
85
86 if err := s.store.SetResource(ctx, resourceID, value); err != nil {
87 return http.StatusInternalServerError, err
88 }
89
90 return http.StatusOK, nil
91}
92
93// SetDeleteFileRule deletes a rule from file store
94func (s *Manager) SetDeleteFileRule(ctx context.Context, project, filename string, params model.RequestParams) (int, error) {

Callers 2

TestManager_SetFileRuleFunction · 0.80
HandleSetFileRuleFunction · 0.80

Calls 9

getConfigWithoutLockMethod · 0.95
InvokeHookMethod · 0.65
CheckResponseMethod · 0.65
ErrorMethod · 0.65
StatusMethod · 0.65
SetResourceMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1

TestManager_SetFileRuleFunction · 0.64