MCPcopy
hub / github.com/lxc/incus / storagePoolBucketPut

Function storagePoolBucketPut

cmd/incusd/storage_buckets.go:821–887  ·  view source on GitHub ↗

swagger:operation PATCH /1.0/storage-pools/{name}/buckets/{bucketName} storage storage_pool_bucket_patch Partially update the storage bucket. Updates a subset of the storage bucket configuration. --- consumes: - application/json produces: - application/json parameters: - in: path name: name descr

(d *Daemon, r *http.Request)

Source from the content-addressed store, hash-verified

819// "500":
820// $ref: "#/responses/InternalServerError"
821func storagePoolBucketPut(d *Daemon, r *http.Request) response.Response {
822 s := d.State()
823
824 resp := forwardedResponseIfTargetIsRemote(s, r)
825 if resp != nil {
826 return resp
827 }
828
829 bucketProjectName, err := project.StorageBucketProject(r.Context(), s.DB.Cluster, request.ProjectParam(r))
830 if err != nil {
831 return response.SmartError(err)
832 }
833
834 poolName, err := pathVar(r, "poolName")
835 if err != nil {
836 return response.SmartError(err)
837 }
838
839 pool, err := storagePools.LoadByName(s, poolName)
840 if err != nil {
841 return response.SmartError(fmt.Errorf("Failed loading storage pool: %w", err))
842 }
843
844 bucketName, err := pathVar(r, "bucketName")
845 if err != nil {
846 return response.SmartError(err)
847 }
848
849 // Decode the request.
850 req := api.StorageBucketPut{}
851 err = json.NewDecoder(r.Body).Decode(&req)
852 if err != nil {
853 return response.BadRequest(err)
854 }
855
856 if r.Method == http.MethodPatch {
857 targetMember := request.QueryParam(r, "target")
858 memberSpecific := targetMember != ""
859
860 var bucket *db.StorageBucket
861 err = s.DB.Cluster.Transaction(r.Context(), func(ctx context.Context, tx *db.ClusterTx) error {
862 bucket, err = tx.GetStoragePoolBucket(ctx, pool.ID(), bucketProjectName, memberSpecific, bucketName)
863 return err
864 })
865 if err != nil {
866 return response.SmartError(err)
867 }
868
869 // If config being updated via "patch" method, then merge all existing config with the keys that
870 // are present in the request config.
871 for k, v := range bucket.Config {
872 _, ok := req.Config[k]
873 if !ok {
874 req.Config[k] = v
875 }
876 }
877 }
878

Callers

nothing calls this directly

Calls 15

StorageBucketProjectFunction · 0.92
ProjectParamFunction · 0.92
SmartErrorFunction · 0.92
BadRequestFunction · 0.92
QueryParamFunction · 0.92
CreateRequestorFunction · 0.92
pathVarFunction · 0.85
ContextMethod · 0.80
ErrorfMethod · 0.80
SendLifecycleMethod · 0.80
StateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…