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

Allow linking and unlinking lambdas to applications #8

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

rideam
Copy link

@rideam rideam commented Aug 21, 2023

  • Change adds more lambda commands and allows lambdas to be defined as multiline when uploading

@mooreds mooreds requested a review from ColinFrick August 21, 2023 17:19
@mooreds
Copy link
Contributor

mooreds commented Aug 21, 2023

@ColinFrick can you please take a look?

Copy link
Collaborator

@ColinFrick ColinFrick left a comment

Choose a reason for hiding this comment

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

@rideam Great work!

There are some potential problems in the implementation.

Currently only JWT populate lambdas are supported for the un/link commands, and they are always set on both accessToken and idToken settings. Should this be an option for the commands? Or is this unnecessary?

As soon as the commands are released, we would have to honor backwards compatibility (or release a major update). 😅

Comment on lines 31 to 35
request.application!.lambdaConfiguration!.accessTokenPopulateId = null;
else
request.application!.lambdaConfiguration!.accessTokenPopulateId = accessTokenPopulateId;
if (idTokenPopulateId && idTokenPopulateId == lambdaId)
request.application!.lambdaConfiguration!.idTokenPopulateId = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you set it to undefined instead of null?

TS2322: Type  null  is not assignable to type  string | undefined 

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add brackets to this if statements? It's hard to read.

Copy link
Author

Choose a reason for hiding this comment

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

@ColinFrick Cool will fix this. I forgot to mention I had opened a PR on the typescript client FusionAuth/fusionauth-typescript-client#86 to allow for null which this PR depends on. Though after Dan's comment I realised that change cannot be made directly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Setting the properties to undefined and updating the application with patchApplication works for me

Copy link
Author

Choose a reason for hiding this comment

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

setting to an empty string seems to work better to reset the value otherwise using undefined will not actually update the property


// noinspection JSUnusedGlobalSymbols
export const lambdaCreate = new Command('lambda:create')
.description(`Create a lambda on FusionAuth.
Copy link
Collaborator

@ColinFrick ColinFrick Aug 22, 2023

Choose a reason for hiding this comment

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

Please add a short .summary('Create a lambda on FusionAuth') for commands with a large description. (lamdba:create, lambda:link-to-application, lamdba:unlink-from-application)

}
};
const fusionAuthClient = new FusionAuthClient(apiKey, host);
const clientResponse = await fusionAuthClient.updateApplication(applicationId, request)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is dangerous. As the API documentation states, with PUT / updateApplication you must specify all of the properties of the Application. This will cause data loss in the application configuration.

Use patchApplication instead, then you can also drop the name property in the request.

request.application!.lambdaConfiguration!.idTokenPopulateId = idTokenPopulateId;

const fusionAuthClient = new FusionAuthClient(apiKey, host);
const clientResponse = await fusionAuthClient.updateApplication(applicationId, request)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same problem as before, use patchApplication

RichardJECooke pushed a commit to ritza-co/fusionauth-site that referenced this pull request Aug 22, 2023
…pdate the application in cases where Typescript does not allow nulls. Origin: FusionAuth/fusionauth-node-cli#8
@mooreds
Copy link
Contributor

mooreds commented Aug 23, 2023

I think it would be a lot of work to support linking and unlinking lambdas across all their locations. I didn't consider the ramifications (both for initial implementation and ongoing support--every time a new lambda is added, we'd have to update this tool).

Since this tool is really about making it easier to develop custom components for FusionAuth, any issues with removing the link/unlink commands? @ColinFrick @rideam

@rideam
Copy link
Author

rideam commented Aug 23, 2023

@mooreds no issues removing the link/unlink commands,, I will just update the lambda testing article to remove where they are mentioned. Let me know what you decide.

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.

3 participants