Skip to content
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

Azure: Populate cloud.account.name with DisplayName #1396

Merged
merged 3 commits into from
Oct 10, 2023

Conversation

orestisfl
Copy link
Contributor

@orestisfl orestisfl commented Oct 4, 2023

Summary of your changes

Changes provider initialization to map subscription ids to names

Screenshot/Data

image

Related Issues

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary README/documentation (if appropriate)

@orestisfl orestisfl self-assigned this Oct 4, 2023
@orestisfl orestisfl marked this pull request as ready for review October 4, 2023 15:18
@orestisfl orestisfl requested a review from a team as a code owner October 4, 2023 15:18
@github-actions
Copy link

github-actions bot commented Oct 4, 2023

📊 Allure Report - 💚 No failures were reported.

Result Count
🟥 Failed 0
🟩 Passed 38
⬜ Skipped 1

@@ -108,10 +110,10 @@ func (p *ProviderInitializer) Init(ctx context.Context, log *logp.Logger, azureC
}, nil
}

func (p *ProviderInitializer) getSubscriptionIds(ctx context.Context, azureConfig auth.AzureFactoryConfig) ([]*string, error) {
func (p *ProviderInitializer) getSubscriptionIds(ctx context.Context, azureConfig auth.AzureFactoryConfig) (map[string]string, error) {
// TODO: mockable
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this TODO still relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes 👍 we are missing tests for these paths (whole Init())


func (p *Provider) getAssetFromData(data map[string]any) AzureAsset {
subId := getString(data, "subscriptionId")
properties, _ := data["properties"].(map[string]any)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have error handling if type assertions fail here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much we can do if these are missing since that would either mean the specific asset doesn't have "properties" (I don't know if that's possible) or the output was malformed. Since the code was just moved around, I'd argue to keep the code as is for now and decide on what to do for these cases (also for getString which ignores missing values / wrong types).

The code is safe from panics.

if subscription != nil {
result = append(result, subscription.SubscriptionID)
if subscription != nil && subscription.SubscriptionID != nil {
result[*subscription.SubscriptionID] = strings.Dereference(subscription.DisplayName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this lead to a panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I check the subscription.SubscriptionID for nilness in the if above

@@ -28,6 +28,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions"
"github.com/elastic/elastic-agent-libs/logp"
"github.com/samber/lo"
"golang.org/x/exp/maps"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orestisfl orestisfl enabled auto-merge (squash) October 10, 2023 10:12
@orestisfl orestisfl merged commit 5d8738c into elastic:main Oct 10, 2023
26 checks passed
mergify bot pushed a commit that referenced this pull request Oct 10, 2023
Changes provider initialization to map subscription ids to names

(cherry picked from commit 5d8738c)
orestisfl added a commit that referenced this pull request Oct 10, 2023
…yName (#1403)

Azure: Populate cloud.account.name with DisplayName (#1396)

Changes provider initialization to map subscription ids to names

(cherry picked from commit 5d8738c)

Co-authored-by: Orestis Floros <orestis.floros@elastic.co>
@orestisfl orestisfl deleted the 1395/sub-name branch November 14, 2023 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CIS Azure] Use human-friendly subscription name in ECS fields
3 participants