public static Future selectDeployment()

in server/src/main/java/com/epam/aidial/core/server/controller/DeploymentController.java [67:132]


    public static Future<Deployment> selectDeployment(ProxyContext context, String id, boolean filterCustomProperties, boolean modifyEndpoint) {
        Deployment deployment = context.getConfig().selectDeployment(id);
        Proxy proxy = context.getProxy();
        if (deployment != null) {
            if (!deployment.hasAccess(context.getUserRoles())) {
                return Future.failedFuture(new PermissionDeniedException("Forbidden deployment: " + id));
            } else {
                try {
                    if (deployment instanceof Application application) {
                        if (!modifyEndpoint && !filterCustomProperties) {
                            return Future.succeededFuture(deployment);
                        }
                        return proxy.getVertx().executeBlocking(() -> {
                            if (application.getApplicationTypeSchemaId() == null) {
                                return application;
                            }
                            Application modifiedApp = application;
                            if (filterCustomProperties) {
                                modifiedApp = ApplicationTypeSchemaUtils.filterCustomClientProperties(context.getConfig(), application);
                            }
                            if (modifyEndpoint) {
                                modifiedApp = ApplicationTypeSchemaUtils.modifyEndpointForCustomApplication(context.getConfig(), modifiedApp);
                            }
                            return modifiedApp;
                        }, false);
                    }
                    return Future.succeededFuture(deployment);
                } catch (Throwable e) {
                    return Future.failedFuture(e);
                }
            }
        }

        return proxy.getVertx().executeBlocking(() -> {
            String url;
            ResourceDescriptor resource;

            try {
                url = UrlUtil.encodePath(id);
                resource = ResourceDescriptorFactory.fromAnyUrl(url, proxy.getEncryptionService());
            } catch (Throwable ignore) {
                throw new ResourceNotFoundException("Unknown application: " + id);
            }

            if (resource.isFolder() || resource.getType() != ResourceTypes.APPLICATION) {
                throw new ResourceNotFoundException("Invalid application url: " + url);
            }

            if (!proxy.getAccessService().hasReadAccess(resource, context)) {
                throw new PermissionDeniedException();
            }

            Application app = proxy.getApplicationService().getApplication(resource).getValue();

            if (app.getApplicationTypeSchemaId() != null) {
                if (filterCustomProperties) {
                    app = ApplicationTypeSchemaUtils.filterCustomClientPropertiesWhenNoWriteAccess(context, resource, app);
                }
                if (modifyEndpoint) {
                    app = ApplicationTypeSchemaUtils.modifyEndpointForCustomApplication(context.getConfig(), app);
                }
            }

            return app;
        }, false);
    }