gitlab-cloud-connector 1.7.0 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2561683322a95d6bc39cd443dd05a9da52d3e68af94c618720944a8f6be3879
4
- data.tar.gz: ab54fe6abd39b2b287acb07097110dc6c9a86abbac8e5a78680bac0d48cf27d6
3
+ metadata.gz: a799818f88f7e618976e9cdaddaf37d9e1e44204e94b98f37d7454725066f2db
4
+ data.tar.gz: 21b818d8a78eddde6fd1987c3f75162407782eef12d78732561ec3c2e0f5f879
5
5
  SHA512:
6
- metadata.gz: d71e3bfabb8607f2bfdfc0afcca62101a80800ed4659b60912a448b80a788849f2b5f55f279628f5de163a6070590fd9d009fefb0e03d48300773bb41eee4c6b
7
- data.tar.gz: 50549c2ff8accfa95a8cdf25728d5e216d77eb66877e4e14dd3b272602d31971bec3795210fee85ac9024cc2051f0769d40200de6fd517c5dbbc01e25e560225
6
+ metadata.gz: a7f6ac2d65dc4421f0f96ba321fd1d90eb77c3ac1caab2302c1d13a0378f256b77cba20c417c7e04986abeaedbd271a898386d010a9caad212902b4604d567d9
7
+ data.tar.gz: ccc4a1b97987a3817ff1fb7d4e46acc374544aabcc5d854737b733064abf20524b811b82e2fef042c74a4f0d155f571995a4e9d21d263f64292a6531363fd934
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'data_model/yaml_data_loader'
4
- require_relative 'data_model/abstract_data_loader'
5
-
6
3
  module Gitlab
7
4
  module CloudConnector
8
5
  module Configuration
9
6
  DEFAULT_DATA_LOADER_CLASS = Gitlab::CloudConnector::DataModel::YamlDataLoader
10
7
  INVALID_LOADER_MESSAGE = "Data loader must inherit from Gitlab::CloudConnector::DataModel::AbstractDataLoader"
8
+ INVALID_CONFIG_MESSAGE = "Override configuration must be a Hash or respond to :call"
11
9
 
12
10
  InvalidDataLoaderError = Class.new(StandardError)
11
+ InvalidConfigError = Class.new(StandardError)
13
12
 
14
13
  class << self
15
14
  attr_writer :config_dir, :memoize_data
15
+ attr_reader :override_config
16
16
 
17
17
  def config_dir
18
18
  @config_dir ||= File.expand_path("../../../config", __dir__).freeze
@@ -27,10 +27,15 @@ module Gitlab
27
27
  @data_loader_class = klass
28
28
  end
29
29
 
30
+ def override_config=(value)
31
+ validate_override_config!(value)
32
+ @override_config = value
33
+ end
34
+
30
35
  def memoize_data?
31
36
  return @memoize_data unless @memoize_data.nil?
32
37
 
33
- (data_loader_class == DEFAULT_DATA_LOADER_CLASS)
38
+ data_loader_class == DEFAULT_DATA_LOADER_CLASS
34
39
  end
35
40
 
36
41
  def configure
@@ -44,6 +49,12 @@ module Gitlab
44
49
 
45
50
  raise InvalidDataLoaderError, INVALID_LOADER_MESSAGE
46
51
  end
52
+
53
+ def validate_override_config!(value)
54
+ return if value.nil? || value.is_a?(Hash) || value.respond_to?(:call)
55
+
56
+ raise InvalidConfigError, INVALID_CONFIG_MESSAGE
57
+ end
47
58
  end
48
59
  end
49
60
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gitlab
4
+ module CloudConnector
5
+ module DataModel
6
+ module Overridable
7
+ OverrideLoadError = Class.new(StandardError)
8
+
9
+ extend ActiveSupport::Concern
10
+
11
+ def apply_overrides(base_data, model_class)
12
+ overrides = fetch_relevant_overrides(base_data, model_class)
13
+ return base_data unless overrides
14
+
15
+ base_data.merge(overrides)
16
+ end
17
+
18
+ private
19
+
20
+ def fetch_relevant_overrides(base_data, model_class)
21
+ data = load_override_data
22
+ return unless data
23
+
24
+ model_name = base_data[:name]&.to_sym
25
+ return unless model_name
26
+
27
+ model_type = model_class.model_name.tableize.to_sym
28
+ data.dig(model_type, model_name)
29
+ end
30
+
31
+ def load_override_data
32
+ config = Gitlab::CloudConnector::Configuration.override_config
33
+
34
+ data = config.respond_to?(:call) ? config.call : config
35
+ unless data.is_a?(Hash) || data.nil?
36
+ raise OverrideLoadError, "Invalid override config type: #{data.class}. Expected Hash or nil."
37
+ end
38
+
39
+ data
40
+ rescue StandardError => e
41
+ raise e if e.is_a?(OverrideLoadError)
42
+
43
+ raise OverrideLoadError, "Failed to load override config: #{e.class}: #{e.message}"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -2,11 +2,14 @@
2
2
 
3
3
  require 'yaml'
4
4
  require_relative 'abstract_data_loader'
5
+ require_relative 'overridable'
5
6
 
6
7
  module Gitlab
7
8
  module CloudConnector
8
9
  module DataModel
9
10
  class YamlDataLoader < AbstractDataLoader
11
+ include Overridable
12
+
10
13
  def load!
11
14
  Dir.glob(data_files_path).map { |file| load_model_from_file(file) }
12
15
  end
@@ -18,16 +21,21 @@ module Gitlab
18
21
  end
19
22
 
20
23
  def load_model_from_file(file_path)
21
- data = YAML.safe_load(
22
- File.read(file_path),
23
- permitted_classes: [Time],
24
- symbolize_names: true
25
- ).deep_symbolize_keys!
24
+ raw_data = load_yaml_file(file_path)
25
+ data = apply_overrides(raw_data, model_class)
26
26
 
27
27
  model_class.new(**data)
28
28
  rescue StandardError => e
29
29
  raise "Error loading file #{file_path}: #{e.message}"
30
30
  end
31
+
32
+ def load_yaml_file(file_path)
33
+ YAML.safe_load(
34
+ File.read(file_path),
35
+ permitted_classes: [Time],
36
+ symbolize_names: true
37
+ ) || {}
38
+ end
31
39
  end
32
40
  end
33
41
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Gitlab
4
4
  module CloudConnector
5
- VERSION = '1.7.0'
5
+ VERSION = '1.8.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-cloud-connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikola Milojevic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-04-03 00:00:00.000000000 Z
11
+ date: 2025-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -169,6 +169,7 @@ files:
169
169
  - lib/gitlab/cloud_connector/data_model/abstract_data_loader.rb
170
170
  - lib/gitlab/cloud_connector/data_model/associations.rb
171
171
  - lib/gitlab/cloud_connector/data_model/base.rb
172
+ - lib/gitlab/cloud_connector/data_model/overridable.rb
172
173
  - lib/gitlab/cloud_connector/data_model/yaml_data_loader.rb
173
174
  - lib/gitlab/cloud_connector/json_web_token.rb
174
175
  - lib/gitlab/cloud_connector/version.rb