From d98e9e887c427d77f5fc7f9670419cae6ef5d999 Mon Sep 17 00:00:00 2001 From: Robert Waffen Date: Mon, 10 Jul 2023 17:46:43 +0200 Subject: [PATCH] extent s3 options --- README.md | 14 ++++++++++---- catalog_viewer.js | 11 +++++++---- entrypoint.sh | 3 +++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 99148d9..ba1fdd2 100644 --- a/README.md +++ b/README.md @@ -38,18 +38,22 @@ Server Side storage The will automatically populate the drop-down list of available reports, if they can be read from `reportlist.json`. This file contains a record of the json files in `data`. Assuming you have -``` + +```text data/ file1.json file2.json ``` + the `reportlist.json` should have the format + ```json { "First Report": "file1", "Second Report": "file2" } ``` + The python script `generate_reportlist.py` will autopopulate it with all `data/*.json` using the filename also as key. With the docker image, you can put everything in `/data`: @@ -61,7 +65,6 @@ $ docker run -ti \ ghcr.io/voxpupuli/puppet-catalog-diff-viewer ``` - S3 storage ---------- @@ -71,6 +74,11 @@ The viewer can automatically retrieve catalogs from an S3 bucket. In order to us var s3_bucketName = 'your-bucket-name'; var s3_access_key = 'your-access-key'; var s3_secret_key = 'your-secret-key'; + +// if you selfhost a s3 engine or use a path within it: +var s3_host = 'your.endpoint.example.com'; +var s3_bucketPathPrefix = '/yur/prefix'; +var s3_ForcePathStyle = true; ``` With the docker image, you can use: @@ -130,5 +138,3 @@ Make sure the access key belongs to a user that can perform actions `s3:GetObjec ] } ``` - - diff --git a/catalog_viewer.js b/catalog_viewer.js index a503fe5..a8b4406 100644 --- a/catalog_viewer.js +++ b/catalog_viewer.js @@ -964,11 +964,14 @@ function refreshStats(type, data) { function listS3Reports() { AWS.config.update({accessKeyId: s3_access_key, secretAccessKey: s3_secret_key}); var s3Bucket = new AWS.S3({ - params: { - Bucket: s3_bucketName - } + params: { + Bucket: s3_bucketName, + endpoint: s3_host, // Set the S3 host, when self hosting + s3ForcePathStyle: s3_ForcePathStyle, // Enable path-style URLs, necessary when using custom S3 host + } }); - s3Bucket.listObjects(function(err, data) { + // Add prefix to listObjects, if undefined, it is ignored + s3Bucket.listObjects({Prefix: s3_bucketPathPrefix}, function(err, data) { if (err) { console.log(err); } else { diff --git a/entrypoint.sh b/entrypoint.sh index 6059d4a..80309f5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,6 +5,9 @@ if test -n "$S3_BUCKET" ; then var s3_bucketName = '${S3_BUCKET}'; var s3_access_key = '${S3_ACCESS_KEY}'; var s3_secret_key = '${S3_SECRET_KEY}'; +var s3_host = '${S3_HOST}'; // S3 host, when self hosting s3 +var s3_bucketPathPrefix = '${S3_BUCKET_PATH_PREFIX}'; // S3 bucket path prefix +var s3_ForcePathStyle = ${S3_FORCE_PATH_STYLE}; // true or false EOF fi