Commit e265c6d9 authored by Fabien Combernous's avatar Fabien Combernous

initial work

parent d334960a
Pipeline #9241 passed with stages
in 11 minutes and 10 seconds
...@@ -82,7 +82,7 @@ But removing a setting from `$config` does not remove it from `config.php` (`ens ...@@ -82,7 +82,7 @@ But removing a setting from `$config` does not remove it from `config.php` (`ens
'filelocking.enabled' => true, 'filelocking.enabled' => true,
'redis' => { 'redis' => {
'host' => '127.0.0.1', 'host' => '127.0.0.1',
'port' => 6379, 'port' => '6379',
'timeout' => '1.5', 'timeout' => '1.5',
}, },
``` ```
......
...@@ -22,6 +22,7 @@ _Public Resource types_ ...@@ -22,6 +22,7 @@ _Public Resource types_
_Private Resource types_ _Private Resource types_
* `nextcloud_application`: This type provides Puppet with the capabilities to manage Nextcloud apps * `nextcloud_application`: This type provides Puppet with the capabilities to manage Nextcloud apps
* `nextcloud_config`: This type provides Puppet with the capabilities to manage Nextcloud configuration
**Data types** **Data types**
...@@ -190,7 +191,7 @@ handle redis part of settings in config.php ...@@ -190,7 +191,7 @@ handle redis part of settings in config.php
Alias of `Struct[{ Alias of `Struct[{
Optional['host'] => Stdlib::Host, Optional['host'] => Stdlib::Host,
Optional['port'] => Stdlib::Port, Optional['port'] => Pattern['^\d+'],
Optional['timeout'] => String, Optional['timeout'] => String,
}]` }]`
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'nextcloud.rb'))
require 'json'
Puppet::Type.type(:nextcloud_config).provide(:php, parent: Puppet::Provider::Nextcloud) do
desc 'provider for nextcloud_config resource'
confine kernel: 'Linux'
defaultfor kernel: 'Linux'
commands php: 'php'
def set_config_system(setting, value)
if value.is_a?(String) || value.is_a?(Integer) || [true, false].include?(value)
execute_occ("config:system:set #{setting} --value='#{value}'")
elsif value.is_a?(Array)
value.each_with_index do |val, index|
execute_occ("config:system:set #{setting} #{index} --value='#{val}'")
end
elsif value.is_a?(Hash)
value.each do |key, val|
execute_occ("config:system:set #{setting} '#{key}' --value='#{val}'")
end
else
raise Puppet::Error, "Unexpected object in Nextcloud config : #{value.class}"
end
end
def self.instances
config = JSON.parse(execute_occ('config:list --ansi --output=json'))
if config
config['system'].map do |name, value|
# initializes @property_hash
new(
name: name,
ensure: :present,
value: value,
)
end
else
[]
end
end
def self.prefetch(resources)
# discover all nextcloud_config resources on the system by invoking self.instances
configs = instances
# iterates through all nextcloud_config resources in the catalog
resources.keys.each do |name|
# if the managed app exists in the self.instances cache,
# assigns its provider to set its property hash
provider = configs.find { |config| config.name == name }
resources[name].provider = provider if provider
end
end
def exists?
@property_hash[:ensure] == :present
end
def create
set_config_system(resource[:name], resource[:value])
@property_hash[:value] = resource[:value]
end
def destroy
execute_occ("config:system:delete #{resource[:name]}")
end
def value
# The occ command used to dump all config in self.instances hides some data considered as sensitive.
# The getter have to get unhidden information.
case @property_hash[:value].to_s
when %r{.*REMOVED SENSITIVE VALUE.*}
@property_hash[:value] = JSON.parse(execute_occ("config:system:get #{resource[:name]} --ansi --output=json").chomp)
end
@property_hash[:value]
end
def value=(val)
set_config_system(resource[:name], val)
end
end
Puppet::Type.newtype(:nextcloud_config) do
@doc = <<-MANIFEST
@summary This type provides Puppet with the capabilities to manage Nextcloud configuration
@example Basic usage
nextcloud_config { 'dbname':
value => 'exampledb',
}
@api private
MANIFEST
ensurable
newparam(:name, namevar: true) do
desc 'Name of config key.'
end
newproperty(:value) do
desc 'Value of the config key'
end
end
...@@ -14,41 +14,46 @@ class nextcloud::config ( ...@@ -14,41 +14,46 @@ class nextcloud::config (
assert_private() assert_private()
$config.each | $_config_key, $_config_value | { $config.each | $_config_key, $_config_value | {
case $_config_value { # case $_config_value {
String, Boolean, Integer: { # String, Boolean, Integer: {
exec { "occ config:system:set ${_config_key}": nextcloud_config { $_config_key :
path => '/usr/sbin:/usr/bin:/sbin:/bin', ensure => present,
command => "php occ config:system:set ${_config_key} --value='${_config_value}'", value => $_config_value,
cwd => "${appdirectory}/nextcloud",
user => $nextcloud::system_user,
unless => "php occ config:system:get ${_config_key} | grep -qF '${_config_value}'",
} }
}
Array: { ## exec { "occ config:system:set ${_config_key}":
$_config_value.each | $_index, $_config_array_value | { ## path => '/usr/sbin:/usr/bin:/sbin:/bin',
exec { "occ config:system:set ${_config_key} index ${_index}": ## command => "php occ config:system:set ${_config_key} --value='${_config_value}'",
path => '/usr/sbin:/usr/bin:/sbin:/bin', ## cwd => "${appdirectory}/nextcloud",
command => "php occ config:system:set ${_config_key} ${_index} --value='${_config_array_value}'", ## user => $nextcloud::system_user,
cwd => "${appdirectory}/nextcloud", ## unless => "php occ config:system:get ${_config_key} | grep -qF '${_config_value}'",
user => $nextcloud::system_user, ## }
unless => "php occ config:system:get ${_config_key} | grep -qF '${_config_array_value}'", # }
} # Array: {
} # $_config_value.each | $_index, $_config_array_value | {
} # exec { "occ config:system:set ${_config_key} index ${_index}":
Hash: { # path => '/usr/sbin:/usr/bin:/sbin:/bin',
$_config_value.each | $_config_hash_key, $_config_hash_value | { # command => "php occ config:system:set ${_config_key} ${_index} --value='${_config_array_value}'",
exec { "occ config:system:set ${_config_key} key ${_config_hash_key}": # cwd => "${appdirectory}/nextcloud",
path => '/usr/sbin:/usr/bin:/sbin:/bin', # user => $nextcloud::system_user,
command => "php occ config:system:set ${_config_key} '${_config_hash_key}' --value='${_config_hash_value}'", # unless => "php occ config:system:get ${_config_key} | grep -qF '${_config_array_value}'",
cwd => "${appdirectory}/nextcloud", # }
user => $nextcloud::system_user, # }
unless => "php occ config:system:get ${_config_key} ${_config_hash_key} | grep -qF '${_config_hash_value}'", # }
} # Hash: {
} # $_config_value.each | $_config_hash_key, $_config_hash_value | {
} # exec { "occ config:system:set ${_config_key} key ${_config_hash_key}":
default: { # path => '/usr/sbin:/usr/bin:/sbin:/bin',
fail('unexpected data type in config') # command => "php occ config:system:set ${_config_key} '${_config_hash_key}' --value='${_config_hash_value}'",
} # cwd => "${appdirectory}/nextcloud",
} # user => $nextcloud::system_user,
# unless => "php occ config:system:get ${_config_key} ${_config_hash_key} | grep -qF '${_config_hash_value}'",
# }
# }
# }
# default: {
# fail('unexpected data type in config')
# }
# }
} }
} }
...@@ -83,7 +83,7 @@ class nextcloud ( ...@@ -83,7 +83,7 @@ class nextcloud (
'filelocking.enabled' => true, 'filelocking.enabled' => true,
'redis' => { 'redis' => {
'host' => '127.0.0.1', 'host' => '127.0.0.1',
'port' => 6379, 'port' => '6379',
'timeout' => '1.5', 'timeout' => '1.5',
}, },
} }
......
...@@ -33,6 +33,7 @@ describe 'nextcloud' do ...@@ -33,6 +33,7 @@ describe 'nextcloud' do
it 'applies idempotently' do it 'applies idempotently' do
apply_manifest(pp, catch_changes: true) apply_manifest(pp, catch_changes: true)
shell('systemctl restart apache2') # gives apache knowledge of news shell('systemctl restart apache2') # gives apache knowledge of news
shell('sleep 2') # gives apache some time to restart
end end
describe command("chromium-browser --no-sandbox --headless --disable-gpu --dump-dom http://#{fqdn}/") do describe command("chromium-browser --no-sandbox --headless --disable-gpu --dump-dom http://#{fqdn}/") do
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
# #
type Nextcloud::Config::Redis = Struct[{ type Nextcloud::Config::Redis = Struct[{
Optional['host'] => Stdlib::Host, Optional['host'] => Stdlib::Host,
Optional['port'] => Stdlib::Port, Optional['port'] => Pattern['^\d+'], # It is harder to handle Stdlib::Port in provider of nextcloud_config
Optional['timeout'] => String, Optional['timeout'] => String,
}] }]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment