Skip to content

Commit

Permalink
fix: azure config handling reference
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Nov 19, 2023
1 parent 58dcfb2 commit 5ec9102
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions scrapers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5ec9102

Please sign in to comment.