From c0f1e8e43f3bfa7e07812a880d3576867c434ce8 Mon Sep 17 00:00:00 2001 From: Maybelline Boon Date: Fri, 7 Jun 2024 18:14:28 +0000 Subject: [PATCH 1/4] update private aggregation demo to dynamically request for key and cloud environment. --- services/dsp/src/public/js/dsp.js | 14 +++++----- .../src/public/js/private-aggregation-aws.js | 14 ---------- .../src/public/js/private-aggregation-gcp.js | 14 ---------- .../js/private-aggregation-worklet-aws.js | 24 ----------------- .../js/private-aggregation-worklet-gcp.js | 24 ----------------- .../public/js/private-aggregation-worklet.js | 26 +++++++++++++++++++ .../dsp/src/public/js/private-aggregation.js | 20 ++++++++++++++ .../dsp/src/views/private-aggregation.ejs | 2 +- services/news/src/index.ts | 6 ++++- services/news/src/views/index.ejs | 2 +- 10 files changed, 60 insertions(+), 86 deletions(-) delete mode 100644 services/dsp/src/public/js/private-aggregation-aws.js delete mode 100644 services/dsp/src/public/js/private-aggregation-gcp.js delete mode 100644 services/dsp/src/public/js/private-aggregation-worklet-aws.js delete mode 100644 services/dsp/src/public/js/private-aggregation-worklet-gcp.js create mode 100644 services/dsp/src/public/js/private-aggregation-worklet.js create mode 100644 services/dsp/src/public/js/private-aggregation.js diff --git a/services/dsp/src/public/js/dsp.js b/services/dsp/src/public/js/dsp.js index 2fcaede0..57e29bbb 100644 --- a/services/dsp/src/public/js/dsp.js +++ b/services/dsp/src/public/js/dsp.js @@ -1,10 +1,10 @@ let dsp = document.currentScript.getAttribute('dsp'); +let bucket = document.currentScript.getAttribute('bucket'); +let cloudEnv = document.currentScript.getAttribute('cloudenv'); window.addEventListener('load', (event) => { - let iframeAws = document.createElement('iframe'); - let iframeGcp = document.createElement('iframe'); - // let dsp = document.currentScript.getAttribute('dsp'); - iframeAws.src = `https://${dsp}/private-aggregation-aws`; - iframeGcp.src = `https://${dsp}/private-aggregation-gcp`; - document.body.appendChild(iframeAws); - document.body.appendChild(iframeGcp); + if ((cloudEnv == 'aws' || cloudEnv == 'gcp') && bucket != 'undefined') { + let iframe = document.createElement('iframe'); + iframe.src = `https://${dsp}/private-aggregation?bucket=${bucket}&cloudEnv=${cloudEnv}`; + document.body.appendChild(iframe); + } }); diff --git a/services/dsp/src/public/js/private-aggregation-aws.js b/services/dsp/src/public/js/private-aggregation-aws.js deleted file mode 100644 index eb3d14b1..00000000 --- a/services/dsp/src/public/js/private-aggregation-aws.js +++ /dev/null @@ -1,14 +0,0 @@ -async function runPrivateAggregationAws() { - const privateAggCloud = { - 'privateAggregationConfig': { - 'aggregationCoordinatorOrigin': - 'https://publickeyservice.msmt.aws.privacysandboxservices.com', - }, - }; - await window.sharedStorage.worklet.addModule( - 'js/private-aggregation-worklet-aws.js', - ); - await window.sharedStorage.run('test-private-aggregation', privateAggCloud); -} - -runPrivateAggregationAws(); diff --git a/services/dsp/src/public/js/private-aggregation-gcp.js b/services/dsp/src/public/js/private-aggregation-gcp.js deleted file mode 100644 index cefbb8be..00000000 --- a/services/dsp/src/public/js/private-aggregation-gcp.js +++ /dev/null @@ -1,14 +0,0 @@ -async function runPrivateAggregationGcp() { - const privateAggCloud = { - 'privateAggregationConfig': { - 'aggregationCoordinatorOrigin': - 'https://publickeyservice.msmt.gcp.privacysandboxservices.com', - }, - }; - await window.sharedStorage.worklet.addModule( - 'js/private-aggregation-worklet-gcp.js', - ); - await window.sharedStorage.run('test-private-aggregation', privateAggCloud); -} - -runPrivateAggregationGcp(); diff --git a/services/dsp/src/public/js/private-aggregation-worklet-aws.js b/services/dsp/src/public/js/private-aggregation-worklet-aws.js deleted file mode 100644 index 6c72ddde..00000000 --- a/services/dsp/src/public/js/private-aggregation-worklet-aws.js +++ /dev/null @@ -1,24 +0,0 @@ -class TestPrivateAggregation { - async run(data) { - console.log('Enabling AWS Private Aggregation Debug Mode'); - privateAggregation.enableDebugMode({debugKey: 1234n}); - let campaignId = await sharedStorage.get('campaignId'); - if (!campaignId) { - console.log( - 'No campaign id found for client. Adding campaignId 1234567890.', - ); - campaignId = '1234567890'; - sharedStorage.set('campaignId', campaignId); - } else { - console.log(`Campaign ID found: ${campaignId}`); - } - function convertToBucket(bucketId) { - return BigInt(bucketId); - } - const bucket = convertToBucket(campaignId); - const value = 128; - privateAggregation.contributeToHistogram({bucket, value}); - } -} - -register('test-private-aggregation', TestPrivateAggregation); diff --git a/services/dsp/src/public/js/private-aggregation-worklet-gcp.js b/services/dsp/src/public/js/private-aggregation-worklet-gcp.js deleted file mode 100644 index 586ebd80..00000000 --- a/services/dsp/src/public/js/private-aggregation-worklet-gcp.js +++ /dev/null @@ -1,24 +0,0 @@ -class TestPrivateAggregation { - async run(data) { - console.log('Enabling GCP Private Aggregation Debug Mode'); - privateAggregation.enableDebugMode({debugKey: 1234n}); - let campaignId = await sharedStorage.get('campaignId'); - if (!campaignId) { - console.log( - 'No campaign id found for client. Adding campaignId 1234567890.', - ); - campaignId = '1234567890'; - sharedStorage.set('campaignId', campaignId); - } else { - console.log(`Campaign ID found: ${campaignId}`); - } - function convertToBucket(bucketId) { - return BigInt(bucketId); - } - const bucket = convertToBucket(campaignId); - const value = 128; - privateAggregation.contributeToHistogram({bucket, value}); - } -} - -register('test-private-aggregation', TestPrivateAggregation); diff --git a/services/dsp/src/public/js/private-aggregation-worklet.js b/services/dsp/src/public/js/private-aggregation-worklet.js new file mode 100644 index 00000000..a0e4411e --- /dev/null +++ b/services/dsp/src/public/js/private-aggregation-worklet.js @@ -0,0 +1,26 @@ +class TestPrivateAggregation { + async run(data) { + let cloudEnv = await sharedStorage.get('cloudenv'); + console.log(`Enabling ${cloudEnv} Private Aggregation Debug Mode`); + privateAggregation.enableDebugMode({debugKey: 1234n}); + let bucketKey = await sharedStorage.get('bucket'); + if (!bucketKey) { + console.log( + 'No bucket key found for client. Adding default bucketKey 1234567890.', + ); + bucketKey = '1234567890'; + sharedStorage.set('bucketKey', bucketKey); + } else { + console.log(`Bucket Key found: ${bucketKey}`); + } + function convertToBucket(bucketId) { + return BigInt(bucketId); + } + const bucket = convertToBucket(bucketKey); + const value = 128; + privateAggregation.contributeToHistogram({bucket, value}); + sharedStorage.clear(); + } +} + +register('test-private-aggregation', TestPrivateAggregation); diff --git a/services/dsp/src/public/js/private-aggregation.js b/services/dsp/src/public/js/private-aggregation.js new file mode 100644 index 00000000..fd94eca2 --- /dev/null +++ b/services/dsp/src/public/js/private-aggregation.js @@ -0,0 +1,20 @@ +let bucket = document.currentScript.getAttribute('bucket'); +let cloudEnv = document.currentScript.getAttribute('cloudenv'); + +sharedStorage.set('bucket', `${bucket}`); +sharedStorage.set('cloudenv', `${cloudEnv}`); +console.log(`https://publickeyservice.msmt.${cloudEnv}.privacysandboxservices.com`); + +async function runPrivateAggregation() { + const privateAggCloud = { + 'privateAggregationConfig': { + 'aggregationCoordinatorOrigin': `https://publickeyservice.msmt.${cloudEnv}.privacysandboxservices.com`, + }, + }; + await window.sharedStorage.worklet.addModule( + 'js/private-aggregation-worklet.js', + ); + await window.sharedStorage.run('test-private-aggregation', privateAggCloud); +} + +runPrivateAggregation(); diff --git a/services/dsp/src/views/private-aggregation.ejs b/services/dsp/src/views/private-aggregation.ejs index 81aeb6b5..1f2508e8 100644 --- a/services/dsp/src/views/private-aggregation.ejs +++ b/services/dsp/src/views/private-aggregation.ejs @@ -1,5 +1,5 @@
- +
\ No newline at end of file diff --git a/services/news/src/index.ts b/services/news/src/index.ts index 2db209e8..e2e97091 100644 --- a/services/news/src/index.ts +++ b/services/news/src/index.ts @@ -46,7 +46,9 @@ app.set('views', 'src/views'); app.get('/', async (req: Request, res: Response) => { const {auctionType} = req.query; - + const bucket = req.query.key; + const cloudEnv = req.query.env; + res.render('index', { title: TITLE, lorem: LOREM, @@ -61,6 +63,8 @@ app.get('/', async (req: Request, res: Response) => { AD_SERVER_LIB_URL: `https://${AD_SERVER_HOST}/js/ad-server-lib.js`, HEADER_BIDDING_LIB_URL: `https://${NEWS_HOST}/js/header-bidding-lib.js`, isMultiSeller: auctionType === 'multi', + bucket: bucket, + cloudEnv: cloudEnv, }); }); diff --git a/services/news/src/views/index.ejs b/services/news/src/views/index.ejs index 1499a141..93d9340c 100644 --- a/services/news/src/views/index.ejs +++ b/services/news/src/views/index.ejs @@ -9,7 +9,7 @@ - +