Commit 35a53cae authored by Sashi's avatar Sashi

Add policy name to ScanExecutionPolicyCommit mutation

This commit adds the name of the policy as
one of the arguments to the ScanExecutionPolicyCommit mutation.

EE: true
Changelog: changed
parent 5f0c22c2
...@@ -69,6 +69,7 @@ const createMergeRequest = async ({ projectPath, sourceBranch, targetBranch }) = ...@@ -69,6 +69,7 @@ const createMergeRequest = async ({ projectPath, sourceBranch, targetBranch }) =
*/ */
const updatePolicy = async ({ const updatePolicy = async ({
action = SECURITY_POLICY_ACTIONS.APPEND, action = SECURITY_POLICY_ACTIONS.APPEND,
name,
projectPath, projectPath,
yamlEditorValue, yamlEditorValue,
}) => { }) => {
...@@ -80,6 +81,7 @@ const updatePolicy = async ({ ...@@ -80,6 +81,7 @@ const updatePolicy = async ({
mutation: createScanExecutionPolicy, mutation: createScanExecutionPolicy,
variables: { variables: {
mode: action, mode: action,
name,
projectPath, projectPath,
policyYaml: yamlEditorValue, policyYaml: yamlEditorValue,
}, },
...@@ -96,6 +98,7 @@ const updatePolicy = async ({ ...@@ -96,6 +98,7 @@ const updatePolicy = async ({
export const modifyPolicy = async ({ export const modifyPolicy = async ({
action, action,
assignedPolicyProject, assignedPolicyProject,
name,
projectPath, projectPath,
yamlEditorValue, yamlEditorValue,
}) => { }) => {
...@@ -109,6 +112,7 @@ export const modifyPolicy = async ({ ...@@ -109,6 +112,7 @@ export const modifyPolicy = async ({
const newPolicyCommitBranch = await updatePolicy({ const newPolicyCommitBranch = await updatePolicy({
action, action,
name,
projectPath, projectPath,
yamlEditorValue, yamlEditorValue,
}); });
......
...@@ -64,6 +64,11 @@ export default { ...@@ -64,6 +64,11 @@ export default {
yamlEditorValue, yamlEditorValue,
}; };
}, },
computed: {
originalName() {
return this.existingPolicy?.name;
},
},
methods: { methods: {
handleError(error) { handleError(error) {
if (error.message.toLowerCase().includes('graphql')) { if (error.message.toLowerCase().includes('graphql')) {
...@@ -86,6 +91,7 @@ export default { ...@@ -86,6 +91,7 @@ export default {
const { mergeRequest, policyProject } = await modifyPolicy({ const { mergeRequest, policyProject } = await modifyPolicy({
action, action,
assignedPolicyProject: this.assignedPolicyProject, assignedPolicyProject: this.assignedPolicyProject,
name: this.originalName || fromYaml(this.yamlEditorValue)?.name,
projectPath: this.projectPath, projectPath: this.projectPath,
yamlEditorValue: this.yamlEditorValue, yamlEditorValue: this.yamlEditorValue,
}); });
......
mutation updatePolicy( mutation updatePolicy(
$projectPath: ID! $projectPath: ID!
$mode: MutationOperationMode = APPEND $mode: MutationOperationMode = APPEND
$name: String
$policyYaml: String! $policyYaml: String!
) { ) {
scanExecutionPolicyCommit( scanExecutionPolicyCommit(
input: { projectPath: $projectPath, operationMode: $mode, policyYaml: $policyYaml } input: { name: $name, projectPath: $projectPath, operationMode: $mode, policyYaml: $policyYaml }
) { ) {
branch branch
errors errors
......
...@@ -14,10 +14,12 @@ const newAssignedPolicyProject = { ...@@ -14,10 +14,12 @@ const newAssignedPolicyProject = {
branch: { rootRef: 'main' }, branch: { rootRef: 'main' },
}; };
const projectPath = 'path/to/current-project'; const projectPath = 'path/to/current-project';
const yamlEditorValue = 'some yaml'; const policyName = 'policy-01';
const yamlEditorValue = `\nname: ${policyName}\ndescription: some yaml`;
const createSavePolicyInput = (assignedPolicyProject = defaultAssignedPolicyProject, action) => ({ const createSavePolicyInput = (assignedPolicyProject = defaultAssignedPolicyProject, action) => ({
action, action,
assignedPolicyProject, assignedPolicyProject,
name: policyName,
projectPath, projectPath,
yamlEditorValue, yamlEditorValue,
}); });
......
...@@ -3,6 +3,7 @@ import { GlEmptyState } from '@gitlab/ui'; ...@@ -3,6 +3,7 @@ import { GlEmptyState } from '@gitlab/ui';
import PolicyEditorLayout from 'ee/threat_monitoring/components/policy_editor/policy_editor_layout.vue'; import PolicyEditorLayout from 'ee/threat_monitoring/components/policy_editor/policy_editor_layout.vue';
import { import {
DEFAULT_SCAN_EXECUTION_POLICY, DEFAULT_SCAN_EXECUTION_POLICY,
fromYaml,
modifyPolicy, modifyPolicy,
SECURITY_POLICY_ACTIONS, SECURITY_POLICY_ACTIONS,
} from 'ee/threat_monitoring/components/policy_editor/scan_execution_policy/lib'; } from 'ee/threat_monitoring/components/policy_editor/scan_execution_policy/lib';
...@@ -100,6 +101,10 @@ describe('ScanExecutionPolicyEditor', () => { ...@@ -100,6 +101,10 @@ describe('ScanExecutionPolicyEditor', () => {
expect(modifyPolicy).toHaveBeenCalledWith({ expect(modifyPolicy).toHaveBeenCalledWith({
action, action,
assignedPolicyProject: DEFAULT_ASSIGNED_POLICY_PROJECT, assignedPolicyProject: DEFAULT_ASSIGNED_POLICY_PROJECT,
name:
action === SECURITY_POLICY_ACTIONS.APPEND
? fromYaml(yamlEditorValue).name
: mockDastScanExecutionObject.name,
projectPath: defaultProjectPath, projectPath: defaultProjectPath,
yamlEditorValue, yamlEditorValue,
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment