From 87ae25495a4c81aba9f79e8a99f44871f4bd968a Mon Sep 17 00:00:00 2001 From: Mohammed Ibrahim Date: Thu, 10 Oct 2024 16:07:45 -0400 Subject: [PATCH] Cleanup Validation flow (#3171) --- .../api/HostedServiceService.java | 1 - .../pom.xml | 4 -- .../HostedServiceArtifactGenerator.java | 21 -------- .../control/DeploymentOwnerValidator.java | 35 ------------ .../HostedServiceOwnerValidationService.java | 53 ------------------- .../control/HostedServiceOwnerValidator.java | 26 --------- .../control/UserListOwnerValidator.java | 48 ----------------- ...ration.control.HostedServiceOwnerValidator | 2 - 8 files changed, 190 deletions(-) delete mode 100644 legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/DeploymentOwnerValidator.java delete mode 100644 legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/HostedServiceOwnerValidationService.java delete mode 100644 legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/HostedServiceOwnerValidator.java delete mode 100644 legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/UserListOwnerValidator.java delete mode 100644 legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/resources/META-INF/services/org.finos.legend.engine.language.hostedService.generation.control.HostedServiceOwnerValidator diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-api/src/main/java/org/finos/legend/engine/language/hostedService/api/HostedServiceService.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-api/src/main/java/org/finos/legend/engine/language/hostedService/api/HostedServiceService.java index 0ff8445b48b..f2c8d85e4f0 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-api/src/main/java/org/finos/legend/engine/language/hostedService/api/HostedServiceService.java +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-api/src/main/java/org/finos/legend/engine/language/hostedService/api/HostedServiceService.java @@ -88,7 +88,6 @@ public MutableList validate(Identity identity, MutableList errors = Lists.mutable.empty(); try { - this.hostedServiceArtifactgenerator.validateOwner(identity, pureModel, activator, routerExtensions); core_hostedservice_generation_generation.Root_meta_external_function_activator_hostedService_validator_validateService_HostedService_1__Boolean_1_(activator, pureModel.getExecutionSupport()); //returns true or errors out } diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/pom.xml b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/pom.xml index b48be02c756..c871ac8f2ea 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/pom.xml +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/pom.xml @@ -57,10 +57,6 @@ org.finos.legend.engine legend-engine-protocol-pure - - org.finos.legend.engine - legend-engine-shared-extensions - org.finos.legend.engine legend-engine-shared-core diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/HostedServiceArtifactGenerator.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/HostedServiceArtifactGenerator.java index 31c7cee62fb..f049796b010 100644 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/HostedServiceArtifactGenerator.java +++ b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/HostedServiceArtifactGenerator.java @@ -20,8 +20,6 @@ import org.eclipse.collections.api.factory.Maps; import org.eclipse.collections.api.list.ListIterable; import org.eclipse.collections.api.list.MutableList; -import org.finos.legend.engine.language.hostedService.generation.control.HostedServiceOwnerValidationService; -import org.finos.legend.engine.language.hostedService.generation.control.HostedServiceOwnerValidator; import org.finos.legend.engine.plan.generation.extension.PlanGeneratorExtension; import org.finos.legend.engine.plan.generation.transformers.PlanTransformer; import org.finos.legend.engine.protocol.hostedService.deployment.model.GenerationInfoData; @@ -35,10 +33,7 @@ import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.CompositeExecutionPlan; import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.ExecutionPlan; import org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan; -import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.pure.generated.Root_meta_external_function_activator_Ownership; import org.finos.legend.pure.generated.Root_meta_external_function_activator_hostedService_HostedService; -import org.finos.legend.pure.generated.Root_meta_external_function_activator_Ownership; import org.finos.legend.pure.generated.Root_meta_pure_extension_Extension; import org.finos.legend.pure.generated.core_hostedservice_generation_generation; import org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.function.ConcreteFunctionDefinition; @@ -89,22 +84,6 @@ public static String generateLineage(PureModel pureModel, Root_meta_external_fun return core_hostedservice_generation_generation.Root_meta_external_function_activator_hostedService_generation_computeLineage_HostedService_1__Extension_MANY__String_1_(activator, routerExtensions.apply(pureModel), pureModel.getExecutionSupport()); } - public boolean validateOwner(Identity identity, PureModel pureModel, Root_meta_external_function_activator_hostedService_HostedService activator, Function> routerExtensions) - { - HostedServiceOwnerValidator service = getOwnerValidatorService(activator,pureModel); - return service.isOwner(identity, activator._ownership()); - } - - public HostedServiceOwnerValidator getOwnerValidatorService(Root_meta_external_function_activator_hostedService_HostedService activator, PureModel pureModel) - { - HostedServiceOwnerValidator service = HostedServiceOwnerValidationService.extensions().select(c -> c.supports(activator._ownership())).getFirst(); - if (service == null) - { - throw new RuntimeException(activator._ownership().getClass().getSimpleName() + "is not yet supported as an ownership model!"); - } - return service; - } - public static PureModelContextData fetchHostedService(Root_meta_external_function_activator_hostedService_HostedService activator, PureModelContextData data, PureModel pureModel) { return PureModelContextData.newBuilder() diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/DeploymentOwnerValidator.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/DeploymentOwnerValidator.java deleted file mode 100644 index 3f16c0518a3..00000000000 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/DeploymentOwnerValidator.java +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2023 Goldman Sachs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.finos.legend.engine.language.hostedService.generation.control; - -import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.pure.generated.Root_meta_external_function_activator_DeploymentOwnership; -import org.finos.legend.pure.generated.Root_meta_external_function_activator_Ownership; - -public class DeploymentOwnerValidator implements HostedServiceOwnerValidator -{ - @Override - public boolean isOwner(Identity identity, Root_meta_external_function_activator_DeploymentOwnership ownershipModel) - { - return ownershipModel._id().equals("testId"); - } - - @Override - public boolean supports(Root_meta_external_function_activator_Ownership ownershipModel) - { - return ownershipModel instanceof Root_meta_external_function_activator_DeploymentOwnership; - } - -} diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/HostedServiceOwnerValidationService.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/HostedServiceOwnerValidationService.java deleted file mode 100644 index 4c04d2164a5..00000000000 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/HostedServiceOwnerValidationService.java +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2023 Goldman Sachs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.finos.legend.engine.language.hostedService.generation.control; - -import org.eclipse.collections.api.list.MutableList; -import org.eclipse.collections.impl.factory.Lists; - -import java.util.ServiceLoader; -import java.util.concurrent.atomic.AtomicReference; - - -public class HostedServiceOwnerValidationService -{ - private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger("Alloy Execution Server"); - private static final AtomicReference> INSTANCE = new AtomicReference<>(); - - public static MutableList extensions() - { - return INSTANCE.updateAndGet(existing -> - { - if (existing == null || existing.isEmpty()) - { - MutableList extensions = Lists.mutable.empty(); - for (HostedServiceOwnerValidator extension : ServiceLoader.load(HostedServiceOwnerValidator.class)) - { - try - { - extensions.add(extension); - } - catch (Throwable throwable) - { - LOGGER.error("Failed to load owner validation extension '" + extension.getClass().getSimpleName() + "'"); - // Needs to be silent ... during the build process - } - } - return extensions; - } - return existing; - }); - } -} diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/HostedServiceOwnerValidator.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/HostedServiceOwnerValidator.java deleted file mode 100644 index 87d3d21f49b..00000000000 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/HostedServiceOwnerValidator.java +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2023 Goldman Sachs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.finos.legend.engine.language.hostedService.generation.control; - -import org.finos.legend.engine.shared.core.extension.LegendModuleSpecificExtension; -import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.pure.generated.Root_meta_external_function_activator_Ownership; - -public interface HostedServiceOwnerValidator extends LegendModuleSpecificExtension -{ - boolean isOwner(Identity identity, T ownershipModel); - - public boolean supports(Root_meta_external_function_activator_Ownership ownershipModel); -} diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/UserListOwnerValidator.java b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/UserListOwnerValidator.java deleted file mode 100644 index e2fbb3af96a..00000000000 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/java/org/finos/legend/engine/language/hostedService/generation/control/UserListOwnerValidator.java +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2023 Goldman Sachs -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.finos.legend.engine.language.hostedService.generation.control; - -import org.finos.legend.engine.shared.core.identity.Identity; -import org.finos.legend.engine.shared.core.identity.credential.LegendKerberosCredential; -import org.finos.legend.engine.shared.core.kerberos.SubjectTools; -import org.finos.legend.pure.generated.Root_meta_external_function_activator_Ownership; -import org.finos.legend.pure.generated.Root_meta_external_function_activator_hostedService_UserList; - -import javax.security.auth.Subject; -import java.util.NoSuchElementException; - -public class UserListOwnerValidator implements HostedServiceOwnerValidator -{ - @Override - public boolean isOwner(Identity identity, Root_meta_external_function_activator_hostedService_UserList users) - { - Subject subject = null; - try - { - subject = identity.getCredential(LegendKerberosCredential.class).get().getSubject(); - } - catch (NoSuchElementException e) - { - return false; - } - return users._users().contains(SubjectTools.getKerberos(subject)); //use profile - } - - @Override - public boolean supports(Root_meta_external_function_activator_Ownership ownershipModel) - { - return ownershipModel instanceof Root_meta_external_function_activator_hostedService_UserList; - } -} diff --git a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/resources/META-INF/services/org.finos.legend.engine.language.hostedService.generation.control.HostedServiceOwnerValidator b/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/resources/META-INF/services/org.finos.legend.engine.language.hostedService.generation.control.HostedServiceOwnerValidator deleted file mode 100644 index 5aac5bcc95f..00000000000 --- a/legend-engine-xts-hostedService/legend-engine-xt-hostedService-generation/src/main/resources/META-INF/services/org.finos.legend.engine.language.hostedService.generation.control.HostedServiceOwnerValidator +++ /dev/null @@ -1,2 +0,0 @@ -org.finos.legend.engine.language.hostedService.generation.control.DeploymentOwnerValidator -org.finos.legend.engine.language.hostedService.generation.control.UserListOwnerValidator \ No newline at end of file