Commit af33c69b authored by Josianne Hyson's avatar Josianne Hyson

Create BulkImport::Configuration model for auth

We want to start importing Group and Project data directly from
another GitLab instance, via the API. To do this, we need somewhere
to store authentication data so that we can execute the import in
background jobs.

Create the BulkImport::Configuration model which is associated with
a BulkImport, and used to store the authentication data for the
source GitLab instance. This will be followed up by the
introduction of the other models the store the import data.

This model introduces:

1. `bulk_import_id` -> the bulk import that this configuration
   applies to.
2. `api_url` -> the domain for the source instance.
3. `access_token` -> the personal access token of the user on the
   source instance for authentication.

This is a component of the Group Migration MVC epic:
https://gitlab.com/groups/gitlab-org/-/epics/4374

MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/42978
Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/250280
parent e0622faa
......@@ -3,6 +3,8 @@
class BulkImport < ApplicationRecord
belongs_to :user, optional: false
has_one :configuration, class_name: 'BulkImports::Configuration'
validates :source_type, :status, presence: true
enum source_type: { gitlab: 0 }
......
# frozen_string_literal: true
class BulkImports::Configuration < ApplicationRecord
self.table_name = 'bulk_import_configurations'
belongs_to :bulk_import, inverse_of: :configuration, optional: false
validates :url, :access_token, length: { maximum: 255 }, presence: true
validates :url, public_url: { schemes: %w[http https], enforce_sanitization: true, ascii_only: true },
allow_nil: true
attr_encrypted :url,
key: Settings.attr_encrypted_db_key_base_truncated,
mode: :per_attribute_iv,
algorithm: 'aes-256-gcm'
attr_encrypted :access_token,
key: Settings.attr_encrypted_db_key_base_truncated,
mode: :per_attribute_iv,
algorithm: 'aes-256-gcm'
end
# frozen_string_literal: true
class CreateBulkImportConfigurations < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
create_table :bulk_import_configurations, if_not_exists: true do |t|
t.references :bulk_import, type: :integer, index: true, null: false, foreign_key: { on_delete: :cascade }
t.text :encrypted_url # rubocop: disable Migration/AddLimitToTextColumns
t.text :encrypted_url_iv # rubocop: disable Migration/AddLimitToTextColumns
t.text :encrypted_access_token # rubocop: disable Migration/AddLimitToTextColumns
t.text :encrypted_access_token_iv # rubocop: disable Migration/AddLimitToTextColumns
t.timestamps_with_timezone
end
end
def down
drop_table :bulk_import_configurations
end
end
a14df9e9a115d39636b29bfe73fb175bb1e8d4510bee26e3e0c6c979949b13c4
\ No newline at end of file
......@@ -9816,6 +9816,26 @@ CREATE SEQUENCE broadcast_messages_id_seq
ALTER SEQUENCE broadcast_messages_id_seq OWNED BY broadcast_messages.id;
CREATE TABLE bulk_import_configurations (
id bigint NOT NULL,
bulk_import_id integer NOT NULL,
encrypted_url text,
encrypted_url_iv text,
encrypted_access_token text,
encrypted_access_token_iv text,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL
);
CREATE SEQUENCE bulk_import_configurations_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE bulk_import_configurations_id_seq OWNED BY bulk_import_configurations.id;
CREATE TABLE bulk_imports (
id bigint NOT NULL,
user_id integer NOT NULL,
......@@ -17322,6 +17342,8 @@ ALTER TABLE ONLY boards_epic_user_preferences ALTER COLUMN id SET DEFAULT nextva
ALTER TABLE ONLY broadcast_messages ALTER COLUMN id SET DEFAULT nextval('broadcast_messages_id_seq'::regclass);
ALTER TABLE ONLY bulk_import_configurations ALTER COLUMN id SET DEFAULT nextval('bulk_import_configurations_id_seq'::regclass);
ALTER TABLE ONLY bulk_imports ALTER COLUMN id SET DEFAULT nextval('bulk_imports_id_seq'::regclass);
ALTER TABLE ONLY chat_names ALTER COLUMN id SET DEFAULT nextval('chat_names_id_seq'::regclass);
......@@ -18300,6 +18322,9 @@ ALTER TABLE ONLY boards
ALTER TABLE ONLY broadcast_messages
ADD CONSTRAINT broadcast_messages_pkey PRIMARY KEY (id);
ALTER TABLE ONLY bulk_import_configurations
ADD CONSTRAINT bulk_import_configurations_pkey PRIMARY KEY (id);
ALTER TABLE ONLY bulk_imports
ADD CONSTRAINT bulk_imports_pkey PRIMARY KEY (id);
......@@ -19808,6 +19833,8 @@ CREATE INDEX index_boards_on_project_id ON boards USING btree (project_id);
CREATE INDEX index_broadcast_message_on_ends_at_and_broadcast_type_and_id ON broadcast_messages USING btree (ends_at, broadcast_type, id);
CREATE INDEX index_bulk_import_configurations_on_bulk_import_id ON bulk_import_configurations USING btree (bulk_import_id);
CREATE INDEX index_bulk_imports_on_user_id ON bulk_imports USING btree (user_id);
CREATE UNIQUE INDEX index_chat_names_on_service_id_and_team_id_and_chat_id ON chat_names USING btree (service_id, team_id, chat_id);
......@@ -23175,6 +23202,9 @@ ALTER TABLE ONLY status_page_settings
ALTER TABLE ONLY project_repository_storage_moves
ADD CONSTRAINT fk_rails_5106dbd44a FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
ALTER TABLE ONLY bulk_import_configurations
ADD CONSTRAINT fk_rails_536b96bff1 FOREIGN KEY (bulk_import_id) REFERENCES bulk_imports(id) ON DELETE CASCADE;
ALTER TABLE ONLY x509_commit_signatures
ADD CONSTRAINT fk_rails_53fe41188f FOREIGN KEY (x509_certificate_id) REFERENCES x509_certificates(id) ON DELETE CASCADE;
......
......@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe BulkImport, type: :model do
describe 'associations' do
it { is_expected.to belong_to(:user).required }
it { is_expected.to have_one(:configuration) }
end
describe 'validations' do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkImports::Configuration, type: :model do
describe 'associations' do
it { is_expected.to belong_to(:bulk_import).required }
end
describe 'validations' do
it { is_expected.to validate_length_of(:url).is_at_most(255) }
it { is_expected.to validate_length_of(:access_token).is_at_most(255) }
it { is_expected.to validate_presence_of(:url) }
it { is_expected.to validate_presence_of(:access_token) }
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