Skip to content

Commit 2b03800

Browse files
committed
remove hardcoding of identitiy index
1 parent 898b3e4 commit 2b03800

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

example-apps/internal-knowledge-search/app-ui/src/components/SearchApplicationSettings.tsx

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const SearchApplicationSettings: React.FC = () => {
1414

1515
const fetchPersonaOptions = async () => {
1616
try {
17-
const identitiesIndex = ".search-acl-filter-search-sharepoint" //TODO fix hardcoded
17+
const identitiesIndex = await fetchIdentitiesIndex(await fetchSearchApplicationIndices())
1818
const identitiesPath = searchEndpoint + "/" + identitiesIndex + "/_search"
1919
const response = await fetch(identitiesPath, {
2020
method: "POST",
@@ -36,6 +36,43 @@ const SearchApplicationSettings: React.FC = () => {
3636
}
3737
}
3838

39+
const fetchSearchApplicationIndices = async () => {
40+
try {
41+
const searchApplicationPath = searchEndpoint + "/_application/search_application/" + appName
42+
const response = await fetch(searchApplicationPath, {
43+
headers: {
44+
"Authorization": "Basic " + btoa(appUser + ":" + appPassword)
45+
}
46+
})
47+
const jsonData = await response.json();
48+
const indices = jsonData.indices
49+
return indices
50+
} catch (e) {
51+
console.log("Something went wrong trying to fetch the Search Application underlying indices")
52+
console.log(e)
53+
return []
54+
}
55+
}
56+
57+
const fetchIdentitiesIndex = async(applicationIndices) => {
58+
try {
59+
const identitiesIndexPath = searchEndpoint + "/.search-acl-filter*"
60+
const response = await fetch(identitiesIndexPath, {
61+
headers: {
62+
"Authorization": "Basic " + btoa(appUser + ":" + appPassword)
63+
}
64+
})
65+
const jsonData = await response.json();
66+
const identityIndices = Object.keys(jsonData)
67+
const securedIndex = applicationIndices.find((applicationIndex) => identityIndices.includes(".search-acl-filter-"+applicationIndex))
68+
return ".search-acl-filter-"+securedIndex
69+
} catch (e) {
70+
console.log("Something went wrong trying to fetch the Identities Index")
71+
console.log(e)
72+
return
73+
}
74+
}
75+
3976
const roleName = appName+"-key-role"
4077
const defaultRoleDescriptor = {
4178
[roleName]: {
@@ -69,8 +106,6 @@ const SearchApplicationSettings: React.FC = () => {
69106
const identityPath = searchEndpoint + "/" + identitiesIndex + "/_doc/" + persona
70107
const response = await fetch(identityPath, {headers: {"Authorization": "Basic " + btoa(appUser + ":" + appPassword)}});
71108
const jsonData = await response.json();
72-
console.log("Permissions lookup response is:")
73-
console.log(jsonData)
74109
const permissions = jsonData._source.query.template.params.access_control
75110
return {
76111
"dls-role": {
@@ -140,8 +175,6 @@ const SearchApplicationSettings: React.FC = () => {
140175
})
141176
})
142177
const jsonData = await response.json()
143-
console.log("API key create response is:")
144-
console.log(jsonData)
145178
return jsonData.encoded
146179
}
147180

0 commit comments

Comments
 (0)