Commit 409a76e1 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'compliance_pipeline_configuration' into 'master'

Add support for Compliance Pipeline configuration location

See merge request gitlab-org/gitlab!51663
parents ef30b7da 35b7153d
---
title: Database migration for compliance pipeline configuration location
merge_request: 51663
author:
type: added
# frozen_string_literal: true
class AddPipelineConfigurationFullPathToCompliancePipeline < ActiveRecord::Migration[6.0]
DOWNTIME = false
# rubocop:disable Migration/AddLimitToTextColumns
# limit is added in 20210119162812_add_text_limit_to_compliance_pipeline_configuration_full_path.rb
def up
add_column :compliance_management_frameworks, :pipeline_configuration_full_path, :text
end
# rubocop:enable Migration/AddLimitToTextColumns
def down
remove_column :compliance_management_frameworks, :pipeline_configuration_full_path
end
end
# frozen_string_literal: true
class AddTextLimitToCompliancePipelineConfigurationFullPath < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_text_limit :compliance_management_frameworks, :pipeline_configuration_full_path, 255
end
def down
remove_text_limit :compliance_management_frameworks, :pipeline_configuration_full_path
end
end
e6841491cd7d2cc015fd628f5c14270720d59cbb17b7efb160937963f074f5c2
\ No newline at end of file
cd7643fc762d8b9236ef5ac7cc285ffbd29f1953178b9b6e129082efd7b9e07b
\ No newline at end of file
...@@ -11457,9 +11457,11 @@ CREATE TABLE compliance_management_frameworks ( ...@@ -11457,9 +11457,11 @@ CREATE TABLE compliance_management_frameworks (
color text NOT NULL, color text NOT NULL,
namespace_id integer NOT NULL, namespace_id integer NOT NULL,
regulated boolean DEFAULT true NOT NULL, regulated boolean DEFAULT true NOT NULL,
pipeline_configuration_full_path text,
CONSTRAINT check_08cd34b2c2 CHECK ((char_length(color) <= 10)), CONSTRAINT check_08cd34b2c2 CHECK ((char_length(color) <= 10)),
CONSTRAINT check_1617e0b87e CHECK ((char_length(description) <= 255)), CONSTRAINT check_1617e0b87e CHECK ((char_length(description) <= 255)),
CONSTRAINT check_ab00bc2193 CHECK ((char_length(name) <= 255)) CONSTRAINT check_ab00bc2193 CHECK ((char_length(name) <= 255)),
CONSTRAINT check_e7a9972435 CHECK ((char_length(pipeline_configuration_full_path) <= 255))
); );
CREATE SEQUENCE compliance_management_frameworks_id_seq CREATE SEQUENCE compliance_management_frameworks_id_seq
......
...@@ -3808,6 +3808,12 @@ type ComplianceFramework { ...@@ -3808,6 +3808,12 @@ type ComplianceFramework {
Name of the compliance framework Name of the compliance framework
""" """
name: String! name: String!
"""
Full path of the compliance pipeline configuration stored in a project
repository, such as `.gitlab/compliance/soc2/.gitlab-ci.yml`.
"""
pipelineConfigurationFullPath: String
} }
""" """
...@@ -3860,6 +3866,12 @@ input ComplianceFrameworkInput { ...@@ -3860,6 +3866,12 @@ input ComplianceFrameworkInput {
New name for the compliance framework. New name for the compliance framework.
""" """
name: String name: String
"""
Full path of the compliance pipeline configuration stored in a project
repository, such as `.gitlab/compliance/soc2/.gitlab-ci.yml`.
"""
pipelineConfigurationFullPath: String
} }
""" """
......
...@@ -10370,6 +10370,20 @@ ...@@ -10370,6 +10370,20 @@
}, },
"isDeprecated": false, "isDeprecated": false,
"deprecationReason": null "deprecationReason": null
},
{
"name": "pipelineConfigurationFullPath",
"description": "Full path of the compliance pipeline configuration stored in a project repository, such as `.gitlab/compliance/soc2/.gitlab-ci.yml`.",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
} }
], ],
"inputFields": null, "inputFields": null,
...@@ -10526,6 +10540,16 @@ ...@@ -10526,6 +10540,16 @@
"ofType": null "ofType": null
}, },
"defaultValue": null "defaultValue": null
},
{
"name": "pipelineConfigurationFullPath",
"description": "Full path of the compliance pipeline configuration stored in a project repository, such as `.gitlab/compliance/soc2/.gitlab-ci.yml`.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
} }
], ],
"interfaces": null, "interfaces": null,
...@@ -591,6 +591,7 @@ Represents a ComplianceFramework associated with a Project. ...@@ -591,6 +591,7 @@ Represents a ComplianceFramework associated with a Project.
| `description` | String! | Description of the compliance framework | | `description` | String! | Description of the compliance framework |
| `id` | ID! | Compliance framework ID | | `id` | ID! | Compliance framework ID |
| `name` | String! | Name of the compliance framework | | `name` | String! | Name of the compliance framework |
| `pipelineConfigurationFullPath` | String | Full path of the compliance pipeline configuration stored in a project repository, such as `.gitlab/compliance/soc2/.gitlab-ci.yml`. |
### ConfigureSastPayload ### ConfigureSastPayload
......
...@@ -20,6 +20,11 @@ module Types ...@@ -20,6 +20,11 @@ module Types
GraphQL::STRING_TYPE, GraphQL::STRING_TYPE,
required: false, required: false,
description: 'New color representation of the compliance framework in hex format. e.g. #FCA121.' description: 'New color representation of the compliance framework in hex format. e.g. #FCA121.'
argument :pipeline_configuration_full_path,
GraphQL::STRING_TYPE,
required: false,
description: 'Full path of the compliance pipeline configuration stored in a project repository, such as `.gitlab/compliance/soc2/.gitlab-ci.yml`.'
end end
end end
end end
...@@ -22,6 +22,10 @@ module Types ...@@ -22,6 +22,10 @@ module Types
field :color, GraphQL::STRING_TYPE, field :color, GraphQL::STRING_TYPE,
null: false, null: false,
description: 'Hexadecimal representation of compliance framework\'s label color' description: 'Hexadecimal representation of compliance framework\'s label color'
field :pipeline_configuration_full_path, GraphQL::STRING_TYPE,
null: true,
description: 'Full path of the compliance pipeline configuration stored in a project repository, such as `.gitlab/compliance/soc2/.gitlab-ci.yml`.'
end end
end end
end end
...@@ -68,6 +68,7 @@ module ComplianceManagement ...@@ -68,6 +68,7 @@ module ComplianceManagement
validates :color, color: true, allow_blank: false, length: { maximum: 10 } validates :color, color: true, allow_blank: false, length: { maximum: 10 }
validates :regulated, presence: true validates :regulated, presence: true
validates :namespace_id, uniqueness: { scope: :name } validates :namespace_id, uniqueness: { scope: :name }
validates :pipeline_configuration_full_path, length: { maximum: 255 }
scope :with_projects, ->(project_ids) { includes(:projects).where(projects: { id: project_ids }) } scope :with_projects, ->(project_ids) { includes(:projects).where(projects: { id: project_ids }) }
scope :with_namespaces, ->(namespace_ids) { includes(:namespace).where(namespaces: { id: namespace_ids })} scope :with_namespaces, ->(namespace_ids) { includes(:namespace).where(namespaces: { id: namespace_ids })}
......
...@@ -17,7 +17,8 @@ module ComplianceManagement ...@@ -17,7 +17,8 @@ module ComplianceManagement
namespace: namespace, namespace: namespace,
name: params[:name], name: params[:name],
description: params[:description], description: params[:description],
color: params[:color] color: params[:color],
pipeline_configuration_full_path: params[:pipeline_configuration_full_path]
) )
return ServiceResponse.error(message: 'Not permitted to create framework') unless permitted? return ServiceResponse.error(message: 'Not permitted to create framework') unless permitted?
......
...@@ -10,6 +10,7 @@ RSpec.describe GitlabSchema.types['ComplianceFramework'] do ...@@ -10,6 +10,7 @@ RSpec.describe GitlabSchema.types['ComplianceFramework'] do
name name
description description
color color
pipeline_configuration_full_path
] ]
it 'has the correct fields' do it 'has the correct fields' do
......
...@@ -106,7 +106,8 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Create do ...@@ -106,7 +106,8 @@ RSpec.describe Mutations::ComplianceManagement::Frameworks::Create do
params: { params: {
name: 'GDPR', name: 'GDPR',
description: 'Example description', description: 'Example description',
color: '#abc123' color: '#abc123',
pipeline_configuration_full_path: 'compliance/.gitlab-ci.yml'
} }
} }
end end
......
...@@ -14,6 +14,7 @@ RSpec.describe ComplianceManagement::Framework do ...@@ -14,6 +14,7 @@ RSpec.describe ComplianceManagement::Framework do
it { is_expected.to validate_length_of(:description).is_at_most(255) } it { is_expected.to validate_length_of(:description).is_at_most(255) }
it { is_expected.to validate_length_of(:color).is_at_most(10) } it { is_expected.to validate_length_of(:color).is_at_most(10) }
it { is_expected.to validate_presence_of(:regulated) } it { is_expected.to validate_presence_of(:regulated) }
it { is_expected.to validate_length_of(:pipeline_configuration_full_path).is_at_most(255) }
end end
describe 'color' do describe 'color' do
......
...@@ -15,7 +15,8 @@ RSpec.describe 'Create a Compliance Framework' do ...@@ -15,7 +15,8 @@ RSpec.describe 'Create a Compliance Framework' do
params: { params: {
name: 'GDPR', name: 'GDPR',
description: 'Example Description', description: 'Example Description',
color: '#ABC123' color: '#ABC123',
pipeline_configuration_full_path: 'compliance/.gitlab-ci.yml'
} }
) )
end end
...@@ -31,12 +32,13 @@ RSpec.describe 'Create a Compliance Framework' do ...@@ -31,12 +32,13 @@ RSpec.describe 'Create a Compliance Framework' do
expect { subject }.to change { namespace.compliance_management_frameworks.count }.by 1 expect { subject }.to change { namespace.compliance_management_frameworks.count }.by 1
end end
it 'returns the newly created framework' do it 'returns the newly created framework', :aggregate_failures do
subject subject
expect(mutation_response['framework']['color']).to eq '#ABC123' expect(mutation_response['framework']['color']).to eq '#ABC123'
expect(mutation_response['framework']['name']).to eq 'GDPR' expect(mutation_response['framework']['name']).to eq 'GDPR'
expect(mutation_response['framework']['description']).to eq 'Example Description' expect(mutation_response['framework']['description']).to eq 'Example Description'
expect(mutation_response['framework']['pipelineConfigurationFullPath']).to eq 'compliance/.gitlab-ci.yml'
end end
end end
......
...@@ -13,7 +13,8 @@ RSpec.describe 'Update a compliance framework' do ...@@ -13,7 +13,8 @@ RSpec.describe 'Update a compliance framework' do
params: { params: {
name: 'New Name', name: 'New Name',
description: 'New Description', description: 'New Description',
color: '#AAC112' color: '#AAC112',
pipeline_configuration_full_path: 'compliance/.gitlab-ci.yml'
} }
} }
end end
...@@ -55,12 +56,13 @@ RSpec.describe 'Update a compliance framework' do ...@@ -55,12 +56,13 @@ RSpec.describe 'Update a compliance framework' do
expect(mutation_response['errors']).to be_empty expect(mutation_response['errors']).to be_empty
end end
it 'returns the updated framework' do it 'returns the updated framework', :aggregate_failures do
subject subject
expect(mutation_response['complianceFramework']['name']).to eq 'New Name' expect(mutation_response['complianceFramework']['name']).to eq 'New Name'
expect(mutation_response['complianceFramework']['description']).to eq 'New Description' expect(mutation_response['complianceFramework']['description']).to eq 'New Description'
expect(mutation_response['complianceFramework']['color']).to eq '#AAC112' expect(mutation_response['complianceFramework']['color']).to eq '#AAC112'
expect(mutation_response['complianceFramework']['pipelineConfigurationFullPath']).to eq 'compliance/.gitlab-ci.yml'
end end
context 'current_user is not permitted to update framework' do context 'current_user is not permitted to update framework' do
......
...@@ -8,7 +8,8 @@ RSpec.describe ComplianceManagement::Frameworks::CreateService do ...@@ -8,7 +8,8 @@ RSpec.describe ComplianceManagement::Frameworks::CreateService do
{ {
name: 'GDPR', name: 'GDPR',
description: 'The EUs data protection directive', description: 'The EUs data protection directive',
color: '#abc123' color: '#abc123',
pipeline_configuration_full_path: 'compliance/.gitlab-ci.yml'
} }
end end
...@@ -88,6 +89,7 @@ RSpec.describe ComplianceManagement::Frameworks::CreateService do ...@@ -88,6 +89,7 @@ RSpec.describe ComplianceManagement::Frameworks::CreateService do
expect(framework.name).to eq('GDPR') expect(framework.name).to eq('GDPR')
expect(framework.description).to eq('The EUs data protection directive') expect(framework.description).to eq('The EUs data protection directive')
expect(framework.color).to eq('#abc123') expect(framework.color).to eq('#abc123')
expect(framework.pipeline_configuration_full_path).to eq('compliance/.gitlab-ci.yml')
end end
end end
end end
......
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