Dev set up
This commit is contained in:
59
ops/cookbooks/vendor/postgresql/resources/access.rb
vendored
Normal file
59
ops/cookbooks/vendor/postgresql/resources/access.rb
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# Cookbook:: postgresql
|
||||
# Resource:: access
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
property :access_type, String, required: true, default: 'local'
|
||||
property :access_db, String, required: true, default: 'all'
|
||||
property :access_user, String, required: true, default: 'postgres'
|
||||
property :access_method, String, required: true, default: 'ident'
|
||||
property :cookbook, String, default: 'postgresql'
|
||||
property :source, String, default: 'pg_hba.conf.erb'
|
||||
property :access_addr, String
|
||||
property :comment, String
|
||||
|
||||
action :grant do
|
||||
config_resource = new_resource
|
||||
with_run_context :root do # ~FC037
|
||||
edit_resource(:template, "#{conf_dir}/pg_hba.conf") do |new_resource|
|
||||
source new_resource.source
|
||||
cookbook new_resource.cookbook
|
||||
owner 'postgres'
|
||||
group 'postgres'
|
||||
mode '0600'
|
||||
variables[:pg_hba] ||= {}
|
||||
variables[:pg_hba][new_resource.name] = {
|
||||
comment: new_resource.comment,
|
||||
type: new_resource.access_type,
|
||||
db: new_resource.access_db,
|
||||
user: new_resource.access_user,
|
||||
addr: new_resource.access_addr,
|
||||
method: new_resource.access_method,
|
||||
}
|
||||
action :nothing
|
||||
delayed_action :create
|
||||
notifies :trigger, config_resource, :immediately
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :trigger do
|
||||
new_resource.updated_by_last_action(true) # ~FC085
|
||||
end
|
||||
|
||||
action_class do
|
||||
include PostgresqlCookbook::Helpers
|
||||
end
|
35
ops/cookbooks/vendor/postgresql/resources/client_install.rb
vendored
Normal file
35
ops/cookbooks/vendor/postgresql/resources/client_install.rb
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# Cookbook:: postgresql
|
||||
# Resource:: client_install
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
property :version, String, default: '9.6'
|
||||
property :setup_repo, [true, false], default: true
|
||||
|
||||
action :install do
|
||||
postgresql_repository 'Add downloads.postgresql.org repository' do
|
||||
version new_resource.version
|
||||
only_if { new_resource.setup_repo }
|
||||
end
|
||||
|
||||
case node['platform_family']
|
||||
when 'debian'
|
||||
package "postgresql-client-#{new_resource.version}"
|
||||
when 'rhel', 'fedora', 'amazon'
|
||||
ver = new_resource.version.delete('.')
|
||||
package "postgresql#{ver}"
|
||||
end
|
||||
end
|
67
ops/cookbooks/vendor/postgresql/resources/database.rb
vendored
Normal file
67
ops/cookbooks/vendor/postgresql/resources/database.rb
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
#
|
||||
# Cookbook:: postgresql
|
||||
# Resource:: database
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
property :template, String, default: 'template1'
|
||||
property :encoding, String, default: 'UTF-8'
|
||||
property :locale, String, default: 'en_US.UTF-8'
|
||||
property :owner, String
|
||||
|
||||
# Connection prefernces
|
||||
property :user, String, default: 'postgres'
|
||||
property :database, String, name_property: true
|
||||
property :host, [String, nil], default: nil
|
||||
property :port, Integer, default: 5432
|
||||
|
||||
action :create do
|
||||
createdb = 'createdb'
|
||||
createdb << " -E #{new_resource.encoding}" if new_resource.encoding
|
||||
createdb << " -l #{new_resource.locale}" if new_resource.locale
|
||||
createdb << " -T #{new_resource.template}" unless new_resource.template.empty?
|
||||
createdb << " -O #{new_resource.owner}" if new_resource.owner
|
||||
createdb << " -U #{new_resource.user}" if new_resource.user
|
||||
createdb << " -h #{new_resource.host}" if new_resource.host
|
||||
createdb << " -p #{new_resource.port}" if new_resource.port
|
||||
createdb << " #{new_resource.database}"
|
||||
|
||||
bash "Create Database #{new_resource.database}" do
|
||||
code createdb
|
||||
user new_resource.user
|
||||
not_if { follower? }
|
||||
not_if { database_exists?(new_resource) }
|
||||
end
|
||||
end
|
||||
|
||||
action :drop do
|
||||
converge_by "Drop PostgreSQL Database #{new_resource.database}" do
|
||||
dropdb = 'dropdb'
|
||||
dropdb << " -U #{new_resource.user}" if new_resource.user
|
||||
dropdb << " --host #{new_resource.host}" if new_resource.host
|
||||
dropdb << " --port #{new_resource.port}" if new_resource.port
|
||||
dropdb << " #{new_resource.database}"
|
||||
|
||||
bash "drop postgresql database #{new_resource.database})" do
|
||||
user 'postgres'
|
||||
code dropdb
|
||||
not_if { follower? }
|
||||
only_if { database_exists?(new_resource) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
include PostgresqlCookbook::Helpers
|
||||
end
|
49
ops/cookbooks/vendor/postgresql/resources/extension.rb
vendored
Normal file
49
ops/cookbooks/vendor/postgresql/resources/extension.rb
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
#
|
||||
# Cookbook:: postgresql
|
||||
# Resource:: extension
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
property :extension, String, name_property: true
|
||||
property :old_version, String
|
||||
property :version, String
|
||||
|
||||
# Connection prefernces
|
||||
property :user, String, default: 'postgres'
|
||||
property :database, String, required: true
|
||||
property :host, [String, nil]
|
||||
property :port, Integer, default: 5432
|
||||
|
||||
action :create do
|
||||
bash "CREATE EXTENSION #{new_resource.name}" do
|
||||
code create_extension_sql(new_resource)
|
||||
user 'postgres'
|
||||
action :run
|
||||
not_if { follower? || extension_installed?(new_resource) }
|
||||
end
|
||||
end
|
||||
|
||||
action :drop do
|
||||
bash "DROP EXTENSION #{new_resource.name}" do
|
||||
code psql_command_string(new_resource, "DROP EXTENSION IF EXISTS \"#{new_resource.extension}\"")
|
||||
user 'postgres'
|
||||
action :run
|
||||
not_if { follower? }
|
||||
only_if { extension_installed?(new_resource) }
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
include PostgresqlCookbook::Helpers
|
||||
end
|
55
ops/cookbooks/vendor/postgresql/resources/ident.rb
vendored
Normal file
55
ops/cookbooks/vendor/postgresql/resources/ident.rb
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# Cookbook:: postgresql
|
||||
# Resource:: access
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
property :mapname, String, required: true
|
||||
property :source, String, default: 'pg_ident.conf.erb'
|
||||
property :cookbook, String, default: 'postgresql'
|
||||
property :system_user, String, required: true
|
||||
property :pg_user, String, required: true
|
||||
property :comment, [String, nil], default: nil
|
||||
|
||||
action :create do
|
||||
ident_resource = new_resource
|
||||
with_run_context :root do # ~FC037
|
||||
edit_resource(:template, "#{conf_dir}/pg_ident.conf") do |new_resource|
|
||||
source new_resource.source
|
||||
cookbook new_resource.cookbook
|
||||
owner 'postgres'
|
||||
group 'postgres'
|
||||
mode '0640'
|
||||
variables[:pg_ident] ||= {}
|
||||
variables[:pg_ident][new_resource.name] = {
|
||||
comment: new_resource.comment,
|
||||
mapname: new_resource.mapname,
|
||||
system_user: new_resource.system_user,
|
||||
pg_user: new_resource.pg_user,
|
||||
}
|
||||
action :nothing
|
||||
delayed_action :create
|
||||
notifies :trigger, ident_resource, :immediately
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :trigger do
|
||||
new_resource.updated_by_last_action(true) # ~FC085
|
||||
end
|
||||
|
||||
action_class do
|
||||
include PostgresqlCookbook::Helpers
|
||||
end
|
90
ops/cookbooks/vendor/postgresql/resources/repository.rb
vendored
Normal file
90
ops/cookbooks/vendor/postgresql/resources/repository.rb
vendored
Normal file
@ -0,0 +1,90 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# Cookbook:: postgresql
|
||||
# Resource:: repository
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
property :version, String, default: '9.6'
|
||||
property :enable_pgdg, [true, false], default: true
|
||||
property :enable_pgdg_source, [true, false], default: false
|
||||
property :enable_pgdg_updates_testing, [true, false], default: false
|
||||
property :enable_pgdg_source_updates_testing, [true, false], default: false
|
||||
property :yum_gpg_key_uri, String, default: 'https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG'
|
||||
property :apt_gpg_key_uri, String, default: 'https://download.postgresql.org/pub/repos/apt/ACCC4CF8.asc'
|
||||
|
||||
action :add do
|
||||
case node['platform_family']
|
||||
|
||||
when 'rhel', 'fedora', 'amazon'
|
||||
remote_file "/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-#{new_resource.version}" do
|
||||
source new_resource.yum_gpg_key_uri
|
||||
end
|
||||
|
||||
yum_repository "PostgreSQL #{new_resource.version}" do # ~FC005
|
||||
repositoryid "pgdg#{new_resource.version}"
|
||||
description "PostgreSQL.org #{new_resource.version}"
|
||||
baseurl yum_repo_url('https://download.postgresql.org/pub/repos/yum')
|
||||
enabled new_resource.enable_pgdg
|
||||
gpgcheck true
|
||||
gpgkey "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-#{new_resource.version}"
|
||||
end
|
||||
|
||||
yum_repository "PostgreSQL #{new_resource.version} - source " do
|
||||
repositoryid "pgdg#{new_resource.version}-source"
|
||||
description "PostgreSQL.org #{new_resource.version} Source"
|
||||
baseurl yum_repo_url('https://download.postgresql.org/pub/repos/yum/srpms')
|
||||
enabled new_resource.enable_pgdg_source
|
||||
gpgcheck true
|
||||
gpgkey "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-#{new_resource.version}"
|
||||
end
|
||||
|
||||
yum_repository "PostgreSQL #{new_resource.version} - updates testing" do
|
||||
repositoryid "pgdg#{new_resource.version}-updates-testing"
|
||||
description "PostgreSQL.org #{new_resource.version} Updates Testing"
|
||||
baseurl yum_repo_url('https://download.postgresql.org/pub/repos/yum/testing')
|
||||
enabled new_resource.enable_pgdg_updates_testing
|
||||
gpgcheck true
|
||||
gpgkey "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-#{new_resource.version}"
|
||||
end
|
||||
|
||||
yum_repository "PostgreSQL #{new_resource.version} - source - updates testing" do
|
||||
repositoryid "pgdg#{new_resource.version}-source-updates-testing"
|
||||
description "PostgreSQL.org #{new_resource.version} Source Updates Testing"
|
||||
baseurl yum_repo_url('https://download.postgresql.org/pub/repos/yum/srpms/testing')
|
||||
enabled new_resource.enable_pgdg_source_updates_testing
|
||||
gpgcheck true
|
||||
gpgkey "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-#{new_resource.version}"
|
||||
end
|
||||
|
||||
when 'debian'
|
||||
apt_update
|
||||
|
||||
package 'apt-transport-https'
|
||||
|
||||
apt_repository 'postgresql_org_repository' do
|
||||
uri 'https://download.postgresql.org/pub/repos/apt/'
|
||||
components ['main', new_resource.version.to_s]
|
||||
distribution "#{node['lsb']['codename']}-pgdg"
|
||||
key new_resource.apt_gpg_key_uri
|
||||
cache_rebuild true
|
||||
end
|
||||
else
|
||||
raise "The platform_family '#{node['platform_family']}' or platform '#{node['platform']}' is not supported by the postgresql_repository resource. If you believe this platform can/should be supported by this resource please file and issue or open a pull request at https://github.com/sous-chefs/postgresql"
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
include PostgresqlCookbook::Helpers
|
||||
end
|
52
ops/cookbooks/vendor/postgresql/resources/server_conf.rb
vendored
Normal file
52
ops/cookbooks/vendor/postgresql/resources/server_conf.rb
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# Cookbook:: postgresql
|
||||
# Resource:: server_conf
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include PostgresqlCookbook::Helpers
|
||||
|
||||
property :version, String, default: '9.6'
|
||||
property :data_directory, String, default: lazy { data_dir }
|
||||
property :hba_file, String, default: lazy { "#{conf_dir}/pg_hba.conf" }
|
||||
property :ident_file, String, default: lazy { "#{conf_dir}/pg_ident.conf" }
|
||||
property :external_pid_file, String, default: lazy { "/var/run/postgresql/#{version}-main.pid" }
|
||||
property :stats_temp_directory, String, default: lazy { "/var/run/postgresql/#{version}-main.pg_stat_tmp" }
|
||||
property :port, Integer, default: 5432
|
||||
property :additional_config, Hash, default: {}
|
||||
property :cookbook, String, default: 'postgresql'
|
||||
|
||||
action :modify do
|
||||
template "#{conf_dir}/postgresql.conf" do
|
||||
cookbook new_resource.cookbook
|
||||
source 'postgresql.conf.erb'
|
||||
owner 'postgres'
|
||||
group 'postgres'
|
||||
mode '0644'
|
||||
variables(
|
||||
data_dir: new_resource.data_directory,
|
||||
hba_file: new_resource.hba_file,
|
||||
ident_file: new_resource.ident_file,
|
||||
external_pid_file: new_resource.external_pid_file,
|
||||
stats_temp_directory: new_resource.stats_temp_directory,
|
||||
port: new_resource.port,
|
||||
additional_config: new_resource.additional_config
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
include PostgresqlCookbook::Helpers
|
||||
end
|
76
ops/cookbooks/vendor/postgresql/resources/server_install.rb
vendored
Normal file
76
ops/cookbooks/vendor/postgresql/resources/server_install.rb
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
# frozen_string_literal: true
|
||||
#
|
||||
# Cookbook:: postgresql
|
||||
# Resource:: server_install
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include PostgresqlCookbook::Helpers
|
||||
|
||||
property :version, String, default: '9.6'
|
||||
property :setup_repo, [true, false], default: true
|
||||
property :hba_file, String, default: lazy { "#{conf_dir}/main/pg_hba.conf" }
|
||||
property :ident_file, String, default: lazy { "#{conf_dir}/main/pg_ident.conf" }
|
||||
property :external_pid_file, String, default: lazy { "/var/run/postgresql/#{version}-main.pid" }
|
||||
property :password, [String, nil], default: 'generate' # Set to nil if we do not want to set a password
|
||||
property :port, Integer, default: 5432
|
||||
property :initdb_locale, String
|
||||
|
||||
# Connection preferences
|
||||
property :user, String, default: 'postgres'
|
||||
property :database, String
|
||||
property :host, [String, nil]
|
||||
|
||||
action :install do
|
||||
node.run_state['postgresql'] ||= {}
|
||||
node.run_state['postgresql']['version'] = new_resource.version
|
||||
|
||||
postgresql_client_install 'Install PostgreSQL Client' do
|
||||
version new_resource.version
|
||||
setup_repo new_resource.setup_repo
|
||||
end
|
||||
|
||||
package server_pkg_name
|
||||
end
|
||||
|
||||
action :create do
|
||||
execute 'init_db' do
|
||||
command rhel_init_db_command(new_resource)
|
||||
user new_resource.user
|
||||
not_if { initialized? }
|
||||
only_if { platform_family?('rhel', 'fedora', 'amazon') }
|
||||
end
|
||||
|
||||
# We use to use find_resource here.
|
||||
# But that required the user to do the same in their recipe.
|
||||
# This also seemed to never trigger notifications, therefore requiring a log resource
|
||||
# to notify the enable/start on the service, which always fires (Check v7.0 tag for more)
|
||||
service 'postgresql' do
|
||||
service_name platform_service_name
|
||||
supports restart: true, status: true, reload: true
|
||||
action [:enable, :start]
|
||||
end
|
||||
|
||||
# Generate a random password or set it as per new_resource.password.
|
||||
bash 'generate-postgres-password' do
|
||||
user 'postgres'
|
||||
code alter_role_sql(new_resource)
|
||||
not_if { user_has_password?(new_resource) }
|
||||
not_if { new_resource.password.nil? }
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
include PostgresqlCookbook::Helpers
|
||||
end
|
87
ops/cookbooks/vendor/postgresql/resources/user.rb
vendored
Normal file
87
ops/cookbooks/vendor/postgresql/resources/user.rb
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
#
|
||||
# Cookbook:: postgresql
|
||||
# Resource:: user
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
property :create_user, String, name_property: true
|
||||
property :superuser, [true, false], default: false
|
||||
property :createdb, [true, false], default: false
|
||||
property :createrole, [true, false], default: false
|
||||
property :inherit, [true, false], default: true
|
||||
property :replication, [true, false], default: false
|
||||
property :login, [true, false], default: true
|
||||
property :password, String
|
||||
property :encrypted_password, String
|
||||
property :valid_until, String
|
||||
property :attributes, Hash, default: {}
|
||||
|
||||
# Connection prefernces
|
||||
property :user, String, default: 'postgres'
|
||||
property :database, String
|
||||
property :host, String
|
||||
property :port, Integer, default: 5432
|
||||
|
||||
action :create do
|
||||
Chef::Log.warn('You cannot use "attributes" property with create action.') unless new_resource.attributes.empty?
|
||||
|
||||
execute "create postgresql user #{new_resource.create_user}" do # ~FC009
|
||||
user 'postgres'
|
||||
command create_user_sql(new_resource)
|
||||
sensitive new_resource.sensitive
|
||||
not_if { follower? || user_exists?(new_resource) }
|
||||
end
|
||||
end
|
||||
|
||||
action :update do
|
||||
if new_resource.attributes.empty?
|
||||
execute "update postgresql user #{new_resource.create_user}" do
|
||||
user 'postgres'
|
||||
command update_user_sql(new_resource)
|
||||
sensitive true
|
||||
not_if { follower? }
|
||||
only_if { user_exists?(new_resource) }
|
||||
end
|
||||
else
|
||||
new_resource.attributes.each do |attr, value|
|
||||
v = if value.is_a?(TrueClass) || value.is_a?(FalseClass)
|
||||
value.to_s
|
||||
else
|
||||
"'#{value}'"
|
||||
end
|
||||
|
||||
execute "Update postgresql user #{new_resource.create_user} to set #{attr}" do
|
||||
user 'postgres'
|
||||
command update_user_with_attributes_sql(new_resource, v)
|
||||
sensitive true
|
||||
not_if { follower? }
|
||||
only_if { user_exists?(new_resource) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
action :drop do
|
||||
execute "drop postgresql user #{new_resource.create_user}" do
|
||||
user 'postgres'
|
||||
command drop_user_sql(new_resource)
|
||||
sensitive true
|
||||
not_if { follower? }
|
||||
only_if { user_exists?(new_resource) }
|
||||
end
|
||||
end
|
||||
|
||||
action_class do
|
||||
include PostgresqlCookbook::Helpers
|
||||
end
|
Reference in New Issue
Block a user