Beispiel #1
0
func (s *svc) Endpoints() map[string]map[string]http.HandlerFunc {
	dirs := s.conf.GetDirectives()
	authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)

	return map[string]map[string]http.HandlerFunc{
		"/init": {
			"POST": authenticator.JWTHandlerFunc(s.Init),
		},
		"/examine/{path:.*}": {
			"GET": authenticator.JWTHandlerFunc(s.ExamineObject),
		},
		"/list/{path:.*}": {
			"GET": authenticator.JWTHandlerFunc(s.ListTree),
		},
		"/move/{path:.*}": {
			"POST": authenticator.JWTHandlerFunc(s.MoveObject),
		},
		"/delete/{path:.*}": {
			"DELETE": authenticator.JWTHandlerFunc(s.DeleteObject),
		},
		"/createtree/{path:.*}": {
			"POST": authenticator.JWTHandlerFunc(s.CreateTree),
		},
	}
}
Beispiel #2
0
// New returns a new Service.
func New(cfg *config.Config) (services.Service, error) {
	dirs := cfg.GetDirectives()
	authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)

	dataController, err := data.GetDataController(cfg)
	if err != nil {
		return nil, err
	}

	authenticationController, err := authentication.GetAuthenticationController(cfg)
	if err != nil {
		return nil, err
	}

	metaDataController, err := metadata.GetMetaDataController(cfg)
	if err != nil {
		return nil, err
	}

	if err := os.MkdirAll(dirs.OCWebDAV.ChunksNamespace, 0755); err != nil {
		return nil, err
	}

	if err := os.MkdirAll(dirs.OCWebDAV.ChunksTemporaryNamespace, 0755); err != nil {
		return nil, err
	}

	return &svc{conf: cfg, authenticator: authenticator, dataController: dataController, metaDataController: metaDataController, authenticationController: authenticationController}, nil
}
Beispiel #3
0
func (o *testObject) loadDirs(t *testing.T, dirs *config.Directives) {
	o.mockSource.On("LoadDirectives").Return(dirs, nil)
	err := o.conf.LoadDirectives()
	require.Nil(t, err)

	// Create the token
	authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)
	token, err := authenticator.CreateToken(o.user)
	require.Nil(t, err)
	o.jwtToken = token
}
Beispiel #4
0
// New returns an AuthenticationControler that
// stores users in memory. This controller is for testing purposes.
func New(conf *config.Config) (authenticationcontroller.AuthenticationController, error) {
	dirs := conf.GetDirectives()
	authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)

	users, err := decodeUsers(dirs.Authentication.Memory.Users)
	if err != nil {
		return nil, err
	}

	return &controller{
		users:         users,
		authenticator: authenticator,
	}, nil
}
Beispiel #5
0
// Endpoints is a listing of all endpoints available in the svc.
func (s *svc) Endpoints() map[string]map[string]http.HandlerFunc {
	dirs := s.conf.GetDirectives()
	authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)
	return map[string]map[string]http.HandlerFunc{
		"/metrics": {
			"GET": func(w http.ResponseWriter, r *http.Request) {
				prometheus.Handler().ServeHTTP(w, r)
			},
		},
		"/upload/{path:.*}": {
			"PUT": prometheus.InstrumentHandlerFunc("/upload", authenticator.JWTHandlerFunc(s.Upload)),
		},
		"/download/{path:.*}": {
			"GET": prometheus.InstrumentHandlerFunc("/download", authenticator.JWTHandlerFunc(s.Download)),
		},
	}
}
Beispiel #6
0
// New returns an AuthenticationControler that uses a SQL database for handling
// users and JWT for tokens.
func New(conf *config.Config) (authenticationcontroller.AuthenticationController, error) {
	dirs := conf.GetDirectives()
	authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)
	db, err := gorm.Open(dirs.Authentication.SQL.Driver, dirs.Authentication.SQL.DSN)
	if err != nil {
		return nil, err
	}
	err = db.AutoMigrate(&userRecord{}).Error
	if err != nil {
		return nil, err
	}

	return &controller{
		conf:          conf,
		db:            db,
		authenticator: authenticator,
	}, nil
}
Beispiel #7
0
// Endpoints is a listing of all endpoints available in the Mixedsvc.
func (s *svc) Endpoints() map[string]map[string]http.HandlerFunc {
	dirs := s.conf.GetDirectives()
	authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)

	return map[string]map[string]http.HandlerFunc{
		"/metrics": {
			"GET": func(w http.ResponseWriter, r *http.Request) {
				prometheus.Handler().ServeHTTP(w, r)
			},
		},
		"/token": {
			"POST": prometheus.InstrumentHandlerFunc("/token", s.Token),
		},
		"/ping": {
			"GET": prometheus.InstrumentHandlerFunc("/ping", authenticator.JWTHandlerFunc(s.Ping)),
		},
	}
}
Beispiel #8
0
// New returns a new Service.
func New(cfg *config.Config) (services.Service, error) {
	dirs := cfg.GetDirectives()
	authenticator := lib.NewAuthenticator(dirs.Server.JWTSecret, dirs.Server.JWTSigningMethod)

	dataController, err := data.GetDataController(cfg)
	if err != nil {
		return nil, err
	}

	authenticationController, err := authentication.GetAuthenticationController(cfg)
	if err != nil {
		return nil, err
	}

	metaDataController, err := metadata.GetMetaDataController(cfg)
	if err != nil {
		return nil, err
	}

	return &svc{conf: cfg, authenticator: authenticator, dataController: dataController, metaDataController: metaDataController, authenticationController: authenticationController}, nil
}