resources/config_v1.rb
# Transforms the resource into a JSON format which matches the
# Consul service's configuration format.
Transforms the resource into a JSON format which matches the
Consul service's configuration format.
Transforms the resource into a JSON format which matches the Consul service ' s configuration format .
def params_to_json
  for_keeps = %i(
    acl
    acl_agent_token
    acl_agent_master_token
    acl_datacenter
    acl_default_policy
    acl_down_policy
    acl_enforce_version_8
    acl_master_token
    acl_replication_token
    acl_token
    acl_ttl
    addresses
    advertise_addr
    advertise_addr_ipv4
    advertise_addr_ipv6
    advertise_addr_wan
    advertise_addr_wan_ipv4
    advertise_addr_wan_ipv6
    autopilot
    auto_encrypt
    bind_addr
    check_update_interval
    client_addr
    config_entries
    connect
    data_dir
    datacenter
    disable_anonymous_signature
    disable_host_node_id
    disable_keyring_file
    disable_remote_exec
    disable_update_check
    discard_check_output
    dns_config
    domain
    enable_acl_replication
    enable_additional_node_meta_txt
    enable_central_service_config
    enable_debug
    enable_local_script_checks
    enable_script_checks
    enable_syslog
    encrypt
    encrypt_verify_incoming
    encrypt_verify_outgoing
    gossip_lan
    gossip_wan
    http_config
    leave_on_terminate
    license_path
    limits
    log_file
    log_level
    log_rotate_duration
    log_rotate_bytes
    log_rotate_max_files
    node_id
    node_meta
    node_name
    non_voting_server
    performance
    ports
    primary_datacenter
    protocol
    reap
    raft_protocol
    raft_snapshot_interval
    raft_snapshot_threshold
    raft_trailing_logs
    reconnect_timeout
    reconnect_timeout_wan
    recursors
    rejoin_after_leave
    retry_interval
    retry_interval_wan
    retry_join
    retry_join_wan
    retry_max
    segment
    segments
    serf_lan
    serf_wan
    serf_lan_bind
    serf_wan_bind
    server
    server_name
    session_ttl_min
    skip_leave_on_interrupt
    start_join
    start_join_wan
    syslog_facility
    telemetry
    tls_cipher_suites
    tls_min_version
    tls_prefer_server_cipher_suites
    translate_wan_addrs
    ui
    ui_dir
    unix_sockets
    verify_incoming
    verify_incoming_https
    verify_incoming_rpc
    verify_outgoing
    verify_server_hostname
    watches
  )
  for_keeps << %i(discovery_max_stale) if node['consul']['version'] > '1.0.6'
  for_keeps << %i(bootstrap bootstrap_expect) if server
  for_keeps << %i(ca_file ca_path cert_file enable_agent_tls_for_checks key_file) if tls?
  for_keeps = for_keeps.flatten
  raw_config = to_hash
  if raw_config[:retry_join_ec2]
    Chef::Log.warn("Parameter 'retry_join_ec2' is deprecated")
    join_string = consul_cloud_join_string('aws', retry_join_ec2)
    existing_retry_join = raw_config[:retry_join]
    raw_config[:retry_join] = if existing_retry_join.nil?
                                [join_string]
                              else
                                existing_retry_join.clone << join_string
                              end
  end
  if raw_config[:retry_join_azure]
    Chef::Log.warn("Parameter 'retry_join_azure' is deprecated")
    join_string = consul_cloud_join_string('azure', retry_join_azure)
    existing_retry_join = raw_config[:retry_join]
    raw_config[:retry_join] = if existing_retry_join.nil?
                                [join_string]
                              else
                                existing_retry_join.clone << join_string
                              end
  end
  [:atlas_infrastructure, :atlas_token, :atlas_acl_token, :atlas_join, :atlas_endpoint].each do |field|
    if raw_config[field]
      Chef::Log.warn("Parameter '#{field}' is deprecated")
    end
  end
  if raw_config[:http_api_response_headers]
    Chef::Log.warn("Parameter 'http_api_response_headers' is deprecated")
    raw_config[:http_config] = {
      'response_headers' => raw_config[:http_api_response_headers],
    }
  end
  if raw_config[:recursor]
    Chef::Log.warn("Parameter 'recursor' is deprecated")
    existing_recursors = raw_config[:recursors]
    raw_config[:recursors] = if existing_recursors.nil?
                               [raw_config[:recursor]]
                             else
                               existing_recursors.clone << raw_config[:recursor]
                             end
  end
  {
    statsd_addr: :statsd_address,
    statsite_addr: :statsite_address,
    statsite_prefix: :metrics_prefix,
  }.each do |field, replacement|
    next unless raw_config[field]
    Chef::Log.warn("Parameter '#{field}' is deprecated")
    raw_config[:telemetry] ||= {}
    raw_config[:telemetry][replacement] = raw_config[field]
  end
  config = raw_config.keep_if do |k, v|
    !v.nil? && for_keeps.include?(k.to_sym)
  end.merge(options)
  JSON.pretty_generate(Hash[config.sort_by { |k, _| k.to_s }], quirks_mode: true)
end
def params_to_json for_keeps = %i( acl acl_agent_token acl_agent_master_token acl_datacenter acl_default_policy acl_down_policy acl_enforce_version_8 acl_master_token acl_replication_token acl_token acl_ttl addresses advertise_addr advertise_addr_ipv4 advertise_addr_ipv6 advertise_addr_wan advertise_addr_wan_ipv4 advertise_addr_wan_ipv6 autopilot auto_encrypt bind_addr check_update_interval client_addr config_entries connect data_dir datacenter disable_anonymous_signature disable_host_node_id disable_keyring_file disable_remote_exec disable_update_check discard_check_output dns_config domain enable_acl_replication enable_additional_node_meta_txt enable_central_service_config enable_debug enable_local_script_checks enable_script_checks enable_syslog encrypt encrypt_verify_incoming encrypt_verify_outgoing gossip_lan gossip_wan http_config leave_on_terminate license_path limits log_file log_level log_rotate_duration log_rotate_bytes log_rotate_max_files node_id node_meta node_name non_voting_server performance ports primary_datacenter protocol reap raft_protocol raft_snapshot_interval raft_snapshot_threshold raft_trailing_logs reconnect_timeout reconnect_timeout_wan recursors rejoin_after_leave retry_interval retry_interval_wan retry_join retry_join_wan retry_max segment segments serf_lan serf_wan serf_lan_bind serf_wan_bind server server_name session_ttl_min skip_leave_on_interrupt start_join start_join_wan syslog_facility telemetry tls_cipher_suites tls_min_version tls_prefer_server_cipher_suites translate_wan_addrs ui ui_dir unix_sockets verify_incoming verify_incoming_https verify_incoming_rpc verify_outgoing verify_server_hostname watches ) for_keeps << %i( discovery_max_stale ) if node [ 'consul' ] [ 'version' ] > '1.0.6' for_keeps << %i( bootstrap bootstrap_expect ) if server for_keeps << %i( ca_file ca_path cert_file enable_agent_tls_for_checks key_file ) if tls? for_keeps = for_keeps . flatten raw_config = to_hash if raw_config [ :retry_join_ec2 ] Chef :: Log . warn ( "Parameter 'retry_join_ec2' is deprecated" ) join_string = consul_cloud_join_string ( 'aws' , retry_join_ec2 ) existing_retry_join = raw_config [ :retry_join ] raw_config [ :retry_join ] = if existing_retry_join . nil? [ join_string ] else existing_retry_join . clone << join_string end end if raw_config [ :retry_join_azure ] Chef :: Log . warn ( "Parameter 'retry_join_azure' is deprecated" ) join_string = consul_cloud_join_string ( 'azure' , retry_join_azure ) existing_retry_join = raw_config [ :retry_join ] raw_config [ :retry_join ] = if existing_retry_join . nil? [ join_string ] else existing_retry_join . clone << join_string end end [ :atlas_infrastructure , :atlas_token , :atlas_acl_token , :atlas_join , :atlas_endpoint ] . each do | field | if raw_config [ field ] Chef :: Log . warn ( "Parameter '#{field}' is deprecated" ) end end if raw_config [ :http_api_response_headers ] Chef :: Log . warn ( "Parameter 'http_api_response_headers' is deprecated" ) raw_config [ :http_config ] = { 'response_headers' => raw_config [ :http_api_response_headers ] , } end if raw_config [ :recursor ] Chef :: Log . warn ( "Parameter 'recursor' is deprecated" ) existing_recursors = raw_config [ :recursors ] raw_config [ :recursors ] = if existing_recursors . nil? [ raw_config [ :recursor ] ] else existing_recursors . clone << raw_config [ :recursor ] end end { statsd_addr : :statsd_address , statsite_addr : :statsite_address , statsite_prefix : :metrics_prefix , } . each do | field , replacement | next unless raw_config [ field ] Chef :: Log . warn ( "Parameter '#{field}' is deprecated" ) raw_config [ :telemetry ] ||= { } raw_config [ :telemetry ] [ replacement ] = raw_config [ field ] end config = raw_config . keep_if do | k , v | ! v . nil? && for_keeps . include? ( k . to_sym ) end . merge ( options ) JSON . pretty_generate ( Hash [ config . sort_by { | k , _ | k . to_s } ] , quirks_mode : true ) end
Transforms the resource into a JSON format which matches the
Consul service's configuration format.
Transforms the resource into a JSON format which matches the Consul service ' s configuration format .
# Filter out undefined attributes and keep only those listed above