24 lines
591 B
Go
24 lines
591 B
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
const legacyAPIEnvVar = "VCTP_ENABLE_LEGACY_API"
|
|
|
|
func legacyAPIEnabled() bool {
|
|
return strings.TrimSpace(os.Getenv(legacyAPIEnvVar)) == "1"
|
|
}
|
|
|
|
func (h *Handler) denyLegacyAPI(w http.ResponseWriter, endpoint string) bool {
|
|
if legacyAPIEnabled() {
|
|
return false
|
|
}
|
|
h.Logger.Warn("legacy endpoint request blocked", "endpoint", endpoint, "env_var", legacyAPIEnvVar)
|
|
writeJSONError(w, http.StatusGone, fmt.Sprintf("%s is deprecated and disabled; set %s=1 to temporarily re-enable", endpoint, legacyAPIEnvVar))
|
|
return true
|
|
}
|