Esempio n. 1
0
func handleManifestsReplace(db datastore.Datastore) httprouter.Handle {
	return func(rw http.ResponseWriter, r *http.Request, ps httprouter.Params) {
		name := strings.TrimLeft(ps.ByName("name"), "/")
		accept := acceptHeader(r)
		manifest, err := db.Manifest(name)
		if err != nil {
			respondError(rw, errStatus(err), accept,
				fmt.Errorf("Failed to upddate manifest: %v", err))
			return
		}

		payload := &models.Manifest{}
		err = decodeRequest(r, payload)
		if err != nil {
			respondError(rw, errStatus(err), accept,
				fmt.Errorf("Failed to decode request payload: %v", err))
			return
		}

		if err := db.SaveManifest(manifest); err != nil {
			respondError(rw, errStatus(err), accept,
				fmt.Errorf("Failed to save manifest: %v", err))
			return
		}

		manifest = payload
		manifest.Filename = name

		// manifest updated ok, respond
		respondOK(rw, manifest, accept)
	}
}
Esempio n. 2
0
func handleManifestsUpdate(db datastore.Datastore) httprouter.Handle {
	return func(rw http.ResponseWriter, r *http.Request, ps httprouter.Params) {
		name := strings.TrimLeft(ps.ByName("name"), "/")
		accept := acceptHeader(r)
		manifest, err := db.Manifest(name)
		if err != nil {
			respondError(rw, errStatus(err), accept,
				fmt.Errorf("Failed to delete manifest from the datastore: %v", err))
			return
		}

		// decode payload from request body.
		payload := &models.ManifestPayload{}
		err = decodeRequest(r, payload)
		if err != nil {
			respondError(rw, errStatus(err), accept,
				fmt.Errorf("Failed to decode request payload: %v", err))
			return
		}

		// update manifest from payload fields.
		manifest.UpdateFromPayload(payload)

		if err := db.SaveManifest(manifest); err != nil {
			respondError(rw, errStatus(err), accept,
				fmt.Errorf("Failed to save manifest: %v", err))
			return
		}

		// manifest updated ok, respond
		respondOK(rw, manifest, accept)
	}
}
Esempio n. 3
0
func handleManifestsShow(db datastore.Datastore) httprouter.Handle {
	return func(rw http.ResponseWriter, r *http.Request, ps httprouter.Params) {
		name := strings.TrimLeft(ps.ByName("name"), "/")
		accept := acceptHeader(r)
		manifest, err := db.Manifest(name)
		if err != nil {
			respondError(rw, errStatus(err), accept,
				fmt.Errorf("Failed to fetch manifest from the datastore: %v", err))
			return
		}
		respondOK(rw, manifest, accept)
	}
}