MCPcopy
hub / github.com/grpc/grpc-go / NewFileWatcher

Function NewFileWatcher

authz/grpc_authz_server_interceptors.go:105–121  ·  view source on GitHub ↗

NewFileWatcher returns a new FileWatcherInterceptor from a policy file that contains JSON string of authorization policy and a refresh duration to specify the amount of time between policy refreshes.

(file string, duration time.Duration)

Source from the content-addressed store, hash-verified

103// that contains JSON string of authorization policy and a refresh duration to
104// specify the amount of time between policy refreshes.
105func NewFileWatcher(file string, duration time.Duration) (*FileWatcherInterceptor, error) {
106 if file == "" {
107 return nil, fmt.Errorf("authorization policy file path is empty")
108 }
109 if duration <= time.Duration(0) {
110 return nil, fmt.Errorf("requires refresh interval(%v) greater than 0s", duration)
111 }
112 i := &FileWatcherInterceptor{policyFile: file, refreshDuration: duration}
113 if err := i.updateInternalInterceptor(); err != nil {
114 return nil, err
115 }
116 ctx, cancel := context.WithCancel(context.Background())
117 i.cancel = cancel
118 // Create a background go routine for policy refresh.
119 go i.run(ctx)
120 return i, nil
121}
122
123func (i *FileWatcherInterceptor) run(ctx context.Context) {
124 ticker := time.NewTicker(i.refreshDuration)

Calls 3

runMethod · 0.95
ErrorfMethod · 0.65