gitlab-cloud-connector 0.1.0 → 0.2.1
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/.rubocop.yml +1 -3
- data/CONTRIBUTING.md +50 -0
- data/LICENSE +28 -0
- data/Makefile +33 -0
- data/README.md +11 -221
- data/Rakefile +1 -5
- data/config/add_ons/duo_enterprise.yml +2 -0
- data/config/add_ons/duo_pro.yml +2 -0
- data/config/backend_services/ai_gateway.yml +5 -0
- data/config/backend_services/duo_workflow_service.yml +5 -0
- data/config/backend_services/observability.yml +5 -0
- data/config/backend_services/security_gateway.yml +5 -0
- data/config/license_types/premium.yml +2 -0
- data/config/license_types/ultimate.yml +2 -0
- data/config/schemas/add_on_schema.json +15 -0
- data/config/schemas/backend_service_schema.json +26 -0
- data/config/schemas/license_type_schema.json +15 -0
- data/config/schemas/unit_primitive_schema.json +97 -0
- data/config/unit_primitives/ask_build.yml +15 -0
- data/config/unit_primitives/ask_commit.yml +15 -0
- data/config/unit_primitives/ask_epic.yml +15 -0
- data/config/unit_primitives/ask_issue.yml +15 -0
- data/config/unit_primitives/code_suggestions.yml +19 -0
- data/config/unit_primitives/complete_code.yml +19 -0
- data/config/unit_primitives/documentation_search.yml +19 -0
- data/config/unit_primitives/duo_chat.yml +19 -0
- data/config/unit_primitives/duo_workflow_execute_workflow.yml +13 -0
- data/config/unit_primitives/explain_code.yml +17 -0
- data/config/unit_primitives/explain_vulnerability.yml +17 -0
- data/config/unit_primitives/fix_code.yml +17 -0
- data/config/unit_primitives/generate_code.yml +19 -0
- data/config/unit_primitives/generate_commit_message.yml +17 -0
- data/config/unit_primitives/generate_issue_description.yml +15 -0
- data/config/unit_primitives/glab_ask_git_command.yml +17 -0
- data/config/unit_primitives/include_dependency_context.yml +15 -0
- data/config/unit_primitives/include_file_context.yml +17 -0
- data/config/unit_primitives/include_issue_context.yml +15 -0
- data/config/unit_primitives/include_merge_request_context.yml +15 -0
- data/config/unit_primitives/include_snippet_context.yml +17 -0
- data/config/unit_primitives/observability_all.yml +14 -0
- data/config/unit_primitives/refactor_code.yml +17 -0
- data/config/unit_primitives/resolve_vulnerability.yml +17 -0
- data/config/unit_primitives/security_scans.yml +13 -0
- data/config/unit_primitives/summarize_comments.yml +17 -0
- data/config/unit_primitives/summarize_review.yml +15 -0
- data/config/unit_primitives/troubleshoot_job.yml +17 -0
- data/config/unit_primitives/write_tests.yml +17 -0
- data/lib/cloud_connector.rb +10 -0
- data/lib/gitlab/cloud_connector/json_web_token.rb +59 -0
- data/lib/gitlab/cloud_connector/{backend_service.rb → version.rb} +1 -3
- metadata +85 -48
- data/.idea/.gitignore +0 -8
- data/.idea/gitlab-cloud-connector.iml +0 -127
- data/.idea/inspectionProfiles/Project_Default.xml +0 -9
- data/.idea/misc.xml +0 -4
- data/.idea/modules.xml +0 -8
- data/.idea/vcs.xml +0 -7
- data/CHANGELOG.md +0 -5
- data/Dangerfile +0 -5
- data/config/cloud_connector/backend_services/ai_gateway/unit_primitives/code_suggestions.yml +0 -19
- data/config/cloud_connector/backend_services/ai_gateway/unit_primitives/documentation_search.yml +0 -19
- data/config/cloud_connector/backend_services/ai_gateway/unit_primitives/duo_chat.yml +0 -19
- data/lib/gitlab/cloud_connector/auth/json_web_token.rb +0 -82
- data/lib/gitlab/cloud_connector/base_group.rb +0 -39
- data/lib/gitlab/cloud_connector/configuration.rb +0 -24
- data/lib/gitlab/cloud_connector/deliverable.rb +0 -31
- data/lib/gitlab/cloud_connector/delivered_by.rb +0 -10
- data/lib/gitlab/cloud_connector/purchasable_decorator.rb +0 -59
- data/lib/gitlab/cloud_connector/token_issuer.rb +0 -44
- data/lib/gitlab/cloud_connector/unit_primitives.rb +0 -195
- data/lib/gitlab/cloud_connector.rb +0 -68
- data/lib/gitlab/popen.rb +0 -68
- data/lib/utils/parse_helper.rb +0 -15
- data/lib/utils/strong_memoize.rb +0 -145
- data/sig/gitlab/cloud_connector.rbs +0 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
name: code_suggestions
|
3
|
+
description: Helps you write code more efficiently by generating code and showing suggestions as you type.
|
4
|
+
cut_off_date: 2024-02-15T00:00:00+00:00
|
5
|
+
min_gitlab_version_for_free_access:
|
6
|
+
min_gitlab_version: '16.8'
|
7
|
+
unit_primitive_issue_url:
|
8
|
+
introduced_by_url:
|
9
|
+
documentation_url:
|
10
|
+
group: group::code suggestions
|
11
|
+
feature_category: code_suggestions
|
12
|
+
backend_services:
|
13
|
+
- ai_gateway
|
14
|
+
add_ons:
|
15
|
+
- duo_pro
|
16
|
+
- duo_enterprise
|
17
|
+
license_types:
|
18
|
+
- premium
|
19
|
+
- ultimate
|
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
name: complete_code
|
3
|
+
description: Helps you write code more efficiently by showing code suggestions as you type.
|
4
|
+
cut_off_date: 2024-02-15T00:00:00+00:00
|
5
|
+
min_gitlab_version_for_free_access:
|
6
|
+
min_gitlab_version: "16.8"
|
7
|
+
unit_primitive_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/497813
|
8
|
+
introduced_by_url: https://gitlab.com/gitlab-org/cloud-connector/gitlab-cloud-connector/-/merge_requests/46
|
9
|
+
documentation_url: https://docs.gitlab.com/ee/user/project/repository/code_suggestions/#code-completion
|
10
|
+
group: group::code suggestions
|
11
|
+
feature_category: code_suggestions
|
12
|
+
backend_services:
|
13
|
+
- ai_gateway
|
14
|
+
add_ons:
|
15
|
+
- duo_pro
|
16
|
+
- duo_enterprise
|
17
|
+
license_types:
|
18
|
+
- premium
|
19
|
+
- ultimate
|
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
name: documentation_search
|
3
|
+
description: Perform semantic search on gitlab documentations for a given query.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
min_gitlab_version_for_free_access: '16.8'
|
6
|
+
min_gitlab_version: '16.9'
|
7
|
+
unit_primitive_issue_url:
|
8
|
+
introduced_by_url:
|
9
|
+
documentation_url:
|
10
|
+
group: group::duo_chat
|
11
|
+
feature_category: duo_chat
|
12
|
+
backend_services:
|
13
|
+
- ai_gateway
|
14
|
+
add_ons:
|
15
|
+
- duo_pro
|
16
|
+
- duo_enterprise
|
17
|
+
license_types:
|
18
|
+
- premium
|
19
|
+
- ultimate
|
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
name: duo_chat
|
3
|
+
description: Ask various GitLab-related questions and tasks.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
min_gitlab_version_for_free_access: '16.8'
|
6
|
+
min_gitlab_version: '16.9'
|
7
|
+
unit_primitive_issue_url:
|
8
|
+
introduced_by_url:
|
9
|
+
documentation_url:
|
10
|
+
group: group::duo_chat
|
11
|
+
feature_category: duo_chat
|
12
|
+
backend_services:
|
13
|
+
- ai_gateway
|
14
|
+
add_ons:
|
15
|
+
- duo_pro
|
16
|
+
- duo_enterprise
|
17
|
+
license_types:
|
18
|
+
- premium
|
19
|
+
- ultimate
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
name: duo_workflow_execute_workflow
|
3
|
+
description: Automate tasks and help increase productivity in your development workflow by using GitLab Duo Workflow.
|
4
|
+
cut_off_date:
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::duo workflow
|
9
|
+
feature_category: duo_workflow
|
10
|
+
backend_services:
|
11
|
+
- duo_workflow_service
|
12
|
+
license_types:
|
13
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: explain_code
|
3
|
+
description: Explain function or method of the selected code.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::source code
|
9
|
+
feature_category: source_code_management
|
10
|
+
backend_services:
|
11
|
+
- ai_gateway
|
12
|
+
add_ons:
|
13
|
+
- duo_enterprise
|
14
|
+
- duo_pro
|
15
|
+
license_types:
|
16
|
+
- premium
|
17
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: explain_vulnerability
|
3
|
+
description: Explain a security vulnerability of the given CVE or code.
|
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
|
+
group: group::threat insights
|
11
|
+
feature_category: vulnerability_management
|
12
|
+
backend_services:
|
13
|
+
- ai_gateway
|
14
|
+
add_ons:
|
15
|
+
- duo_enterprise
|
16
|
+
license_types:
|
17
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: fix_code
|
3
|
+
description: Fix the selected code.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::duo_chat
|
9
|
+
feature_category: duo_chat
|
10
|
+
backend_services:
|
11
|
+
- ai_gateway
|
12
|
+
add_ons:
|
13
|
+
- duo_enterprise
|
14
|
+
- duo_pro
|
15
|
+
license_types:
|
16
|
+
- premium
|
17
|
+
- ultimate
|
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
name: generate_code
|
3
|
+
description: Helps you write code more efficiently by generating code as you type.
|
4
|
+
cut_off_date: 2024-02-15T00:00:00+00:00
|
5
|
+
min_gitlab_version_for_free_access:
|
6
|
+
min_gitlab_version: "16.8"
|
7
|
+
unit_primitive_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/497813
|
8
|
+
introduced_by_url: https://gitlab.com/gitlab-org/cloud-connector/gitlab-cloud-connector/-/merge_requests/46
|
9
|
+
documentation_url: https://docs.gitlab.com/ee/user/project/repository/code_suggestions/#code-generation
|
10
|
+
group: group::code suggestions
|
11
|
+
feature_category: code_suggestions
|
12
|
+
backend_services:
|
13
|
+
- ai_gateway
|
14
|
+
add_ons:
|
15
|
+
- duo_pro
|
16
|
+
- duo_enterprise
|
17
|
+
license_types:
|
18
|
+
- premium
|
19
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: generate_commit_message
|
3
|
+
description: Generate a Git commit message.
|
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
|
+
group: group::code review
|
11
|
+
feature_category: code_review_workflow
|
12
|
+
backend_services:
|
13
|
+
- ai_gateway
|
14
|
+
add_ons:
|
15
|
+
- duo_enterprise
|
16
|
+
license_types:
|
17
|
+
- ultimate
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
name: generate_issue_description
|
3
|
+
description: Generate an issue description.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::project management
|
9
|
+
feature_category: team_planning
|
10
|
+
backend_services:
|
11
|
+
- ai_gateway
|
12
|
+
add_ons:
|
13
|
+
- duo_enterprise
|
14
|
+
license_types:
|
15
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: glab_ask_git_command
|
3
|
+
description: Discover or recall git commands when and where you need them.
|
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
|
+
group: group::code review
|
11
|
+
feature_category: code_review_workflow
|
12
|
+
backend_services:
|
13
|
+
- ai_gateway
|
14
|
+
add_ons:
|
15
|
+
- duo_enterprise
|
16
|
+
license_types:
|
17
|
+
- ultimate
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
name: include_dependency_context
|
3
|
+
description: Include dependency context in the prompt.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::duo_chat
|
9
|
+
feature_category: duo_chat
|
10
|
+
backend_services:
|
11
|
+
- ai_gateway
|
12
|
+
add_ons:
|
13
|
+
- duo_enterprise
|
14
|
+
license_types:
|
15
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: include_file_context
|
3
|
+
description: Include file context in the prompt.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::duo_chat
|
9
|
+
feature_category: duo_chat
|
10
|
+
backend_services:
|
11
|
+
- ai_gateway
|
12
|
+
add_ons:
|
13
|
+
- duo_enterprise
|
14
|
+
- duo_pro
|
15
|
+
license_types:
|
16
|
+
- premium
|
17
|
+
- ultimate
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
name: include_issue_context
|
3
|
+
description: Include issue context in the prompt.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::duo_chat
|
9
|
+
feature_category: duo_chat
|
10
|
+
backend_services:
|
11
|
+
- ai_gateway
|
12
|
+
add_ons:
|
13
|
+
- duo_enterprise
|
14
|
+
license_types:
|
15
|
+
- ultimate
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
name: include_merge_request_context
|
3
|
+
description: Include merge request context in the prompt.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::duo_chat
|
9
|
+
feature_category: duo_chat
|
10
|
+
backend_services:
|
11
|
+
- ai_gateway
|
12
|
+
add_ons:
|
13
|
+
- duo_enterprise
|
14
|
+
license_types:
|
15
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: include_snippet_context
|
3
|
+
description: Include snippet context in the prompt.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::duo_chat
|
9
|
+
feature_category: duo_chat
|
10
|
+
backend_services:
|
11
|
+
- ai_gateway
|
12
|
+
add_ons:
|
13
|
+
- duo_enterprise
|
14
|
+
- duo_pro
|
15
|
+
license_types:
|
16
|
+
- premium
|
17
|
+
- ultimate
|
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
name: observability_all
|
3
|
+
description: Observability unit primitive.
|
4
|
+
cut_off_date:
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::platform insights
|
9
|
+
feature_category: observability
|
10
|
+
backend_services:
|
11
|
+
- observability
|
12
|
+
license_types:
|
13
|
+
- premium
|
14
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: refactor_code
|
3
|
+
description: Refactor the selected code.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::duo_chat
|
9
|
+
feature_category: duo_chat
|
10
|
+
backend_services:
|
11
|
+
- ai_gateway
|
12
|
+
add_ons:
|
13
|
+
- duo_enterprise
|
14
|
+
- duo_pro
|
15
|
+
license_types:
|
16
|
+
- premium
|
17
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: resolve_vulnerability
|
3
|
+
description: Write code that fixes the vulnerability.
|
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
|
+
group: group::threat insights
|
11
|
+
feature_category: vulnerability_management
|
12
|
+
backend_services:
|
13
|
+
- ai_gateway
|
14
|
+
add_ons:
|
15
|
+
- duo_enterprise
|
16
|
+
license_types:
|
17
|
+
- ultimate
|
@@ -0,0 +1,13 @@
|
|
1
|
+
---
|
2
|
+
name: security_scans
|
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
|
+
group: group::static analysis
|
9
|
+
feature_category: static_application_security_testing
|
10
|
+
backend_services:
|
11
|
+
- security_gateway
|
12
|
+
license_types:
|
13
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: summarize_comments
|
3
|
+
description: Summarize comments of the issue or epic.
|
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
|
+
group: group::project management
|
11
|
+
feature_category: team_planning
|
12
|
+
backend_services:
|
13
|
+
- ai_gateway
|
14
|
+
add_ons:
|
15
|
+
- duo_enterprise
|
16
|
+
license_types:
|
17
|
+
- ultimate
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
name: summarize_review
|
3
|
+
description: Summarize open reviews in merge requests.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::code review
|
9
|
+
feature_category: code_review_workflow
|
10
|
+
backend_services:
|
11
|
+
- ai_gateway
|
12
|
+
add_ons:
|
13
|
+
- duo_enterprise
|
14
|
+
license_types:
|
15
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: troubleshoot_job
|
3
|
+
description: Troubleshoot why a GitLab CI job failed and suggest a fix for it.
|
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
|
+
group: group::pipeline execution
|
11
|
+
feature_category: continuous_integration
|
12
|
+
backend_services:
|
13
|
+
- ai_gateway
|
14
|
+
add_ons:
|
15
|
+
- duo_enterprise
|
16
|
+
license_types:
|
17
|
+
- ultimate
|
@@ -0,0 +1,17 @@
|
|
1
|
+
---
|
2
|
+
name: write_tests
|
3
|
+
description: Write tests for the selected code.
|
4
|
+
cut_off_date: 2024-10-17T00:00:00+00:00
|
5
|
+
unit_primitive_issue_url:
|
6
|
+
introduced_by_url:
|
7
|
+
documentation_url:
|
8
|
+
group: group::duo_chat
|
9
|
+
feature_category: duo_chat
|
10
|
+
backend_services:
|
11
|
+
- ai_gateway
|
12
|
+
add_ons:
|
13
|
+
- duo_pro
|
14
|
+
- duo_enterprise
|
15
|
+
license_types:
|
16
|
+
- premium
|
17
|
+
- ultimate
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'jwt'
|
4
|
+
|
5
|
+
module Gitlab
|
6
|
+
module CloudConnector
|
7
|
+
class JsonWebToken
|
8
|
+
SIGNING_ALGORITHM = 'RS256'
|
9
|
+
NOT_BEFORE_TIME_SEC = 5.seconds.to_i
|
10
|
+
|
11
|
+
attr_reader :issued_at, :expires_at
|
12
|
+
|
13
|
+
def initialize(issuer:, audience:, subject:, realm:, scopes:, ttl:, extra_claims: {})
|
14
|
+
@id = SecureRandom.uuid
|
15
|
+
@audience = audience
|
16
|
+
@subject = subject
|
17
|
+
@issuer = issuer
|
18
|
+
@issued_at = Time.current.to_i
|
19
|
+
@not_before = @issued_at - NOT_BEFORE_TIME_SEC
|
20
|
+
@expires_at = (@issued_at + ttl).to_i
|
21
|
+
@realm = realm
|
22
|
+
@scopes = scopes
|
23
|
+
@extra_claims = extra_claims
|
24
|
+
end
|
25
|
+
|
26
|
+
# jwk:
|
27
|
+
# The key (pair) as an instance of JWT::JWK.
|
28
|
+
#
|
29
|
+
# Returns a signed and Base64-encoded JSON Web Token string, to be
|
30
|
+
# written to the HTTP Authorization header field.
|
31
|
+
def encode(jwk)
|
32
|
+
header_fields = { typ: 'JWT', kid: jwk.kid }
|
33
|
+
|
34
|
+
JWT.encode(payload, jwk.signing_key, SIGNING_ALGORITHM, header_fields)
|
35
|
+
end
|
36
|
+
|
37
|
+
def payload
|
38
|
+
{
|
39
|
+
jti: @id,
|
40
|
+
aud: @audience,
|
41
|
+
sub: @subject,
|
42
|
+
iss: @issuer,
|
43
|
+
iat: @issued_at,
|
44
|
+
nbf: @not_before,
|
45
|
+
exp: @expires_at
|
46
|
+
}.merge(cloud_connector_claims)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def cloud_connector_claims
|
52
|
+
{
|
53
|
+
gitlab_realm: @realm,
|
54
|
+
scopes: @scopes
|
55
|
+
}.merge(@extra_claims)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|