-
Notifications
You must be signed in to change notification settings - Fork 241
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
Bf/zenko 436 pick read location fix #1264
Closed
alexanderchan-scality
wants to merge
1
commit into
development/8.0
from
bf/ZENKO-436-pickReadLocationFix
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,27 @@ | ||
/** | ||
* checkReadLocation - verify that a bucket's default read location exists | ||
* a for specified read data locator | ||
* @param {Config} config - Config object | ||
* @param {string} locationName - location constraint | ||
* @param {string} objectKey - object key | ||
* @param {string} bucketName - bucket name | ||
* @return {Object | null} return object containing location information | ||
* if location exists; otherwise, null | ||
*/ | ||
function checkReadLocation(config, locationName, objectKey, bucketName) { | ||
const readLocation = config.getLocationConstraint(locationName); | ||
if (readLocation) { | ||
const bucketMatch = readLocation.details && | ||
readLocation.details.bucketMatch; | ||
const backendKey = bucketMatch ? objectKey : | ||
`${bucketName}/${objectKey}`; | ||
return { | ||
location: locationName, | ||
key: backendKey, | ||
locationType: readLocation.type, | ||
}; | ||
} | ||
return null; | ||
} | ||
|
||
module.exports = checkReadLocation; |
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
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,67 @@ | ||
const assert = require('assert'); | ||
|
||
const { ConfigObject } = require('../../../lib/Config'); | ||
const checkReadLocation = | ||
require('../../../lib/api/apiUtils/object/checkReadLocation'); | ||
|
||
const locationConstraints = { // eslint-disable-line quote-props | ||
bucketmatch: { | ||
type: 'aws_s3', | ||
legacyAwsBehavior: true, | ||
details: { | ||
bucketMatch: true, | ||
}, | ||
}, | ||
nobucketmatch: { | ||
type: 'aws_s3', | ||
legacyAwsBehavior: true, | ||
details: { | ||
bucketMatch: false, | ||
}, | ||
}, | ||
'us-east-1': { | ||
type: 'file', | ||
legacyAwsBehavior: true, | ||
details: {}, | ||
}, | ||
}; | ||
|
||
const bucket = 'testBucket'; | ||
const key = 'objectKey'; | ||
|
||
describe('Testing checkReadLocation', () => { | ||
let config; | ||
|
||
before(() => { | ||
config = new ConfigObject(); | ||
config.setLocationConstraints(locationConstraints); | ||
}); | ||
|
||
it('should return null if location does not exist', () => { | ||
const testResult = checkReadLocation( | ||
config, 'nonexistloc', key, bucket); | ||
assert.deepStrictEqual(testResult, null); | ||
}); | ||
|
||
it('should return correct results for bucketMatch true location', () => { | ||
const testResult = checkReadLocation( | ||
config, 'bucketmatch', key, bucket); | ||
const expectedResult = { | ||
location: 'bucketmatch', | ||
key, | ||
locationType: 'aws_s3', | ||
}; | ||
assert.deepStrictEqual(testResult, expectedResult); | ||
}); | ||
|
||
it('should return correct results for bucketMatch false location', () => { | ||
const testResult = checkReadLocation( | ||
config, 'nobucketmatch', key, bucket); | ||
const expectedResult = { | ||
location: 'nobucketmatch', | ||
key: `${bucket}/${key}`, | ||
locationType: 'aws_s3', | ||
}; | ||
assert.deepStrictEqual(testResult, expectedResult); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
minor: for a