admin/api: use gorilla/mux instead of Go router
This commit is contained in:
parent
0e30259b7e
commit
1054dd7086
18 changed files with 642 additions and 762 deletions
31
admin/api/certificate.go
Normal file
31
admin/api/certificate.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
func init() {
|
||||
router.Path("/ca").Methods("GET").HandlerFunc(apiHandler(genCA))
|
||||
|
||||
rt := router.PathPrefix("/teams/{tid}/certificate").Subrouter()
|
||||
rt.Path("/").Methods("GET").HandlerFunc(apiHandler(teamHandler(GetTeamCertificate)))
|
||||
rt.Path("/generate").Methods("GET").HandlerFunc(apiHandler(teamHandler(
|
||||
func(team fic.Team, args map[string]string, body []byte) (interface{}, error) { return team.GenerateCert(), nil })))
|
||||
rt.Path("/revoke").Methods("GET").HandlerFunc(apiHandler(teamHandler(
|
||||
func(team fic.Team, args map[string]string, body []byte) (interface{}, error) { return team.RevokeCert(), nil })))
|
||||
}
|
||||
|
||||
func genCA(args map[string]string, body []byte) (interface{}, error) {
|
||||
return fic.GenerateCA(), nil
|
||||
}
|
||||
|
||||
func GetTeamCertificate(team fic.Team, args map[string]string, body []byte) (interface{}, error) {
|
||||
if fd, err := os.Open("../PKI/pkcs/" + team.Name + ".p12"); err == nil {
|
||||
return ioutil.ReadAll(fd)
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
Reference in a new issue