Refactor network policy editor to be more generic
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 | ||
Test File Structure | ||
UI | No changes | - |
Does this MR meet the acceptance criteria?
Conformity
-
I have included a changelog entry, or it's not needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
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)