Skip to content

Commit

Permalink
fix(agent): Add fallbacks for regions without signers
Browse files Browse the repository at this point in the history
Closes #356
  • Loading branch information
mrickard authored Oct 4, 2019
2 parents 0a343df + cb7c716 commit 4b4d448
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
20 changes: 17 additions & 3 deletions src/fileUploadMeta/getSigner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,23 @@ const supported = new Map(SUPPORTED_SIGNER_REGIONS);
// allow us-east-1 for signer util
supported.set('us-east-1', true);

const fallbackSigners = {
'ap-northeast-2': 'ap-northeast-1',
'ap-south-1': 'ap-southeast-2',
'ap-southeast-1': 'ap-southeast-2',
'ap-southeast-2': 'ap-southeast-2',
'ca-central-1': 'us-east-2',
'eu-central-1': 'eu-west-1',
'eu-west-2': 'eu-west-1',
'eu-east-1': 'eu-east-1',
'us-west-1': 'us-west-1'
};

export default function getSignerHostname() {
const { AWS_REGION } = process.env;
return `https://signer.${
supported.has(AWS_REGION) ? AWS_REGION : 'us-west-2'
}.iopipe.com/`;
const signer = supported.has(AWS_REGION)
? AWS_REGION
: fallbackSigners[AWS_REGION];

return `https://signer.${signer ? signer : 'us-west-2'}.iopipe.com/`;
}
2 changes: 1 addition & 1 deletion src/fileUploadMeta/getSigner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('getSigner', () => {
});

test('Uses us-west-2 if region is not supported', () => {
process.env.AWS_REGION = 'eu-west-2';
process.env.AWS_REGION = 'eu-west-3';
expect(lib()).toEqual('https://signer.us-west-2.iopipe.com/');
});
});
13 changes: 0 additions & 13 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,18 +294,5 @@ describe('smoke test', () => {
sendToRegionTest(region, done);
});
}

test('sends to custom URLs (staging)', done => {
runWrappedFunction(
undefined,
undefined,
createAgent({
url: 'https://metrics-api-staging.iopipe.com'
})
).then(obj => {
expect(obj.response).toEqual('Success');
done();
});
});
});
});

0 comments on commit 4b4d448

Please sign in to comment.