Example #1
0
// PATCH /batch, Update the FS with a list of file changes. Only creates/updates
// can be done here.
func batchUpdateContainerHandler(rw http.ResponseWriter, req *http.Request) {
	// Require a container to exist.
	if currentContainer == nil {
		renderer.JSON(rw, http.StatusBadRequest, map[string]string{
			"status": requests.StatusFailed,
			"error":  delancey.ErrNotInUse.Error(),
		})
		return
	}

	go logClient.Info("batch updating container", map[string]interface{}{
		"container": currentContainer,
		"ip":        agentHost,
	})

	// Untar the tar contents from the body to the containers path.
	err := tar.Untar(req.Body, currentContainer.RemotePath)
	if err != nil {
		renderer.JSON(rw, http.StatusInternalServerError, map[string]string{
			"status": requests.StatusFailed,
			"error":  err.Error(),
		})
		return
	}

	renderer.JSON(rw, http.StatusOK, map[string]string{
		"status": requests.StatusUpdated,
	})
}
Example #2
0
// PUT /ssh, Accepts ssh tarfile for user auth to their container
func uploadSSHHandler(rw http.ResponseWriter, req *http.Request) {
	// Require a container to exist.
	if currentContainer == nil {
		renderer.JSON(rw, http.StatusBadRequest, map[string]string{
			"status": requests.StatusFailed,
			"error":  delancey.ErrNotInUse.Error(),
		})
		return
	}

	// Untar the tar contents from the body to the containers path.
	err := tar.Untar(req.Body, currentContainer.SSHPath)
	if err != nil {
		renderer.JSON(rw, http.StatusInternalServerError, map[string]string{
			"status": requests.StatusFailed,
			"error":  err.Error(),
		})
		return
	}

	// Ensure files/directories are private.
	err = filepath.Walk(currentContainer.SSHPath, func(path string, info os.FileInfo, err error) error {
		if err != nil || currentContainer.SSHPath == path {
			return err
		}

		if info.IsDir() {
			return os.Chmod(path, 0700)
		}

		return os.Chmod(path, 0600)
	})
	if err != nil {
		renderer.JSON(rw, http.StatusInternalServerError, map[string]string{
			"status": requests.StatusFailed,
			"error":  err.Error(),
		})
		return
	}

	renderer.JSON(rw, http.StatusOK, map[string]string{
		"status": requests.StatusSuccess,
	})
}
Example #3
0
// PUT /, Upload code for container.
func uploadContainerHandler(rw http.ResponseWriter, req *http.Request) {
	// Require a container to exist.
	if currentContainer == nil {
		renderer.JSON(rw, http.StatusBadRequest, map[string]string{
			"status": requests.StatusFailed,
			"error":  delancey.ErrNotInUse.Error(),
		})
		return
	}

	// Untar the tar contents from the body to the containers path.
	err := tar.Untar(req.Body, currentContainer.RemotePath)
	if err != nil {
		renderer.JSON(rw, http.StatusInternalServerError, map[string]string{
			"status": requests.StatusFailed,
			"error":  err.Error(),
		})
		return
	}

	renderer.JSON(rw, http.StatusOK, map[string]string{
		"status": requests.StatusSuccess,
	})
}