Beispiel #1
0
// Revoke is used for key revocation by an administrator.
func Revoke(w http.ResponseWriter, r *http.Request) {
	log.Println("request made for key revocation")
	if isLockedOut(r) {
		serverLockOut(w)
		return
	} else if r.Method != "POST" {
		badMethod(w, r)
		return
	}

	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		badRequest(w, r)
		return
	}
	r.Body.Close()

	req, adminData, err := messages.UnpackAdminRequest(body)
	if err != nil {
		badRequest(w, r)
		return
	}
	out, err := revokeKey(req, adminData)
	if err != nil {
		badRequest(w, r)
		return
	}
	w.Write(out)
}
Beispiel #2
0
// Role is the top-level controller for the role endpoint.
func Admin(w http.ResponseWriter, r *http.Request) {
	if isLockedOut(r) {
		serverLockOut(w)
		return
	} else if r.Method != "POST" {
		badMethod(w, r)
		return
	}
	roleName, ok := mux.Vars(r)["role"]
	if !ok {
		log.Println("request for admin action without role")
		badRequest(w, r)
		return
	}

	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		log.Println("unable to read request body")
		badRequest(w, r)
		return
	}
	r.Body.Close()

	req, adminData, err := messages.UnpackAdminRequest(body)
	if err != nil {
		log.Println("invalid request body on request from", r.RemoteAddr)
		badRequest(w, r)
		return
	}
	out, err := alterRole(roleName, req, adminData)
	if err != nil {
		log.Println("error altering role on request from", r.RemoteAddr)
		badRequest(w, r)
		return
	}
	w.Write(out)
}