(w http.ResponseWriter, r *http.Request)
| 81 | } |
| 82 | |
| 83 | func (am *MultitenantAlertmanager) GetUserConfig(w http.ResponseWriter, r *http.Request) { |
| 84 | logger := util_log.WithContext(r.Context(), am.logger) |
| 85 | |
| 86 | userID, err := users.TenantID(r.Context()) |
| 87 | if err != nil { |
| 88 | level.Error(logger).Log("msg", errNoOrgID, "err", err.Error()) |
| 89 | http.Error(w, fmt.Sprintf("%s: %s", errNoOrgID, err.Error()), http.StatusUnauthorized) |
| 90 | return |
| 91 | } |
| 92 | |
| 93 | cfg, err := am.store.GetAlertConfig(r.Context(), userID) |
| 94 | if err != nil { |
| 95 | switch err { |
| 96 | case alertspb.ErrNotFound: |
| 97 | http.Error(w, err.Error(), http.StatusNotFound) |
| 98 | case alertspb.ErrAccessDenied: |
| 99 | http.Error(w, err.Error(), http.StatusForbidden) |
| 100 | default: |
| 101 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 102 | } |
| 103 | return |
| 104 | } |
| 105 | |
| 106 | d, err := yaml.Marshal(&UserConfig{ |
| 107 | TemplateFiles: alertspb.ParseTemplates(cfg), |
| 108 | AlertmanagerConfig: cfg.RawConfig, |
| 109 | }) |
| 110 | |
| 111 | if err != nil { |
| 112 | level.Error(logger).Log("msg", errMarshallingYAML, "err", err, "user", userID) |
| 113 | http.Error(w, fmt.Sprintf("%s: %s", errMarshallingYAML, err.Error()), http.StatusInternalServerError) |
| 114 | return |
| 115 | } |
| 116 | |
| 117 | w.Header().Set("Content-Type", "application/yaml") |
| 118 | if _, err := w.Write(d); err != nil { |
| 119 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 120 | return |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | func (am *MultitenantAlertmanager) SetUserConfig(w http.ResponseWriter, r *http.Request) { |
| 125 | logger := util_log.WithContext(r.Context(), am.logger) |
nothing calls this directly
no test coverage detected