Skip to content

Cannot use "." characters in resource names #1399

Closed

Description

@weikanglim

With a AppHost:

var apiservice = builder.AddProject<Projects.name_ApiService>("api.service");
 
builder.AddProject<Projects.name_Web>("web.frontend")
    .WithReference(apiservice);

You get a manifest that looks like:

"web.frontend": {
      "type": "project.v0",
      "path": "../name.Web/name.Web.csproj",
      "env": {
        "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EXCEPTION_LOG_ATTRIBUTES": "true",
        "OTEL_DOTNET_EXPERIMENTAL_OTLP_EMIT_EVENT_LOG_ATTRIBUTES": "true",
        "services__api.service__0": "{api.service.bindings.http.url}",
        "services__api.service__1": "{api.service.bindings.https.url}"
      },

Which fails infra generation since the dot character in the binding api.service.bindings.http.url is not escaped:

If you run azd up, you get an error that looks like:

ERROR: generating infra/ folder: unknown resource referenced in binding expression: api

Activity

  1. DamianEdwards commented on Dec 15, 2023

    @DamianEdwards
    Member

    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)
  2. mitchdenny commented on Jan 11, 2024

    @mitchdenny
    Member

    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).

  3. DamianEdwards commented on Jan 11, 2024

    @DamianEdwards
    Member

    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.

  4. bradygaster commented on Jan 13, 2024

    @bradygaster
    Member

    Storage account names don't allow capital letters. Sorry to pile on!

  5. mitchdenny commented on Jan 17, 2024

    @mitchdenny
    Member
  6. JamesNK commented on Jan 17, 2024

    @JamesNK
    Member

    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.

  7. JamesNK commented on Jan 18, 2024

    @JamesNK
    Member

    What about other names in the model? For example, endpoints can have a name. Should they have the same restrictions?

  8. mitchdenny commented on Jan 18, 2024

    @mitchdenny
    Member

    This is a good question. I think we should sanitise this input as well. Same restrictions.

  9. JamesNK commented on Jan 18, 2024

    @JamesNK
    Member

    What else has a name?

  10. locked and limited conversation to collaborators on Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions