Skip to content

Commit

Permalink
Merge pull request #245 from nulib/deploy/staging
Browse files Browse the repository at this point in the history
Deploy to production
  • Loading branch information
mbklein authored Aug 15, 2024
2 parents 217d843 + fab7b97 commit 0149709
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
4 changes: 2 additions & 2 deletions chat/src/helpers/hybrid_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def hybrid_query(query: str, model_id: str, vector_field: str = "embedding", k:
"queries": [
filter({
"query_string": {
"default_operator": "AND",
"fields": ["title^5", "all_controlled_labels", "all_ids^5"],
"default_operator": "OR",
"fields": ["title^1", "collection.title^5", "all_controlled_labels", "all_ids^1"],
"query": query
}
}),
Expand Down
41 changes: 20 additions & 21 deletions node/src/handlers/get-auth-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,18 @@ exports.handler = wrap(async (event) => {
return { statusCode: 400 };
});

async function invokeNuApi(path, headers) {
const url = new URL(process.env.NUSSO_BASE_URL);
url.pathname = path;
return await axios.get(url.toString(), {
headers: { apikey: process.env.NUSSO_API_KEY, ...headers },
});
}

async function getNetIdFromToken(nusso) {
const response = await axios.get(
`${process.env.NUSSO_BASE_URL}validateWebSSOToken`,
{
headers: {
apikey: process.env.NUSSO_API_KEY,
webssotoken: nusso,
},
}
);
const response = await invokeNuApi("/agentless-websso/validateWebSSOToken", {
webssotoken: nusso,
});
return response?.data?.netid;
}

Expand All @@ -52,14 +54,8 @@ async function redeemSsoToken(event) {
const netid = await getNetIdFromToken(nusso);
if (netid) {
try {
const response = await axios.get(
`${process.env.NUSSO_BASE_URL}validate-with-directory-search-response`,
{
headers: {
apikey: process.env.NUSSO_API_KEY,
webssotoken: nusso,
},
}
const response = await invokeNuApi(
`/directory-search/res/netid/bas/${netid}`
);
return fillInBlanks({ ...response.data.results[0], uid: netid });
} catch (err) {
Expand All @@ -79,10 +75,13 @@ async function redeemSsoToken(event) {
}

function fillInBlanks(response) {
const { uid } = response;
response.displayName = ifEmpty(response.displayName, [uid]);
response.mail = ifEmpty(response.mail, `${uid}@e.northwestern.edu`);
return response;
const { uid, displayName, givenName, mail } = response;
return {
uid,
givenName,
displayName: ifEmpty(displayName, [uid]),
mail: ifEmpty(mail, `${uid}@e.northwestern.edu`),
};
}

function ifEmpty(val, replacement) {
Expand Down
8 changes: 4 additions & 4 deletions node/test/integration/get-auth-callback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ describe("auth callback", function () {
.render();

nock(process.env.NUSSO_BASE_URL)
.get("/validateWebSSOToken")
.get("/agentless-websso/validateWebSSOToken")
.reply(200, { netid: "uid123" });
});

it("redeems the NUSSO token", async () => {
nock(process.env.NUSSO_BASE_URL)
.get("/validate-with-directory-search-response")
.get("/directory-search/res/netid/bas/uid123")
.reply(200, {
results: [
{ displayName: ["Some User"], mail: "[email protected]" },
Expand All @@ -53,7 +53,7 @@ describe("auth callback", function () {

it("fills in the blanks if the directory search result is incomplete", async () => {
nock(process.env.NUSSO_BASE_URL)
.get("/validate-with-directory-search-response")
.get("/directory-search/res/netid/bas/uid123")
.reply(200, {
results: [{ displayName: [], mail: "" }],
});
Expand Down Expand Up @@ -82,7 +82,7 @@ describe("auth callback", function () {

it("assembles a user object from the netID if directory search fails", async () => {
nock(process.env.NUSSO_BASE_URL)
.get("/validate-with-directory-search-response")
.get("/directory-search/res/netid/bas/uid123")
.reply(500, {
fault: {
faultstring:
Expand Down

0 comments on commit 0149709

Please sign in to comment.