public void registerActions()

in Utils/azure-toolkit-ide-libs/azure-toolkit-ide-containerregistry-lib/src/main/java/com/microsoft/azure/toolkit/ide/containerregistry/ContainerRegistryActionsContributor.java [54:249]


    public void registerActions(AzureActionManager am) {
        new Action<>(PUSH_IMAGE)
            .withLabel("Push Image")
            .withIcon(AzureIcons.DockerSupport.PUSH_IMAGE.getIconPath())
            .visibleWhen(s -> s instanceof ContainerRegistry)
            .enableWhen(s -> s.getFormalStatus().isRunning())
            .withIdParam(AzResource::getName)
            .register(am);

        new Action<>(ENABLE_ADMIN_USER)
            .withLabel("Enable Admin User")
            .visibleWhen(s -> s instanceof ContainerRegistry && !((ContainerRegistry) s).isAdminUserEnabled())
            .withIdParam(AzResource::getName)
            .withHandler(s -> {
                s.enableAdminUser();
                final AzureString message = AzureString.format("Admin user is enabled for Azure Container Registry %s. You can docker login to it now.", s.getName());
                final Action<ContainerRegistry> login = am.getAction(LOGIN).bind(s).withLabel("Login Now!");
                final Action<ContainerRegistry> copyPassword = am.getAction(COPY_PASSWORD).bind(s);
                final Action<ContainerRegistry> copyLoginCommand = am.getAction(COPY_LOGIN_COMMAND).bind(s);
                AzureMessager.getMessager().success(message, login, copyPassword, copyLoginCommand);
            })
            .register(am);

        new Action<>(DISABLE_ADMIN_USER)
            .withLabel("Disable Admin User")
            .visibleWhen(s -> s instanceof ContainerRegistry && ((ContainerRegistry) s).isAdminUserEnabled())
            .withIdParam(AzResource::getName)
            .withHandler(s -> {
                final String message = "You will not be able to docker login to this container registry if admin user is disabled, Azure you sure to disable it?";
                if (AzureMessager.getMessager().confirm(message)) {
                    s.disableAdminUser();
                    final Action<ContainerRegistry> logout = am.getAction(LOGOUT).bind(s);
                    AzureMessager.getMessager().success(AzureString.format("Admin user is disabled for Azure Container Registry %s", s.getName()), logout);
                }
            })
            .register(am);

        new Action<>(COPY_LOGIN_COMMAND)
            .withIcon(AzureIcons.Action.COPY.getIconPath())
            .withLabel("Copy Login Command")
            .withIdParam(AbstractAzResource::getName)
            .visibleWhen(s -> s instanceof ContainerRegistry)
            .enableWhen(ContainerRegistry::isAdminUserEnabled)
            .withHandler((s, e) -> {
                final String command = String.format("docker login %s -u %s -p %s", s.getLoginServerUrl(), s.getUserName(), s.getPrimaryCredential());
                am.getAction(ResourceCommonActionsContributor.COPY_STRING).handle(command, e);
                AzureMessager.getMessager().success(AzureString.format("login command %s is copied into clipboard", command));
            })
            .register(am);

        new Action<>(LOGIN)
            .withLabel("Docker Login")
            .withIdParam(AbstractAzResource::getName)
            .visibleWhen(s -> s instanceof ContainerRegistry)
            .register(am);

        new Action<>(LOGOUT)
            .withLabel("Docker Logout")
            .withIdParam(AbstractAzResource::getName)
            .visibleWhen(s -> s instanceof ContainerRegistry)
            .register(am);

        new Action<>(COPY_REGISTRY_URL)
            .withIcon(AzureIcons.Action.COPY.getIconPath())
            .withLabel("Copy Registry URL")
            .withIdParam(AzResource::getName)
            .visibleWhen(s -> s instanceof ContainerRegistry)
            .withHandler((s, e) -> {
                final Action<ContainerRegistry> login = am.getAction(LOGIN).bind(s);
                final Action<ContainerRegistry> copyPassword = am.getAction(COPY_PASSWORD).bind(s);
                am.getAction(ResourceCommonActionsContributor.COPY_STRING).handle(s.getLoginServerUrl(), e);
                AzureMessager.getMessager().success(AzureString.format("Registry URL %s is copied into clipboard.", s.getLoginServerUrl()), login, copyPassword);
            })
            .register(am);

        new Action<>(COPY_USERNAME)
            .withIcon(AzureIcons.Action.COPY.getIconPath())
            .withLabel("Copy Admin Username")
            .withIdParam(AzResource::getName)
            .visibleWhen(s -> s instanceof ContainerRegistry)
            .withHandler((s, e) -> {
                if (!s.isAdminUserEnabled()) {
                    final Action<ContainerRegistry> enableAdminUser = am.getAction(ContainerRegistryActionsContributor.ENABLE_ADMIN_USER).bind(s);
                    throw new AzureToolkitRuntimeException("Admin user is not enabled.", enableAdminUser);
                }
                final Action<ContainerRegistry> login = am.getAction(LOGIN).bind(s);
                final Action<ContainerRegistry> copyPassword = am.getAction(COPY_PASSWORD).bind(s);
                am.getAction(ResourceCommonActionsContributor.COPY_STRING).handle(s.getUserName(), e);
                AzureMessager.getMessager().success(AzureString.format("Username %s is copied into clipboard.", s.getUserName()), login, copyPassword);
            })
            .register(am);

        new Action<>(COPY_PASSWORD)
            .withIcon(AzureIcons.Action.COPY.getIconPath())
            .withLabel("Copy Admin Password")
            .withIdParam(AzResource::getName)
            .visibleWhen(s -> s instanceof ContainerRegistry)
            .withHandler((s, e) -> {
                if (!s.isAdminUserEnabled()) {
                    final Action<ContainerRegistry> enableAdminUser = am.getAction(ContainerRegistryActionsContributor.ENABLE_ADMIN_USER).bind(s);
                    throw new AzureToolkitRuntimeException("Admin user is not enabled.", enableAdminUser);
                }
                final Action<ContainerRegistry> login = am.getAction(LOGIN).bind(s);
                final Action<ContainerRegistry> copyRegistryUrl = am.getAction(COPY_REGISTRY_URL).bind(s);
                am.getAction(ResourceCommonActionsContributor.COPY_STRING).handle(s.getPrimaryCredential(), e);
                AzureMessager.getMessager().success("Primary password is copied into clipboard.", login, copyRegistryUrl);
            })
            .register(am);

        new Action<>(COPY_DIGEST)
            .withIcon(AzureIcons.Action.COPY.getIconPath())
            .withLabel("Copy Digest")
            .withIdParam(Tag::getImageName)
            .visibleWhen(s -> s instanceof Tag)
            .withHandler((s, e) -> {
                am.getAction(ResourceCommonActionsContributor.COPY_STRING).handle(s.getDigest(), e);
                AzureMessager.getMessager().success(AzureString.format("Digest %s is copied into clipboard.", s.getDigest()));
            })
            .register(am);

        new Action<>(COPY_PULL_COMMAND)
            .withIcon(AzureIcons.Action.COPY.getIconPath())
            .withLabel("Copy Pull Command")
            .withIdParam(Tag::getImageName)
            .visibleWhen(s -> s instanceof Tag)
            .withHandler((s, e) -> {
                final String command = String.format("docker pull %s", s.getFullName());
                am.getAction(ResourceCommonActionsContributor.COPY_STRING).handle(command, e);
                final Action<Tag> pull = am.getAction(ContainerRegistryActionsContributor.PULL_IMAGE).bind(s).withLabel("Pull Now!");
                final ContainerRegistry registry = s.getParent().getParent().getParent();
                if (!registry.isAdminUserEnabled()) {
                    final Action<ContainerRegistry> enableAdminUser = am.getAction(ContainerRegistryActionsContributor.ENABLE_ADMIN_USER).bind(registry);
                    final AzureString message = AzureString.format("Pull command %s is copied into clipboard. " +
                        "But it may fail because admin user is not enabled for Azure Container Registry %s", command, registry.getName());
                    AzureMessager.getMessager().success(message, enableAdminUser, pull);
                } else {
                    AzureMessager.getMessager().success(AzureString.format("Pull command %s is copied into clipboard", command), pull);
                }
            })
            .register(am);

        new Action<>(COPY_RUN_COMMAND)
            .withIcon(AzureIcons.Action.COPY.getIconPath())
            .withLabel("Copy Run Command")
            .withIdParam(Tag::getImageName)
            .visibleWhen(s -> s instanceof Tag)
            .withHandler((s, e) -> {
                final String command = String.format("docker run -p 8080:8080 %s", s.getFullName());
                am.getAction(ResourceCommonActionsContributor.COPY_STRING).handle(command);
                AzureMessager.getMessager().success(AzureString.format("Run command %s is copied into clipboard", command));
            })
            .register(am);

        new Action<>(PULL_IMAGE)
            .withIcon(t -> AzureIcons.DockerSupport.PULL_IMAGE.getIconPath())
            .withLabel("Pull Image")
            .withIdParam(Tag::getImageName)
            .visibleWhen(s -> s instanceof Tag)
            .register(am);

        new Action<>(INSPECT_IMAGE)
            .withIcon(t -> AzureIcons.Action.SEARCH.getIconPath())
            .withLabel("Inspect")
            .withIdParam(Tag::getImageName)
            .visibleWhen(s -> s instanceof Tag)
            .register(am);

        new Action<>(RUN_LOCALLY)
            .withIcon(t -> AzureIcons.Action.START.getIconPath())
            .withLabel("Run as Container")
            .withIdParam(Tag::getImageName)
            .visibleWhen(s -> s instanceof Tag)
            .register(am);

        new Action<>(DEPLOY_IMAGE_ACA)
            .withIcon(t -> AzureIcons.Action.DEPLOY.getIconPath())
            .withLabel("Deploy to Container App")
            .withIdParam(Tag::getImageName)
            .visibleWhen(s -> s instanceof Tag)
            .register(am);

        new Action<>(DEPLOY_IMAGE_WEBAPP)
            .withIcon(t -> AzureIcons.Action.DEPLOY.getIconPath())
            .withLabel("Deploy to Web App")
            .withIdParam(Tag::getImageName)
            .visibleWhen(s -> s instanceof Tag)
            .register(am);

        new Action<>(GROUP_CREATE_CONTAINER_REGISTRY)
            .withLabel("Container Registry")
            .withIdParam(AzResource::getName)
            .visibleWhen(s -> s instanceof ResourceGroup)
            .enableWhen(s -> s.getFormalStatus().isConnected())
            .withHandler((s, e) -> am.getAction(ResourceCommonActionsContributor.CREATE_IN_PORTAL).handle(Azure.az(AzureContainerRegistry.class), e))
            .register(am);
    }