getAuthScopeHandleCreateDB determines the auth scope for a PUT /{db}/ request. This is a special case because we don't have a database initialized yet, so we need to infer the bucket from db config.
(ctx context.Context, h *handler)
| 183 | // getAuthScopeHandleCreateDB determines the auth scope for a PUT /{db}/ request. |
| 184 | // This is a special case because we don't have a database initialized yet, so we need to infer the bucket from db config. |
| 185 | func getAuthScopeHandleCreateDB(ctx context.Context, h *handler) (bucketName string, err error) { |
| 186 | |
| 187 | // grab a copy of the request body and restore body buffer for later handlers |
| 188 | bodyJSON, readErr := h.readBody() |
| 189 | if readErr != nil { |
| 190 | return "", base.HTTPErrorf(http.StatusInternalServerError, "Unable to read body: %v", readErr) |
| 191 | } |
| 192 | // mark the body as already read to avoid double-counting bytes for stats once it gets read again |
| 193 | h.requestBody.bodyRead = true |
| 194 | h.requestBody.reader = io.NopCloser(bytes.NewReader(bodyJSON)) |
| 195 | |
| 196 | var dbConfigBody struct { |
| 197 | Bucket string `json:"bucket"` |
| 198 | } |
| 199 | |
| 200 | bodyJSON, err = sanitiseConfig(ctx, bodyJSON, h.server.Config.Unsupported.AllowDbConfigEnvVars) |
| 201 | if err != nil { |
| 202 | return "", err |
| 203 | } |
| 204 | |
| 205 | d := base.JSONDecoder(bytes.NewBuffer(bodyJSON)) |
| 206 | err = d.Decode(&dbConfigBody) |
| 207 | if err != nil { |
| 208 | return "", err |
| 209 | } |
| 210 | |
| 211 | if dbConfigBody.Bucket == "" { |
| 212 | dbName := h.PathVar("newdb") |
| 213 | if dbName == "" { |
| 214 | return "", base.HTTPErrorf(http.StatusBadRequest, "bucket or db name not specified in request") |
| 215 | } |
| 216 | // imply bucket name from db name in path if not in body |
| 217 | return dbName, nil |
| 218 | } |
| 219 | |
| 220 | return dbConfigBody.Bucket, nil |
| 221 | } |
| 222 | |
| 223 | // Take a DB online, first reload the DB config |
| 224 | func (h *handler) handleDbOnline() error { |
nothing calls this directly
no test coverage detected