Module: Chef::DSL::RestResource
- Defined in:
- lib/chef/dsl/rest_resource.rb
Overview
DSL methods for configuring REST resource behavior. These methods are available when a custom resource uses the 'core::rest_resource' partial.
Instance Method Summary collapse
-
#rest_api_collection(rest_api_collection = NOT_PASSED) ⇒ String
Define the REST API collection URL.
-
#rest_api_document(rest_api_document = NOT_PASSED, first_element_only: false) ⇒ String
Define the REST API document URL with RFC 6570 template support.
- #rest_api_document_first_element_only(rest_api_document_first_element_only = NOT_PASSED) ⇒ Object
-
#rest_identity_map(rest_identity_map = NOT_PASSED) ⇒ Hash?
Define explicit identity mapping for resource identification.
-
#rest_post_only_properties(rest_post_only_properties = NOT_PASSED) ⇒ Array<Symbol>
Declare properties that should only be sent during resource creation.
-
#rest_property_map(rest_property_map = NOT_PASSED) ⇒ Hash
Define property mapping between resource properties and JSON API fields.
Instance Method Details
#rest_api_collection(rest_api_collection = NOT_PASSED) ⇒ String
Define the REST API collection URL
Sets the base URL for the collection of resources. This URL is used for:
- GET requests to list all resources
- POST requests to create new resources
85 86 87 88 89 90 91 92 93 |
# File 'lib/chef/dsl/rest_resource.rb', line 85 def rest_api_collection(rest_api_collection = NOT_PASSED) if rest_api_collection != NOT_PASSED raise ArgumentError, "You must pass an absolute path to rest_api_collection" unless rest_api_collection.start_with? "/" @rest_api_collection = rest_api_collection end @rest_api_collection end |
#rest_api_document(rest_api_document = NOT_PASSED, first_element_only: false) ⇒ String
Define the REST API document URL with RFC 6570 template support
Sets the URL pattern for individual resource documents. The URL can include RFC 6570 URI templates that will be expanded using property values. This URL is used for:
- GET requests to retrieve a specific resource
- PATCH/PUT requests to update a resource
- DELETE requests to remove a resource
133 134 135 136 137 138 139 140 141 |
# File 'lib/chef/dsl/rest_resource.rb', line 133 def rest_api_document(rest_api_document = NOT_PASSED, first_element_only: false) if rest_api_document != NOT_PASSED raise ArgumentError, "You must pass an absolute path to rest_api_document" unless rest_api_document.start_with? "/" @rest_api_document = rest_api_document @rest_api_document_first_element_only = first_element_only end @rest_api_document end |
#rest_api_document_first_element_only(rest_api_document_first_element_only = NOT_PASSED) ⇒ Object
228 229 230 231 232 233 |
# File 'lib/chef/dsl/rest_resource.rb', line 228 def rest_api_document_first_element_only(rest_api_document_first_element_only = NOT_PASSED) if rest_api_document_first_element_only != NOT_PASSED @rest_api_document_first_element_only = rest_api_document_first_element_only end @rest_api_document_first_element_only end |
#rest_identity_map(rest_identity_map = NOT_PASSED) ⇒ Hash?
Define explicit identity mapping for resource identification
Explicitly specifies which JSON fields and resource properties uniquely identify a resource. Use this when automatic identity inference from the document URL is insufficient or when dealing with composite keys.
If not specified, the identity is automatically inferred from RFC 6570 templates in the document URL.
179 180 181 182 |
# File 'lib/chef/dsl/rest_resource.rb', line 179 def rest_identity_map(rest_identity_map = NOT_PASSED) @rest_identity_map = rest_identity_map if rest_identity_map != NOT_PASSED @rest_identity_map end |
#rest_post_only_properties(rest_post_only_properties = NOT_PASSED) ⇒ Array<Symbol>
Declare properties that should only be sent during resource creation
Specifies which properties should only be included in POST (create) requests and excluded from PATCH/PUT (update) requests. This is useful for properties that can only be set during initial creation or would cause errors if included in updates.
221 222 223 224 225 226 |
# File 'lib/chef/dsl/rest_resource.rb', line 221 def rest_post_only_properties(rest_post_only_properties = NOT_PASSED) if rest_post_only_properties != NOT_PASSED @rest_post_only_properties = Array(rest_post_only_properties).map(&:to_sym) end @rest_post_only_properties || [] end |
#rest_property_map(rest_property_map = NOT_PASSED) ⇒ Hash
Define property mapping between resource properties and JSON API fields
Maps resource properties to their corresponding locations in the JSON API payload. Supports both simple 1:1 mappings and complex transformations.
58 59 60 61 62 63 64 65 |
# File 'lib/chef/dsl/rest_resource.rb', line 58 def rest_property_map(rest_property_map = NOT_PASSED) if rest_property_map != NOT_PASSED rest_property_map = rest_property_map.to_h { |k| [k.to_sym, k] } if rest_property_map.is_a? Array @rest_property_map = rest_property_map end @rest_property_map end |