fnproject/cli

CLI must not violate FN name constraints

Closed this issue · 8 comments

As a developer, I'd like to get smooth experience while using CLI: when I create a function with a trigger defined, CLI must validate trigger's name length.
Let's say, my function has 23 chars in its name, so, CLI will append -trigger to that in order to form a trigger name which name a trigger name invalid because it violates a trigger name length constraint of the Fn server.

At this particular moment, CLI doesn't perform length constraint validation for the following attributes:

  1. Function's name. fn init --runtime go --trigger http amplification-threshold-trigger-func works, but not suppose to be.
  2. Trigger's name. CLI appends -trigger to a function name when creating a function (using fn init) with --trigger http.

Fn has strict constraints for names (app, fn, trigger) and CLI must/suppose to inherit them.

What is the length constraint? 32 chars? And why?

@rikgibson the constraint is 31 symbol for now.

Hmmm, my initial reaction to this is "Hey 1992 called and would like it's Pascal strings back". Why 31?

@rikgibson we had this convo long time ago in Iron, but I don't recall an outcome of that. @rdallman do you remember that?

I agree with Rik, but think this is a separate issue - regardless what the limit is, I think we'd still need validation for it. Therefore, I've had a go at this here:

vzDevelopment/fn@d037308
vzDevelopment@e87eee2

I tracked down where the validation is being done on the server side and refactored it slightly so we could make use of the validation here too. This means if the validation on the server side changes we won't need to go and update the CLI too.

To circumvent the issue of the cli adding the -trigger suffix and this pushing a valid function name over the trigger length I am truncating the name before adding the -trigger suffix so that the trigger name won't ever be more than its limit. Other options for this are:

  • Don't add the -trigger suffix - what's the reason it's added? I'm assuming just to make it more obvious when the user is editing the func.yaml.
  • Only add the -trigger suffix if the function name is less than 24 characters.
  • Throw an error if the function name provided is more than 23 characters - although I feel this is unexpected as the server accepts function names that are 30 characters.

Being new to the code base I wasn't 100% sure if using api/models was the correct way to go about this. If it isn't let me know. For example, should I look at to using modelsV2 instead?

I am still waiting to be added to the Oracle Organisation so am not able to assign this ticket to myself or raise a PR for this yet. Edit: I've now been added and a PR has been raised.

Just seen fnproject/fn#1452 which addresses Rik's point

Don't add the -trigger suffix - what's the reason it's added? I'm assuming just to make it more obvious when the user is editing the func.yaml.

I think this is the best option. there are/were a few strange name manipulations we do/did and it seems wise to just get rid of them all if we can. that would also close this issue I believe, thanks for the response here.

it appears that the case here is when creating a trigger under the same name as a function it adds the function name + trigger to be the trigger name. this will be an issue if/when we allow a func file to define multiple triggers in a func file but the way this is now would be problematic, too. possibly we need to allow trigger names to be specified in a func file and/or use the trigger type to dedupe, as trigger name must be unique