Commit 92280a06 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'ck3g-add-custom-mapping-columns-to-http-integrations' into 'master'

Add custom mapping related columns to http_integrations

See merge request gitlab-org/gitlab!49941
parents f2c9081c de151d08
...@@ -22,6 +22,7 @@ module AlertManagement ...@@ -22,6 +22,7 @@ module AlertManagement
validates :name, presence: true, length: { maximum: 255 } validates :name, presence: true, length: { maximum: 255 }
validates :endpoint_identifier, presence: true, length: { maximum: 255 }, format: { with: /\A[A-Za-z0-9]+\z/ } validates :endpoint_identifier, presence: true, length: { maximum: 255 }, format: { with: /\A[A-Za-z0-9]+\z/ }
validates :endpoint_identifier, uniqueness: { scope: [:project_id, :active] }, if: :active? validates :endpoint_identifier, uniqueness: { scope: [:project_id, :active] }, if: :active?
validates :payload_attribute_mapping, json_schema: { filename: 'http_integration_payload_attribute_mapping' }
before_validation :prevent_token_assignment before_validation :prevent_token_assignment
before_validation :prevent_endpoint_identifier_assignment before_validation :prevent_endpoint_identifier_assignment
......
{
"type": "object",
"patternProperties": {
".*": {
"type": "object",
"required": ["path", "type"],
"properties": {
"path": { "type": "array" },
"type": { "type": "string" }
},
"additionalProperties": false
}
}
}
---
title: Add payload_example and payload_attribute_mapping columns to alert_management_http_integrations
table
merge_request: 49941
author:
type: added
# frozen_string_literal: true
class AddCustomMappingColumnsToHttpIntegrations < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column :alert_management_http_integrations, :payload_example, :jsonb, null: false, default: {}
add_column :alert_management_http_integrations, :payload_attribute_mapping, :jsonb, null: false, default: {}
end
end
9c2f6c75126172d4876db33cfd814f974a381df97a23aec21f2550ec288946c2
\ No newline at end of file
...@@ -8837,6 +8837,8 @@ CREATE TABLE alert_management_http_integrations ( ...@@ -8837,6 +8837,8 @@ CREATE TABLE alert_management_http_integrations (
encrypted_token_iv text NOT NULL, encrypted_token_iv text NOT NULL,
endpoint_identifier text NOT NULL, endpoint_identifier text NOT NULL,
name text NOT NULL, name text NOT NULL,
payload_example jsonb DEFAULT '{}'::jsonb NOT NULL,
payload_attribute_mapping jsonb DEFAULT '{}'::jsonb NOT NULL,
CONSTRAINT check_286943b636 CHECK ((char_length(encrypted_token_iv) <= 255)), CONSTRAINT check_286943b636 CHECK ((char_length(encrypted_token_iv) <= 255)),
CONSTRAINT check_392143ccf4 CHECK ((char_length(name) <= 255)), CONSTRAINT check_392143ccf4 CHECK ((char_length(name) <= 255)),
CONSTRAINT check_e270820180 CHECK ((char_length(endpoint_identifier) <= 255)), CONSTRAINT check_e270820180 CHECK ((char_length(endpoint_identifier) <= 255)),
......
...@@ -31,6 +31,54 @@ RSpec.describe AlertManagement::HttpIntegration do ...@@ -31,6 +31,54 @@ RSpec.describe AlertManagement::HttpIntegration do
it { is_expected.not_to validate_uniqueness_of(:endpoint_identifier).scoped_to(:project_id, :active) } it { is_expected.not_to validate_uniqueness_of(:endpoint_identifier).scoped_to(:project_id, :active) }
end end
context 'payload_attribute_mapping' do
subject { build(:alert_management_http_integration, payload_attribute_mapping: attribute_mapping) }
context 'with valid JSON schema' do
let(:attribute_mapping) do
{
title: { path: %w(a b c), type: 'string' },
description: { path: %w(a), type: 'string' }
}
end
it { is_expected.to be_valid }
end
context 'with invalid JSON schema' do
shared_examples 'is invalid record' do
it do
expect(subject).to be_invalid
expect(subject.errors.messages[:payload_attribute_mapping]).to eq(['must be a valid json schema'])
end
end
context 'when property is not an object' do
let(:attribute_mapping) do
{ title: 'That is not a valid schema' }
end
it_behaves_like 'is invalid record'
end
context 'when property missing required attributes' do
let(:attribute_mapping) do
{ title: { type: 'string' } }
end
it_behaves_like 'is invalid record'
end
context 'when property has extra attributes' do
let(:attribute_mapping) do
{ title: { path: %w(a b c), type: 'string', extra: 'property' } }
end
it_behaves_like 'is invalid record'
end
end
end
end end
describe '#token' do describe '#token' do
......
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