Adding acls to websocket, using right context.

This commit is contained in:
Alain Jobart 2016-10-05 07:17:09 -07:00
Родитель ae3e1df224
Коммит 04705ea76b
1 изменённых файлов: 13 добавлений и 1 удалений

Просмотреть файл

@ -1,12 +1,15 @@
package workflow
import (
"context"
"encoding/json"
"fmt"
"net/http"
log "github.com/golang/glog"
"github.com/gorilla/websocket"
"golang.org/x/net/context"
"github.com/youtube/vitess/go/acl"
)
var upgrader = websocket.Upgrader{} // use default options
@ -15,6 +18,15 @@ var upgrader = websocket.Upgrader{} // use default options
func (m *Manager) HandleHTTP(pattern string) {
log.Infof("workflow Manager listening to websocket traffic at %v", pattern)
http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
// Check ACL.
if err := acl.CheckAccessHTTP(r, acl.ADMIN); err != nil {
msg := fmt.Sprintf("WorkflowManager acl.CheckAccessHTTP failed: %v", err)
log.Error(msg)
http.Error(w, msg, http.StatusUnauthorized)
return
}
// Upgrade to WebSocket.
c, err := upgrader.Upgrade(w, r, nil)
if err != nil {
log.Errorf("upgrade error: %v", err)