summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-05 10:19:27 -0800
committerTim Smith <tsmith@chef.io>2018-03-05 20:55:05 -0800
commitdc4b862b11365f7cb71a58c8f48aa9e1b1921b27 (patch)
tree465f0a74a0be62bd9b228d43e13f78abe61879f9
parent86a8e51cf16d87cbc57c2635324ab8a8a04a49d9 (diff)
downloadchef-more_properties.tar.gz
Convert more set_or_returns to proper propertiesmore_properties
Just modernizing our resources so we can start to add descriptions to them for the documentation Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--lib/chef/resource/cron.rb10
-rw-r--r--lib/chef/resource/dsc_resource.rb16
-rw-r--r--lib/chef/resource/dsc_script.rb35
-rw-r--r--lib/chef/resource/execute.rb82
-rw-r--r--lib/chef/resource/group.rb48
-rw-r--r--lib/chef/resource/http_request.rb23
-rw-r--r--lib/chef/resource/link.rb53
-rw-r--r--lib/chef/resource/ruby_block.rb15
-rw-r--r--lib/chef/resource/scm.rb58
9 files changed, 38 insertions, 302 deletions
diff --git a/lib/chef/resource/cron.rb b/lib/chef/resource/cron.rb
index f6c009058c..32c47b963f 100644
--- a/lib/chef/resource/cron.rb
+++ b/lib/chef/resource/cron.rb
@@ -18,6 +18,7 @@
#
require "chef/resource"
+require "chef/provider/cron" # do not remove. we actually need this below
class Chef
class Resource
@@ -135,14 +136,7 @@ class Chef
)
end
- def time(arg = nil)
- set_or_return(
- :time,
- arg,
- :equal_to => Chef::Provider::Cron::SPECIAL_TIME_VALUES
- )
- end
-
+ property :time, Symbol, equal_to: Chef::Provider::Cron::SPECIAL_TIME_VALUES
property :mailto, String
property :path, String
property :home, String
diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb
index 95ee32c946..3f7fc17901 100644
--- a/lib/chef/resource/dsc_resource.rb
+++ b/lib/chef/resource/dsc_resource.rb
@@ -74,13 +74,7 @@ class Chef
end
end
- def module_version(arg = nil)
- set_or_return(
- :module_version,
- arg,
- :kind_of => [ String ]
- )
- end
+ property :module_version, String
def property(property_name, value = nil)
if not property_name.is_a?(Symbol)
@@ -113,13 +107,7 @@ class Chef
end
end
- def timeout(arg = nil)
- set_or_return(
- :timeout,
- arg,
- :kind_of => [ Integer ]
- )
- end
+ property :timeout, Integer
private
diff --git a/lib/chef/resource/dsc_script.rb b/lib/chef/resource/dsc_script.rb
index 45372c091a..f64780e2bc 100644
--- a/lib/chef/resource/dsc_script.rb
+++ b/lib/chef/resource/dsc_script.rb
@@ -114,37 +114,10 @@ class Chef
end
end
- def flags(arg = nil)
- set_or_return(
- :flags,
- arg,
- :kind_of => [ Hash ]
- )
- end
-
- def cwd(arg = nil)
- set_or_return(
- :cwd,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def environment(arg = nil)
- set_or_return(
- :environment,
- arg,
- :kind_of => [ Hash ]
- )
- end
-
- def timeout(arg = nil)
- set_or_return(
- :timeout,
- arg,
- :kind_of => [ Integer ]
- )
- end
+ property :flags, Hash
+ property :cwd, String
+ property :environment, Hash
+ property :timeout, Integer
end
end
end
diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb
index 0c1b187ed0..f8baedd082 100644
--- a/lib/chef/resource/execute.rb
+++ b/lib/chef/resource/execute.rb
@@ -43,25 +43,8 @@ class Chef
super
@command = name
@backup = 5
- @creates = nil
- @cwd = nil
- @environment = nil
- @group = nil
- @returns = 0
- @timeout = nil
- @user = nil
- @umask = nil
@default_guard_interpreter = :execute
@is_guard_interpreter = false
- @live_stream = false
- end
-
- def umask(arg = nil)
- set_or_return(
- :umask,
- arg,
- :kind_of => [ String, Integer ]
- )
end
def command(arg = nil)
@@ -71,68 +54,19 @@ class Chef
:kind_of => [ String, Array ]
)
end
-
- def creates(arg = nil)
- set_or_return(
- :creates,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def cwd(arg = nil)
- set_or_return(
- :cwd,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def environment(arg = nil)
- set_or_return(
- :environment,
- arg,
- :kind_of => [ Hash ]
- )
- end
+ property :umask, [ String, Integer ]
+ property :creates, String
+ property :cwd, String
+ property :environment, Hash
alias :env :environment
- def group(arg = nil)
- set_or_return(
- :group,
- arg,
- :kind_of => [ String, Integer ]
- )
- end
-
- def live_stream(arg = nil)
- set_or_return(
- :live_stream,
- arg,
- :kind_of => [ TrueClass, FalseClass ])
- end
-
- def returns(arg = nil)
- set_or_return(
- :returns,
- arg,
- :kind_of => [ Integer, Array ]
- )
- end
-
- def timeout(arg = nil)
- set_or_return(
- :timeout,
- arg,
- :kind_of => [ Integer, Float ]
- )
- end
-
+ property :group, [ String, Integer ]
+ property :live_stream, [ TrueClass, FalseClass ], default: false
+ property :returns, [ Integer, Array ], default: 0
+ property :timeout, [ Integer, Float ]
property :user, [ String, Integer ]
-
property :domain, String
-
property :password, String, sensitive: true
# lazy used to set default value of sensitive to true if password is set
diff --git a/lib/chef/resource/group.rb b/lib/chef/resource/group.rb
index 79a234cb54..9298fbc150 100644
--- a/lib/chef/resource/group.rb
+++ b/lib/chef/resource/group.rb
@@ -20,7 +20,6 @@
class Chef
class Resource
class Group < Chef::Resource
- identity_attr :group_name
state_attrs :members
description "Use the group resource to manage a local group."
@@ -30,29 +29,12 @@ class Chef
def initialize(name, run_context = nil)
super
- @group_name = name
- @gid = nil
@members = []
@excluded_members = []
- @append = false
- @non_unique = false
end
- def group_name(arg = nil)
- set_or_return(
- :group_name,
- arg,
- :kind_of => [ String ]
- )
- end
-
- def gid(arg = nil)
- set_or_return(
- :gid,
- arg,
- :kind_of => [ String, Integer ]
- )
- end
+ property :group_name, String, name_property: true, identity: true
+ property :gid, [ String, Integer ]
def members(arg = nil)
converted_members = arg.is_a?(String) ? arg.split(",") : arg
@@ -74,29 +56,9 @@ class Chef
)
end
- def append(arg = nil)
- set_or_return(
- :append,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
-
- def system(arg = nil)
- set_or_return(
- :system,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
-
- def non_unique(arg = nil)
- set_or_return(
- :non_unique,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
+ property :append, [ TrueClass, FalseClass ], default: false
+ property :system, [ TrueClass, FalseClass ], default: false
+ property :non_unique, [ TrueClass, FalseClass ], default: false
end
end
end
diff --git a/lib/chef/resource/http_request.rb b/lib/chef/resource/http_request.rb
index d3b782ea12..fd9e3636b1 100644
--- a/lib/chef/resource/http_request.rb
+++ b/lib/chef/resource/http_request.rb
@@ -24,8 +24,6 @@ class Chef
class Resource
class HttpRequest < Chef::Resource
- identity_attr :url
-
description "Use the http_request resource to send an HTTP request (GET, PUT,"\
" POST, DELETE, HEAD, or OPTIONS) with an arbitrary message. This"\
" resource is often useful when custom callbacks are necessary."
@@ -33,19 +31,12 @@ class Chef
default_action :get
allowed_actions :get, :patch, :put, :post, :delete, :head, :options
+ property :url, String, identity: true
+ property :headers, Hash, default: {}
+
def initialize(name, run_context = nil)
super
@message = name
- @url = nil
- @headers = {}
- end
-
- def url(args = nil)
- set_or_return(
- :url,
- args,
- :kind_of => String
- )
end
def message(args = nil, &block)
@@ -57,14 +48,6 @@ class Chef
)
end
- def headers(args = nil)
- set_or_return(
- :headers,
- args,
- :kind_of => Hash
- )
- end
-
end
end
end
diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb
index d51d42b506..b3f8819d2b 100644
--- a/lib/chef/resource/link.rb
+++ b/lib/chef/resource/link.rb
@@ -35,10 +35,9 @@ class Chef
class Link < Chef::Resource
include Chef::Mixin::Securable
resource_name :link
+ provides :link
- identity_attr :target_file
-
- state_attrs :to, :owner, :group
+ state_attrs :owner # required since it's not a property below
default_action :create
allowed_actions :create, :delete
@@ -46,51 +45,13 @@ class Chef
def initialize(name, run_context = nil)
verify_links_supported!
super
- @to = nil
- @link_type = :symbolic
- @target_file = name
- end
-
- def to(arg = nil)
- set_or_return(
- :to,
- arg,
- :kind_of => String
- )
- end
-
- def target_file(arg = nil)
- set_or_return(
- :target_file,
- arg,
- :kind_of => String
- )
end
- def link_type(arg = nil)
- real_arg = arg.kind_of?(String) ? arg.to_sym : arg
- set_or_return(
- :link_type,
- real_arg,
- :equal_to => [ :symbolic, :hard ]
- )
- end
-
- def group(arg = nil)
- set_or_return(
- :group,
- arg,
- :regex => Chef::Config[:group_valid_regex]
- )
- end
-
- def owner(arg = nil)
- set_or_return(
- :owner,
- arg,
- :regex => Chef::Config[:user_valid_regex]
- )
- end
+ property :target_file, String, name_property: true, identity: true
+ property :to, String
+ property :link_type, [String, Symbol], coerce: proc { |arg| arg.kind_of?(String) ? arg.to_sym : arg }, equal_to: [ :symbolic, :hard ], default: :symbolic
+ property :group, [String, Integer], regex: [Chef::Config[:group_valid_regex]]
+ property :user, [String, Integer], regex: [Chef::Config[:user_valid_regex]]
# make link quack like a file (XXX: not for public consumption)
def path
diff --git a/lib/chef/resource/ruby_block.rb b/lib/chef/resource/ruby_block.rb
index 89b90ae70b..a3cb9e56e5 100644
--- a/lib/chef/resource/ruby_block.rb
+++ b/lib/chef/resource/ruby_block.rb
@@ -29,13 +29,6 @@ class Chef
default_action :run
allowed_actions :create, :run
- identity_attr :block_name
-
- def initialize(name, run_context = nil)
- super
- @block_name = name
- end
-
def block(&block)
if block_given? && block
@block = block
@@ -44,13 +37,7 @@ class Chef
end
end
- def block_name(arg = nil)
- set_or_return(
- :block_name,
- arg,
- :kind_of => String
- )
- end
+ property :block_name, String, name_property: true, identity: true
end
end
end
diff --git a/lib/chef/resource/scm.rb b/lib/chef/resource/scm.rb
index 533723c2c4..178dcca640 100644
--- a/lib/chef/resource/scm.rb
+++ b/lib/chef/resource/scm.rb
@@ -21,8 +21,6 @@ require "chef/resource"
class Chef
class Resource
class Scm < Chef::Resource
- identity_attr :destination
-
state_attrs :revision
default_action :sync
@@ -30,10 +28,8 @@ class Chef
def initialize(name, run_context = nil)
super
- @destination = name
@enable_submodules = false
@enable_checkout = true
- @revision = "HEAD"
@remote = "origin"
@ssh_wrapper = nil
@depth = nil
@@ -41,54 +37,12 @@ class Chef
@environment = nil
end
- def destination(arg = nil)
- set_or_return(
- :destination,
- arg,
- :kind_of => String
- )
- end
-
- def repository(arg = nil)
- set_or_return(
- :repository,
- arg,
- :kind_of => String
- )
- end
-
- def revision(arg = nil)
- set_or_return(
- :revision,
- arg,
- :kind_of => String
- )
- end
-
- def user(arg = nil)
- set_or_return(
- :user,
- arg,
- :kind_of => [String, Integer]
- )
- end
-
- def group(arg = nil)
- set_or_return(
- :group,
- arg,
- :kind_of => [String, Integer]
- )
- end
-
- def svn_username(arg = nil)
- set_or_return(
- :svn_username,
- arg,
- :kind_of => String
- )
- end
-
+ property :destination, String, name_property: true, identity: true
+ property :repository, String
+ property :revision, String, default: "HEAD"
+ property :user, [String, Integer]
+ property :group, [String, Integer]
+ property :svn_username, String
property :svn_password, String, sensitive: true, desired_state: false
def svn_arguments(arg = nil)