Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
667d36ca
Commit
667d36ca
authored
Apr 09, 2021
by
Alexander Turinske
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize hasInvalidPolicy code
- remove unnecessary elements
parent
d20c33e2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
66 deletions
+46
-66
ee/app/assets/javascripts/threat_monitoring/components/policy_editor/lib/from_yaml.js
...reat_monitoring/components/policy_editor/lib/from_yaml.js
+4
-7
ee/app/assets/javascripts/threat_monitoring/components/policy_editor/policy_editor.vue
...eat_monitoring/components/policy_editor/policy_editor.vue
+15
-21
ee/spec/frontend/threat_monitoring/components/policy_editor/__snapshots__/policy_editor_spec.js.snap
...ts/policy_editor/__snapshots__/policy_editor_spec.js.snap
+23
-33
ee/spec/frontend/threat_monitoring/components/policy_editor/policy_editor_spec.js
...monitoring/components/policy_editor/policy_editor_spec.js
+4
-5
No files found.
ee/app/assets/javascripts/threat_monitoring/components/policy_editor/lib/from_yaml.js
View file @
667d36ca
...
...
@@ -132,9 +132,9 @@ const hasUnsupportedAttribute = (manifest) => {
return
!
Object
.
keys
(
object
).
every
((
item
)
=>
allowedValues
.
includes
(
item
));
};
const
hasInvalidPolicy
=
(
type
)
=>
{
const
hasInvalidPolicy
=
(
ingress
=
[],
egress
=
[]
)
=>
{
let
isInvalidPolicy
=
false
;
manifest
.
spec
[
type
].
forEach
((
item
)
=>
{
[...
ingress
,
...
egress
].
forEach
((
item
)
=>
{
isInvalidPolicy
=
hasInvalidKey
(
item
,
ruleKeys
);
if
(
item
.
toPorts
?.
length
&&
!
isInvalidPolicy
)
{
item
.
toPorts
.
forEach
((
entry
)
=>
{
...
...
@@ -158,11 +158,8 @@ const hasUnsupportedAttribute = (manifest) => {
if
(
manifest
?.
spec
&&
!
isUnsupported
)
{
isUnsupported
=
hasInvalidKey
(
manifest
.
spec
,
specKeys
);
}
if
(
manifest
?.
spec
?.
ingress
?.
length
&&
!
isUnsupported
)
{
isUnsupported
=
hasInvalidPolicy
(
'
ingress
'
);
}
if
(
manifest
?.
spec
?.
egress
?.
length
&&
!
isUnsupported
)
{
isUnsupported
=
hasInvalidPolicy
(
'
egress
'
);
if
(
!
isUnsupported
&&
(
manifest
?.
spec
?.
ingress
?.
length
||
manifest
?.
spec
?.
egress
?.
length
))
{
isUnsupported
=
hasInvalidPolicy
(
manifest
.
spec
.
ingress
,
manifest
.
spec
.
egress
);
}
return
isUnsupported
;
...
...
ee/app/assets/javascripts/threat_monitoring/components/policy_editor/policy_editor.vue
View file @
667d36ca
...
...
@@ -237,35 +237,29 @@ export default {
<div
class=
"row"
>
<div
class=
"col-sm-6 col-md-4 col-lg-3 col-xl-2"
>
<gl-form-group
:disabled=
"hasParsingError"
>
<gl-form-group
:label=
"s__('NetworkPolicies|Policy type')"
label-for=
"policyType"
>
<gl-form-select
id=
"policyType"
value=
"networkPolicy"
:options=
"$options.policyTypes"
disabled
/>
</gl-form-group>
<gl-form-group
:label=
"s__('NetworkPolicies|Policy type')"
label-for=
"policyType"
>
<gl-form-select
id=
"policyType"
value=
"networkPolicy"
:options=
"$options.policyTypes"
disabled
/>
</gl-form-group>
</div>
<div
class=
"col-sm-6 col-md-6 col-lg-5 col-xl-4"
>
<gl-form-group
:disabled=
"hasParsingError"
data-testid=
"policy-name"
>
<gl-form-group
:disabled=
"hasParsingError"
:label=
"s__('NetworkPolicies|Name')"
label-for=
"policyName"
>
<gl-form-input
id=
"policyName"
v-model=
"policy.name"
/>
</gl-form-group>
<gl-form-group
:label=
"s__('NetworkPolicies|Name')"
label-for=
"policyName"
>
<gl-form-input
id=
"policyName"
v-model=
"policy.name"
:disabled=
"hasParsingError"
/>
</gl-form-group>
</div>
</div>
<div
class=
"row"
>
<div
class=
"col-sm-12 col-md-10 col-lg-8 col-xl-6"
>
<gl-form-group
:disabled=
"hasParsingError"
data-testid=
"policy-description"
>
<gl-form-group
:label=
"s__('NetworkPolicies|Description')"
label-for=
"policyDescription"
>
<gl-form-textarea
id=
"policyDescription"
v-model=
"policy.description"
/>
</gl-form-group>
<gl-form-group
:label=
"s__('NetworkPolicies|Description')"
label-for=
"policyDescription"
>
<gl-form-textarea
id=
"policyDescription"
v-model=
"policy.description"
:disabled=
"hasParsingError"
/>
</gl-form-group>
</div>
</div>
...
...
ee/spec/frontend/threat_monitoring/components/policy_editor/__snapshots__/policy_editor_spec.js.snap
View file @
667d36ca
...
...
@@ -52,18 +52,16 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = `
<div
class="col-sm-6 col-md-4 col-lg-3 col-xl-2"
>
<gl-form-group-stub>
<gl-form-group-stub
label="Policy type"
label-for="policyType"
>
<gl-form-select-stub
disabled=""
id="policyType"
options="[object Object]"
value="networkPolicy"
/>
</gl-form-group-stub>
<gl-form-group-stub
label="Policy type"
label-for="policyType"
>
<gl-form-select-stub
disabled=""
id="policyType"
options="[object Object]"
value="networkPolicy"
/>
</gl-form-group-stub>
</div>
...
...
@@ -71,17 +69,13 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = `
class="col-sm-6 col-md-6 col-lg-5 col-xl-4"
>
<gl-form-group-stub
data-testid="policy-name"
label="Name"
label-for="policyName"
>
<gl-form-group-stub
label="Name"
label-for="policyName"
>
<gl-form-input-stub
id="policyName"
value=""
/>
</gl-form-group-stub>
<gl-form-input-stub
id="policyName"
value=""
/>
</gl-form-group-stub>
</div>
</div>
...
...
@@ -93,18 +87,14 @@ exports[`PolicyEditorApp component renders the policy editor layout 1`] = `
class="col-sm-12 col-md-10 col-lg-8 col-xl-6"
>
<gl-form-group-stub
data-testid="policy-description"
label="Description"
label-for="policyDescription"
>
<gl-form-group-stub
label="Description"
label-for="policyDescription"
>
<gl-form-textarea-stub
id="policyDescription"
noresize="true"
value=""
/>
</gl-form-group-stub>
<gl-form-textarea-stub
id="policyDescription"
noresize="true"
value=""
/>
</gl-form-group-stub>
</div>
</div>
...
...
ee/spec/frontend/threat_monitoring/components/policy_editor/policy_editor_spec.js
View file @
667d36ca
...
...
@@ -79,10 +79,9 @@ spec:
const
findYAMLParsingAlert
=
()
=>
wrapper
.
findByTestId
(
'
parsing-alert
'
);
const
findNetworkPolicyEditor
=
()
=>
wrapper
.
findByTestId
(
'
network-policy-editor
'
);
const
findPolicyAlertPicker
=
()
=>
wrapper
.
find
(
PolicyAlertPicker
);
const
findPolicyDescription
Container
=
()
=>
wrapper
.
findByTestId
(
'
policy-description
'
);
const
findPolicyDescription
=
()
=>
wrapper
.
find
(
"
[id='policyDescription']
"
);
const
findPolicyEnableContainer
=
()
=>
wrapper
.
findByTestId
(
'
policy-enable
'
);
const
findPolicyNameContainer
=
()
=>
wrapper
.
findByTestId
(
'
policy-name
'
);
const
findPolicyName
=
()
=>
findPolicyNameContainer
().
find
(
"
[id='policyName']
"
);
const
findPolicyName
=
()
=>
wrapper
.
find
(
"
[id='policyName']
"
);
const
findSavePolicy
=
()
=>
wrapper
.
findByTestId
(
'
save-policy
'
);
const
findDeletePolicy
=
()
=>
wrapper
.
findByTestId
(
'
delete-policy
'
);
const
findEditorModeToggle
=
()
=>
wrapper
.
findByTestId
(
'
editor-mode
'
);
...
...
@@ -280,11 +279,11 @@ spec:
});
it
(
'
disables policy name field
'
,
()
=>
{
expect
(
findPolicyName
Container
().
attributes
().
disabled
).
toBe
(
'
true
'
);
expect
(
findPolicyName
().
attributes
().
disabled
).
toBe
(
'
true
'
);
});
it
(
'
disables policy description field
'
,
()
=>
{
expect
(
findPolicyDescription
Container
().
attributes
().
disabled
).
toBe
(
'
true
'
);
expect
(
findPolicyDescription
().
attributes
().
disabled
).
toBe
(
'
true
'
);
});
it
(
'
disables policy enable/disable toggle
'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment