From d9eebaa721fcd31d63d50421efff20fd3a7293cc Mon Sep 17 00:00:00 2001 From: Mark Laing Date: Tue, 24 Oct 2023 14:31:30 +0100 Subject: [PATCH] lxd: Updates calls to projectParam and queryParam. Signed-off-by: Mark Laing --- lxd/api_cluster.go | 16 ++++++------- lxd/api_internal.go | 11 +++++---- lxd/api_metrics.go | 3 ++- lxd/daemon.go | 2 +- lxd/events.go | 4 ++-- lxd/images.go | 36 ++++++++++++++--------------- lxd/instance_backup.go | 13 ++++++----- lxd/instance_console.go | 7 +++--- lxd/instance_delete.go | 3 ++- lxd/instance_exec.go | 3 ++- lxd/instance_file.go | 3 ++- lxd/instance_get.go | 3 ++- lxd/instance_logs.go | 12 +++++----- lxd/instance_metadata.go | 12 +++++----- lxd/instance_patch.go | 3 ++- lxd/instance_post.go | 5 ++-- lxd/instance_put.go | 3 ++- lxd/instance_rebuild.go | 3 ++- lxd/instance_sftp.go | 3 ++- lxd/instance_snapshot.go | 7 +++--- lxd/instance_state.go | 5 ++-- lxd/instances_get.go | 3 ++- lxd/instances_post.go | 4 ++-- lxd/instances_put.go | 3 ++- lxd/network_acls.go | 14 +++++------ lxd/network_allocations.go | 5 ++-- lxd/network_forwards.go | 14 +++++------ lxd/network_load_balancers.go | 14 +++++------ lxd/network_peer.go | 10 ++++---- lxd/network_zones.go | 10 ++++---- lxd/network_zones_records.go | 10 ++++---- lxd/networks.go | 22 +++++++++--------- lxd/operations.go | 4 ++-- lxd/profiles.go | 14 +++++------ lxd/response.go | 5 ++-- lxd/storage_buckets.go | 28 +++++++++++----------- lxd/storage_pools.go | 6 ++--- lxd/storage_volumes.go | 41 +++++++++++++++++---------------- lxd/storage_volumes_backup.go | 18 +++++++-------- lxd/storage_volumes_snapshot.go | 23 +++++++++--------- lxd/storage_volumes_state.go | 3 ++- lxd/warnings.go | 2 +- 42 files changed, 216 insertions(+), 194 deletions(-) diff --git a/lxd/api_cluster.go b/lxd/api_cluster.go index 5757c1551b9e..4c402fa2a56e 100644 --- a/lxd/api_cluster.go +++ b/lxd/api_cluster.go @@ -380,7 +380,7 @@ func clusterPutBootstrap(d *Daemon, r *http.Request, req api.ClusterPut) respons return err } - s.Events.SendLifecycle(projectParam(r), lifecycle.ClusterEnabled.Event(req.ServerName, op.Requestor(), nil)) + s.Events.SendLifecycle(request.ProjectParam(r), lifecycle.ClusterEnabled.Event(req.ServerName, op.Requestor(), nil)) return nil } @@ -815,7 +815,7 @@ func clusterPutJoin(d *Daemon, r *http.Request, req api.ClusterPut) response.Res // Update the cert cache again to add client and metric certs to the cache. s.UpdateCertificateCache() - s.Events.SendLifecycle(projectParam(r), lifecycle.ClusterMemberAdded.Event(req.ServerName, op.Requestor(), nil)) + s.Events.SendLifecycle(request.ProjectParam(r), lifecycle.ClusterMemberAdded.Event(req.ServerName, op.Requestor(), nil)) revert.Success() return nil @@ -874,7 +874,7 @@ func clusterPutDisable(d *Daemon, r *http.Request, req api.ClusterPut) response. } requestor := request.CreateRequestor(r) - s.Events.SendLifecycle(projectParam(r), lifecycle.ClusterDisabled.Event(req.ServerName, requestor, nil)) + s.Events.SendLifecycle(request.ProjectParam(r), lifecycle.ClusterDisabled.Event(req.ServerName, requestor, nil)) // Stop database cluster connection. d.gateway.Kill() @@ -1394,7 +1394,7 @@ func clusterNodesPost(d *Daemon, r *http.Request) response.Response { return response.InternalError(err) } - s.Events.SendLifecycle(projectParam(r), lifecycle.ClusterTokenCreated.Event("members", op.Requestor(), nil)) + s.Events.SendLifecycle(request.ProjectParam(r), lifecycle.ClusterTokenCreated.Event("members", op.Requestor(), nil)) return operations.OperationResponse(op) } @@ -1740,7 +1740,7 @@ func updateClusterNode(s *state.State, gateway *cluster.Gateway, r *http.Request } requestor := request.CreateRequestor(r) - s.Events.SendLifecycle(projectParam(r), lifecycle.ClusterMemberUpdated.Event(name, requestor, nil)) + s.Events.SendLifecycle(request.ProjectParam(r), lifecycle.ClusterMemberUpdated.Event(name, requestor, nil)) return response.EmptySyncResponse } @@ -1875,7 +1875,7 @@ func clusterNodePost(d *Daemon, r *http.Request) response.Response { d.globalConfigMu.Unlock() requestor := request.CreateRequestor(r) - s.Events.SendLifecycle(projectParam(r), lifecycle.ClusterMemberRenamed.Event(req.ServerName, requestor, logger.Ctx{"old_name": memberName})) + s.Events.SendLifecycle(request.ProjectParam(r), lifecycle.ClusterMemberRenamed.Event(req.ServerName, requestor, logger.Ctx{"old_name": memberName})) return response.EmptySyncResponse } @@ -2133,7 +2133,7 @@ func clusterNodeDelete(d *Daemon, r *http.Request) response.Response { } requestor := request.CreateRequestor(r) - s.Events.SendLifecycle(projectParam(r), lifecycle.ClusterMemberRemoved.Event(name, requestor, nil)) + s.Events.SendLifecycle(request.ProjectParam(r), lifecycle.ClusterMemberRemoved.Event(name, requestor, nil)) return response.EmptySyncResponse } @@ -2196,7 +2196,7 @@ func clusterCertificatePut(d *Daemon, r *http.Request) response.Response { } requestor := request.CreateRequestor(r) - s.Events.SendLifecycle(projectParam(r), lifecycle.ClusterCertificateUpdated.Event("certificate", requestor, nil)) + s.Events.SendLifecycle(request.ProjectParam(r), lifecycle.ClusterCertificateUpdated.Event("certificate", requestor, nil)) return response.EmptySyncResponse } diff --git a/lxd/api_internal.go b/lxd/api_internal.go index fd37bd28b44d..563c5acffbf5 100644 --- a/lxd/api_internal.go +++ b/lxd/api_internal.go @@ -28,6 +28,7 @@ import ( "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/instance/instancetype" "github.com/canonical/lxd/lxd/project" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/revert" "github.com/canonical/lxd/lxd/state" @@ -232,7 +233,7 @@ func internalWaitReady(d *Daemon, r *http.Request) response.Response { } func internalShutdown(d *Daemon, r *http.Request) response.Response { - force := queryParam(r, "force") + force := request.QueryParam(r, "force") logger.Info("Asked to shutdown by API", logger.Ctx{"force": force}) if d.State().ShutdownCtx.Err() != nil { @@ -284,7 +285,7 @@ func internalContainerHookLoadFromReference(s *state.State, r *http.Request) (in return nil, err } - projectName := projectParam(r) + projectName := request.ProjectParam(r) instanceID, err := strconv.Atoi(instanceRef) if err == nil { @@ -344,12 +345,12 @@ func internalContainerOnStopNS(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - target := queryParam(r, "target") + target := request.QueryParam(r, "target") if target == "" { target = "unknown" } - netns := queryParam(r, "netns") + netns := request.QueryParam(r, "netns") args := map[string]string{ "target": target, @@ -374,7 +375,7 @@ func internalContainerOnStop(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - target := queryParam(r, "target") + target := request.QueryParam(r, "target") if target == "" { target = "unknown" } diff --git a/lxd/api_metrics.go b/lxd/api_metrics.go index 20f5c0961ba1..c37bf5e2f573 100644 --- a/lxd/api_metrics.go +++ b/lxd/api_metrics.go @@ -17,6 +17,7 @@ import ( instanceDrivers "github.com/canonical/lxd/lxd/instance/drivers" "github.com/canonical/lxd/lxd/locking" "github.com/canonical/lxd/lxd/metrics" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/shared" "github.com/canonical/lxd/shared/api" @@ -82,7 +83,7 @@ func allowMetrics(d *Daemon, r *http.Request) response.Response { func metricsGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := queryParam(r, "project") + projectName := request.QueryParam(r, "project") compress := strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") // Forward if requested. diff --git a/lxd/daemon.go b/lxd/daemon.go index 1bee124aea02..f0463baa5436 100644 --- a/lxd/daemon.go +++ b/lxd/daemon.go @@ -250,7 +250,7 @@ func allowProjectPermission(feature string, permission string) func(d *Daemon, r } // Get the project - projectName := projectParam(r) + projectName := request.ProjectParam(r) // Validate whether the user has the needed permission if !s.Authorizer.UserHasPermission(r, projectName, permission) { diff --git a/lxd/events.go b/lxd/events.go index 552546a99e5e..e0ceefa78946 100644 --- a/lxd/events.go +++ b/lxd/events.go @@ -42,8 +42,8 @@ func (r *eventsServe) String() string { func eventsSocket(s *state.State, r *http.Request, w http.ResponseWriter) error { // Detect project mode. - projectName := queryParam(r, "project") - allProjects := shared.IsTrue(queryParam(r, "all-projects")) + projectName := request.QueryParam(r, "project") + allProjects := shared.IsTrue(request.QueryParam(r, "all-projects")) if allProjects && projectName != "" { return api.StatusErrorf(http.StatusBadRequest, "Cannot specify a project when requesting all projects") diff --git a/lxd/images.go b/lxd/images.go index cd535ab83cd0..6088c89f15dd 100644 --- a/lxd/images.go +++ b/lxd/images.go @@ -195,7 +195,7 @@ func compressFile(compress string, infile io.Reader, outfile io.Writer) error { func imgPostInstanceInfo(s *state.State, r *http.Request, req api.ImagesPost, op *operations.Operation, builddir string, budget int64) (*api.Image, error) { info := api.Image{} info.Properties = map[string]string{} - projectName := projectParam(r) + projectName := request.ProjectParam(r) name := req.Source.Name ctype := req.Source.Type if ctype == "" || name == "" { @@ -919,7 +919,7 @@ func imagesPost(d *Daemon, r *http.Request) response.Response { secret := r.Header.Get("X-LXD-secret") fingerprint := r.Header.Get("X-LXD-fingerprint") - projectName := projectParam(r) + projectName := request.ProjectParam(r) var imageMetadata map[string]any @@ -1534,7 +1534,7 @@ func doImagesGet(ctx context.Context, tx *db.ClusterTx, recursion bool, projectN // "500": // $ref: "#/responses/InternalServerError" func imagesGet(d *Daemon, r *http.Request) response.Response { - projectName := projectParam(r) + projectName := request.ProjectParam(r) filterStr := r.FormValue("filter") public := d.checkTrustedClient(r) != nil || allowProjectPermission("images", "view")(d, r) != response.EmptySyncResponse @@ -2459,7 +2459,7 @@ func pruneExpiredImages(ctx context.Context, s *state.State, op *operations.Oper func imageDelete(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := projectParam(r) + projectName := request.ProjectParam(r) fingerprint, err := url.PathUnescape(mux.Vars(r)["fingerprint"]) if err != nil { @@ -2756,7 +2756,7 @@ func imageValidSecret(s *state.State, r *http.Request, projectName string, finge func imageGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := projectParam(r) + projectName := request.ProjectParam(r) fingerprint, err := url.PathUnescape(mux.Vars(r)["fingerprint"]) if err != nil { return response.SmartError(err) @@ -2829,7 +2829,7 @@ func imagePut(d *Daemon, r *http.Request) response.Response { s := d.State() // Get current value - projectName := projectParam(r) + projectName := request.ProjectParam(r) fingerprint, err := url.PathUnescape(mux.Vars(r)["fingerprint"]) if err != nil { return response.SmartError(err) @@ -2924,7 +2924,7 @@ func imagePatch(d *Daemon, r *http.Request) response.Response { s := d.State() // Get current value - projectName := projectParam(r) + projectName := request.ProjectParam(r) fingerprint, err := url.PathUnescape(mux.Vars(r)["fingerprint"]) if err != nil { return response.SmartError(err) @@ -3033,7 +3033,7 @@ func imagePatch(d *Daemon, r *http.Request) response.Response { func imageAliasesPost(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := projectParam(r) + projectName := request.ProjectParam(r) req := api.ImageAliasesPost{} err := json.NewDecoder(r.Body).Decode(&req) if err != nil { @@ -3171,7 +3171,7 @@ func imageAliasesPost(d *Daemon, r *http.Request) response.Response { // "500": // $ref: "#/responses/InternalServerError" func imageAliasesGet(d *Daemon, r *http.Request) response.Response { - projectName := projectParam(r) + projectName := request.ProjectParam(r) recursion := util.IsRecursionRequest(r) var err error @@ -3298,7 +3298,7 @@ func imageAliasesGet(d *Daemon, r *http.Request) response.Response { // "500": // $ref: "#/responses/InternalServerError" func imageAliasGet(d *Daemon, r *http.Request) response.Response { - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -3346,7 +3346,7 @@ func imageAliasGet(d *Daemon, r *http.Request) response.Response { func imageAliasDelete(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -3413,7 +3413,7 @@ func imageAliasPut(d *Daemon, r *http.Request) response.Response { s := d.State() // Get current value - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -3504,7 +3504,7 @@ func imageAliasPatch(d *Daemon, r *http.Request) response.Response { s := d.State() // Get current value - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -3607,7 +3607,7 @@ func imageAliasPatch(d *Daemon, r *http.Request) response.Response { func imageAliasPost(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -3710,7 +3710,7 @@ func imageAliasPost(d *Daemon, r *http.Request) response.Response { func imageExport(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := projectParam(r) + projectName := request.ProjectParam(r) fingerprint, err := url.PathUnescape(mux.Vars(r)["fingerprint"]) if err != nil { return response.SmartError(err) @@ -3842,7 +3842,7 @@ func imageExport(d *Daemon, r *http.Request) response.Response { func imageExportPost(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := projectParam(r) + projectName := request.ProjectParam(r) fingerprint, err := url.PathUnescape(mux.Vars(r)["fingerprint"]) if err != nil { return response.SmartError(err) @@ -3982,7 +3982,7 @@ func imageExportPost(d *Daemon, r *http.Request) response.Response { // "500": // $ref: "#/responses/InternalServerError" func imageSecret(d *Daemon, r *http.Request) response.Response { - projectName := projectParam(r) + projectName := request.ProjectParam(r) fingerprint, err := url.PathUnescape(mux.Vars(r)["fingerprint"]) if err != nil { return response.SmartError(err) @@ -4095,7 +4095,7 @@ func imageImportFromNode(imagesDir string, client lxd.InstanceServer, fingerprin func imageRefresh(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := projectParam(r) + projectName := request.ProjectParam(r) fingerprint, err := url.PathUnescape(mux.Vars(r)["fingerprint"]) if err != nil { return response.SmartError(err) diff --git a/lxd/instance_backup.go b/lxd/instance_backup.go index 29f2d9cf3b2f..0e5c17fc2926 100644 --- a/lxd/instance_backup.go +++ b/lxd/instance_backup.go @@ -18,6 +18,7 @@ import ( "github.com/canonical/lxd/lxd/lifecycle" "github.com/canonical/lxd/lxd/operations" "github.com/canonical/lxd/lxd/project" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/util" "github.com/canonical/lxd/shared" @@ -125,7 +126,7 @@ func instanceBackupsGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) cname, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -218,7 +219,7 @@ func instanceBackupsPost(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -401,7 +402,7 @@ func instanceBackupGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -475,7 +476,7 @@ func instanceBackupPost(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -577,7 +578,7 @@ func instanceBackupDelete(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -662,7 +663,7 @@ func instanceBackupExportGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) diff --git a/lxd/instance_console.go b/lxd/instance_console.go index 82885c2fcaa7..c8de1f676a34 100644 --- a/lxd/instance_console.go +++ b/lxd/instance_console.go @@ -22,6 +22,7 @@ import ( "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/instance/instancetype" "github.com/canonical/lxd/lxd/operations" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/shared" "github.com/canonical/lxd/shared/api" @@ -421,7 +422,7 @@ func instanceConsolePost(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -563,7 +564,7 @@ func instanceConsoleLogGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -676,7 +677,7 @@ func instanceConsoleLogDelete(d *Daemon, r *http.Request) response.Response { return response.BadRequest(fmt.Errorf("Invalid instance name")) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) inst, err := instance.LoadByProjectAndName(d.State(), projectName, name) if err != nil { diff --git a/lxd/instance_delete.go b/lxd/instance_delete.go index 0f22c710ad03..f09f1c2fccc2 100644 --- a/lxd/instance_delete.go +++ b/lxd/instance_delete.go @@ -11,6 +11,7 @@ import ( "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/instance/instancetype" "github.com/canonical/lxd/lxd/operations" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/shared" "github.com/canonical/lxd/shared/api" @@ -54,7 +55,7 @@ func instanceDelete(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) diff --git a/lxd/instance_exec.go b/lxd/instance_exec.go index dc18f7304cc4..c227ecf2b73f 100644 --- a/lxd/instance_exec.go +++ b/lxd/instance_exec.go @@ -25,6 +25,7 @@ import ( "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/instance/instancetype" "github.com/canonical/lxd/lxd/operations" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/state" "github.com/canonical/lxd/shared" @@ -527,7 +528,7 @@ func instanceExecPost(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) diff --git a/lxd/instance_file.go b/lxd/instance_file.go index 583cece80319..b58b99b5873a 100644 --- a/lxd/instance_file.go +++ b/lxd/instance_file.go @@ -17,6 +17,7 @@ import ( "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/lifecycle" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/revert" "github.com/canonical/lxd/lxd/state" @@ -27,7 +28,7 @@ import ( func instanceFileHandler(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) diff --git a/lxd/instance_get.go b/lxd/instance_get.go index 6c528a8fd97b..974ad978db39 100644 --- a/lxd/instance_get.go +++ b/lxd/instance_get.go @@ -10,6 +10,7 @@ import ( "github.com/gorilla/mux" "github.com/canonical/lxd/lxd/instance" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/shared" ) @@ -105,7 +106,7 @@ func instanceGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) diff --git a/lxd/instance_logs.go b/lxd/instance_logs.go index de23a538469d..83fbbe8e9664 100644 --- a/lxd/instance_logs.go +++ b/lxd/instance_logs.go @@ -131,7 +131,7 @@ func instanceLogsGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -215,7 +215,7 @@ func instanceLogGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -299,7 +299,7 @@ func instanceLogDelete(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -411,7 +411,7 @@ func instanceExecOutputsGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -516,7 +516,7 @@ func instanceExecOutputGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -616,7 +616,7 @@ func instanceExecOutputDelete(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) diff --git a/lxd/instance_metadata.go b/lxd/instance_metadata.go index 708b83700821..5e89adf790fc 100644 --- a/lxd/instance_metadata.go +++ b/lxd/instance_metadata.go @@ -73,7 +73,7 @@ func instanceMetadataGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -185,7 +185,7 @@ func instanceMetadataPatch(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -305,7 +305,7 @@ func instanceMetadataPut(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -429,7 +429,7 @@ func instanceMetadataTemplatesGet(d *Daemon, r *http.Request) response.Response return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -581,7 +581,7 @@ func instanceMetadataTemplatesPost(d *Daemon, r *http.Request) response.Response return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -699,7 +699,7 @@ func instanceMetadataTemplatesDelete(d *Daemon, r *http.Request) response.Respon return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { diff --git a/lxd/instance_patch.go b/lxd/instance_patch.go index 8e14c5cb8a4c..d865db8bbe1b 100644 --- a/lxd/instance_patch.go +++ b/lxd/instance_patch.go @@ -16,6 +16,7 @@ import ( deviceConfig "github.com/canonical/lxd/lxd/device/config" "github.com/canonical/lxd/lxd/instance" projecthelpers "github.com/canonical/lxd/lxd/project" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/util" "github.com/canonical/lxd/shared" @@ -65,7 +66,7 @@ func instancePatch(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) // Get the container name, err := url.PathUnescape(mux.Vars(r)["name"]) diff --git a/lxd/instance_post.go b/lxd/instance_post.go index 15dea5585144..2caf07275463 100644 --- a/lxd/instance_post.go +++ b/lxd/instance_post.go @@ -19,6 +19,7 @@ import ( "github.com/canonical/lxd/lxd/instance/instancetype" "github.com/canonical/lxd/lxd/operations" "github.com/canonical/lxd/lxd/project" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/scriptlet" "github.com/canonical/lxd/lxd/state" @@ -78,7 +79,7 @@ func instancePost(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { @@ -102,7 +103,7 @@ func instancePost(d *Daemon, r *http.Request) response.Response { var targetMemberInfo *db.NodeInfo var candidateMembers []db.NodeInfo - target := queryParam(r, "target") + target := request.QueryParam(r, "target") if !clustered && target != "" { return response.BadRequest(fmt.Errorf("Target only allowed when clustered")) } diff --git a/lxd/instance_put.go b/lxd/instance_put.go index f3bfad57c53a..e8c1ccfe84ee 100644 --- a/lxd/instance_put.go +++ b/lxd/instance_put.go @@ -18,6 +18,7 @@ import ( "github.com/canonical/lxd/lxd/instance/instancetype" "github.com/canonical/lxd/lxd/operations" projecthelpers "github.com/canonical/lxd/lxd/project" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/revert" "github.com/canonical/lxd/lxd/state" @@ -70,7 +71,7 @@ func instancePut(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) // Get the container name, err := url.PathUnescape(mux.Vars(r)["name"]) diff --git a/lxd/instance_rebuild.go b/lxd/instance_rebuild.go index 38a346f8a616..8e4f95cf16c2 100644 --- a/lxd/instance_rebuild.go +++ b/lxd/instance_rebuild.go @@ -15,6 +15,7 @@ import ( "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/instance/instancetype" "github.com/canonical/lxd/lxd/operations" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/shared" "github.com/canonical/lxd/shared/api" @@ -59,7 +60,7 @@ import ( func instanceRebuildPost(d *Daemon, r *http.Request) response.Response { s := d.State() - targetProjectName := projectParam(r) + targetProjectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { diff --git a/lxd/instance_sftp.go b/lxd/instance_sftp.go index a4944fd2e219..6a987ef3b6d6 100644 --- a/lxd/instance_sftp.go +++ b/lxd/instance_sftp.go @@ -13,6 +13,7 @@ import ( "github.com/canonical/lxd/lxd/cluster" "github.com/canonical/lxd/lxd/instance" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/shared" "github.com/canonical/lxd/shared/api" @@ -44,7 +45,7 @@ import ( func instanceSFTPHandler(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := projectParam(r) + projectName := request.ProjectParam(r) instName, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) diff --git a/lxd/instance_snapshot.go b/lxd/instance_snapshot.go index fa507e406c93..f235b0a5ba96 100644 --- a/lxd/instance_snapshot.go +++ b/lxd/instance_snapshot.go @@ -19,6 +19,7 @@ import ( "github.com/canonical/lxd/lxd/instance/instancetype" "github.com/canonical/lxd/lxd/operations" "github.com/canonical/lxd/lxd/project" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/state" storagePools "github.com/canonical/lxd/lxd/storage" @@ -129,7 +130,7 @@ func instanceSnapshotsGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) cname, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -237,7 +238,7 @@ func instanceSnapshotsPost(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -348,7 +349,7 @@ func instanceSnapshotHandler(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) instName, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) diff --git a/lxd/instance_state.go b/lxd/instance_state.go index 552cefe1791c..86674151de6a 100644 --- a/lxd/instance_state.go +++ b/lxd/instance_state.go @@ -13,6 +13,7 @@ import ( "github.com/canonical/lxd/lxd/db/operationtype" "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/operations" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/shared" "github.com/canonical/lxd/shared/api" @@ -72,7 +73,7 @@ func instanceState(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) @@ -146,7 +147,7 @@ func instanceStatePut(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName := projectParam(r) + projectName := request.ProjectParam(r) name, err := url.PathUnescape(mux.Vars(r)["name"]) if err != nil { return response.SmartError(err) diff --git a/lxd/instances_get.go b/lxd/instances_get.go index 1de328dd6117..c062f3219aac 100644 --- a/lxd/instances_get.go +++ b/lxd/instances_get.go @@ -19,6 +19,7 @@ import ( "github.com/canonical/lxd/lxd/db/query" "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/instance/instancetype" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/state" "github.com/canonical/lxd/shared" @@ -264,7 +265,7 @@ func doInstancesGet(s *state.State, r *http.Request) (any, error) { mustLoadObjects := recursion > 0 || (recursion == 0 && clauses != nil) // Detect project mode. - projectName := queryParam(r, "project") + projectName := request.QueryParam(r, "project") allProjects := shared.IsTrue(r.FormValue("all-projects")) if allProjects && projectName != "" { diff --git a/lxd/instances_post.go b/lxd/instances_post.go index be2c316caa4d..0a8a20ee3e6f 100644 --- a/lxd/instances_post.go +++ b/lxd/instances_post.go @@ -809,7 +809,7 @@ func createFromBackup(s *state.State, r *http.Request, projectName string, data func instancesPost(d *Daemon, r *http.Request) response.Response { s := d.State() - targetProjectName := projectParam(r) + targetProjectName := request.ProjectParam(r) clusterNotification := isClusterNotification(r) logger.Debug("Responding to instance create") @@ -876,7 +876,7 @@ func instancesPost(d *Daemon, r *http.Request) response.Response { var targetMemberInfo *db.NodeInfo err = s.DB.Cluster.Transaction(r.Context(), func(ctx context.Context, tx *db.ClusterTx) error { - target := queryParam(r, "target") + target := request.QueryParam(r, "target") if !clustered && target != "" { return api.StatusErrorf(http.StatusBadRequest, "Target only allowed when clustered") } diff --git a/lxd/instances_put.go b/lxd/instances_put.go index b50172bc2afb..fcd83418f64d 100644 --- a/lxd/instances_put.go +++ b/lxd/instances_put.go @@ -13,6 +13,7 @@ import ( "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/instance/instancetype" "github.com/canonical/lxd/lxd/operations" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/shared" "github.com/canonical/lxd/shared/api" @@ -73,7 +74,7 @@ func coalesceErrors(local bool, errors map[string]error) error { // "500": // $ref: "#/responses/InternalServerError" func instancesPut(d *Daemon, r *http.Request) response.Response { - projectName := projectParam(r) + projectName := request.ProjectParam(r) // Don't mess with instances while in setup mode. <-d.waitReady.Done() diff --git a/lxd/network_acls.go b/lxd/network_acls.go index 92b7f1734bd2..347c82dcbd52 100644 --- a/lxd/network_acls.go +++ b/lxd/network_acls.go @@ -142,7 +142,7 @@ var networkACLLogCmd = APIEndpoint{ func networkACLsGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -215,7 +215,7 @@ func networkACLsGet(d *Daemon, r *http.Request) response.Response { func networkACLsPost(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -276,7 +276,7 @@ func networkACLsPost(d *Daemon, r *http.Request) response.Response { func networkACLDelete(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -344,7 +344,7 @@ func networkACLDelete(d *Daemon, r *http.Request) response.Response { func networkACLGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -440,7 +440,7 @@ func networkACLGet(d *Daemon, r *http.Request) response.Response { func networkACLPut(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -533,7 +533,7 @@ func networkACLPost(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName, _, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -593,7 +593,7 @@ func networkACLPost(d *Daemon, r *http.Request) response.Response { func networkACLLogGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } diff --git a/lxd/network_allocations.go b/lxd/network_allocations.go index d1a7a68b1ee5..fad0644420e5 100644 --- a/lxd/network_allocations.go +++ b/lxd/network_allocations.go @@ -12,6 +12,7 @@ import ( dbCluster "github.com/canonical/lxd/lxd/db/cluster" "github.com/canonical/lxd/lxd/network" "github.com/canonical/lxd/lxd/project" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/shared" "github.com/canonical/lxd/shared/api" @@ -71,12 +72,12 @@ var networkAllocationsCmd = APIEndpoint{ // "500": // $ref: "#/responses/InternalServerError" func networkAllocationsGet(d *Daemon, r *http.Request) response.Response { - projectName, _, err := project.NetworkProject(d.State().DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkProject(d.State().DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } - allProjects := shared.IsTrue(queryParam(r, "all-projects")) + allProjects := shared.IsTrue(request.QueryParam(r, "all-projects")) var projectNames []string err = d.db.Cluster.Transaction(r.Context(), func(ctx context.Context, tx *db.ClusterTx) error { diff --git a/lxd/network_forwards.go b/lxd/network_forwards.go index 3dabf711a256..c8086e9c2335 100644 --- a/lxd/network_forwards.go +++ b/lxd/network_forwards.go @@ -132,7 +132,7 @@ var networkForwardCmd = APIEndpoint{ func networkForwardsGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -225,7 +225,7 @@ func networkForwardsPost(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -303,7 +303,7 @@ func networkForwardDelete(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -392,7 +392,7 @@ func networkForwardGet(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -421,7 +421,7 @@ func networkForwardGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - targetMember := queryParam(r, "target") + targetMember := request.QueryParam(r, "target") memberSpecific := targetMember != "" _, forward, err := s.DB.Cluster.GetNetworkForward(r.Context(), n.ID(), memberSpecific, listenAddress) @@ -509,7 +509,7 @@ func networkForwardPut(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -545,7 +545,7 @@ func networkForwardPut(d *Daemon, r *http.Request) response.Response { return response.BadRequest(err) } - targetMember := queryParam(r, "target") + targetMember := request.QueryParam(r, "target") memberSpecific := targetMember != "" if r.Method == http.MethodPatch { diff --git a/lxd/network_load_balancers.go b/lxd/network_load_balancers.go index 14ec5057cf82..b82c96773e46 100644 --- a/lxd/network_load_balancers.go +++ b/lxd/network_load_balancers.go @@ -132,7 +132,7 @@ var networkLoadBalancerCmd = APIEndpoint{ func networkLoadBalancersGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -226,7 +226,7 @@ func networkLoadBalancersPost(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -304,7 +304,7 @@ func networkLoadBalancerDelete(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -393,7 +393,7 @@ func networkLoadBalancerGet(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -422,7 +422,7 @@ func networkLoadBalancerGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - targetMember := queryParam(r, "target") + targetMember := request.QueryParam(r, "target") memberSpecific := targetMember != "" _, loadBalancer, err := s.DB.Cluster.GetNetworkLoadBalancer(r.Context(), n.ID(), memberSpecific, listenAddress) @@ -510,7 +510,7 @@ func networkLoadBalancerPut(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -546,7 +546,7 @@ func networkLoadBalancerPut(d *Daemon, r *http.Request) response.Response { return response.BadRequest(err) } - targetMember := queryParam(r, "target") + targetMember := request.QueryParam(r, "target") memberSpecific := targetMember != "" if r.Method == http.MethodPatch { diff --git a/lxd/network_peer.go b/lxd/network_peer.go index 2e7b56069d0f..47432936b089 100644 --- a/lxd/network_peer.go +++ b/lxd/network_peer.go @@ -131,7 +131,7 @@ var networkPeerCmd = APIEndpoint{ func networkPeersGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -225,7 +225,7 @@ func networkPeersPost(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -299,7 +299,7 @@ func networkPeerDelete(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -386,7 +386,7 @@ func networkPeerGet(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -502,7 +502,7 @@ func networkPeerPut(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } diff --git a/lxd/network_zones.go b/lxd/network_zones.go index afc2ef8657d8..0a6281019e2c 100644 --- a/lxd/network_zones.go +++ b/lxd/network_zones.go @@ -132,7 +132,7 @@ var networkZoneCmd = APIEndpoint{ func networkZonesGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -205,7 +205,7 @@ func networkZonesGet(d *Daemon, r *http.Request) response.Response { func networkZonesPost(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -267,7 +267,7 @@ func networkZonesPost(d *Daemon, r *http.Request) response.Response { func networkZoneDelete(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -335,7 +335,7 @@ func networkZoneDelete(d *Daemon, r *http.Request) response.Response { func networkZoneGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -431,7 +431,7 @@ func networkZoneGet(d *Daemon, r *http.Request) response.Response { func networkZonePut(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } diff --git a/lxd/network_zones_records.go b/lxd/network_zones_records.go index 381c1b566b79..4fbed979cd5c 100644 --- a/lxd/network_zones_records.go +++ b/lxd/network_zones_records.go @@ -131,7 +131,7 @@ var networkZoneRecordCmd = APIEndpoint{ func networkZoneRecordsGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -207,7 +207,7 @@ func networkZoneRecordsGet(d *Daemon, r *http.Request) response.Response { func networkZoneRecordsPost(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -269,7 +269,7 @@ func networkZoneRecordsPost(d *Daemon, r *http.Request) response.Response { func networkZoneRecordDelete(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -344,7 +344,7 @@ func networkZoneRecordDelete(d *Daemon, r *http.Request) response.Response { func networkZoneRecordGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -446,7 +446,7 @@ func networkZoneRecordGet(d *Daemon, r *http.Request) response.Response { func networkZoneRecordPut(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, projectParam(r)) + projectName, _, err := project.NetworkZoneProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } diff --git a/lxd/networks.go b/lxd/networks.go index 7559b073bb34..b6e50399e839 100644 --- a/lxd/networks.go +++ b/lxd/networks.go @@ -169,7 +169,7 @@ var networkStateCmd = APIEndpoint{ func networksGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -270,7 +270,7 @@ func networksGet(d *Daemon, r *http.Request) response.Response { func networksPost(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -365,7 +365,7 @@ func networksPost(d *Daemon, r *http.Request) response.Response { return resp } - targetNode := queryParam(r, "target") + targetNode := request.QueryParam(r, "target") if targetNode != "" { if !netTypeInfo.NodeSpecificConfig { return response.BadRequest(fmt.Errorf("Network type %q does not support member specific config", netType.Type())) @@ -761,7 +761,7 @@ func networkGet(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -777,7 +777,7 @@ func networkGet(d *Daemon, r *http.Request) response.Response { } allNodes := false - if clustered && queryParam(r, "target") == "" { + if clustered && request.QueryParam(r, "target") == "" { allNodes = true } @@ -921,7 +921,7 @@ func doNetworkGet(s *state.State, r *http.Request, allNodes bool, projectName st func networkDelete(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -1053,7 +1053,7 @@ func networkPost(d *Daemon, r *http.Request) response.Response { return response.BadRequest(fmt.Errorf("Renaming clustered network not supported")) } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -1177,7 +1177,7 @@ func networkPut(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -1198,7 +1198,7 @@ func networkPut(d *Daemon, r *http.Request) response.Response { return response.SmartError(api.StatusErrorf(http.StatusNotFound, "Network not found")) } - targetNode := queryParam(r, "target") + targetNode := request.QueryParam(r, "target") clustered, err := cluster.Enabled(s.DB.Node) if err != nil { return response.SmartError(err) @@ -1404,7 +1404,7 @@ func doNetworkUpdate(projectName string, n network.Network, req api.NetworkPut, func networkLeasesGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -1774,7 +1774,7 @@ func networkStateGet(d *Daemon, r *http.Request) response.Response { return resp } - projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, projectParam(r)) + projectName, reqProject, err := project.NetworkProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } diff --git a/lxd/operations.go b/lxd/operations.go index 07762badc74d..363b8063c8ec 100644 --- a/lxd/operations.go +++ b/lxd/operations.go @@ -468,8 +468,8 @@ func operationCancel(s *state.State, r *http.Request, projectName string, op *ap func operationsGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := queryParam(r, "project") - allProjects := shared.IsTrue(queryParam(r, "all-projects")) + projectName := request.QueryParam(r, "project") + allProjects := shared.IsTrue(request.QueryParam(r, "all-projects")) recursion := util.IsRecursionRequest(r) if allProjects && projectName != "" { diff --git a/lxd/profiles.go b/lxd/profiles.go index 9422fc9d9e71..2606df1a8488 100644 --- a/lxd/profiles.go +++ b/lxd/profiles.go @@ -143,7 +143,7 @@ var profileCmd = APIEndpoint{ func profilesGet(d *Daemon, r *http.Request) response.Response { s := d.State() - p, err := project.ProfileProject(s.DB.Cluster, projectParam(r)) + p, err := project.ProfileProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -247,7 +247,7 @@ func profileUsedBy(ctx context.Context, tx *db.ClusterTx, profile dbCluster.Prof func profilesPost(d *Daemon, r *http.Request) response.Response { s := d.State() - p, err := project.ProfileProject(s.DB.Cluster, projectParam(r)) + p, err := project.ProfileProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -371,7 +371,7 @@ func profilesPost(d *Daemon, r *http.Request) response.Response { func profileGet(d *Daemon, r *http.Request) response.Response { s := d.State() - p, err := project.ProfileProject(s.DB.Cluster, projectParam(r)) + p, err := project.ProfileProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -448,7 +448,7 @@ func profileGet(d *Daemon, r *http.Request) response.Response { func profilePut(d *Daemon, r *http.Request) response.Response { s := d.State() - p, err := project.ProfileProject(s.DB.Cluster, projectParam(r)) + p, err := project.ProfileProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -566,7 +566,7 @@ func profilePut(d *Daemon, r *http.Request) response.Response { func profilePatch(d *Daemon, r *http.Request) response.Response { s := d.State() - p, err := project.ProfileProject(s.DB.Cluster, projectParam(r)) + p, err := project.ProfileProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -696,7 +696,7 @@ func profilePatch(d *Daemon, r *http.Request) response.Response { func profilePost(d *Daemon, r *http.Request) response.Response { s := d.State() - p, err := project.ProfileProject(s.DB.Cluster, projectParam(r)) + p, err := project.ProfileProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -776,7 +776,7 @@ func profilePost(d *Daemon, r *http.Request) response.Response { func profileDelete(d *Daemon, r *http.Request) response.Response { s := d.State() - p, err := project.ProfileProject(s.DB.Cluster, projectParam(r)) + p, err := project.ProfileProject(s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } diff --git a/lxd/response.go b/lxd/response.go index a9626ac4a6de..87ca3aee4fac 100644 --- a/lxd/response.go +++ b/lxd/response.go @@ -5,6 +5,7 @@ import ( "github.com/canonical/lxd/lxd/cluster" "github.com/canonical/lxd/lxd/instance/instancetype" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/state" ) @@ -32,7 +33,7 @@ func forwardedResponseToNode(s *state.State, r *http.Request, memberName string) // forwardedResponseIfTargetIsRemote forwards a request to the request has a target parameter pointing to a member // which is not the local one. func forwardedResponseIfTargetIsRemote(s *state.State, r *http.Request) response.Response { - targetNode := queryParam(r, "target") + targetNode := request.QueryParam(r, "target") if targetNode == "" { return nil } @@ -64,7 +65,7 @@ func forwardedResponseIfInstanceIsRemote(s *state.State, r *http.Request, projec // This is used when no targetNode is specified, and saves users some typing // when the volume name/type is unique to a node. func forwardedResponseIfVolumeIsRemote(s *state.State, r *http.Request, poolName string, projectName string, volumeName string, volumeType int) response.Response { - if queryParam(r, "target") != "" { + if request.QueryParam(r, "target") != "" { return nil } diff --git a/lxd/storage_buckets.go b/lxd/storage_buckets.go index 5d9fe8966d81..f30020d4d6a9 100644 --- a/lxd/storage_buckets.go +++ b/lxd/storage_buckets.go @@ -150,7 +150,7 @@ var storagePoolBucketKeyCmd = APIEndpoint{ func storagePoolBucketsGet(d *Daemon, r *http.Request) response.Response { s := d.State() - requestProjectName := projectParam(r) + requestProjectName := request.ProjectParam(r) bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, requestProjectName) if err != nil { return response.SmartError(err) @@ -271,7 +271,7 @@ func storagePoolBucketGet(d *Daemon, r *http.Request) response.Response { return resp } - bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, projectParam(r)) + bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -295,7 +295,7 @@ func storagePoolBucketGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - targetMember := queryParam(r, "target") + targetMember := request.QueryParam(r, "target") memberSpecific := targetMember != "" var bucket *db.StorageBucket @@ -355,7 +355,7 @@ func storagePoolBucketsPost(d *Daemon, r *http.Request) response.Response { return resp } - bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, projectParam(r)) + bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -496,7 +496,7 @@ func storagePoolBucketPut(d *Daemon, r *http.Request) response.Response { return resp } - bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, projectParam(r)) + bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -524,7 +524,7 @@ func storagePoolBucketPut(d *Daemon, r *http.Request) response.Response { } if r.Method == http.MethodPatch { - targetMember := queryParam(r, "target") + targetMember := request.QueryParam(r, "target") memberSpecific := targetMember != "" var bucket *db.StorageBucket @@ -593,7 +593,7 @@ func storagePoolBucketDelete(d *Daemon, r *http.Request) response.Response { return resp } - bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, projectParam(r)) + bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -725,7 +725,7 @@ func storagePoolBucketKeysGet(d *Daemon, r *http.Request) response.Response { return resp } - bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, projectParam(r)) + bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -751,7 +751,7 @@ func storagePoolBucketKeysGet(d *Daemon, r *http.Request) response.Response { } // If target is set, get buckets only for this cluster members. - targetMember := queryParam(r, "target") + targetMember := request.QueryParam(r, "target") memberSpecific := targetMember != "" var dbBucket *db.StorageBucket @@ -830,7 +830,7 @@ func storagePoolBucketKeysPost(d *Daemon, r *http.Request) response.Response { return resp } - bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, projectParam(r)) + bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -905,7 +905,7 @@ func storagePoolBucketKeyDelete(d *Daemon, r *http.Request) response.Response { return resp } - bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, projectParam(r)) + bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -988,7 +988,7 @@ func storagePoolBucketKeyGet(d *Daemon, r *http.Request) response.Response { return resp } - bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, projectParam(r)) + bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } @@ -1017,7 +1017,7 @@ func storagePoolBucketKeyGet(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - targetMember := queryParam(r, "target") + targetMember := request.QueryParam(r, "target") memberSpecific := targetMember != "" var bucketKey *db.StorageBucketKey @@ -1088,7 +1088,7 @@ func storagePoolBucketKeyPut(d *Daemon, r *http.Request) response.Response { return resp } - bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, projectParam(r)) + bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, request.ProjectParam(r)) if err != nil { return response.SmartError(err) } diff --git a/lxd/storage_pools.go b/lxd/storage_pools.go index 301e0bb27721..7e526bc929db 100644 --- a/lxd/storage_pools.go +++ b/lxd/storage_pools.go @@ -271,7 +271,7 @@ func storagePoolsPost(d *Daemon, r *http.Request) response.Response { ctx := logger.Ctx{} - targetNode := queryParam(r, "target") + targetNode := request.QueryParam(r, "target") if targetNode != "" { ctx["target"] = targetNode } @@ -590,7 +590,7 @@ func storagePoolGet(d *Daemon, r *http.Request) response.Response { } memberSpecific := false - if queryParam(r, "target") != "" { + if request.QueryParam(r, "target") != "" { memberSpecific = true } @@ -688,7 +688,7 @@ func storagePoolPut(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - targetNode := queryParam(r, "target") + targetNode := request.QueryParam(r, "target") clustered, err := cluster.Enabled(s.DB.Node) if err != nil { return response.SmartError(err) diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go index 937778949f14..865764eedd74 100644 --- a/lxd/storage_volumes.go +++ b/lxd/storage_volumes.go @@ -28,6 +28,7 @@ import ( "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/operations" "github.com/canonical/lxd/lxd/project" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/revert" "github.com/canonical/lxd/lxd/state" @@ -289,7 +290,7 @@ func storagePoolVolumesGet(d *Daemon, r *http.Request) response.Response { return resp } - targetMember := queryParam(r, "target") + targetMember := request.QueryParam(r, "target") memberSpecific := targetMember != "" poolName, err := url.PathUnescape(mux.Vars(r)["poolName"]) @@ -325,8 +326,8 @@ func storagePoolVolumesGet(d *Daemon, r *http.Request) response.Response { } // Detect project mode. - requestProjectName := queryParam(r, "project") - allProjects := shared.IsTrue(queryParam(r, "all-projects")) + requestProjectName := request.QueryParam(r, "project") + allProjects := shared.IsTrue(request.QueryParam(r, "all-projects")) if allProjects && requestProjectName != "" { return response.SmartError(api.StatusErrorf(http.StatusBadRequest, "Cannot specify a project when requesting all projects")) @@ -540,7 +541,7 @@ func storagePoolVolumesTypePost(d *Daemon, r *http.Request) response.Response { return response.SmartError(err) } - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), db.StoragePoolVolumeTypeCustom) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), db.StoragePoolVolumeTypeCustom) if err != nil { return response.SmartError(err) } @@ -553,10 +554,10 @@ func storagePoolVolumesTypePost(d *Daemon, r *http.Request) response.Response { // If we're getting binary content, process separately. if r.Header.Get("Content-Type") == "application/octet-stream" { if r.Header.Get("X-LXD-type") == "iso" { - return createStoragePoolVolumeFromISO(s, r, projectParam(r), projectName, r.Body, poolName, r.Header.Get("X-LXD-name")) + return createStoragePoolVolumeFromISO(s, r, request.ProjectParam(r), projectName, r.Body, poolName, r.Header.Get("X-LXD-name")) } - return createStoragePoolVolumeFromBackup(s, r, projectParam(r), projectName, r.Body, poolName, r.Header.Get("X-LXD-name")) + return createStoragePoolVolumeFromBackup(s, r, request.ProjectParam(r), projectName, r.Body, poolName, r.Header.Get("X-LXD-name")) } req := api.StorageVolumesPost{} @@ -625,15 +626,15 @@ func storagePoolVolumesTypePost(d *Daemon, r *http.Request) response.Response { switch req.Source.Type { case "": - return doVolumeCreateOrCopy(s, r, projectParam(r), projectName, poolName, &req) + return doVolumeCreateOrCopy(s, r, request.ProjectParam(r), projectName, poolName, &req) case "copy": if dbVolume != nil { - return doCustomVolumeRefresh(s, r, projectParam(r), projectName, poolName, &req) + return doCustomVolumeRefresh(s, r, request.ProjectParam(r), projectName, poolName, &req) } - return doVolumeCreateOrCopy(s, r, projectParam(r), projectName, poolName, &req) + return doVolumeCreateOrCopy(s, r, request.ProjectParam(r), projectName, poolName, &req) case "migration": - return doVolumeMigration(s, r, projectParam(r), projectName, poolName, &req) + return doVolumeMigration(s, r, request.ProjectParam(r), projectName, poolName, &req) default: return response.BadRequest(fmt.Errorf("Unknown source type %q", req.Source.Type)) } @@ -802,7 +803,7 @@ func storagePoolVolumesPost(d *Daemon, r *http.Request) response.Response { req.ContentType = db.StoragePoolVolumeContentTypeNameFS } - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), db.StoragePoolVolumeTypeCustom) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), db.StoragePoolVolumeTypeCustom) if err != nil { return response.SmartError(err) } @@ -835,11 +836,11 @@ func storagePoolVolumesPost(d *Daemon, r *http.Request) response.Response { switch req.Source.Type { case "": - return doVolumeCreateOrCopy(s, r, projectParam(r), projectName, poolName, &req) + return doVolumeCreateOrCopy(s, r, request.ProjectParam(r), projectName, poolName, &req) case "copy": - return doVolumeCreateOrCopy(s, r, projectParam(r), projectName, poolName, &req) + return doVolumeCreateOrCopy(s, r, request.ProjectParam(r), projectName, poolName, &req) case "migration": - return doVolumeMigration(s, r, projectParam(r), projectName, poolName, &req) + return doVolumeMigration(s, r, request.ProjectParam(r), projectName, poolName, &req) default: return response.BadRequest(fmt.Errorf("Unknown source type %q", req.Source.Type)) } @@ -1016,7 +1017,7 @@ func storagePoolVolumePost(d *Daemon, r *http.Request) response.Response { return response.BadRequest(fmt.Errorf("Renaming storage volumes of type %q is not allowed", volumeTypeName)) } - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), db.StoragePoolVolumeTypeCustom) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), db.StoragePoolVolumeTypeCustom) if err != nil { return response.SmartError(err) } @@ -1074,7 +1075,7 @@ func storagePoolVolumePost(d *Daemon, r *http.Request) response.Response { // This is a migration request so send back requested secrets. if req.Migration { - return storagePoolVolumeTypePostMigration(s, r, projectParam(r), projectName, srcPoolName, volumeName, req) + return storagePoolVolumeTypePostMigration(s, r, request.ProjectParam(r), projectName, srcPoolName, volumeName, req) } // Retrieve ID of the storage pool (and check if the storage pool exists). @@ -1361,7 +1362,7 @@ func storagePoolVolumeGet(d *Daemon, r *http.Request) response.Response { return response.BadRequest(fmt.Errorf("Invalid storage volume type %q", volumeTypeName)) } - requestProjectName := projectParam(r) + requestProjectName := request.ProjectParam(r) volumeProjectName, err := project.StorageVolumeProject(s.DB.Cluster, requestProjectName, volumeType) if err != nil { return response.SmartError(err) @@ -1447,7 +1448,7 @@ func storagePoolVolumeGet(d *Daemon, r *http.Request) response.Response { func storagePoolVolumePut(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName := projectParam(r) + projectName := request.ProjectParam(r) volumeTypeName, err := url.PathUnescape(mux.Vars(r)["type"]) if err != nil { return response.SmartError(err) @@ -1650,7 +1651,7 @@ func storagePoolVolumePatch(d *Daemon, r *http.Request) response.Response { return response.BadRequest(fmt.Errorf("Invalid storage volume type %q", volumeTypeName)) } - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), volumeType) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), volumeType) if err != nil { return response.SmartError(err) } @@ -1777,7 +1778,7 @@ func storagePoolVolumeDelete(d *Daemon, r *http.Request) response.Response { return response.BadRequest(err) } - requestProjectName := projectParam(r) + requestProjectName := request.ProjectParam(r) volumeProjectName, err := project.StorageVolumeProject(s.DB.Cluster, requestProjectName, volumeType) if err != nil { return response.SmartError(err) diff --git a/lxd/storage_volumes_backup.go b/lxd/storage_volumes_backup.go index 3df8222bffb7..a5ac2ac555ec 100644 --- a/lxd/storage_volumes_backup.go +++ b/lxd/storage_volumes_backup.go @@ -153,7 +153,7 @@ var storagePoolVolumeTypeCustomBackupExportCmd = APIEndpoint{ func storagePoolVolumeTypeCustomBackupsGet(d *Daemon, r *http.Request) response.Response { s := d.State() - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), db.StoragePoolVolumeTypeCustom) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), db.StoragePoolVolumeTypeCustom) if err != nil { return response.SmartError(err) } @@ -300,7 +300,7 @@ func storagePoolVolumeTypeCustomBackupsPost(d *Daemon, r *http.Request) response return response.BadRequest(fmt.Errorf("Invalid storage volume type %q", volumeTypeName)) } - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), db.StoragePoolVolumeTypeCustom) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), db.StoragePoolVolumeTypeCustom) if err != nil { return response.SmartError(err) } @@ -427,7 +427,7 @@ func storagePoolVolumeTypeCustomBackupsPost(d *Daemon, r *http.Request) response resources["storage_volumes"] = []api.URL{*api.NewURL().Path(version.APIVersion, "storage-pools", poolName, "volumes", volumeTypeName, volumeName)} resources["backups"] = []api.URL{*api.NewURL().Path(version.APIVersion, "storage-pools", poolName, "volumes", volumeTypeName, volumeName, "backups", req.Name)} - op, err := operations.OperationCreate(s, projectParam(r), operations.OperationClassTask, operationtype.CustomVolumeBackupCreate, resources, nil, backup, nil, nil, r) + op, err := operations.OperationCreate(s, request.ProjectParam(r), operations.OperationClassTask, operationtype.CustomVolumeBackupCreate, resources, nil, backup, nil, nil, r) if err != nil { return response.InternalError(err) } @@ -518,7 +518,7 @@ func storagePoolVolumeTypeCustomBackupGet(d *Daemon, r *http.Request) response.R return response.BadRequest(fmt.Errorf("Invalid storage volume type %q", volumeTypeName)) } - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), db.StoragePoolVolumeTypeCustom) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), db.StoragePoolVolumeTypeCustom) if err != nil { return response.SmartError(err) } @@ -618,7 +618,7 @@ func storagePoolVolumeTypeCustomBackupPost(d *Daemon, r *http.Request) response. return response.BadRequest(fmt.Errorf("Invalid storage volume type %q", volumeTypeName)) } - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), db.StoragePoolVolumeTypeCustom) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), db.StoragePoolVolumeTypeCustom) if err != nil { return response.SmartError(err) } @@ -668,7 +668,7 @@ func storagePoolVolumeTypeCustomBackupPost(d *Daemon, r *http.Request) response. resources["storage_volumes"] = []api.URL{*api.NewURL().Path(version.APIVersion, "storage-pools", poolName, "volumes", volumeTypeName, volumeName)} resources["backups"] = []api.URL{*api.NewURL().Path(version.APIVersion, "storage-pools", poolName, "volumes", volumeTypeName, volumeName, "backups", oldName)} - op, err := operations.OperationCreate(s, projectParam(r), operations.OperationClassTask, operationtype.CustomVolumeBackupRename, resources, nil, rename, nil, nil, r) + op, err := operations.OperationCreate(s, request.ProjectParam(r), operations.OperationClassTask, operationtype.CustomVolumeBackupRename, resources, nil, rename, nil, nil, r) if err != nil { return response.InternalError(err) } @@ -745,7 +745,7 @@ func storagePoolVolumeTypeCustomBackupDelete(d *Daemon, r *http.Request) respons return response.BadRequest(fmt.Errorf("Invalid storage volume type %q", volumeTypeName)) } - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), db.StoragePoolVolumeTypeCustom) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), db.StoragePoolVolumeTypeCustom) if err != nil { return response.SmartError(err) } @@ -782,7 +782,7 @@ func storagePoolVolumeTypeCustomBackupDelete(d *Daemon, r *http.Request) respons resources["storage_volumes"] = []api.URL{*api.NewURL().Path(version.APIVersion, "storage-pools", poolName, "volumes", volumeTypeName, volumeName)} resources["backups"] = []api.URL{*api.NewURL().Path(version.APIVersion, "storage-pools", poolName, "volumes", volumeTypeName, volumeName, "backups", backupName)} - op, err := operations.OperationCreate(s, projectParam(r), operations.OperationClassTask, operationtype.CustomVolumeBackupRemove, resources, nil, remove, nil, nil, r) + op, err := operations.OperationCreate(s, request.ProjectParam(r), operations.OperationClassTask, operationtype.CustomVolumeBackupRemove, resources, nil, remove, nil, nil, r) if err != nil { return response.InternalError(err) } @@ -855,7 +855,7 @@ func storagePoolVolumeTypeCustomBackupExportGet(d *Daemon, r *http.Request) resp return response.BadRequest(fmt.Errorf("Invalid storage volume type %q", volumeTypeName)) } - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), db.StoragePoolVolumeTypeCustom) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), db.StoragePoolVolumeTypeCustom) if err != nil { return response.SmartError(err) } diff --git a/lxd/storage_volumes_snapshot.go b/lxd/storage_volumes_snapshot.go index 71b0c5f3d65b..31eb5c88bf2a 100644 --- a/lxd/storage_volumes_snapshot.go +++ b/lxd/storage_volumes_snapshot.go @@ -20,6 +20,7 @@ import ( "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/operations" "github.com/canonical/lxd/lxd/project" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" "github.com/canonical/lxd/lxd/state" storagePools "github.com/canonical/lxd/lxd/storage" @@ -118,7 +119,7 @@ func storagePoolVolumeSnapshotsTypePost(d *Daemon, r *http.Request) response.Res } // Get the project name. - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), volumeType) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), volumeType) if err != nil { return response.SmartError(err) } @@ -233,7 +234,7 @@ func storagePoolVolumeSnapshotsTypePost(d *Daemon, r *http.Request) response.Res resources["storage_volumes"] = []api.URL{*api.NewURL().Path(version.APIVersion, "storage-pools", poolName, "volumes", volumeTypeName, volumeName)} resources["storage_volume_snapshots"] = []api.URL{*api.NewURL().Path(version.APIVersion, "storage-pools", poolName, "volumes", volumeTypeName, volumeName, "snapshots", req.Name)} - op, err := operations.OperationCreate(s, projectParam(r), operations.OperationClassTask, operationtype.VolumeSnapshotCreate, resources, nil, snapshot, nil, nil, r) + op, err := operations.OperationCreate(s, request.ProjectParam(r), operations.OperationClassTask, operationtype.VolumeSnapshotCreate, resources, nil, snapshot, nil, nil, r) if err != nil { return response.InternalError(err) } @@ -377,7 +378,7 @@ func storagePoolVolumeSnapshotsTypeGet(d *Daemon, r *http.Request) response.Resp return response.BadRequest(fmt.Errorf("Invalid storage volume type %q", volumeTypeName)) } - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), volumeType) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), volumeType) if err != nil { return response.SmartError(err) } @@ -517,7 +518,7 @@ func storagePoolVolumeSnapshotTypePost(d *Daemon, r *http.Request) response.Resp } // Get the project name. - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), volumeType) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), volumeType) if err != nil { return response.SmartError(err) } @@ -557,7 +558,7 @@ func storagePoolVolumeSnapshotTypePost(d *Daemon, r *http.Request) response.Resp Target: req.Target, } - return storagePoolVolumeTypePostMigration(s, r, projectParam(r), projectName, poolName, fullSnapshotName, req) + return storagePoolVolumeTypePostMigration(s, r, request.ProjectParam(r), projectName, poolName, fullSnapshotName, req) } // Rename the snapshot. @@ -573,7 +574,7 @@ func storagePoolVolumeSnapshotTypePost(d *Daemon, r *http.Request) response.Resp resources := map[string][]api.URL{} resources["storage_volume_snapshots"] = []api.URL{*api.NewURL().Path(version.APIVersion, "storage-pools", poolName, "volumes", volumeTypeName, volumeName, "snapshots", snapshotName)} - op, err := operations.OperationCreate(s, projectParam(r), operations.OperationClassTask, operationtype.VolumeSnapshotRename, resources, nil, snapshotRename, nil, nil, r) + op, err := operations.OperationCreate(s, request.ProjectParam(r), operations.OperationClassTask, operationtype.VolumeSnapshotRename, resources, nil, snapshotRename, nil, nil, r) if err != nil { return response.InternalError(err) } @@ -661,7 +662,7 @@ func storagePoolVolumeSnapshotTypeGet(d *Daemon, r *http.Request) response.Respo } // Get the project name. - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), volumeType) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), volumeType) if err != nil { return response.SmartError(err) } @@ -784,7 +785,7 @@ func storagePoolVolumeSnapshotTypePut(d *Daemon, r *http.Request) response.Respo } // Get the project name. - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), volumeType) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), volumeType) if err != nil { return response.SmartError(err) } @@ -912,7 +913,7 @@ func storagePoolVolumeSnapshotTypePatch(d *Daemon, r *http.Request) response.Res } // Get the project name. - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), volumeType) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), volumeType) if err != nil { return response.SmartError(err) } @@ -1072,7 +1073,7 @@ func storagePoolVolumeSnapshotTypeDelete(d *Daemon, r *http.Request) response.Re } // Get the project name. - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), volumeType) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), volumeType) if err != nil { return response.SmartError(err) } @@ -1101,7 +1102,7 @@ func storagePoolVolumeSnapshotTypeDelete(d *Daemon, r *http.Request) response.Re resources := map[string][]api.URL{} resources["storage_volume_snapshots"] = []api.URL{*api.NewURL().Path(version.APIVersion, "storage-pools", poolName, "volumes", volumeTypeName, volumeName, "snapshots", snapshotName)} - op, err := operations.OperationCreate(s, projectParam(r), operations.OperationClassTask, operationtype.VolumeSnapshotDelete, resources, nil, snapshotDelete, nil, nil, r) + op, err := operations.OperationCreate(s, request.ProjectParam(r), operations.OperationClassTask, operationtype.VolumeSnapshotDelete, resources, nil, snapshotDelete, nil, nil, r) if err != nil { return response.InternalError(err) } diff --git a/lxd/storage_volumes_state.go b/lxd/storage_volumes_state.go index 18540a728a16..732db3c58740 100644 --- a/lxd/storage_volumes_state.go +++ b/lxd/storage_volumes_state.go @@ -11,6 +11,7 @@ import ( "github.com/canonical/lxd/lxd/instance" "github.com/canonical/lxd/lxd/instance/instancetype" "github.com/canonical/lxd/lxd/project" + "github.com/canonical/lxd/lxd/request" "github.com/canonical/lxd/lxd/response" storagePools "github.com/canonical/lxd/lxd/storage" "github.com/canonical/lxd/shared" @@ -101,7 +102,7 @@ func storagePoolVolumeTypeStateGet(d *Daemon, r *http.Request) response.Response } // Get the storage project name. - projectName, err := project.StorageVolumeProject(s.DB.Cluster, projectParam(r), volumeType) + projectName, err := project.StorageVolumeProject(s.DB.Cluster, request.ProjectParam(r), volumeType) if err != nil { return response.SmartError(err) } diff --git a/lxd/warnings.go b/lxd/warnings.go index c3e97a3fa549..3f61f33ff227 100644 --- a/lxd/warnings.go +++ b/lxd/warnings.go @@ -167,7 +167,7 @@ func warningsGet(d *Daemon, r *http.Request) response.Response { } // Parse the project field - projectName := queryParam(r, "project") + projectName := request.QueryParam(r, "project") var warnings []api.Warning err = d.State().DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {