mirror of
https://github.com/hanzoai/ca.git
synced 2026-11-03 18:08:27 +00:00
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
// Code generated by protoc-gen-go-http. DO NOT EDIT.
|
|
// source: admin.proto
|
|
|
|
package httppb
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/effective-security/porto/restserver"
|
|
"github.com/effective-security/porto/xhttp/correlation"
|
|
"github.com/effective-security/porto/xhttp/httperror"
|
|
"github.com/effective-security/porto/xhttp/marshal"
|
|
"github.com/effective-security/trustyca/privpb"
|
|
)
|
|
|
|
// GetAdminHTTPHandler handles HTTP requests for Admin service
|
|
func GetAdminHTTPHandler(s privpb.AdminServer, withAccessCheck privpb.CheckAccessFunc) restserver.Handle {
|
|
return func(w http.ResponseWriter, r *http.Request, p restserver.Params) {
|
|
action := r.URL.Path
|
|
ctx := correlation.WithMetaFromRequest(r)
|
|
|
|
var err error
|
|
var res any
|
|
|
|
req, _, err := privpb.UnmarshalRequest(w, r)
|
|
if err != nil {
|
|
// UnmarshalRequest already writes error response
|
|
return
|
|
}
|
|
|
|
if withAccessCheck != nil {
|
|
err = withAccessCheck(ctx, req, action)
|
|
if err != nil {
|
|
marshal.WriteJSON(w, r, err)
|
|
return
|
|
}
|
|
}
|
|
|
|
switch action {
|
|
|
|
case privpb.Admin_ListOrgs_FullMethodName:
|
|
res, err = s.ListOrgs(ctx, req.(*privpb.ListOrgsRequest))
|
|
|
|
case privpb.Admin_ListProjects_FullMethodName:
|
|
res, err = s.ListProjects(ctx, req.(*privpb.ListProjectsRequest))
|
|
|
|
case privpb.Admin_ListIssuers_FullMethodName:
|
|
res, err = s.ListIssuers(ctx, req.(*privpb.ListAllIssuersRequest))
|
|
|
|
case privpb.Admin_ListCertificates_FullMethodName:
|
|
res, err = s.ListCertificates(ctx, req.(*privpb.ListAllCertificatesRequest))
|
|
|
|
default:
|
|
err = httperror.Malformed("invalid action: %s", action)
|
|
}
|
|
if err != nil {
|
|
marshal.WriteJSON(w, r, err)
|
|
return
|
|
}
|
|
|
|
marshal.WriteJSON(w, r, res)
|
|
}
|
|
}
|