Exemplo n.º 1
0
/*
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),
	}
}
Exemplo n.º 2
0
/*
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
}
Exemplo n.º 3
0
/*
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,
	}
}
Exemplo n.º 4
0
/*
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
}
Exemplo n.º 5
0
/*
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
}
Exemplo n.º 6
0
/*
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
}
Exemplo n.º 7
0
/*
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
}
Exemplo n.º 8
0
/*
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
}