gitlab-cloud-connector 0.3.0 → 1.1.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 +4 -4
- data/README.md +2 -4
- data/config/unit_primitives/categorize_duo_chat_question.yml +1 -1
- data/lib/gitlab/cloud_connector/configuration.rb +30 -3
- data/lib/gitlab/cloud_connector/data_model/abstract_data_loader.rb +21 -0
- data/lib/gitlab/cloud_connector/data_model/base.rb +13 -3
- data/lib/gitlab/cloud_connector/data_model/yaml_data_loader.rb +34 -0
- data/lib/gitlab/cloud_connector/version.rb +1 -1
- metadata +5 -3
- /data/lib/{cloud_connector.rb → gitlab/cloud_connector.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d3a9c6cb24eae104dda40308b879b159d1e1583da6c39292dc864b3f9306746
|
4
|
+
data.tar.gz: 474c1fa8efc2fb0480818d74ac587152aa3ab907a5c340e3d5de7524c95fb3e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f502784866d6d67fdbccbf262591ccc14d0a96fd44c6e38ab0de5273e224ce85258e0e504ded2d90f8d00b6f7a48662afae650a3dc8afe6de39ad8adcba37b26
|
7
|
+
data.tar.gz: ce85d65412bf2722bc68c5dcc2c8f16fa5da8c80147abef96c606dce03367aaaf053396671cf88281530aba9cce406440ef6b4ce11ce35a0379e3966c989edd9
|
data/README.md
CHANGED
@@ -7,11 +7,9 @@ Ruby gem containing shared code for Cloud Connector token issuers (GitLab, Custo
|
|
7
7
|
We expect Bundler is used to manage dependencies. To add the dependency, add it to `Gemfile`:
|
8
8
|
|
9
9
|
```Gemfile
|
10
|
-
gem "gitlab-cloud-connector", "~> 0.
|
10
|
+
gem "gitlab-cloud-connector", "~> 1.0.0", require: 'gitlab/cloud_connector'
|
11
11
|
```
|
12
12
|
|
13
|
-
## Usage
|
14
|
-
|
15
13
|
### Data Storage
|
16
14
|
|
17
15
|
Cloud Connector uses YAML files stored in the project's `/config` directory. The data is organized by model type:
|
@@ -41,7 +39,7 @@ add_ons:
|
|
41
39
|
`DataModels` are the core data structures in the Cloud Connector. Each model inherits from `DataModel::Base`. The data is loaded from YAML files into memory at runtime, making it efficient for read operations and relationship traversal.
|
42
40
|
|
43
41
|
```ruby
|
44
|
-
require 'cloud_connector'
|
42
|
+
require 'gitlab/cloud_connector'
|
45
43
|
|
46
44
|
# Find unit primitive by name
|
47
45
|
# Note: value should be a symbol (e.g., `:duo_chat` instead of `'duo_chat'`).
|
@@ -1,21 +1,48 @@
|
|
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
|
+
|
3
6
|
module Gitlab
|
4
7
|
module CloudConnector
|
5
8
|
module Configuration
|
9
|
+
DEFAULT_DATA_LOADER_CLASS = Gitlab::CloudConnector::DataModel::YamlDataLoader
|
10
|
+
INVALID_LOADER_MESSAGE = "Data loader must inherit from Gitlab::CloudConnector::DataModel::AbstractDataLoader"
|
11
|
+
|
12
|
+
InvalidDataLoaderError = Class.new(StandardError)
|
13
|
+
|
6
14
|
class << self
|
7
|
-
attr_writer :config_dir
|
15
|
+
attr_writer :config_dir, :memoize_data
|
8
16
|
|
9
17
|
def config_dir
|
10
18
|
@config_dir ||= File.expand_path("../../../config", __dir__).freeze
|
11
19
|
end
|
12
20
|
|
21
|
+
def data_loader_class
|
22
|
+
@data_loader_class ||= DEFAULT_DATA_LOADER_CLASS
|
23
|
+
end
|
24
|
+
|
25
|
+
def data_loader_class=(klass)
|
26
|
+
validate_data_loader!(klass)
|
27
|
+
@data_loader_class = klass
|
28
|
+
end
|
29
|
+
|
30
|
+
def memoize_data?
|
31
|
+
return @memoize_data unless @memoize_data.nil?
|
32
|
+
|
33
|
+
(data_loader_class == DEFAULT_DATA_LOADER_CLASS)
|
34
|
+
end
|
35
|
+
|
13
36
|
def configure
|
14
37
|
yield self if block_given?
|
15
38
|
end
|
16
39
|
|
17
|
-
|
18
|
-
|
40
|
+
private
|
41
|
+
|
42
|
+
def validate_data_loader!(klass)
|
43
|
+
return if klass && klass < Gitlab::CloudConnector::DataModel::AbstractDataLoader
|
44
|
+
|
45
|
+
raise InvalidDataLoaderError, INVALID_LOADER_MESSAGE
|
19
46
|
end
|
20
47
|
end
|
21
48
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gitlab
|
4
|
+
module CloudConnector
|
5
|
+
module DataModel
|
6
|
+
class AbstractDataLoader
|
7
|
+
def initialize(model_class)
|
8
|
+
@model_class = model_class
|
9
|
+
end
|
10
|
+
|
11
|
+
def load!
|
12
|
+
raise NotImplementedError, "#{self.class} must implement #load!"
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
attr_reader :model_class
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'associations'
|
4
|
-
require_relative 'data_loader'
|
5
4
|
|
6
5
|
module Gitlab
|
7
6
|
module CloudConnector
|
@@ -24,13 +23,17 @@ module Gitlab
|
|
24
23
|
end
|
25
24
|
|
26
25
|
def all
|
27
|
-
|
26
|
+
if Configuration.memoize_data?
|
27
|
+
@all ||= data_loader.load!
|
28
|
+
else
|
29
|
+
data_loader.load!
|
30
|
+
end
|
28
31
|
end
|
29
32
|
|
30
33
|
private
|
31
34
|
|
32
35
|
def data_loader
|
33
|
-
|
36
|
+
Configuration.data_loader_class.new(self)
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
@@ -43,6 +46,13 @@ module Gitlab
|
|
43
46
|
def [](name)
|
44
47
|
instance_variable_get(:"@#{name}")
|
45
48
|
end
|
49
|
+
|
50
|
+
def to_hash
|
51
|
+
instance_variables.each_with_object({}) do |var, hash|
|
52
|
+
key = var.to_s.delete('@').to_sym
|
53
|
+
hash[key] = instance_variable_get(var)
|
54
|
+
end
|
55
|
+
end
|
46
56
|
end
|
47
57
|
end
|
48
58
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require_relative 'abstract_data_loader'
|
5
|
+
|
6
|
+
module Gitlab
|
7
|
+
module CloudConnector
|
8
|
+
module DataModel
|
9
|
+
class YamlDataLoader < AbstractDataLoader
|
10
|
+
def load!
|
11
|
+
Dir.glob(data_files_path).map { |file| load_model_from_file(file) }
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def data_files_path
|
17
|
+
File.join(CloudConnector::Configuration.config_dir, model_class.model_name.tableize, '*.yml')
|
18
|
+
end
|
19
|
+
|
20
|
+
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!
|
26
|
+
|
27
|
+
model_class.new(**data)
|
28
|
+
rescue StandardError => e
|
29
|
+
raise "Error loading file #{file_path}: #{e.message}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
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:
|
4
|
+
version: 1.1.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:
|
11
|
+
date: 2025-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -160,12 +160,14 @@ files:
|
|
160
160
|
- config/unit_primitives/summarize_review.yml
|
161
161
|
- config/unit_primitives/troubleshoot_job.yml
|
162
162
|
- config/unit_primitives/write_tests.yml
|
163
|
-
- lib/cloud_connector.rb
|
163
|
+
- lib/gitlab/cloud_connector.rb
|
164
164
|
- lib/gitlab/cloud_connector/available_services_generator.rb
|
165
165
|
- lib/gitlab/cloud_connector/configuration.rb
|
166
|
+
- lib/gitlab/cloud_connector/data_model/abstract_data_loader.rb
|
166
167
|
- lib/gitlab/cloud_connector/data_model/associations.rb
|
167
168
|
- lib/gitlab/cloud_connector/data_model/base.rb
|
168
169
|
- lib/gitlab/cloud_connector/data_model/data_loader.rb
|
170
|
+
- lib/gitlab/cloud_connector/data_model/yaml_data_loader.rb
|
169
171
|
- lib/gitlab/cloud_connector/data_models.rb
|
170
172
|
- lib/gitlab/cloud_connector/json_web_token.rb
|
171
173
|
- lib/gitlab/cloud_connector/version.rb
|
File without changes
|