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
··· 202 exp int64 203 lxm string 204 dev bool 205 } 206 207 type ServiceClientOpt func(*ServiceClientOpts) 208 209 func WithService(service string) ServiceClientOpt { 210 return func(s *ServiceClientOpts) { ··· 233 } 234 } 235 236 func (s *ServiceClientOpts) Audience() string { 237 return fmt.Sprintf("did:web:%s", s.service) 238 } ··· 247 } 248 249 func (o *OAuth) ServiceClient(r *http.Request, os ...ServiceClientOpt) (*xrpc.Client, error) { 250 - opts := ServiceClientOpts{} 251 for _, o := range os { 252 o(&opts) 253 } ··· 274 }, 275 Host: opts.Host(), 276 Client: &http.Client{ 277 - Timeout: time.Second * 5, 278 }, 279 }, nil 280 }
··· 202 exp int64 203 lxm string 204 dev bool 205 + timeout time.Duration 206 } 207 208 type ServiceClientOpt func(*ServiceClientOpts) 209 + 210 + func DefaultServiceClientOpts() ServiceClientOpts { 211 + return ServiceClientOpts{ 212 + timeout: time.Second * 5, 213 + } 214 + } 215 216 func WithService(service string) ServiceClientOpt { 217 return func(s *ServiceClientOpts) { ··· 240 } 241 } 242 243 + func WithTimeout(timeout time.Duration) ServiceClientOpt { 244 + return func(s *ServiceClientOpts) { 245 + s.timeout = timeout 246 + } 247 + } 248 + 249 func (s *ServiceClientOpts) Audience() string { 250 return fmt.Sprintf("did:web:%s", s.service) 251 } ··· 260 } 261 262 func (o *OAuth) ServiceClient(r *http.Request, os ...ServiceClientOpt) (*xrpc.Client, error) { 263 + opts := DefaultServiceClientOpts() 264 for _, o := range os { 265 o(&opts) 266 } ··· 287 }, 288 Host: opts.Host(), 289 Client: &http.Client{ 290 + Timeout: opts.timeout, 291 }, 292 }, nil 293 }
+2
appview/repo/repo.go
··· 1130 } 1131 defer rollback() 1132 1133 client, err := rp.oauth.ServiceClient( 1134 r, 1135 oauth.WithService(targetKnot), 1136 oauth.WithLxm(tangled.RepoCreateNSID), 1137 oauth.WithDev(rp.config.Core.Dev), 1138 ) 1139 if err != nil { 1140 l.Error("could not create service client", "err", err)
··· 1130 } 1131 defer rollback() 1132 1133 + // TODO: this could coordinate better with the knot to recieve a clone status 1134 client, err := rp.oauth.ServiceClient( 1135 r, 1136 oauth.WithService(targetKnot), 1137 oauth.WithLxm(tangled.RepoCreateNSID), 1138 oauth.WithDev(rp.config.Core.Dev), 1139 + oauth.WithTimeout(time.Second*20), // big repos take time to clone 1140 ) 1141 if err != nil { 1142 l.Error("could not create service client", "err", err)