uffizzi-core 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +201 -0
- data/README.md +52 -0
- data/Rakefile +31 -0
- data/app/assets/config/uffizzi_core_manifest.js +1 -0
- data/app/assets/stylesheets/uffizzi_core/application.css +15 -0
- data/app/clients/uffizzi_core/amazon_registry_client.rb +18 -0
- data/app/clients/uffizzi_core/azure_registry_client/request_result.rb +5 -0
- data/app/clients/uffizzi_core/azure_registry_client.rb +42 -0
- data/app/clients/uffizzi_core/controller_client/request_result.rb +5 -0
- data/app/clients/uffizzi_core/controller_client.rb +106 -0
- data/app/clients/uffizzi_core/docker_hub_client/request_result.rb +7 -0
- data/app/clients/uffizzi_core/docker_hub_client.rb +141 -0
- data/app/clients/uffizzi_core/github_container_registry_client/request_result.rb +7 -0
- data/app/clients/uffizzi_core/github_container_registry_client.rb +52 -0
- data/app/clients/uffizzi_core/google_registry_client/request_result.rb +5 -0
- data/app/clients/uffizzi_core/google_registry_client.rb +42 -0
- data/app/contexts/uffizzi_core/base_context.rb +12 -0
- data/app/contexts/uffizzi_core/project_context.rb +13 -0
- data/app/contexts/uffizzi_core/webhooks_context.rb +9 -0
- data/app/controllers/concerns/uffizzi_core/auth_management.rb +23 -0
- data/app/controllers/concerns/uffizzi_core/authorization_concern.rb +38 -0
- data/app/controllers/concerns/uffizzi_core/dependency_injection_concern.rb +19 -0
- data/app/controllers/uffizzi_core/api/cli/v1/account/application_controller.rb +7 -0
- data/app/controllers/uffizzi_core/api/cli/v1/account/credentials_controller.rb +91 -0
- data/app/controllers/uffizzi_core/api/cli/v1/application_controller.rb +5 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/application_controller.rb +11 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/compose_files_controller.rb +93 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/activity_items_controller.rb +36 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/application_controller.rb +7 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/containers/application_controller.rb +8 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/containers/logs_controller.rb +27 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/containers_controller.rb +24 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/events_controller.rb +29 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments_controller.rb +179 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects/secrets_controller.rb +61 -0
- data/app/controllers/uffizzi_core/api/cli/v1/projects_controller.rb +85 -0
- data/app/controllers/uffizzi_core/api/cli/v1/sessions_controller.rb +43 -0
- data/app/controllers/uffizzi_core/application_controller.rb +57 -0
- data/app/errors/uffizzi_core/compose_file/build_error.rb +4 -0
- data/app/errors/uffizzi_core/compose_file/credential_error.rb +4 -0
- data/app/errors/uffizzi_core/compose_file/parse_error.rb +4 -0
- data/app/errors/uffizzi_core/compose_file/secrets_error.rb +4 -0
- data/app/errors/uffizzi_core/deployment/image_pull_error.rb +10 -0
- data/app/errors/uffizzi_core/deployment_not_found_error.rb +10 -0
- data/app/forms/uffizzi_core/api/cli/v1/account/credential/check_credential_form.rb +16 -0
- data/app/forms/uffizzi_core/api/cli/v1/account/credential/create_form.rb +26 -0
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/check_credentials_form.rb +21 -0
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/cli_form.rb +22 -0
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/create_form.rb +13 -0
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/template_form.rb +44 -0
- data/app/forms/uffizzi_core/api/cli/v1/compose_file/update_form.rb +9 -0
- data/app/forms/uffizzi_core/api/cli/v1/config_file/create_form.rb +11 -0
- data/app/forms/uffizzi_core/api/cli/v1/deployment/create_form.rb +92 -0
- data/app/forms/uffizzi_core/api/cli/v1/deployment/update_form.rb +90 -0
- data/app/forms/uffizzi_core/api/cli/v1/project/create_form.rb +7 -0
- data/app/forms/uffizzi_core/api/cli/v1/project/update_form.rb +10 -0
- data/app/forms/uffizzi_core/api/cli/v1/secret/bulk_assign_form.rb +39 -0
- data/app/forms/uffizzi_core/api/cli/v1/session_create_form.rb +29 -0
- data/app/forms/uffizzi_core/api/cli/v1/template/create_form.rb +65 -0
- data/app/forms/uffizzi_core/application_form.rb +11 -0
- data/app/forms/uffizzi_core/application_form_without_active_record.rb +17 -0
- data/app/forms/uffizzi_core/mass_assignment_control_concern.rb +22 -0
- data/app/helpers/uffizzi_core/application_helper.rb +6 -0
- data/app/jobs/uffizzi_core/account/create_credential_job.rb +10 -0
- data/app/jobs/uffizzi_core/activity_item/docker/update_digest_job.rb +11 -0
- data/app/jobs/uffizzi_core/application_job.rb +7 -0
- data/app/jobs/uffizzi_core/config_file/apply_job.rb +31 -0
- data/app/jobs/uffizzi_core/credential/docker_hub/create_webhook_job.rb +15 -0
- data/app/jobs/uffizzi_core/deployment/create_credential_job.rb +32 -0
- data/app/jobs/uffizzi_core/deployment/create_credentials_job.rb +17 -0
- data/app/jobs/uffizzi_core/deployment/create_job.rb +15 -0
- data/app/jobs/uffizzi_core/deployment/create_webhooks_job.rb +13 -0
- data/app/jobs/uffizzi_core/deployment/delete_credential_job.rb +13 -0
- data/app/jobs/uffizzi_core/deployment/delete_job.rb +11 -0
- data/app/jobs/uffizzi_core/deployment/deploy_containers_job.rb +27 -0
- data/app/jobs/uffizzi_core/deployment/manage_deploy_activity_item_job.rb +38 -0
- data/app/lib/uffizzi_core/concerns/models/activity_item.rb +39 -0
- data/app/lib/uffizzi_core/concerns/models/credential.rb +65 -0
- data/app/lib/uffizzi_core/concerns/models/repo.rb +33 -0
- data/app/lib/uffizzi_core/rbac/user_access_service.rb +45 -0
- data/app/mailers/uffizzi_core/application_mailer.rb +8 -0
- data/app/models/concerns/uffizzi_core/hashid_concern.rb +25 -0
- data/app/models/concerns/uffizzi_core/state_machine_concern.rb +16 -0
- data/app/models/uffizzi_core/account.rb +83 -0
- data/app/models/uffizzi_core/activity_item/docker.rb +4 -0
- data/app/models/uffizzi_core/activity_item/github.rb +4 -0
- data/app/models/uffizzi_core/activity_item/memory_limit.rb +4 -0
- data/app/models/uffizzi_core/activity_item.rb +53 -0
- data/app/models/uffizzi_core/application_record.rb +7 -0
- data/app/models/uffizzi_core/build.rb +39 -0
- data/app/models/uffizzi_core/comment.rb +16 -0
- data/app/models/uffizzi_core/compose_file.rb +57 -0
- data/app/models/uffizzi_core/config_file.rb +24 -0
- data/app/models/uffizzi_core/container.rb +100 -0
- data/app/models/uffizzi_core/container_config_file.rb +8 -0
- data/app/models/uffizzi_core/continuous_preview.rb +4 -0
- data/app/models/uffizzi_core/coupon.rb +5 -0
- data/app/models/uffizzi_core/credential/amazon.rb +4 -0
- data/app/models/uffizzi_core/credential/azure.rb +4 -0
- data/app/models/uffizzi_core/credential/docker_hub.rb +4 -0
- data/app/models/uffizzi_core/credential/github.rb +4 -0
- data/app/models/uffizzi_core/credential/github_container_registry.rb +4 -0
- data/app/models/uffizzi_core/credential/google.rb +4 -0
- data/app/models/uffizzi_core/credential.rb +61 -0
- data/app/models/uffizzi_core/database.rb +4 -0
- data/app/models/uffizzi_core/database_offering.rb +4 -0
- data/app/models/uffizzi_core/deployment.rb +86 -0
- data/app/models/uffizzi_core/event.rb +13 -0
- data/app/models/uffizzi_core/invitation.rb +27 -0
- data/app/models/uffizzi_core/membership.rb +16 -0
- data/app/models/uffizzi_core/payment.rb +11 -0
- data/app/models/uffizzi_core/price.rb +9 -0
- data/app/models/uffizzi_core/product.rb +11 -0
- data/app/models/uffizzi_core/project.rb +67 -0
- data/app/models/uffizzi_core/rating.rb +20 -0
- data/app/models/uffizzi_core/repo/amazon.rb +4 -0
- data/app/models/uffizzi_core/repo/azure.rb +4 -0
- data/app/models/uffizzi_core/repo/docker_hub.rb +4 -0
- data/app/models/uffizzi_core/repo/github.rb +4 -0
- data/app/models/uffizzi_core/repo/github_container_registry.rb +4 -0
- data/app/models/uffizzi_core/repo/google.rb +4 -0
- data/app/models/uffizzi_core/repo.rb +29 -0
- data/app/models/uffizzi_core/role.rb +17 -0
- data/app/models/uffizzi_core/secret.rb +9 -0
- data/app/models/uffizzi_core/template.rb +19 -0
- data/app/models/uffizzi_core/user.rb +62 -0
- data/app/models/uffizzi_core/user_project.rb +14 -0
- data/app/policies/uffizzi_core/api/cli/v1/account/credentials_policy.rb +19 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/compose_files_policy.rb +15 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/deployments/activity_items_policy.rb +7 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/deployments/containers_policy.rb +7 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/deployments/events_policy.rb +7 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/deployments_policy.rb +27 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects/secrets_policy.rb +15 -0
- data/app/policies/uffizzi_core/api/cli/v1/projects_policy.rb +19 -0
- data/app/policies/uffizzi_core/application_policy.rb +12 -0
- data/app/repositories/uffizzi_core/activity_item_repo.rb +9 -0
- data/app/repositories/uffizzi_core/basic_order_repo.rb +11 -0
- data/app/repositories/uffizzi_core/build_repo.rb +23 -0
- data/app/repositories/uffizzi_core/comment_repo.rb +11 -0
- data/app/repositories/uffizzi_core/compose_file_repo.rb +11 -0
- data/app/repositories/uffizzi_core/config_file_repo.rb +40 -0
- data/app/repositories/uffizzi_core/container_repo.rb +25 -0
- data/app/repositories/uffizzi_core/credential_repo.rb +31 -0
- data/app/repositories/uffizzi_core/deployment_repo.rb +24 -0
- data/app/repositories/uffizzi_core/event_repo.rb +9 -0
- data/app/repositories/uffizzi_core/membership_repo.rb +10 -0
- data/app/repositories/uffizzi_core/price_repo.rb +11 -0
- data/app/repositories/uffizzi_core/product_repo.rb +11 -0
- data/app/repositories/uffizzi_core/project_repo.rb +10 -0
- data/app/repositories/uffizzi_core/repo_repo.rb +10 -0
- data/app/repositories/uffizzi_core/template_repo.rb +87 -0
- data/app/repositories/uffizzi_core/usage_repo.rb +9 -0
- data/app/repositories/uffizzi_core/user_repo.rb +11 -0
- data/app/responders/uffizzi_core/json_responder.rb +13 -0
- data/app/serializers/uffizzi_core/api/cli/v1/account/credential_serializer.rb +9 -0
- data/app/serializers/uffizzi_core/api/cli/v1/project_serializer/compose_file_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/api/cli/v1/project_serializer/deployment_serializer.rb +13 -0
- data/app/serializers/uffizzi_core/api/cli/v1/project_serializer.rb +30 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/compose_file_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer/container_serializer.rb +32 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer/user_serializer.rb +11 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployment_serializer.rb +74 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/activity_item_serializer.rb +24 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer/container_config_file_serializer/config_file_serializer.rb +6 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer/container_config_file_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/deployments/container_serializer.rb +30 -0
- data/app/serializers/uffizzi_core/api/cli/v1/projects/secret_serializer.rb +5 -0
- data/app/serializers/uffizzi_core/api/cli/v1/short_project_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/api/cli/v1/user_serializer/account_serializer.rb +5 -0
- data/app/serializers/uffizzi_core/api/cli/v1/user_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/base_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/controller/apply_config_file/config_file_serializer.rb +5 -0
- data/app/serializers/uffizzi_core/controller/create_credential/credential_serializer.rb +19 -0
- data/app/serializers/uffizzi_core/controller/create_deployment/deployment_serializer.rb +5 -0
- data/app/serializers/uffizzi_core/controller/deploy_containers/container_serializer/container_config_file_serializer/config_file_serializer.rb +8 -0
- data/app/serializers/uffizzi_core/controller/deploy_containers/container_serializer/container_config_file_serializer.rb +7 -0
- data/app/serializers/uffizzi_core/controller/deploy_containers/container_serializer.rb +70 -0
- data/app/serializers/uffizzi_core/controller/deploy_containers/credential_serializer.rb +5 -0
- data/app/services/uffizzi_core/account_service.rb +21 -0
- data/app/services/uffizzi_core/activity_item_service.rb +88 -0
- data/app/services/uffizzi_core/amazon/credential_service.rb +31 -0
- data/app/services/uffizzi_core/amazon_service.rb +45 -0
- data/app/services/uffizzi_core/azure/credential_service.rb +18 -0
- data/app/services/uffizzi_core/compose_file/builders/config_files_builder_service.rb +31 -0
- data/app/services/uffizzi_core/compose_file/builders/container_builder_service.rb +222 -0
- data/app/services/uffizzi_core/compose_file/builders/docker_repo_builder_service.rb +25 -0
- data/app/services/uffizzi_core/compose_file/builders/template_builder_service.rb +45 -0
- data/app/services/uffizzi_core/compose_file/builders/variables_builder_service.rb +58 -0
- data/app/services/uffizzi_core/compose_file/config_files_service.rb +52 -0
- data/app/services/uffizzi_core/compose_file/config_option_service.rb +41 -0
- data/app/services/uffizzi_core/compose_file/configs_options_service.rb +26 -0
- data/app/services/uffizzi_core/compose_file/container_service.rb +68 -0
- data/app/services/uffizzi_core/compose_file/continuous_preview_options_service.rb +57 -0
- data/app/services/uffizzi_core/compose_file/dependencies_service.rb +56 -0
- data/app/services/uffizzi_core/compose_file/errors_service.rb +46 -0
- data/app/services/uffizzi_core/compose_file/github_dependencies_service.rb +38 -0
- data/app/services/uffizzi_core/compose_file/ingress_options_service.rb +51 -0
- data/app/services/uffizzi_core/compose_file/parsers/services/healthcheck_parser_service.rb +73 -0
- data/app/services/uffizzi_core/compose_file/secrets_options_service.rb +28 -0
- data/app/services/uffizzi_core/compose_file/services_options/command_service.rb +18 -0
- data/app/services/uffizzi_core/compose_file/services_options/configs_service.rb +51 -0
- data/app/services/uffizzi_core/compose_file/services_options/deploy_service.rb +44 -0
- data/app/services/uffizzi_core/compose_file/services_options/entrypoint_service.rb +18 -0
- data/app/services/uffizzi_core/compose_file/services_options/env_file_service.rb +34 -0
- data/app/services/uffizzi_core/compose_file/services_options/environment_service.rb +20 -0
- data/app/services/uffizzi_core/compose_file/services_options/image_service.rb +89 -0
- data/app/services/uffizzi_core/compose_file/services_options/secrets_service.rb +35 -0
- data/app/services/uffizzi_core/compose_file/services_options_service.rb +57 -0
- data/app/services/uffizzi_core/compose_file/template_service.rb +55 -0
- data/app/services/uffizzi_core/compose_file/variables_service.rb +25 -0
- data/app/services/uffizzi_core/compose_file_service.rb +181 -0
- data/app/services/uffizzi_core/container_service.rb +42 -0
- data/app/services/uffizzi_core/controller_service.rb +86 -0
- data/app/services/uffizzi_core/credential_service.rb +44 -0
- data/app/services/uffizzi_core/deployment_service.rb +307 -0
- data/app/services/uffizzi_core/docker_hub/credential_service.rb +15 -0
- data/app/services/uffizzi_core/docker_hub_service.rb +77 -0
- data/app/services/uffizzi_core/github_container_registry/credential_service.rb +24 -0
- data/app/services/uffizzi_core/google/credential_service.rb +18 -0
- data/app/services/uffizzi_core/logs_service.rb +33 -0
- data/app/services/uffizzi_core/manage_activity_items_service.rb +159 -0
- data/app/services/uffizzi_core/project_service.rb +48 -0
- data/app/services/uffizzi_core/repo_service.rb +43 -0
- data/app/services/uffizzi_core/response_service.rb +13 -0
- data/app/services/uffizzi_core/starter_template_service.rb +200 -0
- data/app/services/uffizzi_core/template_service.rb +21 -0
- data/app/services/uffizzi_core/token_service.rb +19 -0
- data/app/services/uffizzi_core/user_access_service.rb +14 -0
- data/app/services/uffizzi_core/user_generator_service.rb +84 -0
- data/app/utils/uffizzi_core/converters.rb +33 -0
- data/app/validators/uffizzi_core/email_validator.rb +9 -0
- data/app/validators/uffizzi_core/environment_variable_list_validator.rb +15 -0
- data/app/validators/uffizzi_core/image_command_args_validator.rb +21 -0
- data/config/initializers/rswag_api.rb +15 -0
- data/config/initializers/rswag_ui.rb +15 -0
- data/config/initializers/swagger_yard.rb +17 -0
- data/config/locales/en.activerecord.yml +23 -0
- data/config/locales/en.yml +66 -0
- data/config/routes.rb +69 -0
- data/db/migrate/20220218121438_create_uffizzi_core_tables.rb +375 -0
- data/db/migrate/20220309110201_remove_secrets_from_projects.rb +7 -0
- data/db/migrate/20220310110150_create_project_secrets.rb +14 -0
- data/db/migrate/20220325113342_add_name_to_uffizzi_containers.rb +7 -0
- data/db/migrate/20220329123323_rename_project_secrets_to_secrets.rb +7 -0
- data/db/migrate/20220329124542_add_resource_to_secrets.rb +7 -0
- data/db/migrate/20220329143241_remove_project_ref_from_secrets.rb +7 -0
- data/db/migrate/20220419074956_add_health_check_to_containers.rb +7 -0
- data/db/migrate/20220525113412_rename_name_to_uffizzi_containers.rb +7 -0
- data/db/seeds.rb +16 -0
- data/lib/tasks/uffizzi_core_tasks.rake +19 -0
- data/lib/uffizzi_core/engine.rb +15 -0
- data/lib/uffizzi_core/version.rb +5 -0
- data/lib/uffizzi_core.rb +61 -0
- data/swagger/v1/swagger.json +1659 -0
- metadata +966 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::GithubContainerRegistryClient
|
4
|
+
attr_accessor :token, :registry_url
|
5
|
+
|
6
|
+
def initialize(registry_url:, username:, password:)
|
7
|
+
@registry_url = registry_url
|
8
|
+
@username = username
|
9
|
+
@password = password
|
10
|
+
@token = access_token&.result&.token
|
11
|
+
end
|
12
|
+
|
13
|
+
def access_token
|
14
|
+
service = URI.parse(registry_url).hostname
|
15
|
+
url = "/token?service=#{service}"
|
16
|
+
|
17
|
+
response = connection.get(url, {})
|
18
|
+
|
19
|
+
RequestResult.new(result: response.body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def authentificated?
|
23
|
+
token.present?
|
24
|
+
end
|
25
|
+
|
26
|
+
def manifests(image:, tag:)
|
27
|
+
url = "/v2/#{@username}/#{image}/manifests/#{tag}"
|
28
|
+
response = token_connection.get(url)
|
29
|
+
|
30
|
+
RequestResult.quiet.new(result: response.body, headers: response.headers)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def connection
|
36
|
+
Faraday.new(registry_url) do |conn|
|
37
|
+
conn.request(:basic_auth, @username, @password)
|
38
|
+
conn.request(:json)
|
39
|
+
conn.response(:json)
|
40
|
+
conn.adapter(Faraday.default_adapter)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def token_connection
|
45
|
+
Faraday.new(registry_url) do |conn|
|
46
|
+
conn.request(:authorization, 'Bearer', token)
|
47
|
+
conn.request(:json)
|
48
|
+
conn.response(:json)
|
49
|
+
conn.adapter(Faraday.default_adapter)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::GoogleRegistryClient
|
4
|
+
attr_accessor :connection, :token, :registry_url
|
5
|
+
|
6
|
+
def initialize(registry_url:, username:, password:)
|
7
|
+
@registry_url = registry_url
|
8
|
+
@connection = build_connection(registry_url, username, password)
|
9
|
+
@token = access_token&.result&.token
|
10
|
+
end
|
11
|
+
|
12
|
+
def manifests(image:, tag:)
|
13
|
+
url = "/v2/#{image}/manifests/#{tag}"
|
14
|
+
response = connection.get(url)
|
15
|
+
|
16
|
+
RequestResult.quiet.new(result: response.body, headers: response.headers)
|
17
|
+
end
|
18
|
+
|
19
|
+
def access_token
|
20
|
+
service = URI.parse(registry_url).hostname
|
21
|
+
url = "/v2/token?service=#{service}"
|
22
|
+
|
23
|
+
response = connection.get(url, {})
|
24
|
+
|
25
|
+
RequestResult.new(result: response.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
def authentificated?
|
29
|
+
token.present?
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def build_connection(registry_url, username, password)
|
35
|
+
Faraday.new(registry_url) do |conn|
|
36
|
+
conn.request(:basic_auth, username, password)
|
37
|
+
conn.request(:json)
|
38
|
+
conn.response(:json)
|
39
|
+
conn.adapter(Faraday.default_adapter)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::BaseContext
|
4
|
+
attr_reader :user, :user_access_module, :params, :account
|
5
|
+
|
6
|
+
def initialize(user, user_access_module, params)
|
7
|
+
@user = user
|
8
|
+
@user_access_module = user_access_module
|
9
|
+
@account = user.organizational_account
|
10
|
+
@params = params
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::ProjectContext
|
4
|
+
attr_reader :user, :user_access_module, :project, :account, :params
|
5
|
+
|
6
|
+
def initialize(user, user_access_module, project, params)
|
7
|
+
@user = user
|
8
|
+
@user_access_module = user_access_module
|
9
|
+
@account = user.organizational_account
|
10
|
+
@project = project
|
11
|
+
@params = params
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::AuthManagement
|
4
|
+
def sign_in(user)
|
5
|
+
session[:user_id] = user.id
|
6
|
+
end
|
7
|
+
|
8
|
+
def sign_out
|
9
|
+
session[:user_id] = @current_user = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def signed_in?
|
13
|
+
session[:user_id].present? && current_user.present?
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_user
|
17
|
+
@current_user ||= UffizziCore::User.find_by(id: session[:user_id])
|
18
|
+
end
|
19
|
+
|
20
|
+
def authenticate_request!
|
21
|
+
current_user ? true : head(:unauthorized)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::AuthorizationConcern
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
before_action :init_authorize
|
8
|
+
end
|
9
|
+
|
10
|
+
def init_authorize
|
11
|
+
return unless self.class.ancestors.include?(UffizziCore::ApplicationController)
|
12
|
+
|
13
|
+
self.class.send(:define_method, policy_method_name) { send(:authorize, policy_method_params) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def pundit_user
|
17
|
+
policy_context
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def policy_method_name
|
23
|
+
[:authorize, policy_name].join('_')
|
24
|
+
end
|
25
|
+
|
26
|
+
def policy_name
|
27
|
+
controller_class = self.class.to_s
|
28
|
+
|
29
|
+
controller_class.gsub(/::|Controller/, '').underscore
|
30
|
+
end
|
31
|
+
|
32
|
+
def policy_method_params
|
33
|
+
controller_class = self.class.to_s
|
34
|
+
|
35
|
+
params = controller_class.gsub(/Controller/, '').split('::')
|
36
|
+
params.map(&:underscore).map(&:downcase).map(&:to_sym)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module UffizziCore::DependencyInjectionConcern
|
4
|
+
def user_access_module
|
5
|
+
return unless module_exists?(:rbac)
|
6
|
+
|
7
|
+
UffizziCore::UserAccessService.new(module_class(:rbac))
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def module_exists?(module_name)
|
13
|
+
module_class(module_name).present?
|
14
|
+
end
|
15
|
+
|
16
|
+
def module_class(module_name)
|
17
|
+
UffizziCore.dependencies[module_name]&.constantize
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @resource Account/Credential
|
4
|
+
class UffizziCore::Api::Cli::V1::Account::CredentialsController < UffizziCore::Api::Cli::V1::Account::ApplicationController
|
5
|
+
before_action :authorize_uffizzi_core_api_cli_v1_account_credentials
|
6
|
+
|
7
|
+
# Get a list of accounts credential
|
8
|
+
#
|
9
|
+
# @path [GET] /api/cli/v1/account/credentials
|
10
|
+
#
|
11
|
+
# @parameter credential(required,body) [object<username:string, password: string, type:string>]
|
12
|
+
def index
|
13
|
+
credentials = resource_account.credentials.pluck(:type)
|
14
|
+
|
15
|
+
render json: { credentials: credentials }, status: :ok
|
16
|
+
end
|
17
|
+
|
18
|
+
# Create account credential
|
19
|
+
#
|
20
|
+
# @path [POST] /api/cli/v1/account/credentials
|
21
|
+
#
|
22
|
+
# @parameter credential(required,body) [object<username:string, password: string, type:string>]
|
23
|
+
# @response [object<id:integer, username:string, password:string, type:string, state:string>] 201 Created successfully
|
24
|
+
# @response [object<errors>] 422 Unprocessable entity
|
25
|
+
#
|
26
|
+
# @example
|
27
|
+
# type can be one of UffizziCore::Credential::Amazon, UffizziCore::Credential::Azure,
|
28
|
+
# UffizziCore::Credential::DockerHub, UffizziCore::Credential::Google, UffizziCore::Credential::GithubContainerRegistry
|
29
|
+
|
30
|
+
def create
|
31
|
+
credential_form = UffizziCore::Api::Cli::V1::Account::Credential::CreateForm.new
|
32
|
+
credential_form.assign_attributes(credential_params)
|
33
|
+
credential_form.account = resource_account
|
34
|
+
credential_form.registry_url = registry_url(credential_form)
|
35
|
+
credential_form.username = '_json_key' if credential_form.google?
|
36
|
+
credential_form.activate
|
37
|
+
|
38
|
+
UffizziCore::Account::CreateCredentialJob.perform_async(credential_form.id) if credential_form.save
|
39
|
+
|
40
|
+
respond_with credential_form
|
41
|
+
end
|
42
|
+
|
43
|
+
# Check if credential of the type already exists in the account
|
44
|
+
#
|
45
|
+
# @path [GET] /api/cli/v1/account/credentials/{type}/check_credential
|
46
|
+
#
|
47
|
+
# @parameter credential(required,body) [object<type:string>]
|
48
|
+
# @response 422 Unprocessable entity
|
49
|
+
# @response 200 OK
|
50
|
+
def check_credential
|
51
|
+
credential_form = UffizziCore::Api::Cli::V1::Account::Credential::CheckCredentialForm.new
|
52
|
+
credential_form.type = params[:type]
|
53
|
+
credential_form.account = resource_account
|
54
|
+
if credential_form.valid?
|
55
|
+
respond_with credential_form
|
56
|
+
else
|
57
|
+
respond_with credential_form.errors, status: :unprocessable_entity
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Delete account credential
|
62
|
+
#
|
63
|
+
# @path [DELETE] /api/cli/v1/account/credentials/{type}
|
64
|
+
#
|
65
|
+
# @parameter type(required,path) [string] Type of the credential
|
66
|
+
# @response 204 No Content
|
67
|
+
# @response 401 Not authorized
|
68
|
+
# @response [object<errors: object<title: string>>] 404 Not found
|
69
|
+
def destroy
|
70
|
+
credential = resource_account.credentials.find_by!(type: params[:type])
|
71
|
+
credential.destroy
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def credential_params
|
77
|
+
params.require(:credential)
|
78
|
+
end
|
79
|
+
|
80
|
+
def registry_url(credential_form)
|
81
|
+
if credential_form.docker_hub?
|
82
|
+
Settings.docker_hub.registry_url
|
83
|
+
elsif credential_form.google?
|
84
|
+
Settings.google.registry_url
|
85
|
+
elsif credential_form.github_container_registry?
|
86
|
+
Settings.github_container_registry.registry_url
|
87
|
+
else
|
88
|
+
credential_form.registry_url
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::Api::Cli::V1::Projects::ApplicationController < UffizziCore::Api::Cli::V1::ApplicationController
|
4
|
+
def resource_project
|
5
|
+
@resource_project ||= current_user.projects.find_by!(slug: params[:project_slug])
|
6
|
+
end
|
7
|
+
|
8
|
+
def policy_context
|
9
|
+
UffizziCore::ProjectContext.new(current_user, user_access_module, resource_project, params)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @resource ComposeFile
|
4
|
+
class UffizziCore::Api::Cli::V1::Projects::ComposeFilesController < UffizziCore::Api::Cli::V1::Projects::ApplicationController
|
5
|
+
before_action :authorize_uffizzi_core_api_cli_v1_projects_compose_files
|
6
|
+
|
7
|
+
# Get the compose file for the project
|
8
|
+
#
|
9
|
+
# @path [GET] /api/cli/v1/projects/{project_slug}/compose_file
|
10
|
+
#
|
11
|
+
# @parameter project_slug(required,path) [string] The project slug
|
12
|
+
#
|
13
|
+
# @response [ComposeFile] 200 OK
|
14
|
+
# @response 401 Not authorized
|
15
|
+
# @response [object<errors: object<title: string>>] 404 Not found
|
16
|
+
def show
|
17
|
+
respond_with compose_file
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create a compose file for the project
|
21
|
+
#
|
22
|
+
# @path [POST] /api/cli/v1/projects/{project_slug}/compose_file
|
23
|
+
#
|
24
|
+
# @parameter project_slug(required,path) [string] The project slug
|
25
|
+
# @parameter params(required,body) [object <
|
26
|
+
# compose_file: object<path: string, source: string, content: string>,
|
27
|
+
# dependencies: Array<object<path: string, source: string, content: string>>>]
|
28
|
+
#
|
29
|
+
# @response [ComposeFile] 201 OK
|
30
|
+
# @response 422 A compose file already exists for this project
|
31
|
+
# @response [ComposeFile] 422 Invalid compose file
|
32
|
+
# @response 401 Not authorized
|
33
|
+
def create
|
34
|
+
params = {
|
35
|
+
project: resource_project,
|
36
|
+
user: current_user,
|
37
|
+
compose_file_params: compose_file_params,
|
38
|
+
dependencies: dependencies_params[:dependencies] || [],
|
39
|
+
}
|
40
|
+
|
41
|
+
compose_file_form, errors = create_or_update_compose_file(params)
|
42
|
+
return render_errors(errors) if errors.present?
|
43
|
+
|
44
|
+
respond_with compose_file_form
|
45
|
+
end
|
46
|
+
|
47
|
+
# Delete the compose file for the project
|
48
|
+
#
|
49
|
+
# @path [DELETE] /api/cli/v1/projects/{project_slug}/compose_file
|
50
|
+
#
|
51
|
+
# @parameter project_slug(required,path) [string] The project slug
|
52
|
+
#
|
53
|
+
# @response 204 No Content
|
54
|
+
# @response 401 Not authorized
|
55
|
+
def destroy
|
56
|
+
compose_file.destroy
|
57
|
+
|
58
|
+
head :no_content
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def compose_file
|
64
|
+
compose_file = resource_project.compose_file
|
65
|
+
raise ActiveRecord::RecordNotFound if compose_file.blank?
|
66
|
+
|
67
|
+
compose_file
|
68
|
+
end
|
69
|
+
|
70
|
+
def compose_file_params
|
71
|
+
params.require(:compose_file)
|
72
|
+
end
|
73
|
+
|
74
|
+
def dependencies_params
|
75
|
+
params.permit(dependencies: [:name, :path, :source, :content])
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_or_update_compose_file(params)
|
79
|
+
existing_compose_file = resource_project.compose_file
|
80
|
+
if existing_compose_file.present?
|
81
|
+
UffizziCore::ComposeFileService.update(existing_compose_file, params)
|
82
|
+
else
|
83
|
+
kind = UffizziCore::ComposeFile.kind.main
|
84
|
+
UffizziCore::ComposeFileService.create(params, kind)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def render_errors(errors)
|
89
|
+
json = { errors: errors }
|
90
|
+
|
91
|
+
render json: json, status: :unprocessable_entity
|
92
|
+
end
|
93
|
+
end
|
data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/activity_items_controller.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::Api::Cli::V1::Projects::Deployments::ActivityItemsController <
|
4
|
+
UffizziCore::Api::Cli::V1::Projects::Deployments::ApplicationController
|
5
|
+
before_action :authorize_uffizzi_core_api_cli_v1_projects_deployments_activity_items
|
6
|
+
|
7
|
+
# Get activity items for a deployment
|
8
|
+
#
|
9
|
+
# @path [GET] /api/cli/v1/projects/{project_slug}/deployment/{deployment_id}/actiivity_items
|
10
|
+
#
|
11
|
+
# @parameter project_slug(required,path) [string] The project slug
|
12
|
+
# @parameter deployment_d(required,path) [integer] The id of the deployment
|
13
|
+
#
|
14
|
+
# @response [ActivtyItem] 200 OK
|
15
|
+
# @response 401 Not authorized
|
16
|
+
# @response 404 Not found
|
17
|
+
def index
|
18
|
+
activity_items = resource_deployment
|
19
|
+
.activity_items
|
20
|
+
.page(page)
|
21
|
+
.per(per_page)
|
22
|
+
.order(updated_at: :desc)
|
23
|
+
.ransack(q_param)
|
24
|
+
.result
|
25
|
+
|
26
|
+
meta = meta(activity_items)
|
27
|
+
activity_items = activity_items.map do |activity_item|
|
28
|
+
UffizziCore::Api::Cli::V1::Projects::Deployments::ActivityItemSerializer.new(activity_item).as_json
|
29
|
+
end
|
30
|
+
|
31
|
+
render json: {
|
32
|
+
activity_items: activity_items,
|
33
|
+
meta: meta,
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::Api::Cli::V1::Projects::Deployments::ApplicationController < UffizziCore::Api::Cli::V1::Projects::ApplicationController
|
4
|
+
def resource_deployment
|
5
|
+
@resource_deployment ||= resource_project.deployments.active.find(params[:deployment_id])
|
6
|
+
end
|
7
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class UffizziCore::Api::Cli::V1::Projects::Deployments::Containers::ApplicationController <
|
4
|
+
UffizziCore::Api::Cli::V1::Projects::Deployments::ApplicationController
|
5
|
+
def resource_container
|
6
|
+
@resource_container ||= resource_deployment.active_containers.find_by!(service_name: params[:container_name])
|
7
|
+
end
|
8
|
+
end
|
data/app/controllers/uffizzi_core/api/cli/v1/projects/deployments/containers/logs_controller.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @resource Project/Deployment/Container/Log
|
4
|
+
|
5
|
+
class UffizziCore::Api::Cli::V1::Projects::Deployments::Containers::LogsController <
|
6
|
+
UffizziCore::Api::Cli::V1::Projects::Deployments::Containers::ApplicationController
|
7
|
+
# @path [GET] /api/cli/v1/projects/{project_slug}/deployments/{deployment_id}/containers/{container_name}/logs
|
8
|
+
#
|
9
|
+
# @parameter project_slug(required,path) [string] The slug of the project
|
10
|
+
# @parameter deployment_id(required,path) [integer] The id of the deployment
|
11
|
+
# @parameter container_name(required,path) [integer] The name of the container
|
12
|
+
#
|
13
|
+
# @response [object <logs: Array<object<insert_id: string, payload: string>>>] 200 OK
|
14
|
+
# @response [object<errors: object<title: string>>] 404 Not found
|
15
|
+
# @response 401 Not authorized
|
16
|
+
def index
|
17
|
+
response = UffizziCore::LogsService.fetch_container_logs(resource_container, logs_params)
|
18
|
+
|
19
|
+
render json: response
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def logs_params
|
25
|
+
params.permit(:limit)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @resource Container
|
4
|
+
|
5
|
+
class UffizziCore::Api::Cli::V1::Projects::Deployments::ContainersController <
|
6
|
+
UffizziCore::Api::Cli::V1::Projects::Deployments::ApplicationController
|
7
|
+
before_action :authorize_uffizzi_core_api_cli_v1_projects_deployments_containers
|
8
|
+
|
9
|
+
# Get a list of container services for a deployment
|
10
|
+
#
|
11
|
+
# @path [GET] /api/cli/v1/projects/{project_slug}/deployments/{deployment_id}/containers
|
12
|
+
#
|
13
|
+
# @parameter project_slug(required,path) [string] The project slug
|
14
|
+
# @parameter deployment_id(required,path) [integer] The id of the deployment
|
15
|
+
#
|
16
|
+
# @response [Container] 200 OK
|
17
|
+
# @response 401 Not authorized
|
18
|
+
# @response 404 Not found
|
19
|
+
def index
|
20
|
+
containers = resource_deployment.containers.active
|
21
|
+
|
22
|
+
respond_with containers
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @resource Event
|
4
|
+
class UffizziCore::Api::Cli::V1::Projects::Deployments::EventsController <
|
5
|
+
UffizziCore::Api::Cli::V1::Projects::Deployments::ApplicationController
|
6
|
+
before_action :authorize_uffizzi_core_api_cli_v1_projects_deployments_events
|
7
|
+
|
8
|
+
# Get the events associated with deployment
|
9
|
+
#
|
10
|
+
# @path [GET] /api/cli/v1/projects/{project_slug}/deployments/{deployment_id}/events
|
11
|
+
#
|
12
|
+
# @parameter project_slug(required,path) [string] The project_slug for the project
|
13
|
+
# @parameter deployment_id(required,path) [integer] The id of the deployment
|
14
|
+
#
|
15
|
+
# @response [object<
|
16
|
+
# events: Array<object
|
17
|
+
# <first_timestamp: string, last_timestamp: string, reason: string, message: string>
|
18
|
+
# > >] 200 OK
|
19
|
+
#
|
20
|
+
# @response 401 Not authorized
|
21
|
+
# @response 404 Not found
|
22
|
+
def index
|
23
|
+
response = UffizziCore::ControllerService.fetch_deployment_events(resource_deployment)
|
24
|
+
|
25
|
+
events = { events: response }
|
26
|
+
|
27
|
+
render json: events
|
28
|
+
end
|
29
|
+
end
|