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
snap/naming: move various name validation helpers to separate package #6016
snap/naming: move various name validation helpers to separate package #6016
Conversation
Introuduce a new package that pulls out the validation of various names around snaps. Name validation covers: snaps, instances, apps, aliases, hooks, slots/plugs/interfaces, sockets. The package has no extra dependencies. Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
wouldn't (super big +1 to the change beyond this) |
@chipaca that's something I thought of in the beginning. The downside is, you'd still need to have access to |
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change itself looks fine. I don't have any strong opinions either way about this move so +1 to unblock progress.
I think this is nice - I am not sure if I understand @chipaca correct but I also prefer |
Please deconflict @bboozzoo |
…ame-separate-package
…ame-separate-package
Rename the package Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
As discussed, I've renamed the package to |
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like.
return fmt.Errorf("invalid instance key: %q", instanceKey) | ||
} | ||
return nil | ||
return naming.ValidateInstance(instanceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what are your thoughts? is that a intermediate step for churn? I would suppose in the end we don't want this indirection functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I didn't want the diff to be overly large. The cleanup can be introduced once this PR lands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, +1 with some minor but relevant comments (some are old stuff spotted now because of the move)
snap/naming/validate.go
Outdated
} | ||
if !validInstanceKey.MatchString(instanceKey) { | ||
// TODO parallel-install: extend the error message once snap | ||
// install help has been updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this TODO still relevant? something we can do now?
snap/naming/validate.go
Outdated
// validators. | ||
var almostValidName = regexp.MustCompile("^[a-z0-9-]*[a-z][a-z0-9-]*$") | ||
|
||
// validInstanceKey is a regular expression describing valid snap instance key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a valid
* | ||
*/ | ||
|
||
package naming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Package naming implements naming constraints for snaps and their elements.
snap/naming/validate.go
Outdated
// validInstanceKey is a regular expression describing valid snap instance key | ||
var validInstanceKey = regexp.MustCompile("^[a-z0-9]{1,10}$") | ||
|
||
// isValidName checks snap and socket socket identifiers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/socket socket/socket/ ?
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
…ame-separate-package
Follow-up on the package separation idea discussed in #5948. The PR moves various snap related name validation helpers into a separate package that can be easily imported without pulling in the whole of
githut.com/snapcore/snapd/snap
baggage.As part of the PR, the package is used by model assertion validation code, where the
snap
package could not have been previously used.