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) } }
// RunServerWithConfig starts a new Go routine based server with a configuration file. func RunServerWithConfig(configFile string) (srv *server.Server, opts *server.Options) { opts = LoadConfig(configFile) // Check for auth var a server.Auth if opts.Authorization != "" { a = &auth.Token{Token: opts.Authorization} } if opts.Username != "" { a = &auth.Plain{Username: opts.Username, Password: opts.Password} } if opts.Users != nil { a = auth.NewMultiUser(opts.Users) } srv = RunServerWithAuth(opts, a) return }