MCPcopy Index your code
hub / github.com/cortexproject/cortex / GetUserConfig

Method GetUserConfig

pkg/alertmanager/api.go:83–122  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

81}
82
83func (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
124func (am *MultitenantAlertmanager) SetUserConfig(w http.ResponseWriter, r *http.Request) {
125 logger := util_log.WithContext(r.Context(), am.logger)

Callers

nothing calls this directly

Calls 10

TenantIDFunction · 0.92
ParseTemplatesFunction · 0.92
GetAlertConfigMethod · 0.65
SetMethod · 0.65
ContextMethod · 0.45
LogMethod · 0.45
ErrorMethod · 0.45
MarshalMethod · 0.45
HeaderMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected