func (localAuth LocalAuth) Purge(ctx *gin.Context) {
	ctx.Writer.Header().Add("Content-Type", "application/json")
	datastore, err := localAuth.ctxDatastore(ctx)
	if err != nil {
		ctx.JSON(500, ExitResponse{Msg: err.Error()})
		return
	}
	err = localAuth.ctxAdminToken(ctx)
	if err != nil {
		ctx.JSON(500, ExitResponse{Msg: err.Error()})
		return
	}
	ctx.JSON(200, datastore.Purge())
}
/*
Purge removes all keys from datastore enquired, without decryption required.
package doryBackend
import (
	"fmt"
	"io/ioutil"
	"net/http"
	"strconv"
	"strings"
	doryMemory "github.com/abhishekkr/dory/doryMemory"
	"github.com/abhishekkr/gol/golenv"
	"github.com/abhishekkr/gol/golerror"
	"github.com/abhishekkr/gol/gollog"
	"github.com/gin-gonic/gin"
)
var (
	DORY_ADMIN_TOKEN = golenv.OverrideIfEnv("DORY_ADMIN_TOKEN", "")
)
type LocalAuth struct {
	Cache doryMemory.DataStore
	Disk  doryMemory.DataStore
	Item  doryMemory.LocalAuth
}
func NewLocalAuth(cacheName string) LocalAuth {
	localAuth := LocalAuth{
		Cache: doryMemory.NewLocalAuthStore(cacheName),
		Disk:  doryMemory.NewDiskv(cacheName),
		Item:  doryMemory.LocalAuth{},
	}
	return localAuth
}
func (localAuth LocalAuth) ctxPersist(ctx *gin.Context) (datastore doryMemory.DataStore) {
	requestURI := ctx.Request.RequestURI
	requestAt := strings.Split(requestURI, "/")[1]
	if requestAt == "local-cache" {
		gollog.Debug(fmt.Sprintf("key '%s' is provided for memory store with expiry", localAuth.Item.Name))
		datastore = localAuth.Cache
		return
	} else if requestAt == "local-disk" {
		gollog.Debug(fmt.Sprintf("key '%s' is provided for long-term disk store", localAuth.Item.Name))
		datastore = localAuth.Disk
		return
	}
	if ctx.DefaultQuery("persist", "false") == "false" {
		gollog.Debug(fmt.Sprintf("key '%s' is provided for memory store with expiry", localAuth.Item.Name))
		datastore = localAuth.Cache
	} else {
		gollog.Debug(fmt.Sprintf("key '%s' is provided for long-term disk store", localAuth.Item.Name))
		datastore = localAuth.Disk
	}
	return
}
func (localAuth LocalAuth) ctxDatastore(ctx *gin.Context) (datastore doryMemory.DataStore, err error) {
	datastoreType := ctx.Param("datastore")
	if datastoreType == "cache" {
		datastore = localAuth.Cache
	} else if datastoreType == "disk" {
		datastore = localAuth.Disk
	} else {
		err = golerror.Error(123, fmt.Sprintf("store %s is not allowed, only 'cache' and 'disk' are allowed"))
	}
	return
}
func (localAuth LocalAuth) ctxAdminToken(ctx *gin.Context) (err error) {
	adminToken := ctx.Request.Header.Get("X-DORY-ADMIN-TOKEN")
	if len(DORY_ADMIN_TOKEN) < 256 {
		err = golerror.Error(123, "configured admin token length is less than 64 chars, not allowed")
		return
	}
	if DORY_ADMIN_TOKEN != adminToken {
		err = golerror.Error(123, "provided admin token doesn't match configured token")
		return
	}
	return
}
func (localAuth LocalAuth) Get(ctx *gin.Context) {
	datastore := localAuth.ctxPersist(ctx)
	localAuth.Item.Name = ctx.Param("uuid")
	localAuth.Item.Value.Key = []byte(ctx.Request.Header.Get("X-DORY-TOKEN"))
	if localAuth.Item.Name == "" {
		ctx.JSON(500, ExitResponse{Msg: "passed uuid is empty"})
		return
	}
	if !localAuth.Item.Get(datastore) {
		ctx.Writer.Header().Add("Content-Type", "application/json")
		ctx.JSON(500, ExitResponse{Msg: "get for required auth identifier failed"})
		return
	}
	response := localAuth.Item.Value.DataBlob
	if ctx.DefaultQuery("keep", "false") == "false" {
		if !localAuth.Item.Delete(datastore) {
			ctx.JSON(500, ExitResponse{Msg: "auth identifier purge failed", Data: response})
			return
		}
	} else {
		gollog.Debug(fmt.Sprintf("GET - key '%s' is queried to be not purged", localAuth.Item.Name))
	}
	ctx.Writer.WriteHeader(http.StatusOK)
	ctx.Writer.Write(response)
}
func (localAuth LocalAuth) AuthMount(ctx *gin.Context) {
	datastore := localAuth.ctxPersist(ctx)
	localAuth.Item.Name = ctx.Param("uuid")
	if localAuth.Item.Name == "" {
		ctx.JSON(500, ExitResponse{Msg: "passed uuid is empty"})
		return
	}
	if localAuth.Item.Exists(datastore) {
		ctx.JSON(409, ExitResponse{Msg: "auth identifier conflict"})
		return
	}
	ttlsecond, err := strconv.Atoi(ctx.DefaultQuery("ttlsecond", "0"))
	if err != nil {
		ctx.Writer.Header().Add("Content-Type", "application/json")
		ctx.JSON(400, ExitResponse{Msg: err.Error()})
		return
	}
	localAuth.Item.TTLSecond = uint64(ttlsecond)
	localAuth.Item.Value.DataBlob, err = ioutil.ReadAll(ctx.Request.Body)
	if err != nil {
		gollog.Err(fmt.Sprintf("SET - key '%s' had failure to read it's data", localAuth.Item.Name))
		ctx.Writer.Header().Add("Content-Type", "application/json")
		ctx.JSON(400, ExitResponse{Msg: err.Error()})
		return
	}
	if len(localAuth.Item.Value.DataBlob) == 0 {
		gollog.Err(fmt.Sprintf("SET - key '%s' is provided with empty data", localAuth.Item.Name))
		ctx.JSON(400, ExitResponse{Msg: "empty data blob recieved"})
		return
	}
	if !localAuth.Item.Set(datastore) {
		ctx.JSON(500, ExitResponse{Msg: "auth identifier creation failed"})
		return
	}
	ctx.String(http.StatusOK, string(localAuth.Item.Value.Key))
}
func (localAuth LocalAuth) AuthUnmount(ctx *gin.Context) {
	datastore := localAuth.ctxPersist(ctx)
	ctx.Writer.Header().Add("Content-Type", "application/json")
	localAuth.Item.Name = ctx.Param("uuid")
	localAuth.Item.Value.Key = []byte(ctx.Request.Header.Get("X-DORY-TOKEN"))
	if localAuth.Item.Name == "" {
		ctx.JSON(500, ExitResponse{Msg: "passed uuid is empty"})
		return
	}
	if !localAuth.Item.Delete(datastore) {
		ctx.JSON(500, ExitResponse{Msg: "auth identifier purge failed"})
		return
	}
	ctx.JSON(200, ExitResponse{Msg: "success"})
}
func (localAuth LocalAuth) List(ctx *gin.Context) {
	var err error
	ctx.Writer.Header().Add("Content-Type", "application/json")
	datastore, err := localAuth.ctxDatastore(ctx)
	if err != nil {
		ctx.JSON(500, ExitResponse{Msg: err.Error()})
		return
	}
	err = localAuth.ctxAdminToken(ctx)
	if err != nil {
		ctx.JSON(500, ExitResponse{Msg: err.Error()})
		return
	}
	ctx.JSON(200, datastore.List())
}