Puppet Function: cd4peadm::config

Defined in:
functions/config.pp
Function type:
Puppet Language

Overview

cd4peadm::config()Cd4peadm::Config

Creates a fully populated config object that contains both user data from hiera, and hard coded application config data.

To avoid this object becoming monstrious, it should only contain values that are shared across multiple plans and manifest code.

Returns:

  • (Cd4peadm::Config)


6
7
8
9
10
11
12
13
14
15
16
17
18
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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'functions/config.pp', line 6

function cd4peadm::config() >> Cd4peadm::Config {
  $hiera_config = lookup('cd4peadm::config', Cd4peadm::Hiera_config, 'deep', undef)
  $images = lookup('cd4peadm::images')

  $query_db_username = $hiera_config['query_db_username']
  $cd4pe_db_username = $hiera_config['cd4pe_db_username']
  $runtime = $hiera_config['runtime']
  $backup_dir = cd4peadm::default_for_value($hiera_config['backup_dir'], '/var/lib/puppetlabs/cd4pe/backups')

  $container_defaults = {
    teams_ui => {
      max_log_size_mb => 100,
      keep_log_files => 3,
      extra_parameters => undef,
    },
    pipelinesinfra => {
      max_log_size_mb => 200,
      keep_log_files => 5,
      log_level => 'info',
      extra_parameters => undef,
    },
    postgres => {
      max_log_size_mb => 100,
      keep_log_files => 3,
      log_level => 'ERROR',
      extra_parameters => undef,
    },
    query => {
      max_log_size_mb => 100,
      keep_log_files => 3,
      log_level => 'DEBUG',
      extra_parameters => undef,
    },
  }
  $containers = deep_merge($container_defaults, cd4peadm::default_for_value($hiera_config['containers'], {}))
  $ui_service = Cd4peadm::Config::Teams_ui.new({
    container           => Cd4peadm::Container.new({
      name             => 'ui',
      image            => $images['teams_ui'],
      log_volume_name  => 'ui-logs',
      extra_parameters => $containers['teams_ui']['extra_parameters'],
    }),
    console_log_level   => 'info',
    max_log_size_mb     => $containers['teams_ui']['max_log_size_mb'],
    keep_log_files      => $containers['teams_ui']['keep_log_files'],
    runtime             => $runtime,
    teams_ui_version    => cd4peadm::module_version(),
    webhook_port        => cd4peadm::default_for_value($hiera_config['webhook_port'], 8000),
    enable_ssl_webhooks => cd4peadm::default_for_value($hiera_config['enable_ssl_webhooks'], false),
  })

  $pipelinesinfra_service = Cd4peadm::Config::Pipelinesinfra.new({
    backup_dir          => $backup_dir,
    container           => Cd4peadm::Container.new({
      name             => 'pipelinesinfra',
      image            => $images['pipelinesinfra'],
      log_volume_name  => 'pipelinesinfra-logs',
      extra_parameters => $containers['pipelinesinfra']['extra_parameters'],
    }),
    db_username         => $cd4pe_db_username,
    db_password         => Sensitive($hiera_config['cd4pe_db_password']),
    log_level           => $containers['pipelinesinfra']['log_level'],
    max_log_size_mb     => $containers['pipelinesinfra']['max_log_size_mb'],
    keep_log_files      => $containers['pipelinesinfra']['keep_log_files'],
    resolvable_hostname => $hiera_config['resolvable_hostname'],
    root_password       => Sensitive($hiera_config['root_password']),
    root_username       => $hiera_config['root_username'],
    runtime             => $runtime,
    secret_key          => Sensitive($hiera_config['secret_key']),
    secret_key_path     => '/etc/puppetlabs/cd4pe/secret_key',
    java_args           => $hiera_config['java_args'],
    env_vars            => {
      'CD4PE_JOB_HTTP_READ_TIMEOUT_MINUTES'        => $hiera_config['job_http_read_timeout_mins'],
      'CD4PE_JOB_GLOBAL_TIMEOUT_MINUTES'           => $hiera_config['job_global_timeout_mins'],
      'CD4PE_LDAP_GROUP_SEARCH_SIZE_LIMIT'         => $hiera_config['ldap_group_search_size_limit'],
      'CD4PE_REPO_CACHING'                         => $hiera_config['repo_caching'],
      'CD4PE_REPO_CACHE_RETRIEVAL_TIMEOUT_MINUTES' => $hiera_config['repo_cache_retrieval_timeout_mins'],
      'CD4PE_BOLT_PCP_READ_TIMEOUT_SEC'            => $hiera_config['bolt_pcp_read_timeout_secs'],
      'CD4PE_INCLUDE_GIT_HISTORY_FOR_CD4PE_JOBS'   => $hiera_config['include_git_history_for_jobs'],
      'CD4PE_HTTP_CONNECTION_TIMEOUT_SEC'          => $hiera_config['http_connection_timeout_secs'],
      'CD4PE_HTTP_READ_TIMEOUT_SEC'                => $hiera_config['http_read_timeout_secs'],
      'CD4PE_HTTP_WRITE_TIMEOUT_SEC'               => $hiera_config['http_write_timeout_secs'],
      'CD4PE_HTTP_REQUEST_TIMEOUT_SEC'             => $hiera_config['http_request_timeout_secs'],
      'PUPPETDB_CONNECTION_TIMEOUT_SEC'            => $hiera_config['puppetdb_connection_timeout_secs'],
      'CD4PE_MAX_LOGIN_ATTEMPTS'                   => $hiera_config['max_login_attempts'],
      'CD4PE_FAILED_LOGIN_ATTEMPT_PERIOD_IN_MINS'  => $hiera_config['failed_login_attempt_period_mins'],
      'CD4PE_LOCKOUT_PERIOD_IN_MINS'               => $hiera_config['lockout_period_mins'],
    },
  })

  $query_service = Cd4peadm::Config::Query.new({
    container           => Cd4peadm::Container.new({
      name             => 'query',
      image            => $images['query'],
      log_volume_name  => 'query-logs',
      extra_parameters => $containers['query']['extra_parameters'],
    }),
    db_username         => $query_db_username,
    db_password         => Sensitive($hiera_config['query_db_password']),
    log_level           => $containers['query']['log_level'],
    max_log_size_mb     => $containers['query']['max_log_size_mb'],
    keep_log_files      => $containers['query']['keep_log_files'],
    resolvable_hostname => $hiera_config['resolvable_hostname'],
    runtime             => $runtime,
    db_endpoint         => cd4peadm::default_for_value($hiera_config['db_endpoint'], 'postgres://postgres:5432'),
    env_vars            => {
      'ENABLE_REPORT_TEMPLATES' => $hiera_config['enable_report_templates'],
      'QUERY_COMPLEXITY_LIMIT'  => $hiera_config['query_complexity_limit'],
    },
  })

  $postgres_service = Cd4peadm::Config::Postgres.new({
    container         => Cd4peadm::Container.new({
      name             => 'postgres',
      image            => $images['postgres'],
      log_volume_name  => 'postgres-logs',
      extra_parameters => $containers['postgres']['extra_parameters'],
    }),
    admin_db_password => Sensitive($hiera_config['admin_db_password']),
    admin_db_username => 'postgres',
    cd4pe_db_password => Sensitive($hiera_config['cd4pe_db_password']),
    cd4pe_db_username => $cd4pe_db_username,
    query_db_password => Sensitive($hiera_config['query_db_password']),
    query_db_username => $query_db_username,
    log_level         => $containers['postgres']['log_level'],
    max_log_size_mb   => $containers['postgres']['max_log_size_mb'],
    keep_log_files    => $containers['postgres']['keep_log_files'],
    runtime           => $runtime,
  })

  Cd4peadm::Config.new({
    all_targets => get_targets($hiera_config['targets'].values.flatten.unique),
    images      => $images,
    roles       => Cd4peadm::Roles.new({
      ui => {
        services => { ui => $ui_service },
        targets  => get_targets($hiera_config['targets']['ui']),
      },
      backend => {
        services => {
          pipelinesinfra => $pipelinesinfra_service,
          query => $query_service,
        },
        targets  => get_targets($hiera_config['targets']['backend']),
      },
      database => {
        services => {
          postgres => $postgres_service,
        },
        targets  => get_targets($hiera_config['targets']['database']),
      },
    }),
    runtime       => $runtime,
    backup_dir    => $backup_dir,
    dump_filename => "cd4pe-postgres-${Timestamp.new.strftime('%Y-%m-%d')}.dump",
    ssl => {
      cert_chain => $hiera_config['ssl_cert_chain'],
      crl => $hiera_config['ssl_crl'],
      private_key => Sensitive($hiera_config['ssl_private_key']),
    },
  })
}