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

Matthew john 1894 #1910

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions okta/data_source_okta_app_saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func dataSourceAppSamlRead(ctx context.Context, d *schema.ResourceData, m interf
app = respApp.(*sdk.SamlApplication)
} else {
re := getOktaClientFromMetadata(m).GetRequestExecutor()
qp := &query.Params{Limit: 1, Filter: filters.Status, Q: filters.getQ()}
qp := &query.Params{Filter: filters.Status, Q: filters.getQ()}
req, err := re.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/apps%s", qp.String()), nil)
if err != nil {
return diag.Errorf("failed to list SAML apps: %v", err)
Expand All @@ -319,11 +319,25 @@ func dataSourceAppSamlRead(ctx context.Context, d *schema.ResourceData, m interf
if len(appList) < 1 {
return diag.Errorf("no SAML application found with provided filter: %s", filters)
}
if filters.Label != "" && appList[0].Label != filters.Label {
return diag.Errorf("no SAML application found with the provided label: %s", filters.Label)

// Okta API for list apps uses a starts with query on label and name
// which could result in multiple matches on the data source's "label"
// property. We need to further inspect for an exact label match.
if filters.Label != "" {
// guard on nils, an app is always set
app = appList[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

@duytiennguyen-okta I see you've modified to perform initial assignment, but this will assign it to the first app, even if it doesn't match and there's no logic to fail if a matching app isn't found in the for-loop

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it important that app is always set? Given that if it isn't, we were returning a diag error in 912cfb5#diff-bd713a1119c4af963b9c842b006fdbe0a563da383f7172d61e764375ce3831e6L326

for i, _app := range appList {
if _app.Label == filters.Label {
app = appList[i]
break
}
}
} else {
if len(appList) > 1 {
logger(m).Info("found multiple applications with the criteria supplied, using the first one, sorted by creation date")
}
app = appList[0]
}
logger(m).Info("found multiple SAML applications with the criteria supplied, using the first one, sorted by creation date")
app = appList[0]
}
d.SetId(app.Id)
_ = d.Set("label", app.Label)
Expand Down
Loading