Skip to content

Commit

Permalink
Addressed PR Comments
Browse files Browse the repository at this point in the history
Signed-off-by: Owais Kazi <[email protected]>
  • Loading branch information
owaiskazi19 committed Apr 25, 2024
1 parent 35f04e8 commit 00f912b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
- Reset workflow state to initial state after successful deprovision ([#635](https://github.com/opensearch-project/flow-framework/pull/635))
- Silently ignore content on APIs that don't require it ([#639](https://github.com/opensearch-project/flow-framework/pull/639))
- Hide user and credential field from search response ([#680](https://github.com/opensearch-project/flow-framework/pull/680))

### Infrastructure
### Documentation
### Maintenance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ private CommonValue() {}
public static final String CREATE_TIME = "create_time";
/** The template field name for the user who created the workflow **/
public static final String USER_FIELD = "user";
/** Path to credential field **/
public static final String PATH_TO_CREDENTIAL_FIELD = "workflows.provision.nodes.user_inputs.credential";
/** The created time field */
public static final String CREATED_TIME = "created_time";
/** The last updated time field */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected void doExecute(Task task, WorkflowRequest request, ActionListener<GetW
logger.error(errorMessage);
listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.NOT_FOUND));
} else {
// Remove any credential from response
// Remove any secured field from response
Template template = encryptorUtils.redactTemplateSecuredFields(Template.parse(response.getSourceAsString()));
listener.onResponse(new GetWorkflowResponse(template));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,28 +205,9 @@ String decrypt(final String encryptedCredential) {
* @return the redacted template
*/
public Template redactTemplateSecuredFields(Template template) {
Template updatedTemplate = null;

if (template.getUser() != null) {
updatedTemplate = new Template.Builder(template).name(template.name())
.description(template.description())
.useCase(template.useCase())
.templateVersion(template.templateVersion())
.user(null)
.uiMetadata(template.getUiMetadata())
.compatibilityVersion(template.compatibilityVersion())
.workflows(template.workflows())
.createdTime(template.createdTime())
.lastUpdatedTime(template.lastUpdatedTime())
.lastProvisionedTime(template.lastProvisionedTime())
.build();
} else {
updatedTemplate = template;
}

Map<String, Workflow> processedWorkflows = new HashMap<>();

for (Map.Entry<String, Workflow> entry : updatedTemplate.workflows().entrySet()) {
for (Map.Entry<String, Workflow> entry : template.workflows().entrySet()) {

List<WorkflowNode> processedNodes = new ArrayList<>();
for (WorkflowNode node : entry.getValue().nodes()) {
Expand All @@ -247,7 +228,7 @@ public Template redactTemplateSecuredFields(Template template) {
processedWorkflows.put(entry.getKey(), new Workflow(entry.getValue().userParams(), processedNodes, entry.getValue().edges()));
}

return new Template.Builder(updatedTemplate).workflows(processedWorkflows).build();
return new Template.Builder(template).user(null).workflows(processedWorkflows).build();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
*/
public class RestHandlerUtils {

/** Path to credential field **/
private static final String PATH_TO_CREDENTIAL_FIELD = "workflows.provision.nodes.user_inputs.credential";

/** Fields that need to be excluded from the Search Response*/
public static final String[] DASHBOARD_EXCLUDES = new String[] {
private static final String[] DASHBOARD_EXCLUDES = new String[] {

Check warning on line 27 in src/main/java/org/opensearch/flowframework/util/RestHandlerUtils.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/util/RestHandlerUtils.java#L27

Added line #L27 was not covered by tests
CommonValue.USER_FIELD,
CommonValue.UI_METADATA_FIELD,
CommonValue.PATH_TO_CREDENTIAL_FIELD };
PATH_TO_CREDENTIAL_FIELD };

public static final String[] EXCLUDES = new String[] { CommonValue.USER_FIELD, CommonValue.PATH_TO_CREDENTIAL_FIELD };
private static final String[] EXCLUDES = new String[] { CommonValue.USER_FIELD, PATH_TO_CREDENTIAL_FIELD };

Check warning on line 32 in src/main/java/org/opensearch/flowframework/util/RestHandlerUtils.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/util/RestHandlerUtils.java#L32

Added line #L32 was not covered by tests

private RestHandlerUtils() {}

Expand Down

0 comments on commit 00f912b

Please sign in to comment.