Skip to content
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(packages/twilio-run): regionalize toolkit config and api #433

Merged
merged 6 commits into from
Nov 7, 2022

Conversation

mbeldartwilio
Copy link
Contributor

@mbeldartwilio mbeldartwilio commented Oct 28, 2022

Contributing to Twilio

All third-party contributors acknowledge that any contributions they provide will be made under the same open-source license that the open-source project is provided under.

  • I acknowledge that all my contributions will be made under the project's license.

Copy link
Member

@dkundel dkundel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excited for this :) Left a couple of initial comments

packages/twilio-run/src/serverless-api/utils.ts Outdated Show resolved Hide resolved
packages/twilio-run/src/utils/deployInfoCache.ts Outdated Show resolved Hide resolved
@mbeldartwilio mbeldartwilio changed the title [WIP] feat(packages/twilio-run): regionalize the .twiliodeployinfo eat(packages/twilio-run): regionalize the .twiliodeployinfo Nov 1, 2022
@mbeldartwilio mbeldartwilio changed the title eat(packages/twilio-run): regionalize the .twiliodeployinfo feat(packages/twilio-run): regionalize the .twiliodeployinfo Nov 1, 2022
@mbeldartwilio mbeldartwilio changed the title feat(packages/twilio-run): regionalize the .twiliodeployinfo feat(packages/twilio-run): regionalize toolkit config and api Nov 1, 2022
const region = configRegion ? `${configRegion}.` : '';

if (!configEdge && configRegion) {
const defaultEdge = regionEdgeMap[configRegion]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember Dom mentioning, we should let toolkit fallback to the API and be dumb about this.

if (
deployInfoCache &&
deployInfoCache[`${username}:${region}`] &&
deployInfoCache[`${username}:${region}`].serviceSid
Copy link

@vingiarrusso vingiarrusso Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use optional chaining here? if (deployInfoCache[`${username}:${region}`]?.serviceSid) ...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to since the node version is >14.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, this project should support node12 and above (from readme)
I would like to know Dom's opinion as node12 is deprecated already.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with moving to Node 14 now. I think that's outdated in the README since twilio-run itself already only supports Node 14 since a few versions ago

...result,
...projectsConfig[`${opts.username}:${opts.region}`],
};
} else if (opts.region === 'us1' || opts.region === undefined) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to put this first? not sure if we're allowing username:us1, but it seems like the opts.region === 'us1' case would fall into the if block, so we should remove it or swap the if and else if blocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think logic you mentioned would fail in following case:
region=us1 and the config file with account:us1.

And yes, we will be allowing accountsid:us1

@@ -71,9 +72,15 @@ export function updateDeployInfoCache(
deployInfoCacheFileName
);

if (currentDeployInfoCache.hasOwnProperty(username) && region === 'us1') {
debug('Invalid format for deploy info key. Overriding with region us1');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm confused about this block, is the username always an account sid? if so, it seems like this would only be invalid if just the account sid key is in the cache, but the region is not us1? lmk if i'm misunderstanding though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is handling the case where user has passed us1 in new build request but the existing config is still using 'username' and not 'username:us1'.

We wan't to remove 'username' as we are adding 'username:us1'. (see next few lines)


test('account + region config override', () => {
__setTestConfig({
serviceSid: 'ZS11112222111122221111222211112222',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sid convention is a little confusing here, is this service sid supposed to match up with any of the ones below? or does only the service sids in projects matter for this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what I understand, the ZS...22 is default servicesid. Other service sids under "envs" and "accounts" supposed to override the default one.

Copy link
Member

@dkundel dkundel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .twilioserverlessrc behavior changes and the edge fallbacks work flawlessly. For the .twiliodeplyinfo changes it looks like the regions are not being passed for read and write all the way down. Can you change that? :)

@@ -49,20 +55,22 @@ export async function getFunctionServiceSid(
}

debug('Could not determine existing serviceSid');
debug(`${username}:${region}`);
return undefined;
}

export async function saveLatestDeploymentData(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you are missing in the packages/twilio-run/src/commands/deploy.ts file an update to the call of saveLatestDeploymentData that passes config.region.

@@ -74,6 +74,7 @@ export async function getConfigFromFlags(
(externalCliOptions && externalCliOptions.accountSid) ||
undefined,
environmentSuffix: flags.environment,
region: flags.region,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calls to getFunctionServiceSid are missing the region passed in as the cache from the twilioDeployInfo file are not being read. Same applies in the other files.

@dkundel dkundel merged commit 30d5bdb into main Nov 7, 2022
@github-actions github-actions bot mentioned this pull request Dec 7, 2023
@github-actions github-actions bot mentioned this pull request Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants