Class: ChefDK::PolicyfileServices::Push
- Inherits:
-
Object
- Object
- ChefDK::PolicyfileServices::Push
- Defined in:
- lib/chef-dk/policyfile_services/push.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#policy_group ⇒ Object
readonly
Returns the value of attribute policy_group.
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
-
#ui ⇒ Object
readonly
Returns the value of attribute ui.
Instance Method Summary collapse
- #http_client ⇒ Object
-
#initialize(policyfile: nil, ui: nil, policy_group: nil, config: nil, root_dir: nil) ⇒ Push
constructor
A new instance of Push.
- #lockfile_path ⇒ Object
- #lockfile_relative_path ⇒ Object
- #policy_data ⇒ Object
- #policyfile_lock ⇒ Object
- #policyfile_path ⇒ Object
- #policyfile_relative_path ⇒ Object
- #run ⇒ Object
- #storage_config ⇒ Object
- #uploader ⇒ Object
Constructor Details
#initialize(policyfile: nil, ui: nil, policy_group: nil, config: nil, root_dir: nil) ⇒ Push
Returns a new instance of Push.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 31 def initialize(policyfile: nil, ui: nil, policy_group: nil, config: nil, root_dir: nil) @root_dir = root_dir @policyfile_relative_path = policyfile @ui = ui @config = config @policy_group = policy_group @http_client = nil @storage_config = nil @policy_data = nil end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
27 28 29 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 27 def config @config end |
#policy_group ⇒ Object (readonly)
Returns the value of attribute policy_group.
28 29 30 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 28 def policy_group @policy_group end |
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
26 27 28 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 26 def root_dir @root_dir end |
#ui ⇒ Object (readonly)
Returns the value of attribute ui.
29 30 31 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 29 def ui @ui end |
Instance Method Details
#http_client ⇒ Object
59 60 61 62 63 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 59 def http_client @http_client ||= ChefDK::AuthenticatedHTTP.new(config.chef_server_url, signing_key_filename: config.client_key, client_name: config.node_name) end |
#lockfile_path ⇒ Object
55 56 57 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 55 def lockfile_path File.(lockfile_relative_path, root_dir) end |
#lockfile_relative_path ⇒ Object
51 52 53 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 51 def lockfile_relative_path policyfile_relative_path.gsub(/\.rb\Z/, '') + ".lock.json" end |
#policy_data ⇒ Object
65 66 67 68 69 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 65 def policy_data @policy_data ||= FFI_Yajl::Parser.parse(IO.read(lockfile_path)) rescue => error raise PolicyfilePushError.new("Error reading lockfile #{lockfile_path}", error) end |
#policyfile_lock ⇒ Object
90 91 92 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 90 def policyfile_lock @policyfile_lock || validate_lockfile end |
#policyfile_path ⇒ Object
47 48 49 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 47 def policyfile_path File.(policyfile_relative_path, root_dir) end |
#policyfile_relative_path ⇒ Object
43 44 45 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 43 def policyfile_relative_path @policyfile_relative_path || "Policyfile.rb" end |
#run ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 79 def run unless File.exist?(lockfile_path) raise LockfileNotFound, "No lockfile at #{lockfile_path} - you need to run `install` before `push`" end validate_lockfile write_updated_lockfile upload_policy end |
#storage_config ⇒ Object
71 72 73 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 71 def storage_config @storage_config ||= ChefDK::Policyfile::StorageConfig.new.use_policyfile_lock(lockfile_path) end |
#uploader ⇒ Object
75 76 77 |
# File 'lib/chef-dk/policyfile_services/push.rb', line 75 def uploader ChefDK::Policyfile::Uploader.new(policyfile_lock, policy_group, ui: ui, http_client: http_client) end |