Skip to content

Commit

Permalink
lxd: Updates calls to projectParam and queryParam.
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Laing <[email protected]>
  • Loading branch information
markylaing committed Oct 24, 2023
1 parent 56c3750 commit d9eebaa
Show file tree
Hide file tree
Showing 42 changed files with 216 additions and 194 deletions.
16 changes: 8 additions & 8 deletions lxd/api_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions lxd/api_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -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"
}
Expand Down
3 changes: 2 additions & 1 deletion lxd/api_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lxd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lxd/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
36 changes: 18 additions & 18 deletions lxd/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions lxd/instance_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit d9eebaa

Please sign in to comment.