Skip to content

Commit

Permalink
add DependenciesFunc to get service erda.oap.collector.authentication…
Browse files Browse the repository at this point in the history
….Validator

Signed-off-by: Ash <[email protected]>
  • Loading branch information
iutx committed Sep 23, 2024
1 parent 69a91ab commit b975928
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@ var _ model.Receiver = (*provider)(nil)
type provider struct {
Cfg *config
Log logs.Logger
Router httpserver.Router `autowired:"http-router"`
Validator authentication.Validator `autowired:"erda.oap.collector.authentication.Validator"`
Router httpserver.Router `autowired:"http-router"`
Validator authentication.Validator

auth *Authenticator
consumer model.ObservableDataConsumerFunc
}

type skipValidator struct{}

func (skipValidator) Validate(scope string, scopeId string, token string) bool {
return true
}

func (p *provider) ComponentClose() error {
return nil
}
Expand All @@ -62,6 +68,11 @@ func (p *provider) RegisterConsumer(consumer model.ObservableDataConsumerFunc) {

// Run this is optional
func (p *provider) Init(ctx servicehub.Context) error {
if p.Cfg.Auth.Skip {
p.Validator = skipValidator{}
} else {
p.Validator = ctx.Service("erda.oap.collector.authentication.Validator").(authentication.Validator)
}
p.auth = NewAuthenticator(
WithLogger(p.Log),
WithValidator(p.Validator),
Expand All @@ -84,6 +95,15 @@ func init() {
servicehub.Register(providerName, &servicehub.Spec{
Services: []string{providerName},
Description: "here is description of erda.oap.collector.receiver.collector",
DependenciesFunc: func(hub *servicehub.Hub) (list []string) {
hub.ForeachServices(func(service string) bool {
if service == "erda.oap.collector.authentication.Validator" {
list = append(list, service)

Check warning on line 101 in internal/tools/monitor/oap/collector/plugins/receivers/collector/provider.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/monitor/oap/collector/plugins/receivers/collector/provider.go#L99-L101

Added lines #L99 - L101 were not covered by tests
}
return true

Check warning on line 103 in internal/tools/monitor/oap/collector/plugins/receivers/collector/provider.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/monitor/oap/collector/plugins/receivers/collector/provider.go#L103

Added line #L103 was not covered by tests
})
return list

Check warning on line 105 in internal/tools/monitor/oap/collector/plugins/receivers/collector/provider.go

View check run for this annotation

Codecov / codecov/patch

internal/tools/monitor/oap/collector/plugins/receivers/collector/provider.go#L105

Added line #L105 was not covered by tests
},
ConfigFunc: func() interface{} {
return &config{}
},
Expand Down

0 comments on commit b975928

Please sign in to comment.