Skip to content

KeycloakResourceBuilderExtensions.WithRealmImport is unnecessarily constraining the bind to a directory #5086

@paulomorgado

Description

Background and Motivation

KeycloakResourceBuilderExtensions.WithRealmImport is unnecessarily constraining the bind to a single directory, constraining the user choices.

Proposed API

Consider something like this, instead:

    public static IResourceBuilder<KeycloakResource> WithRealmImport(
        this IResourceBuilder<KeycloakResource> builder,
        string import,
        bool isReadOnly = false)
    {
        ArgumentNullException.ThrowIfNull(importDirectory);

        if (Directory.Exists(import))
        {
            builder.WithBindMount(import, "/opt/keycloak/data/import", isReadOnly);
        }
        else
        {
            var fileName = Path.GetFileName(import);

            builder.WithBindMount(import, $"/opt/keycloak/data/import/{fileName}", isReadOnly);
        }

        return builder;
    }

Do not test if the source file or directory exists, because the user might create them later.

Usage Examples

var keycloak = builder.AddKeycloak(...);
// ...
keycloak.WithRealmImport(<path to file>);
// ...
keycloak.WithRealmImport(<path to another file>);

Metadata

Assignees

No one assigned

    Labels

    area-integrationsIssues pertaining to Aspire Integrations packageskeycloakIssues related to keycloack integrations

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions