Module: OwncloudCookbook::CookbookHelpers

Included in:
FakeRecipe
Defined in:
libraries/cookbook_helpers.rb

Overview

Some helpers to use from owncloud cookbook recipes or resources.

Examples:

self.class.send(:include, OwncloudCookbook::CookbookHelpers)
apply_owncloud_configuration

Instance Method Summary collapse

Instance Method Details

#apply_owncloud_configurationObject

Calculates new configuration options, merged them and save them on disk.

  • Calculates trusted domains.
  • Calculates database host.
  • Updates ownCloud configuration options on disk.
  • Saves some generated options in Chef Node attributes.

Examples:

apply_owncloud_configuration

150
151
152
153
154
155
# File 'libraries/cookbook_helpers.rb', line 150

def apply_owncloud_configuration
  calculate_trusted_domains
  calculate_dbhost
  owncloud_config_update
  save_owncloud_node_configuration
end

#calculate_dbhostString

Calculates the database host.

Examples:

calculate_dbhost #=> "db.example.com:3306"

103
104
105
106
107
108
# File 'libraries/cookbook_helpers.rb', line 103

def calculate_dbhost
  owncloud_cookbook_config['dbhost'] =
    [
      owncloud_cookbook_config['dbhost'], owncloud_cookbook_config['dbport']
    ].join(':')
end

#calculate_trusted_domainsArray

Adds server name and server aliases to trusted_domains configuration option.

Merges the generated owncloud trusted domains and the node['owncloud']['config']['trusted_domains'] attribute values.

Examples:

calculate_trusted_domains
  #=> ["owncloud.example.com", "www.example.com"]

87
88
89
90
91
92
93
94
95
# File 'libraries/cookbook_helpers.rb', line 87

def calculate_trusted_domains
  unless owncloud_cookbook_config.key?('trusted_domains')
    owncloud_cookbook_config['trusted_domains'] = []
  end
  owncloud_trusted_domains.each do |domain|
    next if owncloud_cookbook_config['trusted_domains'].include?(domain)
    owncloud_cookbook_config['trusted_domains'] << domain
  end
end

#owncloud_configOwncloudCookbook::Config

Returns the [OwncloudCookbook::Config] instance.

Examples:

owncloud_config #=> #<OwncloudCookbook::Config:0x00000001b637c0>

46
47
48
# File 'libraries/cookbook_helpers.rb', line 46

def owncloud_config
  @owncloud_config ||= OwncloudCookbook::Config.new(owncloud_config_file)
end

#owncloud_config_fileString

Gets the ownCloud configuration file full path.

Examples:

owncloud_config_file #=> '/var/www/owncloud/config/config.php'

36
37
38
# File 'libraries/cookbook_helpers.rb', line 36

def owncloud_config_file
  ::File.join(node['owncloud']['dir'], 'config', 'config.php')
end

#owncloud_config_updateObject

Updates the disk configuration values from the new calculated values.

Merges all the configuration values.

Examples:

owncloud_config_update

118
119
120
121
122
# File 'libraries/cookbook_helpers.rb', line 118

def owncloud_config_update
  owncloud_config.merge(owncloud_cookbook_config)
  owncloud_config.write
  owncloud_config
end

#owncloud_cookbook_configHash

Gets ownCloud default configuration values.

Examples:

owncloud_cookbook_config
  #=> {"dbtype"=>"mysql", "dbname"=>"owncloud", ...}

57
58
59
# File 'libraries/cookbook_helpers.rb', line 57

def owncloud_cookbook_config
  @owncloud_cookbook_config ||= node['owncloud']['config'].to_hash
end

#owncloud_trusted_domainsArray

Generates the ownCloud trusted domain list.

Generates the domain list from the node['owncloud']['server_name'] and the node['owncloud']['server_aliases'] attribute values.

Examples:

owncloud_trusted_domains #=> ["owncloud.example.com"]

70
71
72
73
74
# File 'libraries/cookbook_helpers.rb', line 70

def owncloud_trusted_domains
  [
    node['owncloud']['server_name'], node['owncloud']['server_aliases']
  ].flatten
end

#save_owncloud_node_configurationObject

Store important options that where generated automatically by the setup.

Saves them in Chef Node attributes.

Examples:

save_owncloud_node_configuration

132
133
134
135
136
137
# File 'libraries/cookbook_helpers.rb', line 132

def save_owncloud_node_configuration
  return if Chef::Config[:solo]
  %w(passwordsalt instanceid).each do |value|
    node.set_unless['owncloud']['config'][value] = owncloud_config[value]
  end
end