-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: simplify ancla setup and startup #599
refactor: simplify ancla setup and startup #599
Conversation
- simplify ancla setup and startup with `anclafx.Provide()`
webhookConfig := in.WebhookConfig | ||
webhookConfig.Logger = in.Logger | ||
listenerMeasures := ancla.ListenerConfig{ | ||
Measures: *in.Measures, | ||
} | ||
webhookConfig.BasicClientConfig.HTTPClient = newHTTPClient(in.ArgusClientTimeout, in.Tracing) | ||
|
||
svc, err := ancla.NewService(webhookConfig, sallust.Get) | ||
if err != nil { | ||
return out, fmt.Errorf("failed to initialize webhook service: %s", err) | ||
} | ||
out.GetAllWebhooksHandler = ancla.NewGetAllWebhooksHandler(in.AnclaSvc, ancla.HandlerConfig{}) | ||
|
||
stopWatches, err := svc.StartListener(listenerMeasures, sallust.With) | ||
if err != nil { | ||
return out, fmt.Errorf("webhook service start listener error: %s", err) | ||
} | ||
in.Logger.Info("Webhook service enabled") | ||
|
||
in.Lifecycle.Append(fx.Hook{ | ||
OnStop: func(_ context.Context) error { | ||
stopWatches() | ||
return nil | ||
}, | ||
}) | ||
|
||
out.GetAllWebhooksHandler = ancla.NewGetAllWebhooksHandler(svc, ancla.HandlerConfig{ | ||
GetLogger: sallust.Get, | ||
}) | ||
|
||
checker, err := webhookConfig.Validation.BuildURLChecker() | ||
checker, err := ancla.BuildURLChecker(in.WebhookConfig.Validation) | ||
if err != nil { | ||
return out, fmt.Errorf("failed to set up url checker for validation: %s", err) | ||
} | ||
validationOpts := webhookConfig.Validation.BuildOptions(checker) | ||
|
||
out.AddWebhookHandler = ancla.NewAddWebhookHandler(svc, ancla.HandlerConfig{ | ||
V: validationOpts, | ||
DisablePartnerIDs: webhookConfig.DisablePartnerIDs, | ||
GetLogger: sallust.Get, | ||
out.AddWebhookHandler = ancla.NewAddWebhookHandler(in.AnclaSvc, ancla.HandlerConfig{ | ||
V: in.WebhookConfig.Validation.BuildOptions(checker), | ||
DisablePartnerIDs: in.WebhookConfig.DisablePartnerIDs, | ||
}) | ||
|
||
v2Validators, err := v2WebhookValidators(webhookConfig) | ||
v2Validators, err := v2WebhookValidators(in.WebhookConfig) | ||
if err != nil { | ||
return out, fmt.Errorf("failed to setup v2 webhook validators: %s", err) | ||
} | ||
|
||
out.V2AddWebhookHandler = ancla.NewAddWebhookHandler(svc, ancla.HandlerConfig{ | ||
out.V2AddWebhookHandler = ancla.NewAddWebhookHandler(in.AnclaSvc, ancla.HandlerConfig{ | ||
V: v2Validators, | ||
DisablePartnerIDs: webhookConfig.DisablePartnerIDs, | ||
GetLogger: sallust.Get, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be taken care of by anclafx.Provide()
pending potential changes from xmidt-org/ancla#269 |
cfd4dc9
to
0a89a21
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/caduceus-updates #599 +/- ##
========================================================
Coverage ? 43.36%
========================================================
Files ? 16
Lines ? 1229
Branches ? 0
========================================================
Hits ? 533
Misses ? 684
Partials ? 12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
anclafx.Provide()