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

app name and id directive limits #71

Merged
merged 5 commits into from
Jan 13, 2023
Merged

Conversation

jhsinger-klotho
Copy link
Contributor

• Does any part of it require special attention?
• Does it relate to or fix any issue? closes #31 and closes #32

allowing max length of 20 and all AlphaNumeric Characters, - and _. (Can easily change this)

Was going to also make sure Id is set, but that breaks almost every single one of our unit tests, so that would make this a much longer task. Can do it if we want though to make sure that plugins dont have to check that each and every time.

Standard checks

  • Unit tests: Any special considerations? None
  • Docs: Do we need to update any docs, internal or public? Will update our docs bassed on what we want to put in
  • Backwards compatibility: Will this break existing apps? If so, what would be the extra work required to keep them working? If people were using special characters in their app name then no, but that likely wouldve broken our pulumi code

}
match, err := regexp.MatchString(`^[A-Za-z0-9-_]+$`, cfg.appName)
Copy link

Choose a reason for hiding this comment

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

nit: ^[\w-]+$ would be a bit more concise

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 can change it. Also do we think 20 characters is too small for these?

Copy link

Choose a reason for hiding this comment

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

That's kind of what I was getting at with having to find a pretty restrictive intersection of all the constraints. I think (a) 20 feels on the small side from a usability perspective, but also (b) 20 feels about right from a useful-as-a-length-constraint perspective.

🤷

I guess we can put it in and see if people complain. Maybe also add a log line when it happens, so we can get metrics on how often that is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the only issue with a log line is then its visible to the user in both an error sense and logging sense right? The only method we have of streaming back to data dog is through the zap logger.

Copy link

Choose a reason for hiding this comment

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

Oh hm, actually, the fact that there's an error will already get reported back. Let me check if that contains the error message; if so, we shouldn't do that (since it's potentially sensitive), but it'd be good to include it as a sanitized field (maybe a new kind called "Silent" that gets ignored in the stderr output?).

Copy link

Choose a reason for hiding this comment

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

Okay yeah, we don't send the log line (whew!). So, I would:

  1. create a new struct in logging/fields.go called silentAnalytics { key string, data any } or similar , along with a SilentAnalytics function (you can look at annotationField for an example)
  2. add an instance of that to this log line
  3. I think you don't need to do anything else; it'll get reported in analytics, but won't get logged extra to console

Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to have ., :, and maybe / added to the allowable characters as well as those are common separators.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can also move the length checking to the regexp ^[\w-.:/]{3,20}$. And if you compile it first, you can use the compiled .String() to print its regex in the error message.

Copy link

@ghost ghost Jan 12, 2023

Choose a reason for hiding this comment

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

We can also move the length checking to the regexp ^[\w-.:/]{3,20}$

I like it as it is now, because it gives a more precise indication of the problem. That is, "can only contain this set of chars" and "has to be 3-20 chars long" are separate enough that I'd prefer (as a user) to be told which of them I'm violating, even though it's true that a single regex can check both.

(I won't fight hard for either option, just providing input.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added the characters requested and added an analytics Error. Verified in datadog we see

[User: [email protected]] Klotho parameter check failed. 'app' can only contain alphanumeric, -, _, ., :, and /.

if len(id) > 20 {
return cap, fmt.Errorf("'id' must be less than 20 characters in length. 'id' was %s", id)
}
match, err := regexp.MatchString(`^[A-Za-z0-9-_]+$`, id)
Copy link

Choose a reason for hiding this comment

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

ditto for the regexp here

@github-actions
Copy link

Package Line Rate Health
github.com/klothoplatform/klotho/pkg/analytics 2%
github.com/klothoplatform/klotho/pkg/annotation 23%
github.com/klothoplatform/klotho/pkg/core 20%
github.com/klothoplatform/klotho/pkg/env_var 82%
github.com/klothoplatform/klotho/pkg/exec_unit 45%
github.com/klothoplatform/klotho/pkg/infra/kubernetes 58%
github.com/klothoplatform/klotho/pkg/infra/kubernetes/helm 52%
github.com/klothoplatform/klotho/pkg/input 63%
github.com/klothoplatform/klotho/pkg/lang 37%
github.com/klothoplatform/klotho/pkg/lang/dockerfile 0%
github.com/klothoplatform/klotho/pkg/lang/golang 9%
github.com/klothoplatform/klotho/pkg/lang/javascript 47%
github.com/klothoplatform/klotho/pkg/lang/python 60%
github.com/klothoplatform/klotho/pkg/lang/yaml 0%
github.com/klothoplatform/klotho/pkg/logging 7%
github.com/klothoplatform/klotho/pkg/multierr 95%
github.com/klothoplatform/klotho/pkg/provider/aws 60%
github.com/klothoplatform/klotho/pkg/runtime 75%
github.com/klothoplatform/klotho/pkg/static_unit 32%
github.com/klothoplatform/klotho/pkg/validation 73%
Summary 42% (3593 / 8601)

@jhsinger-klotho jhsinger-klotho merged commit 5151d94 into main Jan 13, 2023
@jhsinger-klotho jhsinger-klotho deleted the length_char_restrict branch January 13, 2023 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants