You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using etcd, user password authentication is used, but in the current version, I don't see Settings for this part of the configuration, so my current solution is to add a new profile constructor.
The following code is shown:
1.New configuration
type WatcherConfig struct {
Hosts []string
Key string `json:",default=casbin_watcher"`
User string
Pass string
DialKeepAliveTimeout time.Duration `json:",default=10"`
DialTimeout time.Duration `json:",default=30"`
}
2.Added configuration-based constructors
// NewWatcherWithConfig is a configurable Watcher constructor
func NewWatcherWithConfig(config WatcherConfig) (persist.Watcher, error) {
w := &Watcher{}
w.running = true
w.callback = nil
w.conf = &config
// Create the client.
err := w.createClient()
if err != nil {
return nil, err
}
// Call the destructor when the object is released.
runtime.SetFinalizer(w, finalizer)
go func() {
_ = w.startWatch()
}()
return w, nil
}
3.Adjust the createClient method
func (w *Watcher) createClient() error {
cfg := client.Config{
Endpoints: w.endpoints,
// set timeout per request to fail fast when the target endpoints is unavailable
DialKeepAliveTimeout: time.Second * 10,
DialTimeout: time.Second * 30,
Password: w.password,
}
if w.conf != nil {
cfg = client.Config{
Endpoints: w.conf.Hosts,
// set timeout per request to fail fast when the target endpoints is unavailable
DialTimeout: time.Second * w.conf.DialTimeout,
DialKeepAliveTimeout: time.Second * w.conf.DialKeepAliveTimeout,
Username: w.conf.User,
Password: w.conf.Pass,
}
}
c, err := client.New(cfg)
if err != nil {
return err
}
w.client = c
return nil
}
The text was updated successfully, but these errors were encountered:
When using etcd, user password authentication is used, but in the current version, I don't see Settings for this part of the configuration, so my current solution is to add a new profile constructor.
The following code is shown:
1.New configuration
2.Added configuration-based constructors
3.Adjust the createClient method
The text was updated successfully, but these errors were encountered: