(w http.ResponseWriter, r *http.Request)
| 106 | } |
| 107 | |
| 108 | func (s *Server) handleVolume(w http.ResponseWriter, r *http.Request) { |
| 109 | switch { |
| 110 | case r.URL.Path == "/volume/": |
| 111 | handleRequest(w, r, func(ctx context.Context, req CreateVolumeReq) (*CreateVolumeResp, error) { |
| 112 | vol, err := s.Service.CreateVolume(ctx, req.Host, req.Spec) |
| 113 | if err != nil { |
| 114 | return nil, err |
| 115 | } |
| 116 | return &CreateVolumeResp{Handle: *vol}, nil |
| 117 | }) |
| 118 | return |
| 119 | } |
| 120 | var volIDStr string |
| 121 | var method string |
| 122 | if _, err := fmt.Sscanf(r.URL.Path, "/volume/%34s.%s", &volIDStr, &method); err != nil { |
| 123 | http.Error(w, "could not parse path "+r.URL.Path, http.StatusBadRequest) |
| 124 | return |
| 125 | } |
| 126 | var h blobcache.Handle |
| 127 | if err := h.OID.UnmarshalText([]byte(volIDStr)); err != nil { |
| 128 | http.Error(w, "could not decode volume id", http.StatusBadRequest) |
| 129 | return |
| 130 | } |
| 131 | secretStr := r.Header.Get("X-Secret") |
| 132 | if _, err := hex.Decode(h.Secret[:], []byte(secretStr)); err != nil { |
| 133 | http.Error(w, "could not decode secret", http.StatusBadRequest) |
| 134 | return |
| 135 | } |
| 136 | switch method { |
| 137 | case "Inspect": |
| 138 | info, err := s.Service.InspectVolume(r.Context(), h) |
| 139 | if err != nil { |
| 140 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 141 | return |
| 142 | } |
| 143 | if err := json.NewEncoder(w).Encode(info); err != nil { |
| 144 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 145 | return |
| 146 | } |
| 147 | return |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | func (s *Server) handleTx(w http.ResponseWriter, r *http.Request) { |
| 152 | if r.URL.Path == "/tx/" { |
no test coverage detected