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

🐛 space and org data source #111

Merged
merged 2 commits into from
Jun 27, 2024

Conversation

mati007thm
Copy link
Contributor

@mati007thm mati007thm commented Jun 14, 2024

We found some errors when testing the space data source and fixed them in this pull request + some minor changes to the org data source

Signed-off-by: Matthias Theuermann <[email protected]>
@mati007thm mati007thm force-pushed the rework_space_org_data_sources branch from 9b64e0e to bec3f39 Compare June 14, 2024 07:07
@mati007thm mati007thm marked this pull request as ready for review June 14, 2024 07:08
Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

Thank you @mati007thm I added a few comments so that I can understand the change better.

internal/provider/organization_data_source.go Outdated Show resolved Hide resolved
internal/provider/organization_data_source.go Outdated Show resolved Hide resolved
internal/provider/organization_data_source.go Outdated Show resolved Hide resolved
internal/provider/space_data_source.go Outdated Show resolved Hide resolved
@mati007thm
Copy link
Contributor Author

mati007thm commented Jun 20, 2024

@chris-rock I looked over your comments and would like to clarify, why @Pauti and I made certain changes to the code:

As a user I would want to call the data source with either ID or MRN but never with both at the same time, because as a normal user I do not know which of the provided values the returned result would be based of.
Therefore we used data.OrgMrn.ValueString() != "" && data.OrgID.ValueString() == "" { to prevent the user from providing both values (like we did for the allow and deny lists in the azure integration).
This prevents situation like the following, where a user accidentally provides conflicting id and mrn:

data "mondoo_organization" "org" {
  id = "ID_FOR_ORG_X"
  mrn="MRN_FOR_ORG_Y" 
}

@chris-rock
Copy link
Member

chris-rock commented Jun 20, 2024

Thank you @mati007thm for the explanation. In this case we need a hack schema validation eg. as defined in #92 (comment). The problem with the current implementation in this PR is that it would check it at runtime and that is too late. Please switch it to validator check instead.

Signed-off-by: Matthias Theuermann <[email protected]>
@mati007thm
Copy link
Contributor Author

@chris-rock I added the suggested validations

Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

Thank you @mati007thm for adding the validators. Great addition.

@@ -92,9 +108,10 @@ func (d *SpaceDataSource) Read(ctx context.Context, req datasource.ReadRequest,
spaceMrn := ""
if data.SpaceMrn.ValueString() != "" {
spaceMrn = data.SpaceMrn.ValueString()
} else if data.SpaceMrn.ValueString() != "" {
spaceMrn = orgPrefix + data.SpaceID.ValueString()
} else if data.SpaceID.ValueString() != "" {
Copy link
Member

Choose a reason for hiding this comment

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

nice catch

@chris-rock chris-rock changed the title fix: space and org data source 🐛 space and org data source Jun 27, 2024
@chris-rock chris-rock merged commit f301797 into mondoohq:main Jun 27, 2024
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jun 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants