From 5ec91024656c02cdb8d06a7bc67c6b6dd742faa3 Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Sun, 19 Nov 2023 19:31:26 +0530 Subject: [PATCH] fix: azure config handling reference --- scrapers/azure/azure.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scrapers/azure/azure.go b/scrapers/azure/azure.go index 4e4bfb43..3a0e2cd1 100644 --- a/scrapers/azure/azure.go +++ b/scrapers/azure/azure.go @@ -35,39 +35,40 @@ func (azure Scraper) CanScrape(configs v1.ScraperSpec) bool { // HydrateConnection populates the credentials in Azure from the connection name (if available) // else it'll try to fetch the credentials from kubernetes secrets. -func (azure Scraper) hydrateConnection(ctx api.ScrapeContext, t v1.Azure) error { +func (azure Scraper) hydrateConnection(ctx api.ScrapeContext, t v1.Azure) (v1.Azure, error) { if t.ConnectionName != "" { connection, err := ctx.HydrateConnection(t.ConnectionName) if err != nil { - return fmt.Errorf("could not hydrate connection: %w", err) + return t, fmt.Errorf("could not hydrate connection: %w", err) } else if connection == nil { - return fmt.Errorf("connection %s not found", t.ConnectionName) + return t, fmt.Errorf("connection %s not found", t.ConnectionName) } t.ClientID.ValueStatic = connection.Username t.ClientSecret.ValueStatic = connection.Password t.TenantID = connection.Properties["tenant"] - return nil + return t, nil } var err error t.ClientID.ValueStatic, err = ctx.GetEnvValueFromCache(t.ClientID) if err != nil { - return fmt.Errorf("failed to get client id: %w", err) + return t, fmt.Errorf("failed to get client id: %w", err) } t.ClientSecret.ValueStatic, err = ctx.GetEnvValueFromCache(t.ClientSecret) if err != nil { - return fmt.Errorf("failed to get client secret: %w", err) + return t, fmt.Errorf("failed to get client secret: %w", err) } - return nil + return t, nil } func (azure Scraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResults { var results v1.ScrapeResults - for _, config := range ctx.ScrapeConfig().Spec.Azure { - if err := azure.hydrateConnection(ctx, config); err != nil { + for _, _config := range ctx.ScrapeConfig().Spec.Azure { + config, err := azure.hydrateConnection(ctx, _config) + if err != nil { results.Errorf(err, "failed to populate connection") continue }