this is tuto1
This commit is contained in:
parent
9eaa2bf4e8
commit
9262917553
19 changed files with 928 additions and 68 deletions
|
@ -24,14 +24,15 @@ var AuthorizedKeysLocation = "/root/.ssh/authorized_keys"
|
|||
var SshPiperLocation = "/var/sshpiper/"
|
||||
|
||||
func init() {
|
||||
router.GET("/sshkeys/", apiHandler(
|
||||
router.GET("/sshkeys", apiHandler(
|
||||
func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return getStudentKeys()
|
||||
}))
|
||||
router.POST("/sshkeys/", rawHandler(receiveKey))
|
||||
router.POST("/sshkeys", rawHandler(receiveKey))
|
||||
router.GET("/sshkeys/authorizedkeys", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
dumpAuthorizedKeysFile(w)
|
||||
})
|
||||
router.GET("/api/students/:sid/hassshkeys", apiHandler(studentHandler(hasSSHKeys)))
|
||||
router.GET("/api/students/:sid/authorizedkeys", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
if sid, err := strconv.Atoi(string(ps.ByName("sid"))); err != nil {
|
||||
if student, err := getStudentByLogin(ps.ByName("sid")); err != nil {
|
||||
|
@ -48,6 +49,14 @@ func init() {
|
|||
})
|
||||
}
|
||||
|
||||
func hasSSHKeys(student Student, body []byte) (interface{}, error) {
|
||||
if keys, err := student.getKeys(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return len(keys) > 0, nil
|
||||
}
|
||||
}
|
||||
|
||||
type StudentKey struct {
|
||||
Id int64 `json:"id"`
|
||||
IdStudent int64 `json:"id_student"`
|
||||
|
@ -201,7 +210,7 @@ func receiveKey(r *http.Request, ps httprouter.Params, body []byte) (interface{}
|
|||
return nil, errors.New("This is not the expected token.")
|
||||
}
|
||||
|
||||
if _, err := std.NewKey(gt.Data[1]); err != nil {
|
||||
if _, err := std.NewKey(gt.Data[0] + " " + gt.Data[1]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue