admin: new route and interface to manage symlink for team association exclusing certificates
This commit is contained in:
parent
2b95995104
commit
14d31737e0
6 changed files with 132 additions and 21 deletions
|
@ -52,6 +52,25 @@ func init() {
|
|||
}
|
||||
})))
|
||||
|
||||
router.GET("/api/teams/:tid/associations", apiHandler(teamHandler(
|
||||
func(team fic.Team, _ []byte) (interface{}, error) {
|
||||
return pki.GetTeamAssociations(TeamsDir, team.Id)
|
||||
})))
|
||||
router.POST("/api/teams/:tid/associations/:assoc", apiHandler(teamAssocHandler(
|
||||
func(team fic.Team, assoc string, _ []byte) (interface{}, error) {
|
||||
if err := os.Symlink(fmt.Sprintf("%d", team.Id), path.Join(TeamsDir, assoc)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return "\"" + assoc + "\"", nil
|
||||
})))
|
||||
router.DELETE("/api/teams/:tid/associations/:assoc", apiHandler(teamAssocHandler(
|
||||
func(team fic.Team, assoc string, _ []byte) (interface{}, error) {
|
||||
if err := os.Remove(path.Join(TeamsDir, assoc)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return "null", nil
|
||||
})))
|
||||
|
||||
router.GET("/api/certs/", apiHandler(getCertificates))
|
||||
router.POST("/api/certs/", apiHandler(generateClientCert))
|
||||
router.DELETE("/api/certs/", apiHandler(func(_ httprouter.Params, _ []byte) (interface{}, error) { return fic.ClearCertificates() }))
|
||||
|
|
|
@ -110,6 +110,19 @@ func teamHandler(f func(fic.Team, []byte) (interface{}, error)) func(httprouter.
|
|||
}
|
||||
}
|
||||
|
||||
func teamAssocHandler(f func(fic.Team, string, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
var team fic.Team
|
||||
|
||||
teamHandler(func (tm fic.Team, _ []byte) (interface{}, error) {
|
||||
team = tm
|
||||
return nil, nil
|
||||
})(ps, body)
|
||||
|
||||
return f(team, string(ps.ByName("assoc")), body)
|
||||
}
|
||||
}
|
||||
|
||||
func themeHandler(f func(fic.Theme, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
if thid, err := strconv.ParseInt(string(ps.ByName("thid")), 10, 64); err != nil {
|
||||
|
|
|
@ -180,7 +180,13 @@ func disableInactiveTeams(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if len(serials) == 0 {
|
||||
var assocs []string
|
||||
assocs, err = pki.GetTeamAssociations(TeamsDir, team.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(serials) == 0 && len(assocs) == 0 {
|
||||
if team.Active {
|
||||
team.Active = false
|
||||
team.Update()
|
||||
|
|
Reference in a new issue