pgweb icon indicating copy to clipboard operation
pgweb copied to clipboard

[Feature Request] Toggle on/off data download

Open jgerstle4u opened this issue 3 years ago • 6 comments

Provide an argument option for disabling the query data download buttons altogether.

jgerstle4u avatar Jan 26 '22 01:01 jgerstle4u

Do you have any context for this request?

sosedoff avatar Jan 26 '22 02:01 sosedoff

Context for this would be to provide pgweb running in a container in k8s to support ops of a system. Since data in the db should not leave the environment, disabling the buttons for export would be necessary.

Something like:

pgweb --disable-download --readonly

would startup pgweb with readonly access and either hide or disable the JSON/CSV/XML buttons. Removing API route to /export may be necessary as well if the API can be accessed directly.

jgerstle4u avatar Jan 26 '22 02:01 jgerstle4u

Sounds reasonable, although i wont be able to give any ETAs for this request.

sosedoff avatar Jan 26 '22 02:01 sosedoff

Thanks. Doesn't seem like it would take too much work as you are using gin serve up the web app.

Basic approach might be to switch over to templates directory instead of static and and wrap the button lines with templating conditionals, something like:

{{if .disableDownload }}
              <input type="button" id="json" value="JSON" class="btn btn-sm btn-default" />
              <input type="button" id="csv" value="CSV" class="btn btn-sm btn-default" />
              <input type="button" id="xml" value="XML" class="btn btn-sm btn-default" />
{{end}}  

in cli.go add:

func startServer()  {
    router := gin.Default()

   // Load templates
   router.LoadHTMLGlob("templates/*")
...
}

and then in the api.go changing getHome to:

// GetHome renders the home page
func GetHome(prefix string, disableDownload bool) http.Handler {
	if prefix != "" {
		prefix = "/" + prefix
	}
	return http.StripPrefix(prefix, c.HTML(http.StatusOk, "index.tmpl", gin.H{"disableDownload": disableDownload}))
}

and adding in routes.go, modifiying the the call to getHome to include the command option value:

I'd be happy to put this in a PR if you agree with methodology.

jgerstle4u avatar Jan 26 '22 06:01 jgerstle4u

If you're interested in working on a PR then go ahead, i'm more than willing to accept quality contributions.

sosedoff avatar Jan 28 '22 01:01 sosedoff

@jgerstle4u if you're still working on this, don't forget to also disable the endpoint server-side /api/export

Davincible avatar Jun 17 '22 13:06 Davincible

Coming back to this features request - while disabling the download buttons makes more sense, there's still ability to download data via regular queries and saving the output on disk manually, so there's nothing really stops one from getting the data out.

sosedoff avatar Dec 19 '22 22:12 sosedoff

Im gonna close unless there's interest.

sosedoff avatar Feb 16 '23 03:02 sosedoff