Skip to content

Refactor network policy editor to be more generic

Alexander Turinske requested to merge 273787-generalize-policy-editor into master

What does this MR do?

Refactor network policy editor to be more generic

  • generalize policy editor to work for policies that are not the network type
  • move network-policy-editor to its own folder
  • rename files to reflect more generalized nature

As more types of polices are added (in the foreseable future there are at least four different types of policies based on this prototype). As I dug into adding the second type of policy, Scan Execution, I found the current implementation of the policy_editor to be too tied to the network policy type, so I rearranged the files/file structure. Additionally, a lot of the files in lib are already very complex; adding even more logic to account for parsing the yaml of multiple types of policies would make it extremely hard to maintain.

So in the follow up MR for &5362 (closed) where I add another policy, the file structure will look like this. There should be no need for as many files as network policy currently has, but that is because we are only adding YAML mode for this epic, but that will change for &5363 (closed) when there needs to be a rule mode and a lot of similar things to network policy currently has

- policy_editor
  > network_policy
  v scan_execution_policy (new folder)
    - scan_execution_editor.vue
    - constants.js
  - policy_editor.vue
  ... (same files as there are currently)

and this pattern will repeat for any new policy types

question: But Alexander, I see some of the code for the network_policy could be reused by more than one policy type, should you pull that out of the network_policy folder now?

The reason I did not break out X into the general section is because this refactor was so large from just with moving files alone that I wanted to add as few changes as possible to make this work.

I will certainly pull out more pieces of code to be reusable as the instances arise (the buttons will get pulled out as part of my next task, FE: Create Scan execution policy page on the New Policy page, because that task requires form actions as well and I definitely saw a couple of other things that could be further generalized in the future to be used for other policy types (some of the to/from YAML logic just HAS to be reusable)), but it will be so much easier to pull that out in smaller chunks than to add it to here.

How to test

https://gitlab.com/-/snippets/2070592

Screenshots (strongly suggested)

View Before After
Main File Structure image explanation
Test File Structure image image
UI No changes -

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #273787 (closed)

Edited by Alexander Turinske

Merge request reports

Loading