mirror of
				https://github.com/open-metadata/OpenMetadata.git
				synced 2025-10-31 02:29:03 +00:00 
			
		
		
		
	Co-authored-by: Mohit Yadav <105265192+mohityadav766@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									a084b6090a
								
							
						
					
					
						commit
						b0091f7271
					
				| @ -85,7 +85,7 @@ public class WorkflowResource extends EntityResource<Workflow, WorkflowRepositor | |||||||
|   static final String FIELDS = "owners"; |   static final String FIELDS = "owners"; | ||||||
|   private WorkflowMapper mapper; |   private WorkflowMapper mapper; | ||||||
|   private PipelineServiceClientInterface pipelineServiceClient; |   private PipelineServiceClientInterface pipelineServiceClient; | ||||||
|   private OpenMetadataConnectionBuilder openMetadataConnectionBuilder; |   private OpenMetadataApplicationConfig openMetadataApplicationConfig; | ||||||
| 
 | 
 | ||||||
|   public WorkflowResource(Authorizer authorizer, Limits limits) { |   public WorkflowResource(Authorizer authorizer, Limits limits) { | ||||||
|     super(Entity.WORKFLOW, authorizer, limits); |     super(Entity.WORKFLOW, authorizer, limits); | ||||||
| @ -93,11 +93,11 @@ public class WorkflowResource extends EntityResource<Workflow, WorkflowRepositor | |||||||
| 
 | 
 | ||||||
|   @Override |   @Override | ||||||
|   public void initialize(OpenMetadataApplicationConfig config) { |   public void initialize(OpenMetadataApplicationConfig config) { | ||||||
|  |     this.openMetadataApplicationConfig = config; | ||||||
|     this.mapper = new WorkflowMapper(); |     this.mapper = new WorkflowMapper(); | ||||||
|     this.pipelineServiceClient = |     this.pipelineServiceClient = | ||||||
|         PipelineServiceClientFactory.createPipelineServiceClient( |         PipelineServiceClientFactory.createPipelineServiceClient( | ||||||
|             config.getPipelineServiceClientConfiguration()); |             config.getPipelineServiceClientConfiguration()); | ||||||
|     openMetadataConnectionBuilder = new OpenMetadataConnectionBuilder(config); |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   public static class WorkflowList extends ResultList<Workflow> { |   public static class WorkflowList extends ResultList<Workflow> { | ||||||
| @ -359,7 +359,8 @@ public class WorkflowResource extends EntityResource<Workflow, WorkflowRepositor | |||||||
|       @Context SecurityContext securityContext) { |       @Context SecurityContext securityContext) { | ||||||
|     EntityUtil.Fields fields = getFields(FIELD_OWNERS); |     EntityUtil.Fields fields = getFields(FIELD_OWNERS); | ||||||
|     Workflow workflow = repository.get(uriInfo, id, fields); |     Workflow workflow = repository.get(uriInfo, id, fields); | ||||||
|     workflow.setOpenMetadataServerConnection(openMetadataConnectionBuilder.build()); |     workflow.setOpenMetadataServerConnection( | ||||||
|  |         new OpenMetadataConnectionBuilder(openMetadataApplicationConfig).build()); | ||||||
|     /* |     /* | ||||||
|      We will send the encrypted Workflow to the Pipeline Service Client |      We will send the encrypted Workflow to the Pipeline Service Client | ||||||
|      It will be fetched from the API from there, since we are |      It will be fetched from the API from there, since we are | ||||||
| @ -594,7 +595,8 @@ public class WorkflowResource extends EntityResource<Workflow, WorkflowRepositor | |||||||
|       return workflowConverted; |       return workflowConverted; | ||||||
|     } |     } | ||||||
|     Workflow workflowDecrypted = secretsManager.decryptWorkflow(workflow); |     Workflow workflowDecrypted = secretsManager.decryptWorkflow(workflow); | ||||||
|     OpenMetadataConnection openMetadataServerConnection = openMetadataConnectionBuilder.build(); |     OpenMetadataConnection openMetadataServerConnection = | ||||||
|  |         new OpenMetadataConnectionBuilder(openMetadataApplicationConfig).build(); | ||||||
|     workflowDecrypted.setOpenMetadataServerConnection( |     workflowDecrypted.setOpenMetadataServerConnection( | ||||||
|         secretsManager.encryptOpenMetadataConnection(openMetadataServerConnection, false)); |         secretsManager.encryptOpenMetadataConnection(openMetadataServerConnection, false)); | ||||||
|     if (authorizer.shouldMaskPasswords(securityContext)) { |     if (authorizer.shouldMaskPasswords(securityContext)) { | ||||||
|  | |||||||
| @ -166,9 +166,6 @@ public class OpenMetadataConnectionBuilder { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   public OpenMetadataConnection build() { |   public OpenMetadataConnection build() { | ||||||
|     // Initialize the bot user while building to update any |  | ||||||
|     // changes done on the bot like updating jwt token |  | ||||||
|     initializeBotUser(Entity.INGESTION_BOT_NAME); |  | ||||||
|     return new OpenMetadataConnection() |     return new OpenMetadataConnection() | ||||||
|         .withAuthProvider(authProvider) |         .withAuthProvider(authProvider) | ||||||
|         .withHostPort(openMetadataURL) |         .withHostPort(openMetadataURL) | ||||||
|  | |||||||
| @ -0,0 +1,54 @@ | |||||||
|  | package org.openmetadata.service.util; | ||||||
|  | 
 | ||||||
|  | import com.auth0.jwt.JWT; | ||||||
|  | import com.auth0.jwt.interfaces.DecodedJWT; | ||||||
|  | import lombok.extern.slf4j.Slf4j; | ||||||
|  | import org.junit.jupiter.api.Assertions; | ||||||
|  | import org.junit.jupiter.api.BeforeAll; | ||||||
|  | import org.junit.jupiter.api.Test; | ||||||
|  | import org.openmetadata.schema.api.configuration.pipelineServiceClient.PipelineServiceClientConfiguration; | ||||||
|  | import org.openmetadata.schema.security.secrets.SecretsManagerClientLoader; | ||||||
|  | import org.openmetadata.schema.security.secrets.SecretsManagerConfiguration; | ||||||
|  | import org.openmetadata.schema.security.secrets.SecretsManagerProvider; | ||||||
|  | import org.openmetadata.schema.security.ssl.VerifySSL; | ||||||
|  | import org.openmetadata.schema.services.connections.metadata.OpenMetadataConnection; | ||||||
|  | import org.openmetadata.service.OpenMetadataApplicationConfig; | ||||||
|  | import org.openmetadata.service.OpenMetadataApplicationTest; | ||||||
|  | import org.openmetadata.service.secrets.SecretsManagerFactory; | ||||||
|  | 
 | ||||||
|  | @Slf4j | ||||||
|  | public class OpenMetadataConnectionBuilderTest extends OpenMetadataApplicationTest { | ||||||
|  | 
 | ||||||
|  |   private static SecretsManagerConfiguration config; | ||||||
|  |   static final String CLUSTER_NAME = "test"; | ||||||
|  | 
 | ||||||
|  |   @BeforeAll | ||||||
|  |   static void setUp() { | ||||||
|  |     config = new SecretsManagerConfiguration(); | ||||||
|  |     config.setSecretsManager(SecretsManagerProvider.DB); | ||||||
|  |     SecretsManagerFactory.createSecretsManager(config, CLUSTER_NAME); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   @Test | ||||||
|  |   void testOpenMetadataConnectionBuilder() { | ||||||
|  | 
 | ||||||
|  |     OpenMetadataApplicationConfig openMetadataApplicationConfig = | ||||||
|  |         new OpenMetadataApplicationConfig(); | ||||||
|  |     openMetadataApplicationConfig.setClusterName(CLUSTER_NAME); | ||||||
|  |     openMetadataApplicationConfig.setPipelineServiceClientConfiguration( | ||||||
|  |         new PipelineServiceClientConfiguration() | ||||||
|  |             .withMetadataApiEndpoint("http://localhost:8585/api") | ||||||
|  |             .withVerifySSL(VerifySSL.NO_SSL) | ||||||
|  |             .withSecretsManagerLoader(SecretsManagerClientLoader.ENV)); | ||||||
|  | 
 | ||||||
|  |     String botName = | ||||||
|  |         "autoClassification-bot"; // Whichever bot other than the ingestion-bot, which is the | ||||||
|  |     // default | ||||||
|  |     OpenMetadataConnection openMetadataServerConnection = | ||||||
|  |         new OpenMetadataConnectionBuilder(openMetadataApplicationConfig, botName).build(); | ||||||
|  | 
 | ||||||
|  |     // The OM Connection passes the right JWT based on the incoming bot | ||||||
|  |     DecodedJWT jwt = JWT.decode(openMetadataServerConnection.getSecurityConfig().getJwtToken()); | ||||||
|  |     Assertions.assertEquals("autoclassification-bot", jwt.getClaim("sub").asString()); | ||||||
|  |   } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Pere Miquel Brull
						Pere Miquel Brull