Add API endpoint for getting information about the latest hishtory version and download URLs

This commit is contained in:
David Dworken 2022-04-16 16:34:09 -07:00
parent 05f1af8714
commit 735a98a611
2 changed files with 20 additions and 0 deletions

View File

@ -239,6 +239,19 @@ func InitDB() {
}
}
func apiDownloadHandler(w http.ResponseWriter, r *http.Request) {
updateInfo := shared.UpdateInfo{
LinuxAmd64Url: fmt.Sprintf("https://github.com/ddworken/hishtory/releases/download/%s/hishtory-linux-amd64", ReleaseVersion),
LinuxAmd64AttestationUrl: fmt.Sprintf("https://github.com/ddworken/hishtory/releases/download/%s/hishtory-linux-amd64.intoto.jsonl", ReleaseVersion),
Version: ReleaseVersion,
}
resp, err := json.Marshal(updateInfo)
if err != nil {
panic(err)
}
w.Write(resp)
}
func bindaryDownloadHandler(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, fmt.Sprintf("https://github.com/ddworken/hishtory/releases/download/%s/hishtory-linux-amd64", ReleaseVersion), http.StatusFound)
}
@ -313,6 +326,7 @@ func main() {
http.Handle("/api/v1/eregister", withLogging(apiERegisterHandler))
http.Handle("/api/v1/banner", withLogging(apiBannerHandler))
http.Handle("/api/v1/trigger-cron", withLogging(triggerCronHandler))
http.Handle("/api/v1/download", withLogging(apiDownloadHandler))
http.Handle("/download/hishtory-linux-amd64", withLogging(bindaryDownloadHandler))
http.Handle("/download/hishtory-linux-amd64.intoto.jsonl", withLogging(attestationDownloadHandler))
log.Fatal(http.ListenAndServe(":8080", nil))

View File

@ -25,6 +25,12 @@ type Device struct {
RegistrationDate time.Time `json:"registration_date"`
}
type UpdateInfo struct {
LinuxAmd64Url string `json:"linux_amd_64_url"`
LinuxAmd64AttestationUrl string `json:"linux_amd_64_attestation_url"`
Version string `json:"version"`
}
const (
CONFIG_PATH = ".hishtory.config"
HISHTORY_PATH = ".hishtory"