func (h *HandlersAdmin) TokensGETHandler(w http.ResponseWriter, r *http.Request) {
	h.Inc(metricTokenReq)
	utils.DebugHTTPDump(r, h.Settings.DebugHTTP(settings.ServiceAdmin), false)
	ctx := r.Context().Value(sessions.ContextKey("session")).(sessions.ContextValue)
	if !h.Users.CheckPermissions(ctx[sessions.CtxUser], users.AdminLevel, users.NoEnvironment) {
		adminErrorResponse(w, fmt.Sprintf("%s has insuficient permissions", ctx[sessions.CtxUser]), http.StatusForbidden, nil)
		h.Inc(metricAdminErr)
		return
	}
	vars := mux.Vars(r)
	username, ok := vars["username"]
	if !ok {
		adminErrorResponse(w, "error getting username", http.StatusInternalServerError, nil)
		h.Inc(metricAdminErr)
		return
	}
	returned := TokenJSON{}
	if h.Users.Exists(username) {
		user, err := h.Users.Get(username)
		if err != nil {
			adminErrorResponse(w, "error getting user", http.StatusInternalServerError, err)
			h.Inc(metricAdminErr)
			return
		}
		returned = TokenJSON{
			Token:     user.APIToken,
			Expires:   utils.PastFutureTimes(user.TokenExpire),
			ExpiresTS: utils.TimeTimestamp(user.TokenExpire),
		}
	}
	utils.HTTPResponse(w, utils.JSONApplicationUTF8, http.StatusOK, returned)
	h.Inc(metricTokenOK)
}
TokensGETHandler for GET requests for /tokens/{username}
package handlers
import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"github.com/gorilla/mux"
	"github.com/jmpsec/osctrl/admin/sessions"
	"github.com/jmpsec/osctrl/settings"
	"github.com/jmpsec/osctrl/users"
	"github.com/jmpsec/osctrl/utils"
)
type TokenJSON struct {
	Token     string `json:"token"`
	Expires   string `json:"expires"`
	ExpiresTS string `json:"expires_ts"`
}