garcun 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitattributes +17 -0
- data/.gitignore +197 -0
- data/.rspec +2 -0
- data/Gemfile +22 -0
- data/LICENSE +201 -0
- data/README.md +521 -0
- data/Rakefile +47 -0
- data/garcun.gemspec +83 -0
- data/lib/garcon.rb +290 -0
- data/lib/garcon/chef/chef_helpers.rb +343 -0
- data/lib/garcon/chef/coerce/coercer.rb +134 -0
- data/lib/garcon/chef/coerce/coercions/boolean_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/date_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/date_time_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/fixnum_definitions.rb +34 -0
- data/lib/garcon/chef/coerce/coercions/float_definitions.rb +32 -0
- data/lib/garcon/chef/coerce/coercions/hash_definitions.rb +29 -0
- data/lib/garcon/chef/coerce/coercions/integer_definitions.rb +31 -0
- data/lib/garcon/chef/coerce/coercions/string_definitions.rb +45 -0
- data/lib/garcon/chef/coerce/coercions/time_definitions.rb +32 -0
- data/lib/garcon/chef/handler/devreporter.rb +127 -0
- data/lib/garcon/chef/log.rb +64 -0
- data/lib/garcon/chef/node.rb +100 -0
- data/lib/garcon/chef/provider/civilize.rb +209 -0
- data/lib/garcon/chef/provider/development.rb +159 -0
- data/lib/garcon/chef/provider/download.rb +420 -0
- data/lib/garcon/chef/provider/house_keeping.rb +265 -0
- data/lib/garcon/chef/provider/node_cache.rb +31 -0
- data/lib/garcon/chef/provider/partial.rb +183 -0
- data/lib/garcon/chef/provider/recovery.rb +80 -0
- data/lib/garcon/chef/provider/zip_file.rb +271 -0
- data/lib/garcon/chef/resource/attribute.rb +52 -0
- data/lib/garcon/chef/resource/base_dsl.rb +174 -0
- data/lib/garcon/chef/resource/blender.rb +140 -0
- data/lib/garcon/chef/resource/lazy_eval.rb +66 -0
- data/lib/garcon/chef/resource/resource_name.rb +109 -0
- data/lib/garcon/chef/secret_bag.rb +204 -0
- data/lib/garcon/chef/validations.rb +76 -0
- data/lib/garcon/chef_inclusions.rb +151 -0
- data/lib/garcon/configuration.rb +138 -0
- data/lib/garcon/core_ext.rb +39 -0
- data/lib/garcon/core_ext/array.rb +27 -0
- data/lib/garcon/core_ext/binding.rb +64 -0
- data/lib/garcon/core_ext/boolean.rb +66 -0
- data/lib/garcon/core_ext/duration.rb +271 -0
- data/lib/garcon/core_ext/enumerable.rb +34 -0
- data/lib/garcon/core_ext/file.rb +127 -0
- data/lib/garcon/core_ext/filetest.rb +62 -0
- data/lib/garcon/core_ext/hash.rb +279 -0
- data/lib/garcon/core_ext/kernel.rb +159 -0
- data/lib/garcon/core_ext/lazy.rb +222 -0
- data/lib/garcon/core_ext/method_access.rb +243 -0
- data/lib/garcon/core_ext/module.rb +92 -0
- data/lib/garcon/core_ext/nil.rb +53 -0
- data/lib/garcon/core_ext/numeric.rb +44 -0
- data/lib/garcon/core_ext/object.rb +342 -0
- data/lib/garcon/core_ext/pathname.rb +152 -0
- data/lib/garcon/core_ext/process.rb +41 -0
- data/lib/garcon/core_ext/random.rb +497 -0
- data/lib/garcon/core_ext/string.rb +312 -0
- data/lib/garcon/core_ext/struct.rb +49 -0
- data/lib/garcon/core_ext/symbol.rb +170 -0
- data/lib/garcon/core_ext/time.rb +234 -0
- data/lib/garcon/exceptions.rb +101 -0
- data/lib/garcon/inflections.rb +237 -0
- data/lib/garcon/inflections/defaults.rb +79 -0
- data/lib/garcon/inflections/inflections.rb +182 -0
- data/lib/garcon/inflections/rules_collection.rb +37 -0
- data/lib/garcon/secret.rb +271 -0
- data/lib/garcon/stash/format.rb +114 -0
- data/lib/garcon/stash/journal.rb +226 -0
- data/lib/garcon/stash/queue.rb +83 -0
- data/lib/garcon/stash/serializer.rb +86 -0
- data/lib/garcon/stash/store.rb +435 -0
- data/lib/garcon/task.rb +31 -0
- data/lib/garcon/task/atomic.rb +151 -0
- data/lib/garcon/task/atomic_boolean.rb +127 -0
- data/lib/garcon/task/condition.rb +99 -0
- data/lib/garcon/task/copy_on_notify_observer_set.rb +154 -0
- data/lib/garcon/task/copy_on_write_observer_set.rb +153 -0
- data/lib/garcon/task/count_down_latch.rb +92 -0
- data/lib/garcon/task/delay.rb +196 -0
- data/lib/garcon/task/dereferenceable.rb +144 -0
- data/lib/garcon/task/event.rb +119 -0
- data/lib/garcon/task/executor.rb +275 -0
- data/lib/garcon/task/executor_options.rb +59 -0
- data/lib/garcon/task/future.rb +107 -0
- data/lib/garcon/task/immediate_executor.rb +84 -0
- data/lib/garcon/task/ivar.rb +171 -0
- data/lib/garcon/task/lazy_reference.rb +74 -0
- data/lib/garcon/task/monotonic_time.rb +69 -0
- data/lib/garcon/task/obligation.rb +256 -0
- data/lib/garcon/task/observable.rb +101 -0
- data/lib/garcon/task/priority_queue.rb +234 -0
- data/lib/garcon/task/processor_count.rb +128 -0
- data/lib/garcon/task/read_write_lock.rb +304 -0
- data/lib/garcon/task/safe_task_executor.rb +58 -0
- data/lib/garcon/task/single_thread_executor.rb +97 -0
- data/lib/garcon/task/thread_pool/cached.rb +71 -0
- data/lib/garcon/task/thread_pool/executor.rb +294 -0
- data/lib/garcon/task/thread_pool/fixed.rb +61 -0
- data/lib/garcon/task/thread_pool/worker.rb +90 -0
- data/lib/garcon/task/timer.rb +44 -0
- data/lib/garcon/task/timer_set.rb +194 -0
- data/lib/garcon/task/timer_task.rb +377 -0
- data/lib/garcon/task/waitable_list.rb +58 -0
- data/lib/garcon/utility/ansi.rb +199 -0
- data/lib/garcon/utility/at_random.rb +77 -0
- data/lib/garcon/utility/crypto.rb +292 -0
- data/lib/garcon/utility/equalizer.rb +146 -0
- data/lib/garcon/utility/faker/extensions/array.rb +22 -0
- data/lib/garcon/utility/faker/extensions/symbol.rb +9 -0
- data/lib/garcon/utility/faker/faker.rb +164 -0
- data/lib/garcon/utility/faker/faker/company.rb +17 -0
- data/lib/garcon/utility/faker/faker/hacker.rb +30 -0
- data/lib/garcon/utility/faker/faker/version.rb +3 -0
- data/lib/garcon/utility/faker/locales/en-US.yml +83 -0
- data/lib/garcon/utility/faker/locales/en.yml +21 -0
- data/lib/garcon/utility/file_helper.rb +170 -0
- data/lib/garcon/utility/hookers.rb +178 -0
- data/lib/garcon/utility/interpolation.rb +90 -0
- data/lib/garcon/utility/memstash.rb +364 -0
- data/lib/garcon/utility/misc.rb +54 -0
- data/lib/garcon/utility/msg_from_god.rb +62 -0
- data/lib/garcon/utility/retry.rb +238 -0
- data/lib/garcon/utility/timeout.rb +58 -0
- data/lib/garcon/utility/uber/builder.rb +91 -0
- data/lib/garcon/utility/uber/callable.rb +7 -0
- data/lib/garcon/utility/uber/delegates.rb +13 -0
- data/lib/garcon/utility/uber/inheritable_attr.rb +37 -0
- data/lib/garcon/utility/uber/options.rb +101 -0
- data/lib/garcon/utility/uber/uber_version.rb +3 -0
- data/lib/garcon/utility/uber/version.rb +33 -0
- data/lib/garcon/utility/url_helper.rb +100 -0
- data/lib/garcon/utils.rb +29 -0
- data/lib/garcon/version.rb +62 -0
- data/lib/garcun.rb +24 -0
- metadata +680 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
|
4
|
+
# License: Apache License, Version 2.0
|
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
|
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 'garcon'
|
|
21
|
+
|
|
22
|
+
class Chef
|
|
23
|
+
class Resource
|
|
24
|
+
class Development < Chef::Resource
|
|
25
|
+
include Garcon
|
|
26
|
+
|
|
27
|
+
# Chef attributes
|
|
28
|
+
identity_attr :name
|
|
29
|
+
provides :development
|
|
30
|
+
|
|
31
|
+
# Actions
|
|
32
|
+
actions :run
|
|
33
|
+
default_action :run
|
|
34
|
+
|
|
35
|
+
# Attributes
|
|
36
|
+
attribute :name,
|
|
37
|
+
kind_of: String
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class Provider
|
|
42
|
+
class Development < Chef::Provider
|
|
43
|
+
include Garcon
|
|
44
|
+
|
|
45
|
+
# Shortcut to new_resource.
|
|
46
|
+
#
|
|
47
|
+
alias_method :r, :new_resource
|
|
48
|
+
|
|
49
|
+
# Boolean indicating if WhyRun is supported by this provider
|
|
50
|
+
#
|
|
51
|
+
# @return [TrueClass, FalseClass]
|
|
52
|
+
#
|
|
53
|
+
# @api private
|
|
54
|
+
def whyrun_supported?
|
|
55
|
+
true
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Load and return the current resource.
|
|
59
|
+
#
|
|
60
|
+
# @return [Chef::Provider::Civilize]
|
|
61
|
+
#
|
|
62
|
+
# @api private
|
|
63
|
+
def load_current_resource
|
|
64
|
+
@current_resource ||= Chef::Resource::Development.new(r.name)
|
|
65
|
+
@current_resource
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def action_run
|
|
69
|
+
chef_handler
|
|
70
|
+
install_gem('pry')
|
|
71
|
+
Chef::Recipe.send(:require, 'pry')
|
|
72
|
+
install_gem('awesome_print')
|
|
73
|
+
Chef::Recipe.send(:require, 'ap')
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private # P R O P R I E T À P R I V A T A Vietato L'accesso
|
|
77
|
+
|
|
78
|
+
def chef_handler
|
|
79
|
+
include_recipe 'chef_handler::default'
|
|
80
|
+
|
|
81
|
+
file = ::File.join(node[:chef_handler][:handler_path], 'devreporter.rb')
|
|
82
|
+
f ||= Chef::Resource::CookbookFile.new(file, run_context)
|
|
83
|
+
f.cookbook 'garcon'
|
|
84
|
+
f.backup false
|
|
85
|
+
f.owner 'root'
|
|
86
|
+
f.group 'root'
|
|
87
|
+
f.mode 00600
|
|
88
|
+
f.run_action :create
|
|
89
|
+
|
|
90
|
+
h ||= Chef::Resource::ChefHandler.new('DevReporter', run_context)
|
|
91
|
+
h.source file
|
|
92
|
+
h.supports report: true, exception: true
|
|
93
|
+
h.run_action :enable
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def install_gem(name)
|
|
97
|
+
g ||= Chef::Resource::ChefGem.new(name, run_context)
|
|
98
|
+
g.compile_time(false) if respond_to?(:compile_time)
|
|
99
|
+
g.not_if { gem_installed?(name) }
|
|
100
|
+
g.run_action :install
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Chef::Platform mapping for resource and providers
|
|
107
|
+
#
|
|
108
|
+
# @return [undefined]
|
|
109
|
+
#
|
|
110
|
+
# @api private.
|
|
111
|
+
Chef::Platform.set(
|
|
112
|
+
platform: :amazon,
|
|
113
|
+
resource: :civilize,
|
|
114
|
+
provider: Chef::Provider::Civilize
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# Chef::Platform mapping for resource and providers
|
|
118
|
+
#
|
|
119
|
+
# @return [undefined]
|
|
120
|
+
#
|
|
121
|
+
# @api private.
|
|
122
|
+
Chef::Platform.set(
|
|
123
|
+
platform: :centos,
|
|
124
|
+
resource: :civilize,
|
|
125
|
+
provider: Chef::Provider::Civilize
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
# Chef::Platform mapping for resource and providers
|
|
129
|
+
#
|
|
130
|
+
# @return [undefined]
|
|
131
|
+
#
|
|
132
|
+
# @api private.
|
|
133
|
+
Chef::Platform.set(
|
|
134
|
+
platform: :oracle,
|
|
135
|
+
resource: :civilize,
|
|
136
|
+
provider: Chef::Provider::Civilize
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# Chef::Platform mapping for resource and providers
|
|
140
|
+
#
|
|
141
|
+
# @return [undefined]
|
|
142
|
+
#
|
|
143
|
+
# @api private.
|
|
144
|
+
Chef::Platform.set(
|
|
145
|
+
platform: :redhat,
|
|
146
|
+
resource: :civilize,
|
|
147
|
+
provider: Chef::Provider::Civilize
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# Chef::Platform mapping for resource and providers
|
|
151
|
+
#
|
|
152
|
+
# @return [undefined]
|
|
153
|
+
#
|
|
154
|
+
# @api private.
|
|
155
|
+
Chef::Platform.set(
|
|
156
|
+
platform: :scientific,
|
|
157
|
+
resource: :civilize,
|
|
158
|
+
provider: Chef::Provider::Civilize
|
|
159
|
+
)
|
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
#
|
|
3
|
+
# Author: Stefano Harding <riddopic@gmail.com>
|
|
4
|
+
# License: Apache License, Version 2.0
|
|
5
|
+
# Copyright: (C) 2014-2015 Stefano Harding
|
|
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 'garcon'
|
|
21
|
+
|
|
22
|
+
class Chef
|
|
23
|
+
class Resource
|
|
24
|
+
class Download < Chef::Resource
|
|
25
|
+
include Garcon
|
|
26
|
+
|
|
27
|
+
# Chef attributes
|
|
28
|
+
identity_attr :path
|
|
29
|
+
provides :download
|
|
30
|
+
state_attrs :checksum, :owner, :group, :mode
|
|
31
|
+
|
|
32
|
+
# Actions
|
|
33
|
+
actions :create, :create_if_missing, :delete, :touch
|
|
34
|
+
default_action :create
|
|
35
|
+
|
|
36
|
+
# Attributes
|
|
37
|
+
attribute :path,
|
|
38
|
+
kind_of: String,
|
|
39
|
+
name_attribute: true
|
|
40
|
+
attribute :source,
|
|
41
|
+
kind_of: [String, URI::HTTP],
|
|
42
|
+
callbacks: source_callbacks,
|
|
43
|
+
required: true
|
|
44
|
+
attribute :backup,
|
|
45
|
+
kind_of: [Integer, FalseClass],
|
|
46
|
+
default: 5
|
|
47
|
+
attribute :checksum,
|
|
48
|
+
kind_of: String,
|
|
49
|
+
regex: /^[0-9a-f]{32}$|^[a-zA-Z0-9]{40,64}$/
|
|
50
|
+
attribute :connections,
|
|
51
|
+
kind_of: Integer,
|
|
52
|
+
default: 8
|
|
53
|
+
attribute :owner,
|
|
54
|
+
kind_of: [String, Integer],
|
|
55
|
+
regex: Chef::Config[:user_valid_regex]
|
|
56
|
+
attribute :group,
|
|
57
|
+
kind_of: [String, Integer],
|
|
58
|
+
regex: Chef::Config[:group_valid_regex]
|
|
59
|
+
attribute :mode,
|
|
60
|
+
kind_of: [String, Integer],
|
|
61
|
+
regex: /^0?\d{3,4}$/
|
|
62
|
+
attribute :check_cert,
|
|
63
|
+
kind_of: [TrueClass, FalseClass],
|
|
64
|
+
default: true
|
|
65
|
+
attribute :header,
|
|
66
|
+
kind_of: String,
|
|
67
|
+
default: nil
|
|
68
|
+
|
|
69
|
+
# @!attribute [rw] installed
|
|
70
|
+
# @return [TrueClass, FalseClass] True if resource exists.
|
|
71
|
+
attr_accessor :exist
|
|
72
|
+
|
|
73
|
+
# Determine if the resource exists. This value is set by the provider
|
|
74
|
+
# when the current resource is loaded.
|
|
75
|
+
#
|
|
76
|
+
# @see Dsccsetup#action_create
|
|
77
|
+
#
|
|
78
|
+
# @return [Boolean]
|
|
79
|
+
#
|
|
80
|
+
# @api public
|
|
81
|
+
def exist?
|
|
82
|
+
!!@exist
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
class Provider
|
|
88
|
+
class Download < Chef::Provider
|
|
89
|
+
include Chef::Mixin::EnforceOwnershipAndPermissions
|
|
90
|
+
include Chef::Mixin::Checksum
|
|
91
|
+
include Garcon
|
|
92
|
+
|
|
93
|
+
def initialize(name, run_context = nil)
|
|
94
|
+
super
|
|
95
|
+
@resource_name = :download
|
|
96
|
+
@provider = Chef::Provider::Download
|
|
97
|
+
@ready = AtomicBoolean.new(installed?('aria2c'))
|
|
98
|
+
@lock = ReadWriteLock.new
|
|
99
|
+
|
|
100
|
+
make_ready unless ready?
|
|
101
|
+
poll(300) { ready? }
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Shortcut to new_resource.
|
|
105
|
+
#
|
|
106
|
+
alias_method :r, :new_resource
|
|
107
|
+
|
|
108
|
+
# Boolean indicating if WhyRun is supported by this provider
|
|
109
|
+
#
|
|
110
|
+
# @return [TrueClass, FalseClass]
|
|
111
|
+
#
|
|
112
|
+
# @api private
|
|
113
|
+
def whyrun_supported?
|
|
114
|
+
true
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Reload the resource state when something changes
|
|
118
|
+
#
|
|
119
|
+
# @return [undefined]
|
|
120
|
+
#
|
|
121
|
+
# @api private
|
|
122
|
+
def load_new_resource_state
|
|
123
|
+
r.exist = @current_resource.exist if r.exist.nil?
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Load and return the current resource.
|
|
127
|
+
#
|
|
128
|
+
# @return [Chef::Provider::Download]
|
|
129
|
+
#
|
|
130
|
+
# @api private
|
|
131
|
+
def load_current_resource
|
|
132
|
+
@current_resource ||= Chef::Resource::Download.new(r.name)
|
|
133
|
+
@current_resource.path(r.path)
|
|
134
|
+
|
|
135
|
+
if ::File.exist?(@current_resource.path)
|
|
136
|
+
@current_resource.checksum(checksum(@current_resource.path))
|
|
137
|
+
if @current_resource.checksum == r.checksum
|
|
138
|
+
@current_resource.exist = true
|
|
139
|
+
else
|
|
140
|
+
@current_resource.exist = false
|
|
141
|
+
end
|
|
142
|
+
else
|
|
143
|
+
@current_resource.exist = false
|
|
144
|
+
end
|
|
145
|
+
@current_resource
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Default, download the specified source file if it does not exist. If a
|
|
149
|
+
# file already exists (but does not match), use to update that file to
|
|
150
|
+
# match.
|
|
151
|
+
#
|
|
152
|
+
# @return [undefined]
|
|
153
|
+
#
|
|
154
|
+
# @api public
|
|
155
|
+
def action_create
|
|
156
|
+
if @current_resource.exist? && !access_controls.requires_changes?
|
|
157
|
+
Chef::Log.debug "#{r.path} already exists - nothing to do"
|
|
158
|
+
|
|
159
|
+
elsif @current_resource.exist? && access_controls.requires_changes?
|
|
160
|
+
converge_by(access_controls.describe_changes) do
|
|
161
|
+
access_controls.set_all
|
|
162
|
+
end
|
|
163
|
+
r.updated_by_last_action(true)
|
|
164
|
+
|
|
165
|
+
else
|
|
166
|
+
converge_by "Download #{r.path}" do
|
|
167
|
+
backup unless ::File.symlink?(r.path)
|
|
168
|
+
do_download
|
|
169
|
+
end
|
|
170
|
+
do_acl_changes
|
|
171
|
+
load_resource_attributes_from_file(r)
|
|
172
|
+
r.updated_by_last_action(true)
|
|
173
|
+
load_new_resource_state
|
|
174
|
+
r.exist = true
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
alias_method :action_create_if_missing, :action_create
|
|
179
|
+
|
|
180
|
+
# Use to delete a file.
|
|
181
|
+
#
|
|
182
|
+
# @return [undefined]
|
|
183
|
+
#
|
|
184
|
+
# @api public
|
|
185
|
+
def action_delete
|
|
186
|
+
if @current_resource.exist?
|
|
187
|
+
converge_by "Delete #{r.path}" do
|
|
188
|
+
backup unless ::File.symlink?(r.path)
|
|
189
|
+
::File.delete(r.path)
|
|
190
|
+
end
|
|
191
|
+
r.updated_by_last_action(true)
|
|
192
|
+
load_new_resource_state
|
|
193
|
+
r.exist = false
|
|
194
|
+
else
|
|
195
|
+
Chef::Log.debug "#{r.path} does not exists - nothing to do"
|
|
196
|
+
end
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# Use to touch a file. This updates the access (atime) and file
|
|
200
|
+
# modification (mtime) times for a file. (This action may be used with
|
|
201
|
+
# this resource, but is typically only used with the file resource.)
|
|
202
|
+
#
|
|
203
|
+
# @return [undefined]
|
|
204
|
+
#
|
|
205
|
+
# @api public
|
|
206
|
+
def action_touch
|
|
207
|
+
if @current_resource.exist?
|
|
208
|
+
converge_by "Update utime on #{r.path}" do
|
|
209
|
+
time = Time.now
|
|
210
|
+
::File.utime(time, time, r.path)
|
|
211
|
+
end
|
|
212
|
+
r.updated_by_last_action(true)
|
|
213
|
+
load_new_resource_state
|
|
214
|
+
r.exist = true
|
|
215
|
+
else
|
|
216
|
+
Chef::Log.debug "#{r.path} does not exists - nothing to do"
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
# Implementation components *should* follow symlinks when managing access
|
|
221
|
+
# control (e.g., use chmod instead of lchmod even if the path we're
|
|
222
|
+
# managing is a symlink).
|
|
223
|
+
#
|
|
224
|
+
def manage_symlink_access?
|
|
225
|
+
false
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
private # P R O P R I E T À P R I V A T A Vietato L'accesso
|
|
229
|
+
|
|
230
|
+
# Handle the download action.
|
|
231
|
+
#
|
|
232
|
+
# @return [undefined]
|
|
233
|
+
#
|
|
234
|
+
# @api private
|
|
235
|
+
def do_create
|
|
236
|
+
if @current_resource.exist? && !access_controls.requires_changes?
|
|
237
|
+
Chef::Log.debug "#{r.path} already exists - nothing to do"
|
|
238
|
+
|
|
239
|
+
elsif @current_resource.exist? && access_controls.requires_changes?
|
|
240
|
+
converge_by(access_controls.describe_changes) do
|
|
241
|
+
access_controls.set_all
|
|
242
|
+
end
|
|
243
|
+
r.updated_by_last_action(true)
|
|
244
|
+
|
|
245
|
+
else
|
|
246
|
+
converge_by "Download #{r.path}" do
|
|
247
|
+
backup unless ::File.symlink?(r.path)
|
|
248
|
+
do_download
|
|
249
|
+
end
|
|
250
|
+
do_acl_changes
|
|
251
|
+
load_resource_attributes_from_file(r)
|
|
252
|
+
r.updated_by_last_action(true)
|
|
253
|
+
load_new_resource_state
|
|
254
|
+
r.exist = true
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
# Change file ownership and mode.
|
|
259
|
+
#
|
|
260
|
+
# @return [undefined]
|
|
261
|
+
#
|
|
262
|
+
# @api private
|
|
263
|
+
def do_acl_changes
|
|
264
|
+
if access_controls.requires_changes?
|
|
265
|
+
converge_by(access_controls.describe_changes) do
|
|
266
|
+
access_controls.set_all
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# Reads Access Control Settings on a file and writes them out to a
|
|
272
|
+
# resource, attempting to match the style used by the new resource, that
|
|
273
|
+
# is, if users are specified with usernames in new_resource, then the
|
|
274
|
+
# uids from stat will be looked up and usernames will be added to
|
|
275
|
+
# current_resource.
|
|
276
|
+
#
|
|
277
|
+
# @return [undefined]
|
|
278
|
+
#
|
|
279
|
+
# @api private
|
|
280
|
+
def load_resource_attributes_from_file(resource)
|
|
281
|
+
acl_scanner = Chef::ScanAccessControl.new(@new_resource, resource)
|
|
282
|
+
acl_scanner.set_all!
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# Gather options to download file.
|
|
286
|
+
#
|
|
287
|
+
# @return [Array]
|
|
288
|
+
#
|
|
289
|
+
# @api private
|
|
290
|
+
def args(args = [])
|
|
291
|
+
args << "--out=#{::File.basename(r.path)}"
|
|
292
|
+
args << "--dir=#{::File.dirname(r.path)}"
|
|
293
|
+
args << "--checksum=sha-256=#{r.checksum}" if r.checksum
|
|
294
|
+
args << "--header='#{r.header}'" if r.header
|
|
295
|
+
args << "--check-certificate=#{r.check_cert}"
|
|
296
|
+
args << "--file-allocation=falloc"
|
|
297
|
+
args << "--max-connection-per-server=#{r.connections}"
|
|
298
|
+
args << r.source
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
# Command line executioner for running aria2.
|
|
302
|
+
#
|
|
303
|
+
# @return [undefined]
|
|
304
|
+
#
|
|
305
|
+
# @api private
|
|
306
|
+
def do_download
|
|
307
|
+
retrier(tries: 10, sleep: ->(n) { 4**n }) { installed?('aria2') }
|
|
308
|
+
cmd = [which('aria2c')] << args.flatten.join(' ')
|
|
309
|
+
Chef::Log.info shell_out!(cmd.flatten.join(' ')).stdout
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
# Backup the file before overwriting or replacing it unless
|
|
313
|
+
# `new_resource.backup` is `false`
|
|
314
|
+
#
|
|
315
|
+
# @return [undefined]
|
|
316
|
+
#
|
|
317
|
+
# @api private
|
|
318
|
+
def backup(file = nil)
|
|
319
|
+
Chef::Util::Backup.new(new_resource, file).backup!
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
def ready?
|
|
323
|
+
@ready.value
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
def make_ready
|
|
327
|
+
return true if @ready.value == true
|
|
328
|
+
@lock.with_write_lock { handle_prerequisites }
|
|
329
|
+
installed?('aria2c') ? @ready.make_true : @ready.make_false
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
def handle_prerequisites
|
|
333
|
+
package 'gnutls', :install
|
|
334
|
+
yumrepo :create
|
|
335
|
+
package 'aria2', :install
|
|
336
|
+
wipe_repo
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
def package(name, action = :nothing)
|
|
340
|
+
p = Chef::Resource::Package.new(name, run_context)
|
|
341
|
+
p.retries 30
|
|
342
|
+
p.retry_delay 10
|
|
343
|
+
p.run_action action
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
def yumrepo(action = :nothing)
|
|
347
|
+
y = Chef::Resource::YumRepository.new('garcon', run_context)
|
|
348
|
+
y.mirrorlist node[:garcon][:repo][:mirrorlist]
|
|
349
|
+
y.gpgcheck node[:garcon][:repo][:gpgcheck]
|
|
350
|
+
y.gpgkey node[:garcon][:repo][:gpgkey]
|
|
351
|
+
y.run_action action
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
def wipe_repo
|
|
355
|
+
# Seems Chef::Resource::YumRepository action :delete is foobared, so
|
|
356
|
+
# nuke the repo another way.
|
|
357
|
+
Future.execute do
|
|
358
|
+
::File.unlink('/etc/yum.repos.d/garcon.repo')
|
|
359
|
+
shell_out!('yum clean all && yum -q makecache')
|
|
360
|
+
Chef::Provider::Package::Yum::YumCache.instance.reload
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
# Chef::Platform mapping for resource and providers
|
|
368
|
+
#
|
|
369
|
+
# @return [undefined]
|
|
370
|
+
#
|
|
371
|
+
# @api private.
|
|
372
|
+
Chef::Platform.set(
|
|
373
|
+
platform: :amazon,
|
|
374
|
+
resource: :download,
|
|
375
|
+
provider: Chef::Provider::Download
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
# Chef::Platform mapping for resource and providers
|
|
379
|
+
#
|
|
380
|
+
# @return [undefined]
|
|
381
|
+
#
|
|
382
|
+
# @api private.
|
|
383
|
+
Chef::Platform.set(
|
|
384
|
+
platform: :centos,
|
|
385
|
+
resource: :download,
|
|
386
|
+
provider: Chef::Provider::Download
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
# Chef::Platform mapping for resource and providers
|
|
390
|
+
#
|
|
391
|
+
# @return [undefined]
|
|
392
|
+
#
|
|
393
|
+
# @api private.
|
|
394
|
+
Chef::Platform.set(
|
|
395
|
+
platform: :oracle,
|
|
396
|
+
resource: :download,
|
|
397
|
+
provider: Chef::Provider::Download
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
# Chef::Platform mapping for resource and providers
|
|
401
|
+
#
|
|
402
|
+
# @return [undefined]
|
|
403
|
+
#
|
|
404
|
+
# @api private.
|
|
405
|
+
Chef::Platform.set(
|
|
406
|
+
platform: :redhat,
|
|
407
|
+
resource: :download,
|
|
408
|
+
provider: Chef::Provider::Download
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
# Chef::Platform mapping for resource and providers
|
|
412
|
+
#
|
|
413
|
+
# @return [undefined]
|
|
414
|
+
#
|
|
415
|
+
# @api private.
|
|
416
|
+
Chef::Platform.set(
|
|
417
|
+
platform: :scientific,
|
|
418
|
+
resource: :download,
|
|
419
|
+
provider: Chef::Provider::Download
|
|
420
|
+
)
|