Skip to content

Commit

Permalink
s3 module docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dbauszus-glx committed Nov 14, 2024
1 parent 90bc15e commit 75f48a2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
18 changes: 9 additions & 9 deletions mod/provider/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ Provides methods for list, get, trash and put
**/
module.exports = async function s3(req, res) {

const commands = {
get,
put,
trash,
list
}
// const commands = {
// get,
// put,
// trash,
// list
// }

if (!Object.hasOwn(commands, req.params.command)) {
return res.status(400).send(`S3 command validation failed.`)
}
// if (!Object.hasOwn(commands, req.params.command)) {
// return res.status(400).send(`S3 command validation failed.`)
// }

const paramString = Object.keys(req.params).filter(param => ['command','bucket','key','region'].includes(param)).map(param => `${param}=${req.params[param]}`).join('&')

Expand Down
26 changes: 16 additions & 10 deletions mod/sign/s3.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
/**
@module /sign/s3
### /sign/s3
Signs requests to S3. Provides functions for get, list, delete and put to S3.
The module requires AWS_S3_CLIENT credentials in the process.env and will export as null if the credentials are not provided. The credentials consist of two parts: an access key ID and a secret access key eg: `AWS_S3_CLIENT="accessKeyId=AKIAIOSFODNN7EXAMPLE&secretAccessKey=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"`. [Both the access key ID and secret access key together are required to authenticate your requests]{@link https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html}.
The aws-sdk/client-s3 and aws-sdk/s3-request-presigner are optional dependencies. The require will fail and the module will export as null if these optional dependencies are not installed.
@requires aws-sdk/client-s3
@requires aws-sdk/s3-request-presigner
Signs requests to S3. Provides functions for get, list, delete and put to S3.
@module /sign/s3
*/

//The S3 packages are optional.
//Need a temporary assignment to determine if they are available.
let
credentials,
S3Client,
PutObjectCommand,
GetObjectCommand,
DeleteObjectCommand,
ListObjectsCommand,
getSignedUrl;

//Check for credentials
// Check for credentials
if (!process.env?.AWS_S3_CLIENT) {
console.log('S3 Sign: Missing credentials from env: AWS_S3_CLIENT')
module.exports = null
}
else {

} else {

//Read credentials from an env key
credentials = Object.fromEntries(new URLSearchParams(process.env.AWS_S3_CLIENT))

//Attempt import if credentials are found
try {
Expand Down Expand Up @@ -71,9 +80,6 @@ Provides methods for list, get, trash and put
**/
async function s3(req, res) {

//Read credentials from an env key
const credentials = Object.fromEntries(new URLSearchParams(process.env.AWS_S3_CLIENT))

const s3Client = new S3Client({
credentials,
region: req.params.region
Expand Down

0 comments on commit 75f48a2

Please sign in to comment.