-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: move getCachePlugin to shared #799
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,4 +70,8 @@ export class FSCachePlugin { | |
} | ||
return false; | ||
} | ||
|
||
get location() { | ||
return this.filePath; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,4 +85,8 @@ export class MemCachePlugin { | |
} | ||
return false; | ||
} | ||
|
||
get location() { | ||
return this.base ? this.base.location : this.key; | ||
} | ||
Comment on lines
+89
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when a |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,10 @@ export class S3CachePlugin { | |
} | ||
return false; | ||
} | ||
|
||
get location() { | ||
return `${this.bucket}/${this.key}`; | ||
} | ||
Comment on lines
+114
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for S3, the location is just the S3 URI |
||
} | ||
|
||
S3CachePlugin.encrypt = encrypt; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2023 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
/* eslint-disable no-param-reassign */ | ||
|
||
import { MemCachePlugin } from './MemCachePlugin.js'; | ||
import { S3CacheManager } from './S3CacheManager.js'; | ||
|
||
/** | ||
* Returns the S3 cache plugin | ||
* | ||
* @returns {ICachePlugin} the cache plugin | ||
*/ | ||
export async function getCachePlugin(opts, type) { | ||
const { log, contentBusId } = opts; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: the content bus id is expected in |
||
|
||
const derivedOpts = []; | ||
if (contentBusId) { | ||
derivedOpts.push({ | ||
prefix: `${contentBusId}/.helix-auth`, | ||
secret: contentBusId, | ||
}); | ||
} | ||
const basePlugin = await S3CacheManager.findCache('content', { | ||
log, | ||
prefix: 'default/.helix-auth', | ||
secret: 'default', | ||
bucket: 'helix-content-bus', | ||
type, | ||
}, ...derivedOpts); | ||
|
||
log.info(`using connected user from ${basePlugin.location}`); | ||
|
||
/** @type MemCachePluginOptions */ | ||
const cacheOpts = { | ||
log, | ||
key: basePlugin.key, | ||
base: basePlugin, | ||
}; | ||
if (process.env.HELIX_ONEDRIVE_LOCAL_AUTH_CACHE) { | ||
cacheOpts.caches = new Map(); | ||
} | ||
return new MemCachePlugin(cacheOpts); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2023 Adobe. All rights reserved. | ||
* This file is licensed to you under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. You may obtain a copy | ||
* of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under | ||
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS | ||
* OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
/* eslint-env mocha */ | ||
import assert from 'assert'; | ||
import { getCachePlugin } from '../src/getCachePlugin.js'; | ||
import { Nock } from './utils.js'; | ||
|
||
const DEFAULT_ENV = { | ||
AZURE_HELIX_SERVICE_CLIENT_ID: 'client-id', | ||
AZURE_HELIX_SERVICE_CLIENT_SECRET: 'client-secret', | ||
}; | ||
|
||
describe('getCachePlugin tests', () => { | ||
let nock; | ||
let savedProcessEnv; | ||
beforeEach(() => { | ||
nock = new Nock(); | ||
savedProcessEnv = process.env; | ||
process.env = { | ||
...process.env, | ||
AWS_REGION: 'us-east-1', | ||
AWS_ACCESS_KEY_ID: 'fake-key-id', | ||
AWS_SECRET_ACCESS_KEY: 'fake-secret', | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
nock.done(); | ||
process.env = savedProcessEnv; | ||
}); | ||
|
||
it('uses derived opts if contentBusId is available', async () => { | ||
const contentBusId = '0123456789abcdef0123456789abcdef0123456789abcdef0123456789a'; | ||
nock('https://helix-content-bus.s3.us-east-1.amazonaws.com') | ||
.head(`/${contentBusId}/.helix-auth/auth-onedrive-content.json`) | ||
.reply(200); | ||
|
||
const cachePlugin = await getCachePlugin({ | ||
log: console, | ||
env: DEFAULT_ENV, | ||
contentBusId, | ||
}, 'onedrive'); | ||
assert.ok(cachePlugin); | ||
assert.strictEqual(cachePlugin.location, `helix-content-bus/${contentBusId}/.helix-auth/auth-onedrive-content.json`); | ||
}); | ||
|
||
it('uses empty opts if contentBusId is not available', async () => { | ||
// "content-bus-id/.helix-auth/auth-onedrive-content.json" | ||
const cachePlugin = await getCachePlugin({ | ||
log: console, | ||
env: DEFAULT_ENV, | ||
contentBusId: null, | ||
}, 'onedrive'); | ||
assert.ok(cachePlugin); | ||
assert.strictEqual(cachePlugin.location, 'helix-content-bus/default/.helix-auth/auth-onedrive-content.json'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all cache plugins now have a
location