Commit 93cd1688 authored by Fabien Combernous's avatar Fabien Combernous

initial work

parent d334960a
Pipeline #9240 failed with stages
in 10 minutes and 44 seconds
......@@ -22,6 +22,7 @@ _Public Resource types_
_Private Resource types_
* `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**
......
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 (
assert_private()
$config.each | $_config_key, $_config_value | {
case $_config_value {
String, Boolean, Integer: {
exec { "occ config:system:set ${_config_key}":
path => '/usr/sbin:/usr/bin:/sbin:/bin',
command => "php occ config:system:set ${_config_key} --value='${_config_value}'",
cwd => "${appdirectory}/nextcloud",
user => $nextcloud::system_user,
unless => "php occ config:system:get ${_config_key} | grep -qF '${_config_value}'",
# case $_config_value {
# String, Boolean, Integer: {
nextcloud_config { $_config_key :
ensure => present,
value => $_config_value,
}
}
Array: {
$_config_value.each | $_index, $_config_array_value | {
exec { "occ config:system:set ${_config_key} index ${_index}":
path => '/usr/sbin:/usr/bin:/sbin:/bin',
command => "php occ config:system:set ${_config_key} ${_index} --value='${_config_array_value}'",
cwd => "${appdirectory}/nextcloud",
user => $nextcloud::system_user,
unless => "php occ config:system:get ${_config_key} | grep -qF '${_config_array_value}'",
}
}
}
Hash: {
$_config_value.each | $_config_hash_key, $_config_hash_value | {
exec { "occ config:system:set ${_config_key} key ${_config_hash_key}":
path => '/usr/sbin:/usr/bin:/sbin:/bin',
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')
}
}
## exec { "occ config:system:set ${_config_key}":
## path => '/usr/sbin:/usr/bin:/sbin:/bin',
## command => "php occ config:system:set ${_config_key} --value='${_config_value}'",
## cwd => "${appdirectory}/nextcloud",
## user => $nextcloud::system_user,
## unless => "php occ config:system:get ${_config_key} | grep -qF '${_config_value}'",
## }
# }
# Array: {
# $_config_value.each | $_index, $_config_array_value | {
# exec { "occ config:system:set ${_config_key} index ${_index}":
# path => '/usr/sbin:/usr/bin:/sbin:/bin',
# command => "php occ config:system:set ${_config_key} ${_index} --value='${_config_array_value}'",
# cwd => "${appdirectory}/nextcloud",
# user => $nextcloud::system_user,
# unless => "php occ config:system:get ${_config_key} | grep -qF '${_config_array_value}'",
# }
# }
# }
# Hash: {
# $_config_value.each | $_config_hash_key, $_config_hash_value | {
# exec { "occ config:system:set ${_config_key} key ${_config_hash_key}":
# path => '/usr/sbin:/usr/bin:/sbin:/bin',
# 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')
# }
# }
}
}
......@@ -33,6 +33,7 @@ describe 'nextcloud' do
it 'applies idempotently' do
apply_manifest(pp, catch_changes: true)
shell('systemctl restart apache2') # gives apache knowledge of news
shell('sleep 2') # gives apache some time to restart
end
describe command("chromium-browser --no-sandbox --headless --disable-gpu --dump-dom http://#{fqdn}/") do
......
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