fast_food 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +73 -0
- data/Rakefile +8 -0
- data/chef/.chef/bootstrap/chef-solo.erb +27 -0
- data/chef/.chef/knife.rb +8 -0
- data/chef/.gitignore +1 -0
- data/chef/README +3 -0
- data/chef/cookbooks/README +1 -0
- data/chef/cookbooks/apache2/.gitignore +1 -0
- data/chef/cookbooks/apache2/CHANGELOG.md +81 -0
- data/chef/cookbooks/apache2/CONTRIBUTING +29 -0
- data/chef/cookbooks/apache2/Gemfile +10 -0
- data/chef/cookbooks/apache2/LICENSE +201 -0
- data/chef/cookbooks/apache2/README.md +373 -0
- data/chef/cookbooks/apache2/attributes/default.rb +149 -0
- data/chef/cookbooks/apache2/attributes/mod_auth_openid.rb +32 -0
- data/chef/cookbooks/apache2/definitions/apache_conf.rb +26 -0
- data/chef/cookbooks/apache2/definitions/apache_module.rb +53 -0
- data/chef/cookbooks/apache2/definitions/apache_site.rb +43 -0
- data/chef/cookbooks/apache2/definitions/web_app.rb +49 -0
- data/chef/cookbooks/apache2/files/default/apache2_module_conf_generate.pl +41 -0
- data/chef/cookbooks/apache2/files/default/tests/minitest/default_test.rb +64 -0
- data/chef/cookbooks/apache2/files/default/tests/minitest/helpers.rb +36 -0
- data/chef/cookbooks/apache2/files/default/tests/minitest/mod_auth_openid_test.rb +25 -0
- data/chef/cookbooks/apache2/files/default/tests/minitest/mod_dav_svn_test.rb +16 -0
- data/chef/cookbooks/apache2/files/default/tests/minitest/mod_perl_test.rb +22 -0
- data/chef/cookbooks/apache2/files/default/tests/minitest/mod_php5_test.rb +19 -0
- data/chef/cookbooks/apache2/files/default/tests/minitest/mod_python_test.rb +14 -0
- data/chef/cookbooks/apache2/files/default/tests/minitest/mod_ssl_test.rb +19 -0
- data/chef/cookbooks/apache2/files/default/tests/minitest/mod_wsgi_test.rb +14 -0
- data/chef/cookbooks/apache2/files/default/tests/minitest/mod_xsendfile_test.rb +14 -0
- data/chef/cookbooks/apache2/files/default/tests/minitest/modules_test.rb +19 -0
- data/chef/cookbooks/apache2/metadata.json +511 -0
- data/chef/cookbooks/apache2/metadata.rb +205 -0
- data/chef/cookbooks/apache2/recipes/default.rb +221 -0
- data/chef/cookbooks/apache2/recipes/god_monitor.rb +33 -0
- data/chef/cookbooks/apache2/recipes/mod_alias.rb +22 -0
- data/chef/cookbooks/apache2/recipes/mod_apreq2.rb +45 -0
- data/chef/cookbooks/apache2/recipes/mod_auth_basic.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_auth_digest.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_auth_openid.rb +113 -0
- data/chef/cookbooks/apache2/recipes/mod_authn_file.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_authnz_ldap.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_authz_default.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_authz_groupfile.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_authz_host.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_authz_user.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_autoindex.rb +22 -0
- data/chef/cookbooks/apache2/recipes/mod_cgi.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_dav.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_dav_fs.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_dav_svn.rb +29 -0
- data/chef/cookbooks/apache2/recipes/mod_deflate.rb +22 -0
- data/chef/cookbooks/apache2/recipes/mod_dir.rb +22 -0
- data/chef/cookbooks/apache2/recipes/mod_env.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_expires.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_fastcgi.rb +26 -0
- data/chef/cookbooks/apache2/recipes/mod_fcgid.rb +53 -0
- data/chef/cookbooks/apache2/recipes/mod_headers.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_ldap.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_log_config.rb +24 -0
- data/chef/cookbooks/apache2/recipes/mod_logio.rb +24 -0
- data/chef/cookbooks/apache2/recipes/mod_mime.rb +22 -0
- data/chef/cookbooks/apache2/recipes/mod_negotiation.rb +22 -0
- data/chef/cookbooks/apache2/recipes/mod_perl.rb +39 -0
- data/chef/cookbooks/apache2/recipes/mod_php5.rb +99 -0
- data/chef/cookbooks/apache2/recipes/mod_proxy.rb +22 -0
- data/chef/cookbooks/apache2/recipes/mod_proxy_ajp.rb +21 -0
- data/chef/cookbooks/apache2/recipes/mod_proxy_balancer.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_proxy_connect.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_proxy_http.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_python.rb +32 -0
- data/chef/cookbooks/apache2/recipes/mod_rewrite.rb +20 -0
- data/chef/cookbooks/apache2/recipes/mod_setenvif.rb +22 -0
- data/chef/cookbooks/apache2/recipes/mod_ssl.rb +43 -0
- data/chef/cookbooks/apache2/recipes/mod_status.rb +22 -0
- data/chef/cookbooks/apache2/recipes/mod_wsgi.rb +27 -0
- data/chef/cookbooks/apache2/recipes/mod_xsendfile.rb +27 -0
- data/chef/cookbooks/apache2/templates/default/a2dismod.erb +22 -0
- data/chef/cookbooks/apache2/templates/default/a2dissite.erb +29 -0
- data/chef/cookbooks/apache2/templates/default/a2enmod.erb +37 -0
- data/chef/cookbooks/apache2/templates/default/a2ensite.erb +38 -0
- data/chef/cookbooks/apache2/templates/default/apache2.conf.erb +237 -0
- data/chef/cookbooks/apache2/templates/default/apache2.god.erb +19 -0
- data/chef/cookbooks/apache2/templates/default/charset.erb +6 -0
- data/chef/cookbooks/apache2/templates/default/default-site.erb +57 -0
- data/chef/cookbooks/apache2/templates/default/mods/README +2 -0
- data/chef/cookbooks/apache2/templates/default/mods/alias.conf.erb +24 -0
- data/chef/cookbooks/apache2/templates/default/mods/authopenid.load.erb +1 -0
- data/chef/cookbooks/apache2/templates/default/mods/autoindex.conf.erb +101 -0
- data/chef/cookbooks/apache2/templates/default/mods/deflate.conf.erb +16 -0
- data/chef/cookbooks/apache2/templates/default/mods/dir.conf.erb +5 -0
- data/chef/cookbooks/apache2/templates/default/mods/fastcgi.conf.erb +5 -0
- data/chef/cookbooks/apache2/templates/default/mods/fcgid.conf.erb +10 -0
- data/chef/cookbooks/apache2/templates/default/mods/mime.conf.erb +198 -0
- data/chef/cookbooks/apache2/templates/default/mods/negotiation.conf.erb +18 -0
- data/chef/cookbooks/apache2/templates/default/mods/php5.conf.erb +16 -0
- data/chef/cookbooks/apache2/templates/default/mods/proxy.conf.erb +19 -0
- data/chef/cookbooks/apache2/templates/default/mods/setenvif.conf.erb +28 -0
- data/chef/cookbooks/apache2/templates/default/mods/ssl.conf.erb +76 -0
- data/chef/cookbooks/apache2/templates/default/mods/status.conf.erb +26 -0
- data/chef/cookbooks/apache2/templates/default/port_apache.erb +2 -0
- data/chef/cookbooks/apache2/templates/default/ports.conf.erb +6 -0
- data/chef/cookbooks/apache2/templates/default/security.erb +50 -0
- data/chef/cookbooks/apache2/templates/default/web_app.conf.erb +43 -0
- data/chef/cookbooks/build-essential/.gitignore +4 -0
- data/chef/cookbooks/build-essential/CHANGELOG.md +31 -0
- data/chef/cookbooks/build-essential/CONTRIBUTING +29 -0
- data/chef/cookbooks/build-essential/Gemfile +3 -0
- data/chef/cookbooks/build-essential/LICENSE +201 -0
- data/chef/cookbooks/build-essential/README.md +129 -0
- data/chef/cookbooks/build-essential/attributes/default.rb +33 -0
- data/chef/cookbooks/build-essential/metadata.json +41 -0
- data/chef/cookbooks/build-essential/metadata.rb +14 -0
- data/chef/cookbooks/build-essential/recipes/default.rb +92 -0
- data/chef/cookbooks/database/.gitignore +1 -0
- data/chef/cookbooks/database/CHANGELOG.md +46 -0
- data/chef/cookbooks/database/CONTRIBUTING +29 -0
- data/chef/cookbooks/database/LICENSE +201 -0
- data/chef/cookbooks/database/README.md +468 -0
- data/chef/cookbooks/database/libraries/provider_database_mysql.rb +103 -0
- data/chef/cookbooks/database/libraries/provider_database_mysql_user.rb +76 -0
- data/chef/cookbooks/database/libraries/provider_database_postgresql.rb +131 -0
- data/chef/cookbooks/database/libraries/provider_database_postgresql_user.rb +83 -0
- data/chef/cookbooks/database/libraries/provider_database_sql_server.rb +109 -0
- data/chef/cookbooks/database/libraries/provider_database_sql_server_user.rb +106 -0
- data/chef/cookbooks/database/libraries/resource_database.rb +119 -0
- data/chef/cookbooks/database/libraries/resource_database_user.rb +90 -0
- data/chef/cookbooks/database/libraries/resource_mysql_database.rb +34 -0
- data/chef/cookbooks/database/libraries/resource_mysql_database_user.rb +34 -0
- data/chef/cookbooks/database/libraries/resource_postgresql_database.rb +35 -0
- data/chef/cookbooks/database/libraries/resource_postgresql_database_user.rb +35 -0
- data/chef/cookbooks/database/libraries/resource_sql_server_database.rb +34 -0
- data/chef/cookbooks/database/libraries/resource_sql_server_database_user.rb +34 -0
- data/chef/cookbooks/database/metadata.json +45 -0
- data/chef/cookbooks/database/metadata.rb +22 -0
- data/chef/cookbooks/database/recipes/default.rb +20 -0
- data/chef/cookbooks/database/recipes/ebs_backup.rb +89 -0
- data/chef/cookbooks/database/recipes/ebs_volume.rb +204 -0
- data/chef/cookbooks/database/recipes/master.rb +78 -0
- data/chef/cookbooks/database/recipes/mysql.rb +20 -0
- data/chef/cookbooks/database/recipes/postgresql.rb +20 -0
- data/chef/cookbooks/database/recipes/snapshot.rb +62 -0
- data/chef/cookbooks/database/templates/default/app_grants.sql.erb +8 -0
- data/chef/cookbooks/database/templates/default/aws_config.erb +3 -0
- data/chef/cookbooks/database/templates/default/chef-solo-database-snapshot.cron.erb +6 -0
- data/chef/cookbooks/database/templates/default/chef-solo-database-snapshot.json.erb +1 -0
- data/chef/cookbooks/database/templates/default/chef-solo-database-snapshot.rb.erb +6 -0
- data/chef/cookbooks/database/templates/default/ebs-backup-cron.erb +2 -0
- data/chef/cookbooks/database/templates/default/ebs-db-backup.sh.erb +8 -0
- data/chef/cookbooks/database/templates/default/ebs-db-restore.sh.erb +10 -0
- data/chef/cookbooks/database/templates/default/s3cfg.erb +27 -0
- data/chef/cookbooks/fast_food/recipes/default.rb +24 -0
- data/chef/cookbooks/fast_food/recipes/site.rb +7 -0
- data/chef/cookbooks/fast_food/templates/default/web_app.conf.erb +43 -0
- data/chef/cookbooks/git/CHANGELOG.md +49 -0
- data/chef/cookbooks/git/CONTRIBUTING +29 -0
- data/chef/cookbooks/git/LICENSE +201 -0
- data/chef/cookbooks/git/README.md +115 -0
- data/chef/cookbooks/git/attributes/default.rb +37 -0
- data/chef/cookbooks/git/metadata.json +48 -0
- data/chef/cookbooks/git/metadata.rb +20 -0
- data/chef/cookbooks/git/recipes/default.rb +46 -0
- data/chef/cookbooks/git/recipes/server.rb +38 -0
- data/chef/cookbooks/git/recipes/source.rb +48 -0
- data/chef/cookbooks/git/recipes/windows.rb +32 -0
- data/chef/cookbooks/git/templates/default/sv-git-daemon-log-run.erb +2 -0
- data/chef/cookbooks/git/templates/default/sv-git-daemon-run.erb +3 -0
- data/chef/cookbooks/imagemagick/README.md +57 -0
- data/chef/cookbooks/imagemagick/metadata.json +37 -0
- data/chef/cookbooks/imagemagick/metadata.rb +14 -0
- data/chef/cookbooks/imagemagick/recipes/default.rb +25 -0
- data/chef/cookbooks/imagemagick/recipes/devel.rb +32 -0
- data/chef/cookbooks/imagemagick/recipes/rmagick.rb +22 -0
- data/chef/cookbooks/mysql/.gitignore +5 -0
- data/chef/cookbooks/mysql/CHANGELOG.md +125 -0
- data/chef/cookbooks/mysql/CONTRIBUTING +29 -0
- data/chef/cookbooks/mysql/Gemfile +8 -0
- data/chef/cookbooks/mysql/LICENSE +201 -0
- data/chef/cookbooks/mysql/README.md +227 -0
- data/chef/cookbooks/mysql/attributes/client.rb +50 -0
- data/chef/cookbooks/mysql/attributes/server.rb +240 -0
- data/chef/cookbooks/mysql/files/default/tests/minitest/server_test.rb +36 -0
- data/chef/cookbooks/mysql/files/default/tests/minitest/support/helpers.rb +11 -0
- data/chef/cookbooks/mysql/libraries/helpers.rb +33 -0
- data/chef/cookbooks/mysql/metadata.json +418 -0
- data/chef/cookbooks/mysql/metadata.rb +140 -0
- data/chef/cookbooks/mysql/recipes/client.rb +59 -0
- data/chef/cookbooks/mysql/recipes/default.rb +20 -0
- data/chef/cookbooks/mysql/recipes/ruby.rb +36 -0
- data/chef/cookbooks/mysql/recipes/server.rb +221 -0
- data/chef/cookbooks/mysql/recipes/server_ec2.rb +51 -0
- data/chef/cookbooks/mysql/templates/default/debian.cnf.erb +12 -0
- data/chef/cookbooks/mysql/templates/default/grants.sql.erb +15 -0
- data/chef/cookbooks/mysql/templates/default/my.cnf.erb +312 -0
- data/chef/cookbooks/mysql/templates/default/mysql-server.seed.erb +10 -0
- data/chef/cookbooks/mysql/templates/default/port_mysql.erb +3 -0
- data/chef/cookbooks/mysql/templates/windows/my.cnf.erb +61 -0
- data/chef/cookbooks/openssl/README.md +37 -0
- data/chef/cookbooks/openssl/libraries/secure_password.rb +37 -0
- data/chef/cookbooks/openssl/metadata.json +30 -0
- data/chef/cookbooks/openssl/metadata.rb +8 -0
- data/chef/cookbooks/openssl/recipes/default.rb +19 -0
- data/chef/cookbooks/passenger_apache2/.gitignore +4 -0
- data/chef/cookbooks/passenger_apache2/CHANGELOG.md +29 -0
- data/chef/cookbooks/passenger_apache2/CONTRIBUTING +29 -0
- data/chef/cookbooks/passenger_apache2/Gemfile +3 -0
- data/chef/cookbooks/passenger_apache2/LICENSE +201 -0
- data/chef/cookbooks/passenger_apache2/README.md +77 -0
- data/chef/cookbooks/passenger_apache2/attributes/default.rb +5 -0
- data/chef/cookbooks/passenger_apache2/metadata.json +38 -0
- data/chef/cookbooks/passenger_apache2/metadata.rb +17 -0
- data/chef/cookbooks/passenger_apache2/recipes/default.rb +60 -0
- data/chef/cookbooks/passenger_apache2/recipes/mod_rails.rb +47 -0
- data/chef/cookbooks/passenger_apache2/templates/default/passenger.conf.erb +3 -0
- data/chef/cookbooks/passenger_apache2/templates/default/passenger.load.erb +1 -0
- data/chef/cookbooks/passenger_apache2/templates/default/passenger_web_app.conf.erb +32 -0
- data/chef/cookbooks/passenger_apache2/templates/default/web_app.conf.erb +32 -0
- data/chef/roles/apache2.rb +12 -0
- data/chef/roles/mysql.rb +18 -0
- data/chef/solo.rb +5 -0
- data/config/deploy/centos.sh +17 -0
- data/config/deploy/production.rb +3 -0
- data/config/deploy/ubuntu.sh +10 -0
- data/config/deploy.rb +99 -0
- data/config/deployment.yml +6 -0
- data/fast_food.gemspec +26 -0
- data/lib/fast_food/railtie.rb +9 -0
- data/lib/fast_food/version.rb +3 -0
- data/lib/fast_food.rb +5 -0
- data/lib/tasks/fast_food.rake +100 -0
- data/spec/lib/fast_food_spec.rb +0 -0
- data/spec/spec_helper.rb +1 -0
- metadata +349 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/provider'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Provider
|
23
|
+
class Database
|
24
|
+
class Mysql < Chef::Provider
|
25
|
+
include Chef::Mixin::ShellOut
|
26
|
+
|
27
|
+
def load_current_resource
|
28
|
+
Gem.clear_paths
|
29
|
+
require 'mysql'
|
30
|
+
@current_resource = Chef::Resource::Database.new(@new_resource.name)
|
31
|
+
@current_resource.database_name(@new_resource.database_name)
|
32
|
+
@current_resource
|
33
|
+
end
|
34
|
+
|
35
|
+
def action_create
|
36
|
+
unless exists?
|
37
|
+
begin
|
38
|
+
Chef::Log.debug("#{@new_resource}: Creating database #{new_resource.database_name}")
|
39
|
+
create_sql = "CREATE DATABASE #{new_resource.database_name}"
|
40
|
+
create_sql += " CHARACTER SET = #{new_resource.encoding}" if new_resource.encoding
|
41
|
+
create_sql += " COLLATE = #{new_resource.collation}" if new_resource.collation
|
42
|
+
Chef::Log.debug("#{@new_resource}: Performing query [#{create_sql}]")
|
43
|
+
db.query(create_sql)
|
44
|
+
@new_resource.updated_by_last_action(true)
|
45
|
+
ensure
|
46
|
+
close
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def action_drop
|
52
|
+
if exists?
|
53
|
+
begin
|
54
|
+
Chef::Log.debug("#{@new_resource}: Dropping database #{new_resource.database_name}")
|
55
|
+
db.query("drop database #{new_resource.database_name}")
|
56
|
+
@new_resource.updated_by_last_action(true)
|
57
|
+
ensure
|
58
|
+
close
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def action_query
|
64
|
+
if exists?
|
65
|
+
begin
|
66
|
+
db.select_db(@new_resource.database_name) if @new_resource.database_name
|
67
|
+
Chef::Log.debug("#{@new_resource}: Performing query [#{new_resource.sql_query}]")
|
68
|
+
db.query(@new_resource.sql_query)
|
69
|
+
@new_resource.updated_by_last_action(true)
|
70
|
+
ensure
|
71
|
+
close
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
def exists?
|
78
|
+
db.list_dbs.include?(@new_resource.database_name)
|
79
|
+
end
|
80
|
+
|
81
|
+
def db
|
82
|
+
@db ||= begin
|
83
|
+
connection = ::Mysql.new(
|
84
|
+
@new_resource.connection[:host],
|
85
|
+
@new_resource.connection[:username],
|
86
|
+
@new_resource.connection[:password],
|
87
|
+
nil,
|
88
|
+
@new_resource.connection[:port] || 3306
|
89
|
+
)
|
90
|
+
connection.set_server_option ::Mysql::OPTION_MULTI_STATEMENTS_ON
|
91
|
+
connection
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def close
|
96
|
+
@db.close rescue nil
|
97
|
+
@db = nil
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require File.join(File.dirname(__FILE__), 'provider_database_mysql')
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Provider
|
23
|
+
class Database
|
24
|
+
class MysqlUser < Chef::Provider::Database::Mysql
|
25
|
+
include Chef::Mixin::ShellOut
|
26
|
+
|
27
|
+
def load_current_resource
|
28
|
+
Gem.clear_paths
|
29
|
+
require 'mysql'
|
30
|
+
@current_resource = Chef::Resource::DatabaseUser.new(@new_resource.name)
|
31
|
+
@current_resource.username(@new_resource.name)
|
32
|
+
@current_resource
|
33
|
+
end
|
34
|
+
|
35
|
+
def action_create
|
36
|
+
unless exists?
|
37
|
+
begin
|
38
|
+
db.query("CREATE USER '#{@new_resource.username}'@'#{@new_resource.host}' IDENTIFIED BY '#{@new_resource.password}'")
|
39
|
+
@new_resource.updated_by_last_action(true)
|
40
|
+
ensure
|
41
|
+
close
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def action_drop
|
47
|
+
if exists?
|
48
|
+
begin
|
49
|
+
db.query("DROP USER '#{@new_resource.username}'@'#{@new_resource.host}'")
|
50
|
+
@new_resource.updated_by_last_action(true)
|
51
|
+
ensure
|
52
|
+
close
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def action_grant
|
58
|
+
begin
|
59
|
+
grant_statement = "GRANT #{@new_resource.privileges.join(', ')} ON #{@new_resource.database_name || "*"}.#{@new_resource.table || "*"} TO '#{@new_resource.username}'@'#{@new_resource.host}' IDENTIFIED BY '#{@new_resource.password}'"
|
60
|
+
Chef::Log.info("#{@new_resource}: granting access with statement [#{grant_statement}]")
|
61
|
+
db.query(grant_statement)
|
62
|
+
@new_resource.updated_by_last_action(true)
|
63
|
+
ensure
|
64
|
+
close
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
def exists?
|
70
|
+
db.query("select User,host from mysql.user where User='#{@new_resource.username}' AND host = '#{@new_resource.host}'").num_rows != 0
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Author:: Lamont Granquist (<lamont@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require 'chef/provider'
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Database
|
25
|
+
class Postgresql < Chef::Provider
|
26
|
+
include Chef::Mixin::ShellOut
|
27
|
+
|
28
|
+
def load_current_resource
|
29
|
+
Gem.clear_paths
|
30
|
+
require 'pg'
|
31
|
+
@current_resource = Chef::Resource::Database.new(@new_resource.name)
|
32
|
+
@current_resource.database_name(@new_resource.database_name)
|
33
|
+
@current_resource
|
34
|
+
end
|
35
|
+
|
36
|
+
def action_create
|
37
|
+
unless exists?
|
38
|
+
begin
|
39
|
+
encoding = @new_resource.encoding
|
40
|
+
if encoding != "DEFAULT"
|
41
|
+
encoding = "'#{@new_resource.encoding}'"
|
42
|
+
end
|
43
|
+
Chef::Log.debug("#{@new_resource}: Creating database #{new_resource.database_name}")
|
44
|
+
create_sql = "CREATE DATABASE #{new_resource.database_name}"
|
45
|
+
create_sql += " TEMPLATE = #{new_resource.template}" if new_resource.template
|
46
|
+
create_sql += " ENCODING = #{encoding}" if new_resource.encoding
|
47
|
+
create_sql += " TABLESPACE = #{new_resource.tablespace}" if new_resource.tablespace
|
48
|
+
create_sql += " LC_CTYPE = '#{new_resource.collation}' LC_COLLATE = '#{new_resource.collation}'" if new_resource.collation
|
49
|
+
create_sql += " CONNECTION LIMIT = #{new_resource.connection_limit}" if new_resource.connection_limit
|
50
|
+
create_sql += " OWNER = #{new_resource.owner}" if new_resource.owner
|
51
|
+
Chef::Log.debug("#{@new_resource}: Performing query [#{create_sql}]")
|
52
|
+
db("template1").query(create_sql)
|
53
|
+
@new_resource.updated_by_last_action(true)
|
54
|
+
ensure
|
55
|
+
close
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def action_drop
|
61
|
+
if exists?
|
62
|
+
begin
|
63
|
+
Chef::Log.debug("#{@new_resource}: Dropping database #{new_resource.database_name}")
|
64
|
+
db("template1").query("drop database #{new_resource.database_name}")
|
65
|
+
@new_resource.updated_by_last_action(true)
|
66
|
+
ensure
|
67
|
+
close
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def action_query
|
73
|
+
if exists?
|
74
|
+
begin
|
75
|
+
Chef::Log.debug("#{@new_resource}: Performing query [#{new_resource.sql_query}]")
|
76
|
+
db(@new_resource.database_name).query(@new_resource.sql_query)
|
77
|
+
Chef::Log.debug("#{@new_resource}: query [#{new_resource.sql_query}] succeeded")
|
78
|
+
@new_resource.updated_by_last_action(true)
|
79
|
+
ensure
|
80
|
+
close
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def exists?
|
88
|
+
begin
|
89
|
+
Chef::Log.debug("#{@new_resource}: checking if database #{@new_resource.database_name} exists")
|
90
|
+
ret = db("template1").query("select * from pg_database where datname = '#{@new_resource.database_name}'").num_tuples != 0
|
91
|
+
ret ? Chef::Log.debug("#{@new_resource}: database #{@new_resource.database_name} exists") :
|
92
|
+
Chef::Log.debug("#{@new_resource}: database #{@new_resource.database_name} does not exist")
|
93
|
+
ensure
|
94
|
+
close
|
95
|
+
end
|
96
|
+
ret
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Specifying the database in the connection parameter for the postgres resource is not recommended.
|
101
|
+
#
|
102
|
+
# - action_create/drop/exists will use the "template1" database to do work by default.
|
103
|
+
# - action_query will use the resource database_name.
|
104
|
+
# - specifying a database in the connection will override this behavior
|
105
|
+
#
|
106
|
+
def db(dbname = nil)
|
107
|
+
close if @db
|
108
|
+
dbname = @new_resource.connection[:database] if @new_resource.connection[:database]
|
109
|
+
host = @new_resource.connection[:host]
|
110
|
+
port = @new_resource.connection[:port] || 5432
|
111
|
+
user = @new_resource.connection[:username] || "postgres"
|
112
|
+
Chef::Log.debug("#{@new_resource}: connecting to database #{dbname} on #{host}:#{port} as #{user}")
|
113
|
+
password = @new_resource.connection[:password] || node[:postgresql][:password][:postgres]
|
114
|
+
@db = ::PGconn.new(
|
115
|
+
:host => host,
|
116
|
+
:port => port,
|
117
|
+
:dbname => dbname,
|
118
|
+
:user => user,
|
119
|
+
:password => password
|
120
|
+
)
|
121
|
+
end
|
122
|
+
|
123
|
+
def close
|
124
|
+
@db.close rescue nil
|
125
|
+
@db = nil
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Author:: Lamont Granquist (<lamont@opscode.com>)
|
4
|
+
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
require File.join(File.dirname(__FILE__), 'provider_database_postgresql')
|
21
|
+
|
22
|
+
class Chef
|
23
|
+
class Provider
|
24
|
+
class Database
|
25
|
+
class PostgresqlUser < Chef::Provider::Database::Postgresql
|
26
|
+
include Chef::Mixin::ShellOut
|
27
|
+
|
28
|
+
def load_current_resource
|
29
|
+
Gem.clear_paths
|
30
|
+
require 'pg'
|
31
|
+
@current_resource = Chef::Resource::DatabaseUser.new(@new_resource.name)
|
32
|
+
@current_resource.username(@new_resource.name)
|
33
|
+
@current_resource
|
34
|
+
end
|
35
|
+
|
36
|
+
def action_create
|
37
|
+
unless exists?
|
38
|
+
begin
|
39
|
+
db("template1").query("CREATE USER #{@new_resource.username} WITH PASSWORD '#{@new_resource.password}'")
|
40
|
+
@new_resource.updated_by_last_action(true)
|
41
|
+
ensure
|
42
|
+
close
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def action_drop
|
48
|
+
if exists?
|
49
|
+
begin
|
50
|
+
db("template1").query("DROP USER #{@new_resource.username}")
|
51
|
+
@new_resource.updated_by_last_action(true)
|
52
|
+
ensure
|
53
|
+
close
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def action_grant
|
59
|
+
begin
|
60
|
+
# FIXME: grants on individual tables
|
61
|
+
grant_statement = "GRANT #{@new_resource.privileges.join(', ')} ON DATABASE #{@new_resource.database_name} TO #{@new_resource.username}"
|
62
|
+
Chef::Log.info("#{@new_resource}: granting access with statement [#{grant_statement}]")
|
63
|
+
db(@new_resource.database_name).query(grant_statement)
|
64
|
+
@new_resource.updated_by_last_action(true)
|
65
|
+
ensure
|
66
|
+
close
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def exists?
|
72
|
+
begin
|
73
|
+
exists = db("template1").query("select * from pg_user where usename='#{@new_resource.username}'").num_tuples != 0
|
74
|
+
ensure
|
75
|
+
close
|
76
|
+
end
|
77
|
+
exists
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/provider'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Provider
|
23
|
+
class Database
|
24
|
+
class SqlServer < Chef::Provider
|
25
|
+
include Chef::Mixin::ShellOut
|
26
|
+
|
27
|
+
def load_current_resource
|
28
|
+
Gem.clear_paths
|
29
|
+
require 'tiny_tds'
|
30
|
+
@current_resource = Chef::Resource::Database.new(@new_resource.name)
|
31
|
+
@current_resource.database_name(@new_resource.database_name)
|
32
|
+
@current_resource
|
33
|
+
end
|
34
|
+
|
35
|
+
def action_create
|
36
|
+
unless exists?
|
37
|
+
begin
|
38
|
+
Chef::Log.debug("#{@new_resource}: Creating database #{new_resource.database_name}")
|
39
|
+
db.execute("CREATE DATABASE [#{new_resource.database_name}]").do
|
40
|
+
@new_resource.updated_by_last_action(true)
|
41
|
+
ensure
|
42
|
+
close
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def action_drop
|
48
|
+
if exists?
|
49
|
+
begin
|
50
|
+
Chef::Log.debug("#{@new_resource}: Dropping database #{new_resource.database_name}")
|
51
|
+
db.execute("DROP DATABASE #{new_resource.database_name}").do
|
52
|
+
@new_resource.updated_by_last_action(true)
|
53
|
+
ensure
|
54
|
+
close
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def action_query
|
60
|
+
if exists?
|
61
|
+
begin
|
62
|
+
#db.select_db(@new_resource.database_name) if @new_resource.database_name
|
63
|
+
Chef::Log.debug("#{@new_resource}: Performing query [#{new_resource.sql_query}]")
|
64
|
+
db.execute(@new_resource.sql_query).do
|
65
|
+
@new_resource.updated_by_last_action(true)
|
66
|
+
ensure
|
67
|
+
close
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def exists?
|
74
|
+
exists = false
|
75
|
+
begin
|
76
|
+
result = db.execute("SELECT name FROM sys.databases")
|
77
|
+
result.each do |row|
|
78
|
+
if row['name'] =~ /#{@new_resource.database_name}/i
|
79
|
+
exists = true
|
80
|
+
break
|
81
|
+
end
|
82
|
+
end
|
83
|
+
result.cancel
|
84
|
+
ensure
|
85
|
+
close
|
86
|
+
end
|
87
|
+
exists
|
88
|
+
end
|
89
|
+
|
90
|
+
def db
|
91
|
+
@db ||= begin
|
92
|
+
::TinyTds::Client.new(
|
93
|
+
:host => @new_resource.connection[:host],
|
94
|
+
:username => @new_resource.connection[:username],
|
95
|
+
:password => @new_resource.connection[:password],
|
96
|
+
:port => @new_resource.connection[:port] || 1433
|
97
|
+
)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def close
|
102
|
+
@db.close rescue nil
|
103
|
+
@db = nil
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require File.join(File.dirname(__FILE__), 'provider_database_sql_server')
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Provider
|
23
|
+
class Database
|
24
|
+
class SqlServerUser < Chef::Provider::Database::SqlServer
|
25
|
+
include Chef::Mixin::ShellOut
|
26
|
+
|
27
|
+
def load_current_resource
|
28
|
+
Gem.clear_paths
|
29
|
+
require 'tiny_tds'
|
30
|
+
@current_resource = Chef::Resource::DatabaseUser.new(@new_resource.name)
|
31
|
+
@current_resource.username(@new_resource.name)
|
32
|
+
@current_resource
|
33
|
+
end
|
34
|
+
|
35
|
+
def action_create
|
36
|
+
begin
|
37
|
+
unless exists?(:logins)
|
38
|
+
db.execute("CREATE LOGIN #{@new_resource.username} WITH PASSWORD = '#{@new_resource.password}', CHECK_POLICY = OFF").do
|
39
|
+
@new_resource.updated_by_last_action(true)
|
40
|
+
end
|
41
|
+
unless exists?(:users)
|
42
|
+
if @new_resource.database_name
|
43
|
+
Chef::Log.info("#{@new_resource} creating user in '#{@new_resource.database_name}' database context.")
|
44
|
+
db.execute("USE #{@new_resource.database_name}").do
|
45
|
+
else
|
46
|
+
Chef::Log.info("#{@new_resource} database_name not provided, creating user in global context.")
|
47
|
+
end
|
48
|
+
db.execute("CREATE USER #{@new_resource.username} FOR LOGIN #{@new_resource.username}").do
|
49
|
+
@new_resource.updated_by_last_action(true)
|
50
|
+
end
|
51
|
+
ensure
|
52
|
+
close
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def action_drop
|
57
|
+
begin
|
58
|
+
if exists?(:users)
|
59
|
+
db.execute("DROP USER #{@new_resource.username}").do
|
60
|
+
@new_resource.updated_by_last_action(true)
|
61
|
+
end
|
62
|
+
if exists?(:logins)
|
63
|
+
db.execute("DROP LOGIN #{@new_resource.username}").do
|
64
|
+
@new_resource.updated_by_last_action(true)
|
65
|
+
end
|
66
|
+
ensure
|
67
|
+
close
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def action_grant
|
72
|
+
begin
|
73
|
+
if @new_resource.password
|
74
|
+
action_create
|
75
|
+
end
|
76
|
+
Chef::Application.fatal!('Please provide a database_name, SQL Server does not support global GRANT statements.') unless @new_resource.database_name
|
77
|
+
grant_statement = "GRANT #{@new_resource.privileges.join(', ')} ON DATABASE::#{@new_resource.database_name} TO #{@new_resource.username}"
|
78
|
+
Chef::Log.info("#{@new_resource} granting access with statement [#{grant_statement}]")
|
79
|
+
db.execute("USE #{@new_resource.database_name}").do
|
80
|
+
db.execute(grant_statement).do
|
81
|
+
@new_resource.updated_by_last_action(true)
|
82
|
+
ensure
|
83
|
+
close
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def exists?(type=:users)
|
89
|
+
case type
|
90
|
+
when :users
|
91
|
+
table = "database_principals"
|
92
|
+
if @new_resource.database_name
|
93
|
+
Chef::Log.debug("#{@new_resource} searching for existing user in '#{@new_resource.database_name}' database context.")
|
94
|
+
db.execute("USE #{@new_resource.database_name}").do
|
95
|
+
end
|
96
|
+
when :logins
|
97
|
+
table = "server_principals"
|
98
|
+
end
|
99
|
+
|
100
|
+
result = db.execute("SELECT name FROM sys.#{table} WHERE name='#{@new_resource.username}'")
|
101
|
+
result.each.any?
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|