Skip to content

Commit

Permalink
Fail defined types if nginx class was not declared before
Browse files Browse the repository at this point in the history
Because the `ngnix::resource:*` types access ::ngnix class
parameters the nginx class needs to be declared before calling
the defined type.

`include ::nginx` inside the defined type is not enough because
params are evaluated before include is parsed.

Two of the defined types only access params inside. The include
way would work there - but for consistency I also added the fail.

Closes voxpupuli#983
  • Loading branch information
vinzent committed Apr 11, 2017
1 parent c104b98 commit e61476c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions manifests/resource/geo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
Optional[Boolean] $proxy_recursive = undef
) {

if ! defined(Class['nginx']) {
fail('You must include the nginx base class before using any defined resources')
}

$root_group = $::nginx::root_group
$conf_dir = "${::nginx::conf_dir}/conf.d"

Expand Down
4 changes: 4 additions & 0 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@
Optional[String] $expires = undef,
) {

if ! defined(Class['nginx']) {
fail('You must include the nginx base class before using any defined resources')
}

$root_group = $::nginx::root_group

File {
Expand Down
4 changes: 4 additions & 0 deletions manifests/resource/mailhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@
Array $server_name = [$name]
) {

if ! defined(Class['nginx']) {
fail('You must include the nginx base class before using any defined resources')
}

$root_group = $::nginx::root_group

File {
Expand Down
4 changes: 4 additions & 0 deletions manifests/resource/map.pp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
Enum['absent', 'present'] $ensure = 'present',
Boolean $hostnames = false
) {
if ! defined(Class['nginx']) {
fail('You must include the nginx base class before using any defined resources')
}

validate_re($string, '^.{2,}$',
"Invalid string value [${string}]. Expected a minimum of 2 characters.")

Expand Down
4 changes: 4 additions & 0 deletions manifests/resource/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@
Hash $locations = {}
) {

if ! defined(Class['nginx']) {
fail('You must include the nginx base class before using any defined resources')
}

# Variables
if $::nginx::confd_only {
$server_dir = "${::nginx::conf_dir}/conf.d"
Expand Down
4 changes: 4 additions & 0 deletions manifests/resource/streamhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
String $mode = $::nginx::global_mode,
) {

if ! defined(Class['nginx']) {
fail('You must include the nginx base class before using any defined resources')
}

# Variables
if $::nginx::confd_only {
$streamhost_dir = "${::nginx::conf_dir}/conf.stream.d"
Expand Down
4 changes: 4 additions & 0 deletions manifests/resource/upstream.pp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
Enum['http', 'stream'] $upstream_context = 'http',
) {

if ! defined(Class['nginx']) {
fail('You must include the nginx base class before using any defined resources')
}

$root_group = $::nginx::root_group

$ensure_real = $ensure ? {
Expand Down
3 changes: 3 additions & 0 deletions manifests/resource/upstream/member.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
Integer $port = 80,
$upstream_fail_timeout = '10s',
) {
if ! defined(Class['nginx']) {
fail('You must include the nginx base class before using any defined resources')
}

# Uses: $server, $port, $upstream_fail_timeout
concat::fragment { "${upstream}_upstream_member_${name}":
Expand Down

0 comments on commit e61476c

Please sign in to comment.