You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm open to introducing restrictions on resource identifiers as long as we author an analyzer for it at the same time, so that the format validity can be seen directly in the editor as an error (and at build time too).
Based on some offline discussions, a suggested set of restrictions to start with might be:
Limited to ASCII alphanumeric chars
Must start with an alpha char
Only special character allowed is hyphen (-) as a separator
❓ Should we allow a trailing hyphen
❓ Should we allow consecutive hyphens
Must be between 1 and 64 chars total length
Must be unique within the built app model
Is case-insensitive (e.g. "api1" and "API1" are equivalent)
Should we allow trailing hyphen ... no.
Should we allow consecutive hypens ... no.
Should we allow hyphens at all ... in my opinion .. no. The reason is that some resource types in cloud providers don't allow them.
We should consider forcing them all the lower case as well (also a constraint in some cloud providers).
Should we allow hyphens at all ... in my opinion .. no. The reason is that some resource types in cloud providers don't allow them.
I think that's too restrictive of a baseline principle. Aspire doesn't itself map to any online cloud provider by itself and we shouldn't restrict resources to the union-set of all possible providers or even major providers. I think allowing a single separator char like hyphen in our resource names is required. If a given cloud platform doesn't support it for a given resource type, then the deployment tech should handle that translation.
tldr; I like the rules that Damian Edwards (@DamianEdwards) proposed. I think the important part of this is sanitizing and reporting problematic names where required, e.g. convent name to lower case for an Azure storage account.
Only special character allowed is hyphen (-) as a separator
How often will resource names be used as an identifier in code gen C#? Hyphen isn't allowed in C# identifiers so a resource name can't be used to code gen a my-cool-resource property for example.
I think the solution in this case is to convert hyphen to underscore in generated C# identifiers, e.g. my-cool-resource -> Resources.my_cool_resource.
We should consider forcing them all the lower case as well (also a constraint in some cloud providers).
Storage account names don't allow capital letters. Sorry to pile on!
If names are case-insensitive, then it doesn't matter if capitals are allowed or not. If the resource name needs to be used as a storage account name, then it can safely be converted to lowercase, e.g. MyCoolResource -> mycoolresource.
Should we allow hyphens at all ... in my opinion .. no. The reason is that some resource types in cloud providers don't allow them.
If a cloud provider doesn't support hyphens, then they could be removed when generating names for that cloud provider. For example, my-cool-resource is converted to my_cool_resource (if underscores are allow) or mycoolresource if only alpha characters are allowed.
There could be conflicts between resources if there is my-cool-resource and mycoolresource because they resolve to the same name, but we can prompt with an error if that rare situation occurs.
Activity
DamianEdwards commentedon Dec 15, 2023
I'm open to introducing restrictions on resource identifiers as long as we author an analyzer for it at the same time, so that the format validity can be seen directly in the editor as an error (and at build time too).
Based on some offline discussions, a suggested set of restrictions to start with might be:
mitchdenny commentedon Jan 11, 2024
Should we allow trailing hyphen ... no.
Should we allow consecutive hypens ... no.
Should we allow hyphens at all ... in my opinion .. no. The reason is that some resource types in cloud providers don't allow them.
We should consider forcing them all the lower case as well (also a constraint in some cloud providers).
DamianEdwards commentedon Jan 11, 2024
I think that's too restrictive of a baseline principle. Aspire doesn't itself map to any online cloud provider by itself and we shouldn't restrict resources to the union-set of all possible providers or even major providers. I think allowing a single separator char like hyphen in our resource names is required. If a given cloud platform doesn't support it for a given resource type, then the deployment tech should handle that translation.
bradygaster commentedon Jan 13, 2024
Storage account names don't allow capital letters. Sorry to pile on!
mitchdenny commentedon Jan 17, 2024
James Newton-King (@JamesNK)
JamesNK commentedon Jan 17, 2024
tldr; I like the rules that Damian Edwards (@DamianEdwards) proposed. I think the important part of this is sanitizing and reporting problematic names where required, e.g. convent name to lower case for an Azure storage account.
How often will resource names be used as an identifier in code gen C#? Hyphen isn't allowed in C# identifiers so a resource name can't be used to code gen a
my-cool-resourceproperty for example.I think the solution in this case is to convert hyphen to underscore in generated C# identifiers, e.g.
my-cool-resource->Resources.my_cool_resource.If names are case-insensitive, then it doesn't matter if capitals are allowed or not. If the resource name needs to be used as a storage account name, then it can safely be converted to lowercase, e.g.
MyCoolResource->mycoolresource.If a cloud provider doesn't support hyphens, then they could be removed when generating names for that cloud provider. For example,
my-cool-resourceis converted tomy_cool_resource(if underscores are allow) ormycoolresourceif only alpha characters are allowed.There could be conflicts between resources if there is
my-cool-resourceandmycoolresourcebecause they resolve to the same name, but we can prompt with an error if that rare situation occurs.JamesNK commentedon Jan 18, 2024
What about other names in the model? For example, endpoints can have a name. Should they have the same restrictions?
mitchdenny commentedon Jan 18, 2024
This is a good question. I think we should sanitise this input as well. Same restrictions.
JamesNK commentedon Jan 18, 2024
What else has a name?