blob: ddea7c3f64c360586449e81dd4e25076a7fd65c7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# frozen_string_literal: true
module BulkImports
module FileTransfer
class BaseConfig
include Gitlab::Utils::StrongMemoize
def initialize(portable)
@portable = portable
end
def portable_tree
attributes_finder.find_root(portable_class_sym)
end
def top_relation_tree(relation)
portable_relations_tree[relation.to_s]
end
def relation_excluded_keys(relation)
attributes_finder.find_excluded_keys(relation)
end
def export_path
strong_memoize(:export_path) do
relative_path = File.join(base_export_path, SecureRandom.hex)
::Gitlab::ImportExport.export_path(relative_path: relative_path)
end
end
def portable_relations
import_export_config.dig(:tree, portable_class_sym).keys.map(&:to_s) - skipped_relations
end
private
attr_reader :portable
def attributes_finder
strong_memoize(:attributes_finder) do
::Gitlab::ImportExport::AttributesFinder.new(config: import_export_config)
end
end
def import_export_config
::Gitlab::ImportExport::Config.new(config: import_export_yaml).to_h
end
def portable_class
@portable_class ||= portable.class
end
def portable_class_sym
@portable_class_sym ||= portable_class.to_s.demodulize.underscore.to_sym
end
def portable_relations_tree
@portable_relations_tree ||= attributes_finder.find_relations_tree(portable_class_sym).deep_stringify_keys
end
def import_export_yaml
raise NotImplementedError
end
def base_export_path
raise NotImplementedError
end
def skipped_relations
[]
end
end
end
end
|