Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit fc60df4e authored by Bastien Gounon's avatar Bastien Gounon 🐗
Browse files

implement cache clearing and return statuses

parent 9454e017
Hi !
\ No newline at end of file
package main
import (
"os"
"path/filepath"
)
// ClearAllFiles remove all files and folders inside of a given path
func ClearAllFiles(dir string) error {
d, err := os.Open(dir)
if err != nil {
return err
}
defer d.Close()
names, err := d.Readdirnames(-1)
if err != nil {
return err
}
for _, name := range names {
err = os.RemoveAll(filepath.Join(dir, name))
if err != nil {
return err
}
}
return nil
}
package main
import (
"flag"
"log"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
var dir, serverToken string
flag.StringVar(&dir, "cachedir", "", "Folder where the cache is stored")
flag.StringVar(&serverToken, "token", "", "Token for user authentication")
flag.Parse()
if dir == "" {
log.Fatal("cachedir parameter must not be empty, exiting.")
}
r := gin.Default()
r.DELETE("/flush", func(c *gin.Context) {
userToken := c.Query("token")
if userToken != serverToken {
c.String(http.StatusUnauthorized, "Permission denied.")
} else {
err := ClearAllFiles(dir)
if err != nil {
c.String(http.StatusInternalServerError, "Error while trying to flush the cache, please check with the system administrator: %s", err.Error())
} else {
c.String(http.StatusOK, "Cache successfully flushed.")
}
}
})
r.Run()
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment