Method: Cfdef::Driver#update_distribution

Defined in:
lib/cfdef/driver.rb

#update_distribution(dist_id, distribution, old_distribution) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cfdef/driver.rb', line 43

def update_distribution(dist_id, distribution, old_distribution)
  log(:info, "Update Distribution `#{dist_id}`", color: :green)
  log(:info, diff(old_distribution, distribution, color: @options[:color]), color: false)

  unless @options[:dry_run]
    resp = @client.get_distribution(id: dist_id)
    etag = resp.etag
    caller_reference = resp.distribution.distribution_config.caller_reference

    dist_conf = {
      caller_reference: caller_reference,
    }.merge(distribution)

    unless dist_conf[:default_root_object]
      dist_conf[:default_root_object] = ""
    end

    unless dist_conf[:logging]
      dist_conf[:logging] = {
        enabled: false,
        include_cookies: false,
        bucket: '',
        prefix: '',
      }
    end

    params = {
      distribution_config: dist_conf,
      id: dist_id,
      if_match: etag,
    }

    @client.update_distribution(params)
  end
end