-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adeb31d
commit 8c7604d
Showing
4 changed files
with
84 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { isString } from './functions.js'; | ||
|
||
/** | ||
* Resolves the name of the secret based on the function version. | ||
* @param {Object} opts - The options object, not used in this implementation. | ||
* @param {Object} ctx - The context object containing the function version. | ||
* @param {string} defaultPath - The default path for the secret. | ||
* @returns {string} - The resolved secret name. | ||
*/ | ||
const resolveSecretsName = (opts, ctx, defaultPath) => { | ||
const funcVersion = ctx?.func?.version; | ||
|
||
if (!isString(funcVersion)) { | ||
throw new Error('Invalid context: func.version is required and must be a string'); | ||
} | ||
if (!isString(defaultPath)) { | ||
throw new Error('Invalid defaultPath: must be a string'); | ||
} | ||
|
||
return `${defaultPath}/${funcVersion}`; | ||
}; | ||
|
||
export { | ||
resolveSecretsName, | ||
}; |
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 |
---|---|---|
|
@@ -25,3 +25,5 @@ export { | |
toBoolean, | ||
isValidUrl, | ||
} from './functions.js'; | ||
|
||
export { resolveSecretsName } from './helpers.js'; |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* 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 { expect } from 'chai'; | ||
|
||
import { resolveSecretsName } from '../src/helpers.js'; | ||
|
||
describe('resolveSecretsName', () => { | ||
it('resolves name correctly with valid inputs', () => { | ||
const ctx = { func: { version: '1.0.0' } }; | ||
const defaultPath = 'secretPath'; | ||
expect(resolveSecretsName({}, ctx, defaultPath)).to.equal('secretPath/1.0.0'); | ||
}); | ||
|
||
it('throws error when ctx is undefined', () => { | ||
expect(() => resolveSecretsName({}, undefined, 'defaultPath')).to.throw('Invalid context: func.version is required and must be a string'); | ||
}); | ||
|
||
it('throws error when ctx.func is undefined', () => { | ||
const ctx = {}; | ||
expect(() => resolveSecretsName({}, ctx, 'defaultPath')).to.throw('Invalid context: func.version is required and must be a string'); | ||
}); | ||
|
||
it('throws error when ctx.func.version is not a string', () => { | ||
const ctx = { func: { version: null } }; | ||
expect(() => resolveSecretsName({}, ctx, 'defaultPath')).to.throw('Invalid context: func.version is required and must be a string'); | ||
}); | ||
|
||
it('throws error when defaultPath is not a string', () => { | ||
const ctx = { func: { version: '1.0.0' } }; | ||
expect(() => resolveSecretsName({}, ctx, null)).to.throw('Invalid defaultPath: must be a string'); | ||
}); | ||
}); |
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