forked from puppetlabs/bolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(puppetlabsGH-1244) Serialize plan variables as pcore
There are 4 custom types in the Bolt plan language that we want to make available inside apply blocks: Target, Result, ResultSet, ApplyResult. For each of the *Result* objects this is accomplished by serializing the plan variables to the apply block as pcore instead of as json. We also needed to add pcore_init methods to the implementation classes of the objects, because the pcore deserializer will by default call `initialize` on the class and pass in the values of the attributes of the type, which doesn't match the signature of the actual implementations. Using `_pcore_init_hash` and `_pcore_init_from_hash` lets us define what data gets serialized and how it gets deserialized for those types. Target objects are trickier for a few reasons: 1. They must have an associate inventory 2. ... Stil TODO: - [] Future proof - [] Tests - [] Docs - [] Threading
- Loading branch information
Showing
8 changed files
with
171 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
Puppet::DataTypes.create_type('ApplyTarget') do | ||
load_file('bolt/apply_target') | ||
interface <<-PUPPET | ||
attributes => { | ||
'target_hash' => Hash | ||
}, | ||
functions => { | ||
uri => Callable[[], String[1]], | ||
name => Callable[[], String[1]], | ||
target_alias => Callable[[], Optional[String]], | ||
config => Callable[[], Optional[Hash[String[1], Data]]], | ||
vars => Callable[[], Optional[Hash[String[1], Data]]], | ||
facts => Callable[[], Optional[Hash[String[1], Data]]], | ||
features => Callable[[], Optional[Array[String[1]]]], | ||
plugin_hooks => Callable[[], Optional[Hash[String[1], Data]]], | ||
safe_name => Callable[[], String[1]], | ||
host => Callable[[], Optional[String]], | ||
password => Callable[[], Optional[String[1]]], | ||
port => Callable[[], Optional[Integer]], | ||
protocol => Callable[[], Optional[String[1]]], | ||
user => Callable[[], Optional[String[1]]], | ||
} | ||
PUPPET | ||
|
||
implementation_class Bolt::ApplyTarget | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bolt | ||
# Alt: ReadOnlyTarget | ||
class ApplyTarget | ||
# Should this be memoized instead? | ||
ATTRIBUTES ||= %i[uri name target_alias config vars facts features | ||
plugin_hooks safe_name host password port protocol user].freeze | ||
|
||
attr_reader *ATTRIBUTES, :target_hash | ||
|
||
# Puppet calls this method when it needs an instance of this type | ||
def self.from_asserted_hash(target_hash) | ||
new(target_hash) | ||
end | ||
|
||
def self.from_asserted_args(target_hash) | ||
new(target_hash) | ||
end | ||
|
||
def initialize(target_hash) | ||
# TODO: Do we actually need this? | ||
@target_hash = target_hash | ||
ATTRIBUTES.each do |attr| | ||
instance_variable_set("@#{attr}", target_hash[attr.to_s]) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters