コード例 #1
0
ファイル: accessmanager.go プロジェクト: mley/guble
func (am RestAccessManager) AccessAllowed(accessType AccessType, userId string, path guble.Path) bool {

	u, _ := url.Parse(string(am))
	q := u.Query()
	if accessType == READ {
		q.Set("type", "read")
	} else {
		q.Set("type", "write")
	}

	q.Set("userId", userId)
	q.Set("path", string(path))

	resp, err := http.DefaultClient.Get(u.String())

	if err != nil {
		guble.Warn("RestAccessManager: %v", err)
		return false
	}
	defer resp.Body.Close()
	responseBody, err := ioutil.ReadAll(resp.Body)

	if err != nil || resp.StatusCode != 200 {
		guble.Info("error getting permission", err)
		guble.Debug("error getting permission", responseBody)
		return false
	}

	guble.Debug("RestAccessManager: %v, %v, %v, %v", accessType, userId, path, string(responseBody))

	return "true" == string(responseBody)

}
コード例 #2
0
ファイル: router.go プロジェクト: tkrille/guble
func (router *PubSubRouter) HandleMessage(message *guble.Message) error {
	if float32(len(router.messageIn))/float32(cap(router.messageIn)) > 0.9 {
		guble.Warn("router.messageIn channel very full: current=%v, max=%v\n", len(router.messageIn), cap(router.messageIn))
		time.Sleep(time.Millisecond)
	}
	router.messageIn <- message
	return nil
}
コード例 #3
0
ファイル: websocket_connector.go プロジェクト: mley/guble
func (factory *WSHandlerFactory) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	c, err := webSocketUpgrader.Upgrade(w, r, nil)
	if err != nil {
		guble.Warn("error on upgrading %v", err.Error())
		return
	}
	defer c.Close()

	_ = NewWSHandler(factory.Router, factory.MessageSink, factory.messageStore, &wsconn{c}, extractUserId(r.RequestURI), factory.accessManager).
		Start()
}
コード例 #4
0
ファイル: router.go プロジェクト: mley/guble
func (router *PubSubRouter) HandleMessage(message *guble.Message) error {
	guble.Debug("Route.HandleMessage: %v %v", message.PublisherUserId, message.Path)
	if !router.accessManager.AccessAllowed(WRITE, message.PublisherUserId, message.Path) {
		return errors.New("User not allowed to post message to topic.")
	}

	if float32(len(router.messageIn))/float32(cap(router.messageIn)) > 0.9 {
		guble.Warn("router.messageIn channel very full: current=%v, max=%v\n", len(router.messageIn), cap(router.messageIn))
		time.Sleep(time.Millisecond)
	}
	router.messageIn <- message
	return nil
}