appview/oauth: allow customizing client timeouts in xrpc reqs #840

closed
opened by oppi.li targeting master from op/tzszvtloukvm
Changed files
+17 -2
appview
oauth
repo
+15 -2
appview/oauth/oauth.go
···
exp int64
lxm string
dev bool
}
type ServiceClientOpt func(*ServiceClientOpts)
func WithService(service string) ServiceClientOpt {
return func(s *ServiceClientOpts) {
···
}
}
func (s *ServiceClientOpts) Audience() string {
return fmt.Sprintf("did:web:%s", s.service)
}
···
}
func (o *OAuth) ServiceClient(r *http.Request, os ...ServiceClientOpt) (*xrpc.Client, error) {
-
opts := ServiceClientOpts{}
for _, o := range os {
o(&opts)
}
···
},
Host: opts.Host(),
Client: &http.Client{
-
Timeout: time.Second * 5,
},
}, nil
}
···
exp int64
lxm string
dev bool
+
timeout time.Duration
}
type ServiceClientOpt func(*ServiceClientOpts)
+
+
func DefaultServiceClientOpts() ServiceClientOpts {
+
return ServiceClientOpts{
+
timeout: time.Second * 5,
+
}
+
}
func WithService(service string) ServiceClientOpt {
return func(s *ServiceClientOpts) {
···
}
}
+
func WithTimeout(timeout time.Duration) ServiceClientOpt {
+
return func(s *ServiceClientOpts) {
+
s.timeout = timeout
+
}
+
}
+
func (s *ServiceClientOpts) Audience() string {
return fmt.Sprintf("did:web:%s", s.service)
}
···
}
func (o *OAuth) ServiceClient(r *http.Request, os ...ServiceClientOpt) (*xrpc.Client, error) {
+
opts := DefaultServiceClientOpts()
for _, o := range os {
o(&opts)
}
···
},
Host: opts.Host(),
Client: &http.Client{
+
Timeout: opts.timeout,
},
}, nil
}
+2
appview/repo/repo.go
···
}
defer rollback()
client, err := rp.oauth.ServiceClient(
r,
oauth.WithService(targetKnot),
oauth.WithLxm(tangled.RepoCreateNSID),
oauth.WithDev(rp.config.Core.Dev),
)
if err != nil {
l.Error("could not create service client", "err", err)
···
}
defer rollback()
+
// TODO: this could coordinate better with the knot to recieve a clone status
client, err := rp.oauth.ServiceClient(
r,
oauth.WithService(targetKnot),
oauth.WithLxm(tangled.RepoCreateNSID),
oauth.WithDev(rp.config.Core.Dev),
+
oauth.WithTimeout(time.Second*20), // big repos take time to clone
)
if err != nil {
l.Error("could not create service client", "err", err)