-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1791 from jrjohnson/aws-sdk-v3
Switch out our AWS SDK
- Loading branch information
Showing
10 changed files
with
1,278 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,24 @@ | ||
import { createHash } from 'crypto'; | ||
const sha256 = x => createHash('sha256').update(x, 'utf8').digest('hex'); | ||
export default async ({ fetch, createJWT, config, searchString }) => { | ||
let url = config.apiServer + config.apiNameSpace; | ||
switch (config.iliosMatchField) { | ||
case 'authentication-username': | ||
url += `/authentications?filters[username]=${searchString}`; | ||
break; | ||
} | ||
const adminToken = createJWT(config.ltiUserId, config.apiServer, config.apiNameSpace, config.iliosSecret); | ||
console.log(`Searching for user ${searchString} at ${url} with token ${adminToken}`); | ||
const data = await fetch(url, { | ||
headers: { | ||
'X-JWT-Authorization': `Token ${adminToken}` | ||
} | ||
}); | ||
const result = await data.json(); | ||
|
||
export default async ({ fetch, createJWT, config, searchString, aws }) => { | ||
const db = new aws.SimpleDB(); | ||
const key = `${config.apiServer}:${config.apiNameSpace}:${config.ltiPostField}:${config.iliosMatchField}:userId:${searchString}`; | ||
const keyHash = sha256(key); | ||
console.log(`Hashed key ${key} to ${keyHash}`); | ||
console.log(`Searching for cached ${searchString} in SimpleDB ${process.env.USERID_SIMPLEDB_DOMAIN}`); | ||
const result = await db.getAttributes({ | ||
DomainName: process.env.USERID_SIMPLEDB_DOMAIN, | ||
ItemName: keyHash | ||
}).promise(); | ||
if (('Attributes' in result) && result.Attributes.length > 0 && result.Attributes[0].Name === 'userId') { | ||
const userId = result.Attributes[0].Value; | ||
console.log(`User ${userId} was found in cache for ${keyHash}`); | ||
if ('authentications' in result && result.authentications.length > 0) { | ||
const userId = result.authentications[0].user; | ||
console.log(`User ${userId} found`); | ||
return userId; | ||
} else { | ||
console.log(`No User found in cache for ${keyHash}`); | ||
let url = config.apiServer + config.apiNameSpace; | ||
switch (config.iliosMatchField) { | ||
case 'authentication-username': | ||
url += `/authentications?filters[username]=${searchString}`; | ||
break; | ||
} | ||
const adminToken = createJWT(config.ltiUserId, config.apiServer, config.apiNameSpace, config.iliosSecret); | ||
console.log(`Searching for user ${searchString} at ${url} with token ${adminToken}`); | ||
const data = await fetch(url, { | ||
headers: { | ||
'X-JWT-Authorization': `Token ${adminToken}` | ||
} | ||
}); | ||
const result = await data.json(); | ||
|
||
if ('authentications' in result && result.authentications.length > 0) { | ||
const userId = result.authentications[0].user; | ||
await db.putAttributes({ | ||
DomainName: process.env.USERID_SIMPLEDB_DOMAIN, | ||
ItemName: keyHash, | ||
Attributes: [ | ||
{ Name: 'userId', Value: userId } | ||
] | ||
}); | ||
console.log(`User ${userId} found and saved to cache as ${keyHash}`); | ||
return userId; | ||
} else { | ||
return `Unable to find Ilios account for ${searchString}.`; | ||
} | ||
return `Unable to find Ilios account for ${searchString}.`; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
export default async(key, aws) => { | ||
const s3 = new aws.S3(); | ||
import { GetObjectCommand } from '@aws-sdk/client-s3'; | ||
|
||
export default async(key, s3Client) => { | ||
const params = { | ||
Bucket: process.env.CONFIG_BUCKET, | ||
Key: 'config.json', | ||
}; | ||
const command = new GetObjectCommand(params); | ||
console.log('Looking for configuration for school in: '); | ||
console.log(params); | ||
const data = await s3.getObject(params).promise(); | ||
const obj = JSON.parse(data.Body); | ||
const response = await s3Client.send(command); | ||
const str = await response.Body.transformToString(); | ||
const obj = JSON.parse(str); | ||
if (!(key in obj)) { | ||
throw new Error(`The Consumer Key "${key}" is not known to Ilios. Please contact [email protected] to set it up.`); | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.