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

Method getConfig

pkg/configs/api/api.go:113–149  ·  view source on GitHub ↗

getConfig returns the request configuration.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

111
112// getConfig returns the request configuration.
113func (a *API) getConfig(w http.ResponseWriter, r *http.Request) {
114 userID, _, err := users.ExtractTenantIDFromHTTPRequest(r)
115 if err != nil {
116 http.Error(w, err.Error(), http.StatusUnauthorized)
117 return
118 }
119 logger := util_log.WithContext(r.Context(), util_log.Logger)
120
121 cfg, err := a.db.GetConfig(r.Context(), userID)
122 if err == sql.ErrNoRows {
123 http.Error(w, "No configuration", http.StatusNotFound)
124 return
125 } else if err != nil {
126 // XXX: Untested
127 level.Error(logger).Log("msg", "error getting config", "err", err)
128 http.Error(w, err.Error(), http.StatusInternalServerError)
129 return
130 }
131
132 switch parseConfigFormat(r.Header.Get("Accept"), FormatJSON) {
133 case FormatJSON:
134 w.Header().Set("Content-Type", "application/json")
135 err = json.NewEncoder(w).Encode(cfg)
136 case FormatYAML:
137 w.Header().Set("Content-Type", "application/yaml")
138 err = yaml.NewEncoder(w).Encode(cfg)
139 default:
140 // should never reach this point
141 level.Error(logger).Log("msg", "unexpected error detecting the config format")
142 http.Error(w, err.Error(), http.StatusInternalServerError)
143 }
144 if err != nil {
145 // XXX: Untested
146 level.Error(logger).Log("msg", "error encoding config", "err", err)
147 http.Error(w, err.Error(), http.StatusInternalServerError)
148 }
149}
150
151func (a *API) setConfig(w http.ResponseWriter, r *http.Request) {
152 userID, _, err := users.ExtractTenantIDFromHTTPRequest(r)

Callers

nothing calls this directly

Calls 10

parseConfigFormatFunction · 0.85
GetConfigMethod · 0.65
GetMethod · 0.65
SetMethod · 0.65
EncodeMethod · 0.65
ErrorMethod · 0.45
ContextMethod · 0.45
LogMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected