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

Handle multiple apps returned by SAML app data source, where one app exactly matches. #1894

Open
wants to merge 3 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
22 changes: 17 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,23 @@ 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)

if filters.Label != "" {
foundMatch := false
for _, appItx := range appList {
if appItx.Label == filters.Label {
app = appItx
foundMatch = true
Copy link
Contributor

@duytiennguyen-okta duytiennguyen-okta Feb 23, 2024

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh course, yes, apologies!

break
}
}
if !foundMatch {
return diag.Errorf("no SAML application found with the provided label: %s", filters.Label)
}
} else {
logger(m).Info("found multiple SAML 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