コード例 #1
0
ファイル: redis_based.go プロジェクト: jonasfj/leaps
/*
NewRedis - Creates a Redis using the provided configuration.
*/
func NewRedis(config Config, logger *log.Logger) *Redis {
	return &Redis{
		logger: logger.NewModule(":redis_auth"),
		config: config,
		pool:   newPool(config.RedisConfig),
	}
}
コード例 #2
0
ファイル: file_based.go プロジェクト: jonasfj/leaps
/*
NewFile - Creates an File using the provided configuration.
*/
func NewFile(config Config, logger *log.Logger) *File {
	fa := File{
		logger: logger.NewModule(":fs_auth"),
		config: config,
		paths:  []string{},
		mutex:  &sync.RWMutex{},
	}
	go fa.loop()
	return &fa
}
コード例 #3
0
ファイル: websocket_server.go プロジェクト: jonasfj/leaps
/*
NewWebsocketServer - Creates a new HTTP websocket client.
*/
func NewWebsocketServer(
	config HTTPBinderConfig,
	socket *websocket.Conn,
	binder lib.BinderPortal,
	closeChan <-chan bool,
	logger *log.Logger,
	stats *log.Stats,
) *WebsocketServer {
	return &WebsocketServer{
		config:    config,
		socket:    socket,
		binder:    binder,
		closeChan: closeChan,
		logger:    logger.NewModule(":socket"),
		stats:     stats,
	}
}
コード例 #4
0
ファイル: http_based.go プロジェクト: jonasfj/leaps
/*
NewHTTP - Creates an HTTP using the provided configuration.
*/
func NewHTTP(config Config, logger *log.Logger, stats *log.Stats) *HTTP {
	authorizer := HTTP{
		logger: logger.NewModule(":http_auth"),
		stats:  stats,
		config: config,
		mutex:  sync.RWMutex{},

		tokensCreate:   tokensMap{},
		tokensJoin:     tokensMap{},
		tokensReadOnly: tokensMap{},
	}

	authorizer.createHandler = authorizer.createGenerateTokenHandler(authorizer.tokensCreate)
	authorizer.joinHandler = authorizer.createGenerateTokenHandler(authorizer.tokensJoin)
	authorizer.readOnlyHandler = authorizer.createGenerateTokenHandler(authorizer.tokensReadOnly)

	return &authorizer
}
コード例 #5
0
ファイル: auth_middleware.go プロジェクト: jonasfj/leaps
/*
NewAuthMiddleware - Create a new leaps AuthMiddleware.
*/
func NewAuthMiddleware(
	config AuthMiddlewareConfig,
	logger *log.Logger,
	stats *log.Stats,
) (*AuthMiddleware, error) {
	auth := AuthMiddleware{
		config:   config,
		accounts: map[string]string{},
		logger:   logger.NewModule(":basic_auth"),
		stats:    stats,
	}
	if config.Enabled {
		if 0 == len(config.PasswdFilePath) {
			return nil, ErrInvalidHtpasswdPath
		}
		if err := auth.accountsFromFile(config.PasswdFilePath); err != nil {
			return nil, fmt.Errorf("htpasswd file read error: %v", err)
		}
	}
	return &auth, nil
}
コード例 #6
0
ファイル: internal_server.go プロジェクト: jonasfj/leaps
/*
NewInternalServer - Create a new leaps InternalServer.
*/
func NewInternalServer(
	admin LeapAdmin,
	config InternalServerConfig,
	logger *log.Logger,
	stats *log.Stats,
) (*InternalServer, error) {
	auth, err := NewAuthMiddleware(config.HTTPAuth, logger, stats)
	if err != nil {
		return nil, err
	}
	httpServer := InternalServer{
		config: config,
		admin:  admin,
		logger: logger.NewModule(":http_admin"),
		stats:  stats,
		mux:    http.NewServeMux(),
		auth:   auth,
	}

	// Register handling for static files
	if len(httpServer.config.StaticFilePath) > 0 {
		if len(httpServer.config.Path) == 0 {
			return nil, ErrInvalidStaticPath
		}
		// If the static file path is relative then we use the location of the binary to resolve it.
		if err := binpath.FromBinaryIfRelative(&httpServer.config.StaticFilePath); err != nil {
			return nil, fmt.Errorf("relative path for static files could not be resolved: %v", err)
		}
		httpServer.mux.Handle(httpServer.config.Path,
			httpServer.auth.WrapHandler( // Auth wrap
				http.StripPrefix(httpServer.config.Path, // File strip prefix wrap
					http.FileServer(http.Dir(httpServer.config.StaticFilePath))))) // File serve handler
	}

	httpServer.registerEndpoints()

	return &httpServer, nil
}
コード例 #7
0
ファイル: curator.go プロジェクト: varver/leaps
/*
NewCurator - Creates and returns a fresh curator, and launches its internal loop.
*/
func NewCurator(
	config CuratorConfig,
	log *log.Logger,
	stats *log.Stats,
	auth auth.Authenticator,
	store store.Store,
) (*Curator, error) {

	curator := Curator{
		config:        config,
		store:         store,
		log:           log.NewModule(":curator"),
		stats:         stats,
		authenticator: auth,
		openBinders:   make(map[string]*Binder),
		errorChan:     make(chan BinderError, 10),
		closeChan:     make(chan struct{}),
		closedChan:    make(chan struct{}),
	}
	go curator.loop()

	return &curator, nil
}
コード例 #8
0
ファイル: binder.go プロジェクト: varver/leaps
/*
NewBinder - Creates a binder targeting an existing document determined via an ID. Must provide a
store.Store to acquire the document and apply future updates to.
*/
func NewBinder(
	id string,
	block store.Store,
	config BinderConfig,
	errorChan chan<- BinderError,
	log *log.Logger,
	stats *log.Stats,
) (*Binder, error) {

	binder := Binder{
		ID:               id,
		config:           config,
		model:            CreateTextModel(config.ModelConfig),
		block:            block,
		log:              log.NewModule(":binder"),
		stats:            stats,
		clients:          make(map[string]BinderClient),
		subscribeChan:    make(chan BinderSubscribeBundle),
		transformChan:    make(chan TransformSubmission),
		messageChan:      make(chan MessageSubmission),
		usersRequestChan: make(chan usersRequestObj),
		exitChan:         make(chan string),
		errorChan:        errorChan,
		closedChan:       make(chan struct{}),
	}
	binder.log.Debugln("Bound to document, attempting flush")

	if _, err := binder.flush(); err != nil {
		stats.Incr("binder.new.error", 1)
		return nil, err
	}
	go binder.loop()

	stats.Incr("binder.new.success", 1)
	return &binder, nil
}