Esempio n. 1
0
// Fetch returns an artifact given a path and job id
func (s3s *S3Store) Fetch(path, jobID string) (*artifact.Artifact, error) {
	a := artifact.New("", path, jobID, nil, uint64(0))

	s3Key, err := s3s.b.GetKey(a.FullDestination())
	if err != nil {
		return nil, err
	}

	s3Stream, err := s3s.b.GetReader(a.FullDestination())
	if err != nil {
		return nil, err
	}

	a.OutReadCloser = s3Stream
	a.Size = uint64(s3Key.Size)
	dateMod, err := time.Parse(time.RFC1123, s3Key.LastModified)
	if err != nil {
		return nil, err
	}
	a.DateModified = dateMod

	s3s.log.WithFields(logrus.Fields{
		"path":          a.FullDestination(),
		"size":          a.Size,
		"date_modified": a.DateModified,
	}).Debug("returning artifact from s3")

	return a, nil
}
Esempio n. 2
0
// Fetch returns an artifact given a path and job id
func (fs *FileStore) Fetch(path, jobID string) (*artifact.Artifact, error) {
	a := artifact.New(path, path, jobID, nil, uint64(0))
	fullPath := fs.artifactFullPath(a)

	fi, err := os.Stat(fullPath)
	if err != nil {
		return nil, err
	}

	fd, err := os.Open(fullPath)
	if err != nil {
		return nil, err
	}

	a.Size = uint64(fi.Size())
	a.DateModified = fi.ModTime()
	a.OutReadSeeker = fd

	return a, nil
}
Esempio n. 3
0
func (srv *Server) saveHandler(w http.ResponseWriter, r *http.Request, vars map[string]string) int {
	if !srv.getAuth(r, vars).CanWrite {
		return srv.serveUnauthorized(w, r)
	}

	filepath, filepathOK := vars["filepath"]
	jobID, jobIDOK := vars["job_id"]

	if !filepathOK || !jobIDOK {
		w.WriteHeader(http.StatusBadRequest)
		fmt.Fprintf(w, `{"error":"this will never work.  stop it"}`)
		return http.StatusBadRequest
	}

	src := r.Header.Get("Artifacts-Source")
	size, _ := strconv.ParseUint(r.Header.Get("Artifacts-Size"), 10, 64)

	// TODO: validation!

	a := artifact.New(src, filepath, jobID, r.Body, size)

	err := srv.store.Store(a)
	if err != nil {
		return srv.serveError(err, w, r)
	}

	resp := newSaveResponse()

	jsonBytes, err := json.Marshal(resp)
	if err != nil {
		return srv.serveError(err, w, r)
	}

	w.WriteHeader(http.StatusOK)
	w.Header().Set("Content-Type", "application/vnd.api+json")
	fmt.Fprintf(w, string(jsonBytes)+"\n")
	return http.StatusOK
}