Пример #1
0
func configureAuth(s *server.Server, opts *server.Options) {
	// Client
	// Check for multiple users first
	if opts.Users != nil {
		auth := auth.NewMultiUser(opts.Users)
		s.SetClientAuthMethod(auth)
	} else if opts.Username != "" {
		auth := &auth.Plain{
			Username: opts.Username,
			Password: opts.Password,
		}
		s.SetClientAuthMethod(auth)
	} else if opts.Authorization != "" {
		auth := &auth.Token{
			Token: opts.Authorization,
		}
		s.SetClientAuthMethod(auth)
	}
	// Routes
	if opts.ClusterUsername != "" {
		auth := &auth.Plain{
			Username: opts.ClusterUsername,
			Password: opts.ClusterPassword,
		}
		s.SetRouteAuthMethod(auth)
	}
}
Пример #2
0
func configureAuth(s *server.Server, opts *server.Options) {
	// Client
	if opts.Username != "" {
		auth := &auth.Plain{
			Username: opts.Username,
			Password: opts.Password,
		}
		s.SetClientAuthMethod(auth)
	} else if opts.Authorization != "" {
		auth := &auth.Token{
			Token: opts.Authorization,
		}
		s.SetClientAuthMethod(auth)
	}
	// Routes
	if opts.ClusterUsername != "" {
		auth := &auth.Plain{
			Username: opts.ClusterUsername,
			Password: opts.ClusterPassword,
		}
		s.SetRouteAuthMethod(auth)
	}
}