gitlab-cloud-connector 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +4 -5
- data/README.md +48 -1
- data/config/backend_services/ai_gateway_agent.yml +5 -0
- data/config/schemas/service_schema.json +38 -0
- data/config/schemas/unit_primitive_schema.json +54 -64
- data/config/services/agent_quick_actions.yml +6 -0
- data/config/services/anthropic_proxy.yml +11 -0
- data/config/services/code_suggestions.yml +5 -0
- data/config/services/duo_chat.yml +21 -0
- data/config/services/duo_workflow.yml +4 -0
- data/config/services/generate_description.yml +4 -0
- data/config/services/sast.yml +6 -0
- data/config/services/self_hosted_models.yml +24 -0
- data/config/services/summarize_new_merge_request.yml +4 -0
- data/config/services/vertex_ai_proxy.yml +9 -0
- data/config/unit_primitives/agent_quick_actions.yml +9 -0
- data/config/unit_primitives/ask_build.yml +1 -5
- data/config/unit_primitives/ask_commit.yml +1 -5
- data/config/unit_primitives/ask_epic.yml +2 -5
- data/config/unit_primitives/ask_issue.yml +2 -5
- data/config/unit_primitives/ask_merge_request.yml +13 -0
- data/config/unit_primitives/categorize_duo_chat_question.yml +10 -0
- data/config/unit_primitives/code_suggestions.yml +3 -7
- data/config/unit_primitives/complete_code.yml +0 -4
- data/config/unit_primitives/documentation_search.yml +0 -8
- data/config/unit_primitives/duo_chat.yml +1 -6
- data/config/unit_primitives/duo_workflow_execute_workflow.yml +3 -6
- data/config/unit_primitives/explain_code.yml +2 -7
- data/config/unit_primitives/explain_vulnerability.yml +3 -7
- data/config/unit_primitives/fix_code.yml +1 -6
- data/config/unit_primitives/generate_code.yml +0 -4
- data/config/unit_primitives/generate_commit_message.yml +2 -7
- data/config/unit_primitives/generate_cube_query.yml +10 -0
- data/config/unit_primitives/generate_issue_description.yml +1 -5
- data/config/unit_primitives/glab_ask_git_command.yml +2 -6
- data/config/unit_primitives/include_dependency_context.yml +2 -5
- data/config/unit_primitives/include_file_context.yml +1 -6
- data/config/unit_primitives/include_issue_context.yml +1 -5
- data/config/unit_primitives/include_local_git_context.yml +11 -0
- data/config/unit_primitives/include_merge_request_context.yml +1 -5
- data/config/unit_primitives/include_snippet_context.yml +1 -6
- data/config/unit_primitives/observability_all.yml +0 -7
- data/config/unit_primitives/refactor_code.yml +1 -6
- data/config/unit_primitives/resolve_vulnerability.yml +2 -7
- data/config/unit_primitives/review_merge_request.yml +11 -0
- data/config/unit_primitives/security_scans.yml +0 -6
- data/config/unit_primitives/semantic_search_issue.yml +9 -0
- data/config/unit_primitives/summarize_comments.yml +0 -7
- data/config/unit_primitives/summarize_issue_discussions.yml +9 -0
- data/config/unit_primitives/summarize_merge_request.yml +11 -0
- data/config/unit_primitives/summarize_review.yml +1 -5
- data/config/unit_primitives/troubleshoot_job.yml +2 -7
- data/config/unit_primitives/write_tests.yml +0 -6
- data/lib/cloud_connector.rb +4 -1
- data/lib/gitlab/cloud_connector/available_services_generator.rb +96 -0
- data/lib/gitlab/cloud_connector/configuration.rb +23 -0
- data/lib/gitlab/cloud_connector/data_model/associations.rb +32 -0
- data/lib/gitlab/cloud_connector/data_model/base.rb +49 -0
- data/lib/gitlab/cloud_connector/data_model/data_loader.rb +39 -0
- data/lib/gitlab/cloud_connector/data_models.rb +37 -0
- data/lib/gitlab/cloud_connector/version.rb +1 -1
- metadata +29 -2
@@ -2,7 +2,6 @@
|
|
2
2
|
name: generate_code
|
3
3
|
description: Helps you write code more efficiently by generating code as you type.
|
4
4
|
cut_off_date: 2024-02-15T00:00:00+00:00
|
5
|
-
min_gitlab_version_for_free_access:
|
6
5
|
min_gitlab_version: "16.8"
|
7
6
|
unit_primitive_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/497813
|
8
7
|
introduced_by_url: https://gitlab.com/gitlab-org/cloud-connector/gitlab-cloud-connector/-/merge_requests/46
|
@@ -14,6 +13,3 @@ backend_services:
|
|
14
13
|
add_ons:
|
15
14
|
- duo_pro
|
16
15
|
- duo_enterprise
|
17
|
-
license_types:
|
18
|
-
- premium
|
19
|
-
- ultimate
|
@@ -2,16 +2,11 @@
|
|
2
2
|
name: generate_commit_message
|
3
3
|
description: Generate a Git commit message.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
min_gitlab_version_for_free_access: '17.2'
|
6
|
-
min_gitlab_version: '17.2'
|
7
|
-
unit_primitive_issue_url:
|
8
|
-
introduced_by_url:
|
9
|
-
documentation_url:
|
10
5
|
group: group::code review
|
11
6
|
feature_category: code_review_workflow
|
7
|
+
documentation_url: https://docs.gitlab.com/ee/user/gitlab_duo/#merge-commit-message-generation
|
8
|
+
introduced_by_url: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10371
|
12
9
|
backend_services:
|
13
10
|
- ai_gateway
|
14
11
|
add_ons:
|
15
12
|
- duo_enterprise
|
16
|
-
license_types:
|
17
|
-
- ultimate
|
@@ -0,0 +1,10 @@
|
|
1
|
+
---
|
2
|
+
name: generate_cube_query
|
3
|
+
description: Convert plain text questions about event data in to a structured query in JSON format.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
group: group::platform insights
|
6
|
+
feature_category: product_analytics_visualization
|
7
|
+
backend_services:
|
8
|
+
- ai_gateway
|
9
|
+
add_ons:
|
10
|
+
- duo_enterprise
|
@@ -2,14 +2,10 @@
|
|
2
2
|
name: generate_issue_description
|
3
3
|
description: Generate an issue description.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
unit_primitive_issue_url:
|
6
|
-
introduced_by_url:
|
7
|
-
documentation_url:
|
8
5
|
group: group::project management
|
9
6
|
feature_category: team_planning
|
7
|
+
documentation_url: https://docs.gitlab.com/ee/user/gitlab_duo/#issue-description-generation
|
10
8
|
backend_services:
|
11
9
|
- ai_gateway
|
12
10
|
add_ons:
|
13
11
|
- duo_enterprise
|
14
|
-
license_types:
|
15
|
-
- ultimate
|
@@ -2,16 +2,12 @@
|
|
2
2
|
name: glab_ask_git_command
|
3
3
|
description: Discover or recall git commands when and where you need them.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
min_gitlab_version_for_free_access: '17.2'
|
6
5
|
min_gitlab_version: '17.2'
|
7
|
-
unit_primitive_issue_url:
|
8
|
-
introduced_by_url:
|
9
|
-
documentation_url:
|
10
6
|
group: group::code review
|
11
7
|
feature_category: code_review_workflow
|
8
|
+
documentation_url: https://docs.gitlab.com/ee/user/gitlab_duo/#gitlab-duo-for-the-cli
|
9
|
+
introduced_by_url: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10298
|
12
10
|
backend_services:
|
13
11
|
- ai_gateway
|
14
12
|
add_ons:
|
15
13
|
- duo_enterprise
|
16
|
-
license_types:
|
17
|
-
- ultimate
|
@@ -2,14 +2,11 @@
|
|
2
2
|
name: include_dependency_context
|
3
3
|
description: Include dependency context in the prompt.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
unit_primitive_issue_url:
|
6
|
-
introduced_by_url:
|
7
|
-
documentation_url:
|
8
5
|
group: group::duo_chat
|
9
6
|
feature_category: duo_chat
|
7
|
+
unit_primitive_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/491740
|
8
|
+
introduced_by_url: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/11140
|
10
9
|
backend_services:
|
11
10
|
- ai_gateway
|
12
11
|
add_ons:
|
13
12
|
- duo_enterprise
|
14
|
-
license_types:
|
15
|
-
- ultimate
|
@@ -2,16 +2,11 @@
|
|
2
2
|
name: include_file_context
|
3
3
|
description: Include file context in the prompt.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
unit_primitive_issue_url:
|
6
|
-
introduced_by_url:
|
7
|
-
documentation_url:
|
8
5
|
group: group::duo_chat
|
9
6
|
feature_category: duo_chat
|
7
|
+
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/168327/
|
10
8
|
backend_services:
|
11
9
|
- ai_gateway
|
12
10
|
add_ons:
|
13
11
|
- duo_enterprise
|
14
12
|
- duo_pro
|
15
|
-
license_types:
|
16
|
-
- premium
|
17
|
-
- ultimate
|
@@ -2,14 +2,10 @@
|
|
2
2
|
name: include_issue_context
|
3
3
|
description: Include issue context in the prompt.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
unit_primitive_issue_url:
|
6
|
-
introduced_by_url:
|
7
|
-
documentation_url:
|
8
5
|
group: group::duo_chat
|
9
6
|
feature_category: duo_chat
|
7
|
+
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/168327/
|
10
8
|
backend_services:
|
11
9
|
- ai_gateway
|
12
10
|
add_ons:
|
13
11
|
- duo_enterprise
|
14
|
-
license_types:
|
15
|
-
- ultimate
|
@@ -0,0 +1,11 @@
|
|
1
|
+
---
|
2
|
+
name: include_local_git_context
|
3
|
+
description: Include local git context (Git Diffs/Commits) in the prompt.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
group: group::duo_chat
|
6
|
+
feature_category: duo_chat
|
7
|
+
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/172401
|
8
|
+
backend_services:
|
9
|
+
- ai_gateway
|
10
|
+
add_ons:
|
11
|
+
- duo_enterprise
|
@@ -2,14 +2,10 @@
|
|
2
2
|
name: include_merge_request_context
|
3
3
|
description: Include merge request context in the prompt.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
unit_primitive_issue_url:
|
6
|
-
introduced_by_url:
|
7
|
-
documentation_url:
|
8
5
|
group: group::duo_chat
|
9
6
|
feature_category: duo_chat
|
7
|
+
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/168327/
|
10
8
|
backend_services:
|
11
9
|
- ai_gateway
|
12
10
|
add_ons:
|
13
11
|
- duo_enterprise
|
14
|
-
license_types:
|
15
|
-
- ultimate
|
@@ -2,16 +2,11 @@
|
|
2
2
|
name: include_snippet_context
|
3
3
|
description: Include snippet context in the prompt.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
unit_primitive_issue_url:
|
6
|
-
introduced_by_url:
|
7
|
-
documentation_url:
|
8
5
|
group: group::duo_chat
|
9
6
|
feature_category: duo_chat
|
7
|
+
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/168327/
|
10
8
|
backend_services:
|
11
9
|
- ai_gateway
|
12
10
|
add_ons:
|
13
11
|
- duo_enterprise
|
14
12
|
- duo_pro
|
15
|
-
license_types:
|
16
|
-
- premium
|
17
|
-
- ultimate
|
@@ -1,14 +1,7 @@
|
|
1
1
|
---
|
2
2
|
name: observability_all
|
3
3
|
description: Observability unit primitive.
|
4
|
-
cut_off_date:
|
5
|
-
unit_primitive_issue_url:
|
6
|
-
introduced_by_url:
|
7
|
-
documentation_url:
|
8
4
|
group: group::platform insights
|
9
5
|
feature_category: observability
|
10
6
|
backend_services:
|
11
7
|
- observability
|
12
|
-
license_types:
|
13
|
-
- premium
|
14
|
-
- ultimate
|
@@ -2,16 +2,11 @@
|
|
2
2
|
name: refactor_code
|
3
3
|
description: Refactor the selected code.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
unit_primitive_issue_url:
|
6
|
-
introduced_by_url:
|
7
|
-
documentation_url:
|
8
5
|
group: group::duo_chat
|
9
6
|
feature_category: duo_chat
|
7
|
+
documentation_url: https://docs.gitlab.com/ee/user/gitlab_duo/#refactor-code
|
10
8
|
backend_services:
|
11
9
|
- ai_gateway
|
12
10
|
add_ons:
|
13
11
|
- duo_enterprise
|
14
12
|
- duo_pro
|
15
|
-
license_types:
|
16
|
-
- premium
|
17
|
-
- ultimate
|
@@ -2,16 +2,11 @@
|
|
2
2
|
name: resolve_vulnerability
|
3
3
|
description: Write code that fixes the vulnerability.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
min_gitlab_version_for_free_access: '17.2'
|
6
|
-
min_gitlab_version: '17.2'
|
7
|
-
unit_primitive_issue_url:
|
8
|
-
introduced_by_url:
|
9
|
-
documentation_url:
|
10
5
|
group: group::threat insights
|
11
6
|
feature_category: vulnerability_management
|
7
|
+
documentation_url: https://docs.gitlab.com/ee/user/gitlab_duo/#vulnerability-resolution
|
8
|
+
introduced_by_url: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10457
|
12
9
|
backend_services:
|
13
10
|
- ai_gateway
|
14
11
|
add_ons:
|
15
12
|
- duo_enterprise
|
16
|
-
license_types:
|
17
|
-
- ultimate
|
@@ -0,0 +1,11 @@
|
|
1
|
+
---
|
2
|
+
name: review_merge_request
|
3
|
+
description: Review new hunk and old hunk of a merge request diff.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
group: group::code review
|
6
|
+
feature_category: code_review_workflow
|
7
|
+
documentation_url: https://docs.gitlab.com/ee/user/gitlab_duo/#code-review
|
8
|
+
backend_services:
|
9
|
+
- ai_gateway
|
10
|
+
add_ons:
|
11
|
+
- duo_enterprise
|
@@ -1,13 +1,7 @@
|
|
1
1
|
---
|
2
2
|
name: security_scans
|
3
3
|
description: Used to check your source code for known vulnerabilities.
|
4
|
-
cut_off_date:
|
5
|
-
unit_primitive_issue_url:
|
6
|
-
introduced_by_url:
|
7
|
-
documentation_url:
|
8
4
|
group: group::static analysis
|
9
5
|
feature_category: static_application_security_testing
|
10
6
|
backend_services:
|
11
7
|
- security_gateway
|
12
|
-
license_types:
|
13
|
-
- ultimate
|
@@ -2,16 +2,9 @@
|
|
2
2
|
name: summarize_comments
|
3
3
|
description: Summarize comments of the issue or epic.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
min_gitlab_version_for_free_access: '17.2'
|
6
|
-
min_gitlab_version: '17.2'
|
7
|
-
unit_primitive_issue_url:
|
8
|
-
introduced_by_url:
|
9
|
-
documentation_url:
|
10
5
|
group: group::project management
|
11
6
|
feature_category: team_planning
|
12
7
|
backend_services:
|
13
8
|
- ai_gateway
|
14
9
|
add_ons:
|
15
10
|
- duo_enterprise
|
16
|
-
license_types:
|
17
|
-
- ultimate
|
@@ -0,0 +1,11 @@
|
|
1
|
+
---
|
2
|
+
name: summarize_merge_request
|
3
|
+
description: Summarize merge request from the comments.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
group: group::code review
|
6
|
+
feature_category: code_review_workflow
|
7
|
+
documentation_url: https://docs.gitlab.com/ee/user/gitlab_duo/#merge-request-summary
|
8
|
+
backend_services:
|
9
|
+
- ai_gateway
|
10
|
+
add_ons:
|
11
|
+
- duo_enterprise
|
@@ -2,14 +2,10 @@
|
|
2
2
|
name: summarize_review
|
3
3
|
description: Summarize open reviews in merge requests.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
unit_primitive_issue_url:
|
6
|
-
introduced_by_url:
|
7
|
-
documentation_url:
|
8
5
|
group: group::code review
|
9
6
|
feature_category: code_review_workflow
|
7
|
+
documentation_url: https://docs.gitlab.com/ee/user/gitlab_duo/#code-review-summary
|
10
8
|
backend_services:
|
11
9
|
- ai_gateway
|
12
10
|
add_ons:
|
13
11
|
- duo_enterprise
|
14
|
-
license_types:
|
15
|
-
- ultimate
|
@@ -2,16 +2,11 @@
|
|
2
2
|
name: troubleshoot_job
|
3
3
|
description: Troubleshoot why a GitLab CI job failed and suggest a fix for it.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
min_gitlab_version_for_free_access: '17.2'
|
6
|
-
min_gitlab_version: '17.2'
|
7
|
-
unit_primitive_issue_url:
|
8
|
-
introduced_by_url:
|
9
|
-
documentation_url:
|
10
5
|
group: group::pipeline execution
|
11
6
|
feature_category: continuous_integration
|
7
|
+
documentation_url: https://docs.gitlab.com/ee/user/gitlab_duo/#root-cause-analysis
|
8
|
+
introduced_by_url: https://gitlab.com/gitlab-org/customers-gitlab-com/-/merge_requests/10457
|
12
9
|
backend_services:
|
13
10
|
- ai_gateway
|
14
11
|
add_ons:
|
15
12
|
- duo_enterprise
|
16
|
-
license_types:
|
17
|
-
- ultimate
|
@@ -2,9 +2,6 @@
|
|
2
2
|
name: write_tests
|
3
3
|
description: Write tests for the selected code.
|
4
4
|
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
-
unit_primitive_issue_url:
|
6
|
-
introduced_by_url:
|
7
|
-
documentation_url:
|
8
5
|
group: group::duo_chat
|
9
6
|
feature_category: duo_chat
|
10
7
|
backend_services:
|
@@ -12,6 +9,3 @@ backend_services:
|
|
12
9
|
add_ons:
|
13
10
|
- duo_pro
|
14
11
|
- duo_enterprise
|
15
|
-
license_types:
|
16
|
-
- premium
|
17
|
-
- ultimate
|
data/lib/cloud_connector.rb
CHANGED
@@ -5,6 +5,9 @@ require 'active_support/time'
|
|
5
5
|
|
6
6
|
module Gitlab
|
7
7
|
module CloudConnector
|
8
|
-
autoload(:JsonWebToken, 'gitlab/cloud_connector/json_web_token
|
8
|
+
autoload(:JsonWebToken, 'gitlab/cloud_connector/json_web_token')
|
9
|
+
autoload(:Configuration, 'gitlab/cloud_connector/configuration')
|
10
|
+
autoload(:DataModels, 'gitlab/cloud_connector/data_models')
|
11
|
+
autoload(:AvailableServicesGenerator, 'gitlab/cloud_connector/available_services_generator')
|
9
12
|
end
|
10
13
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/enumerable'
|
4
|
+
require 'active_support/core_ext/object/blank'
|
5
|
+
|
6
|
+
module Gitlab
|
7
|
+
module CloudConnector
|
8
|
+
class AvailableServicesGenerator
|
9
|
+
GITLAB_REALMS = %w[gitlab-com self-managed].freeze
|
10
|
+
WRONG_GITLAB_REALM_MESSAGE = 'Wrong gitlab_realm. Please use one of the following: %s'
|
11
|
+
IGNORE_UNIT_PRIMITIVES = %w[
|
12
|
+
agent_quick_actions
|
13
|
+
ask_build
|
14
|
+
ask_commit
|
15
|
+
ask_epic
|
16
|
+
ask_issue
|
17
|
+
ask_merge_request
|
18
|
+
categorize_duo_chat_question
|
19
|
+
complete_code
|
20
|
+
documentation_search
|
21
|
+
duo_workflow_execute_workflow
|
22
|
+
duo_workflow_generate_token
|
23
|
+
explain_code
|
24
|
+
fix_code
|
25
|
+
generate_code
|
26
|
+
generate_issue_description
|
27
|
+
refactor_code
|
28
|
+
security_scans
|
29
|
+
semantic_search_issue
|
30
|
+
summarize_issue_discussions
|
31
|
+
summarize_merge_request
|
32
|
+
write_tests
|
33
|
+
].freeze
|
34
|
+
|
35
|
+
def generate(gitlab_realm)
|
36
|
+
raise WRONG_GITLAB_REALM_MESSAGE % GITLAB_REALMS.join(', ') unless GITLAB_REALMS.include?(gitlab_realm)
|
37
|
+
|
38
|
+
{
|
39
|
+
'services' => generate_services_config(gitlab_realm)
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def generate_services_config(gitlab_realm)
|
46
|
+
services_config = {}
|
47
|
+
|
48
|
+
DataModels::Service.each do |service|
|
49
|
+
next if service.gitlab_realm && !service.gitlab_realm&.include?(gitlab_realm)
|
50
|
+
|
51
|
+
service_config = generate_service_config(service.unit_primitives, service.basic_unit_primitive)
|
52
|
+
# Remove duo_pro for self_hosted_models
|
53
|
+
service_config['bundled_with'].delete('duo_pro') if service.name == 'self_hosted_models'
|
54
|
+
|
55
|
+
services_config[service.name] = service_config
|
56
|
+
end
|
57
|
+
|
58
|
+
# Generate a stand-alone service for each unit primitive (except the ones in the ignore list)
|
59
|
+
unit_primitives = DataModels::UnitPrimitive.reject { |up| IGNORE_UNIT_PRIMITIVES.include?(up.name) }
|
60
|
+
unit_primitives.each do |unit_primitive|
|
61
|
+
next if services_config[unit_primitive.name]
|
62
|
+
|
63
|
+
services_config[unit_primitive.name] = generate_service_config([unit_primitive])
|
64
|
+
end
|
65
|
+
|
66
|
+
services_config.sort.to_h
|
67
|
+
end
|
68
|
+
|
69
|
+
def generate_service_config(unit_primitives, basic_unit_primitive = nil)
|
70
|
+
sample_primitive = unit_primitives.find { |up| up.name == basic_unit_primitive } if basic_unit_primitive
|
71
|
+
sample_primitive ||= unit_primitives.first
|
72
|
+
backend_service = sample_primitive&.backend_services&.first
|
73
|
+
|
74
|
+
{
|
75
|
+
'backend' => backend_service&.jwt_aud,
|
76
|
+
'cut_off_date' => sample_primitive&.cut_off_date&.strftime('%Y-%m-%d %H:%M:%S UTC'),
|
77
|
+
'min_gitlab_version' => sample_primitive&.min_gitlab_version,
|
78
|
+
'min_gitlab_version_for_free_access' => sample_primitive&.min_gitlab_version_for_free_access,
|
79
|
+
'bundled_with' => generate_bundled_config(unit_primitives),
|
80
|
+
'license_types' => sample_primitive&.license_types&.map(&:name)
|
81
|
+
}.compact_blank
|
82
|
+
end
|
83
|
+
|
84
|
+
def generate_bundled_config(unit_primitives)
|
85
|
+
unit_primitives.each_with_object({}) do |primitive, bundled|
|
86
|
+
target_groups = primitive.add_ons.any? ? primitive.add_ons.map(&:name) : ['_irrelevant']
|
87
|
+
target_groups.each do |group_name|
|
88
|
+
group_name = group_name.to_s
|
89
|
+
bundled[group_name] ||= { 'unit_primitives' => [] }
|
90
|
+
bundled[group_name]['unit_primitives'] << primitive.name
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gitlab
|
4
|
+
module CloudConnector
|
5
|
+
module Configuration
|
6
|
+
class << self
|
7
|
+
attr_writer :config_dir
|
8
|
+
|
9
|
+
def config_dir
|
10
|
+
@config_dir ||= File.expand_path("../../../config", __dir__).freeze
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield self if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def reset!
|
18
|
+
@config_dir = nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Gitlab
|
4
|
+
module CloudConnector
|
5
|
+
module DataModel
|
6
|
+
module Associations
|
7
|
+
module ClassMethods
|
8
|
+
# rubocop:disable Naming/PredicateName
|
9
|
+
def has_and_belongs_to_many(name)
|
10
|
+
define_method(name) do
|
11
|
+
instance_variable_get(:"@#{name}_association") ||
|
12
|
+
instance_variable_set(:"@#{name}_association", load_association_records(name))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
# rubocop:enable Naming/PredicateName
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.included(base)
|
19
|
+
base.extend ClassMethods
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def load_association_records(association_name)
|
25
|
+
names = Array(self[association_name])
|
26
|
+
association_class = Gitlab::CloudConnector::DataModels.const_get(association_name.to_s.classify)
|
27
|
+
association_class.select { |record| names.include?(record.name.to_s) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'associations'
|
4
|
+
require_relative 'data_loader'
|
5
|
+
|
6
|
+
module Gitlab
|
7
|
+
module CloudConnector
|
8
|
+
module DataModel
|
9
|
+
class Base
|
10
|
+
include Associations
|
11
|
+
extend Enumerable
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def model_name
|
15
|
+
name&.demodulize
|
16
|
+
end
|
17
|
+
|
18
|
+
def each(&block)
|
19
|
+
all.each(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_by_name(name)
|
23
|
+
all.find { |record| record.name.to_sym == name }
|
24
|
+
end
|
25
|
+
|
26
|
+
def all
|
27
|
+
@all ||= data_loader.load!
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def data_loader
|
33
|
+
@data_loader ||= DataLoader.new(self)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(**opts)
|
38
|
+
opts.each do |key, value|
|
39
|
+
instance_variable_set(:"@#{key}", value)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def [](name)
|
44
|
+
instance_variable_get(:"@#{name}")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Gitlab
|
6
|
+
module CloudConnector
|
7
|
+
module DataModel
|
8
|
+
class DataLoader
|
9
|
+
def initialize(model_class)
|
10
|
+
@model_class = model_class
|
11
|
+
end
|
12
|
+
|
13
|
+
def load!
|
14
|
+
Dir.glob(data_files_path).map { |file| load_model_from_file(file) }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :model_class
|
20
|
+
|
21
|
+
def data_files_path
|
22
|
+
File.join(CloudConnector::Configuration.config_dir, model_class.model_name.tableize, '*.yml')
|
23
|
+
end
|
24
|
+
|
25
|
+
def load_model_from_file(file_path)
|
26
|
+
data = YAML.safe_load(
|
27
|
+
File.read(file_path),
|
28
|
+
permitted_classes: [Time],
|
29
|
+
symbolize_names: true
|
30
|
+
).deep_symbolize_keys!
|
31
|
+
|
32
|
+
model_class.new(**data)
|
33
|
+
rescue StandardError => e
|
34
|
+
raise "Error loading file #{file_path}: #{e.message}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'data_model/base'
|
4
|
+
|
5
|
+
module Gitlab
|
6
|
+
module CloudConnector
|
7
|
+
module DataModels
|
8
|
+
class UnitPrimitive < DataModel::Base
|
9
|
+
has_and_belongs_to_many :backend_services
|
10
|
+
has_and_belongs_to_many :add_ons
|
11
|
+
has_and_belongs_to_many :license_types
|
12
|
+
|
13
|
+
attr_reader :cut_off_date, :deprecated_by_url, :deprecation_message, :description, :documentation_url,
|
14
|
+
:feature_category, :group, :introduced_by_url, :milestone, :min_gitlab_version,
|
15
|
+
:min_gitlab_version_for_free_access, :name, :unit_primitive_issue_url
|
16
|
+
end
|
17
|
+
|
18
|
+
class Service < DataModel::Base
|
19
|
+
has_and_belongs_to_many :unit_primitives
|
20
|
+
|
21
|
+
attr_reader :basic_unit_primitive, :description, :gitlab_realm, :name
|
22
|
+
end
|
23
|
+
|
24
|
+
class BackendService < DataModel::Base
|
25
|
+
attr_reader :description, :group, :jwt_aud, :name, :project_url
|
26
|
+
end
|
27
|
+
|
28
|
+
class LicenseType < DataModel::Base
|
29
|
+
attr_reader :description, :name
|
30
|
+
end
|
31
|
+
|
32
|
+
class AddOn < DataModel::Base
|
33
|
+
attr_reader :description, :name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|