Skip to content

Commit

Permalink
Merge pull request #123 from UffizziCloud/feature/98_add-support-for-…
Browse files Browse the repository at this point in the history
…yaml-anchors

[#98] Add support for YAML anchors
  • Loading branch information
the38th authored May 30, 2022
2 parents 9a28aa1 + 93f0cae commit 79e5f6c
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def valid_option_format?(option)

def config_options(compose_data)
compose_data.each_with_object([]) do |(key, value), keys|
if compose_data.equal?(value)
raise UffizziCore::ComposeFile::ParseError, I18n.t('compose.infinite_recursion', key: key)
end

keys << key
keys.concat(config_options(value)) if value.is_a?(Hash)
end
Expand Down
2 changes: 1 addition & 1 deletion core/app/services/uffizzi_core/compose_file_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def persist!(compose_file_form, cli_form)

def load_compose_data(compose_content)
begin
compose_data = YAML.safe_load(compose_content)
compose_data = YAML.safe_load(compose_content, aliases: true)
rescue Psych::SyntaxError
raise UffizziCore::ComposeFile::ParseError, 'Invalid compose file'
end
Expand Down
1 change: 1 addition & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ en:
invalid_healthcheck_command: "Service '%{name}' defines an invalid healthcheck: when 'test' is a list the first item must be either NONE, CMD or CMD-SHELL"
string_or_array_error: "'%{option}' contains an invalid type, it should be a string, or an array"
not_implemented: "'%{option}' option is not implemented"
infinite_recursion: "Found infinite recursion for key '%{key}'"
secrets:
duplicates_exists: Secret with key %{secrets} already exist.
invalid_key_length: A secret key must be no longer than 256 characters.
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,37 @@ class UffizziCore::Api::Cli::V1::Projects::ComposeFilesControllerTest < ActionCo

assert_response :not_found
end

test '#create - with yaml aliases' do
sign_in @admin

@compose_file.destroy!
create(:credential, :docker_hub, :active, account: @account)
base_attributes = attributes_for(:compose_file).slice(:source, :path)
file_content = File.read('test/fixtures/files/uffizzi-compose-with_alias.yml')
encoded_content = Base64.encode64(file_content)
compose_file_attributes = base_attributes.merge(content: encoded_content, repository_id: nil)
dependency = {
path: 'configs/vote.conf',
source: 'vote.conf',
content: json_fixture('files/compose_dependencies/configs/vote_conf.json')[:content],
}

params = {
project_slug: @project.slug,
compose_file: compose_file_attributes,
dependencies: [dependency],
}

differences = {
-> { UffizziCore::ComposeFile.main.count } => 1,
-> { UffizziCore::Template.with_creation_source(UffizziCore::Template.creation_source.compose_file).count } => 1,
}

assert_difference differences do
post :create, params: params, format: :json
end

assert_response :success
end
end
25 changes: 25 additions & 0 deletions core/test/fixtures/files/uffizzi-compose-with_alias.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
x-nginx-configs: &nginx-configs
- source: vote_conf
target: /etc/nginx/conf.d

x-srv-nginx: &srv-nginx
nginx:
image: nginx:latest
configs: *nginx-configs
entrypoint: /usr/sbin/nginx-debug
command:
- "-g"
- "daemon off;"

services:
<<: *srv-nginx

x-uffizzi-ingress:
service: nginx
port: 8080

configs:
vote_conf:
file: configs/vote.conf
defaulf_conf:
file: config_files/config_file.conf

0 comments on commit 79e5f6c

Please sign in to comment.