SetFileRule sets the rule for file store
(ctx context.Context, project, id string, value *config.FileRule, params model.RequestParams)
| 50 | |
| 51 | // SetFileRule sets the rule for file store |
| 52 | func (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 |
| 94 | func (s *Manager) SetDeleteFileRule(ctx context.Context, project, filename string, params model.RequestParams) (int, error) { |