Class: UffizziCore::ComposeFileService

Inherits:
Object
  • Object
show all
Extended by:
DependencyInjectionConcern
Defined in:
app/services/uffizzi_core/compose_file_service.rb

Class Method Summary collapse

Methods included from DependencyInjectionConcern

ci_module, ci_session, controller_settings_service, deployment_memory_module, domain_module, find_build_parser_module, find_ingress_parser_module, find_volume_parser_module, notification_module, password_protection_module, template_memory_module, user_access_module

Class Method Details

.build_template_attributes(compose_data, source, credentials, project, compose_dependencies = [], compose_repositories = []) ⇒ Object



56
57
58
59
60
# File 'app/services/uffizzi_core/compose_file_service.rb', line 56

def build_template_attributes(compose_data, source, credentials, project, compose_dependencies = [], compose_repositories = [])
  builder = UffizziCore::ComposeFile::Builders::TemplateBuilderService.new(credentials, project, compose_repositories)

  builder.build_attributes(compose_data, compose_dependencies, source)
end

.create(params, kind) ⇒ Object



7
8
9
10
11
# File 'app/services/uffizzi_core/compose_file_service.rb', line 7

def create(params, kind)
  compose_file_form = create_compose_form(params, kind)

  process_compose_file(compose_file_form, params)
end

.create_temporary_compose(resource_project, current_user, compose_file_params, dependencies) ⇒ Object



105
106
107
108
109
110
# File 'app/services/uffizzi_core/compose_file_service.rb', line 105

def create_temporary_compose(resource_project, current_user, compose_file_params, dependencies)
  create_params = { project: resource_project, user: current_user, compose_file_params: compose_file_params,
                    dependencies: dependencies || [] }
  kind = UffizziCore::ComposeFile.kind.temporary
  UffizziCore::ComposeFileService.create(create_params, kind)
end

.has_secret?(compose_file, secret) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
# File 'app/services/uffizzi_core/compose_file_service.rb', line 62

def has_secret?(compose_file, secret)
  containers = compose_file.template.payload['containers_attributes']

  containers.any? { |container| UffizziCore::ComposeFile::ContainerService.has_secret?(container, secret) }
end

.parse(compose_content, compose_payload = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/services/uffizzi_core/compose_file_service.rb', line 19

def parse(compose_content, compose_payload = {})
  compose_data = load_compose_data(compose_content)
  check_config_options_format(compose_data)
  configs_data = UffizziCore::ComposeFile::Parsers::ConfigsParserService.parse(compose_data['configs'])
  secrets_data = UffizziCore::ComposeFile::Parsers::SecretsParserService.parse(compose_data['secrets'])
  named_volume_names = UffizziCore::ComposeFile::Parsers::NamedVolumesParserService.parse(compose_data['volumes'])
  containers_data = UffizziCore::ComposeFile::Parsers::ServicesParserService.parse(
    compose_data['services'],
    configs_data,
    secrets_data,
    compose_payload,
    named_volume_names,
  )
  continuous_preview_option = UffizziCore::ComposeFile::ConfigOptionService.continuous_preview_option(compose_data)
  continuous_preview_data = UffizziCore::ComposeFile::Parsers::ContinuousPreviewParserService.parse(continuous_preview_option)

  ingress_option = UffizziCore::ComposeFile::ConfigOptionService.ingress_option(compose_data)
  ingress_data = parse_ingress(ingress_option, compose_data)

  {
    containers: containers_data,
    ingress: ingress_data,
    continuous_preview: continuous_preview_data,
  }
end

.parse_ingress(ingress_option, compose_data) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'app/services/uffizzi_core/compose_file_service.rb', line 45

def parse_ingress(ingress_option, compose_data)
  ingress_parser_module = find_ingress_parser_module

  unless ingress_parser_module
    return UffizziCore::ComposeFile::Parsers::IngressParserService.parse(ingress_option,
                                                                         compose_data['services'])
  end

  ingress_parser_module.parse(ingress_option, compose_data['services'])
end

.secrets_valid?(compose_file, secrets) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
100
101
102
103
# File 'app/services/uffizzi_core/compose_file_service.rb', line 97

def secrets_valid?(compose_file, secrets)
  secret_names = secrets.pluck('name')

  compose_file.template.payload['containers_attributes'].all? do |container|
    container['secret_variables'].all? { |secret| secret_names.include?(secret['name']) }
  end
end

.update(compose_file, params) ⇒ Object



13
14
15
16
17
# File 'app/services/uffizzi_core/compose_file_service.rb', line 13

def update(compose_file, params)
  compose_file_form = create_update_compose_form(compose_file, params)

  process_compose_file(compose_file_form, params)
end

.update_secret!(compose_file, secret) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/services/uffizzi_core/compose_file_service.rb', line 68

def update_secret!(compose_file, secret)
  compose_file.template.payload['containers_attributes'].each do |container|
    next unless UffizziCore::ComposeFile::ContainerService.has_secret?(container, secret)

    UffizziCore::ComposeFile::ContainerService.update_secret(container, secret)
    next if compose_file.payload['errors'].blank?

    compose_file_errors = compose_file.payload['errors'].presence
    secrets_errors = compose_file_errors[UffizziCore::ComposeFile::ErrorsService::SECRETS_ERROR_KEY].presence
    new_secrets_errors = secrets_errors.reject { |secret_errors| secret_errors.include?(secret.name) }

    if new_secrets_errors.present?
      new_errors = { UffizziCore::ComposeFile::ErrorsService::SECRETS_ERROR_KEY => new_secrets_errors }
      UffizziCore::ComposeFile::ErrorsService.update_compose_errors!(compose_file, compose_file_errors.merge(new_errors),
                                                                     compose_file.content)
      next
    end

    compose_file_errors.delete(['secret_variables'])
    next UffizziCore::ComposeFile::ErrorsService.reset_compose_errors!(compose_file) if compose_file_errors.empty?

    UffizziCore::ComposeFile::ErrorsService.update_compose_errors!(compose_file, compose_file_errors, compose_file.content)
  end

  compose_file.template.save!

  compose_file
end