Class: ChefDK::PolicyfileServices::Push

Inherits:
Object
  • Object
show all
Includes:
Helpers, ChefDK::Policyfile::StorageConfigDelegation
Defined in:
lib/chef-dk/policyfile_services/push.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#chefdk_home, #err, #git_bin_dir, #git_windows_bin_dir, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_env, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command, #usr_bin_path, #usr_bin_prefix

Methods included from ChefDK::Policyfile::StorageConfigDelegation

#cache_path, #policyfile_expanded_path, #policyfile_filename, #policyfile_lock_expanded_path, #relative_paths_root

Constructor Details

#initialize(policyfile: nil, ui: nil, policy_group: nil, config: nil, root_dir: nil) ⇒ Push

Returns a new instance of Push.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/chef-dk/policyfile_services/push.rb', line 39

def initialize(policyfile: nil, ui: nil, policy_group: nil, config: nil, root_dir: nil)
  @root_dir = root_dir
  @ui = ui
  @config = config
  @policy_group = policy_group

  policyfile_rel_path = policyfile || "Policyfile.rb"
  policyfile_full_path = File.expand_path(policyfile_rel_path, root_dir)
  @storage_config = Policyfile::StorageConfig.new.use_policyfile(policyfile_full_path)

  @http_client = nil
  @policy_data = nil
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



34
35
36
# File 'lib/chef-dk/policyfile_services/push.rb', line 34

def config
  @config
end

#policy_groupObject (readonly)

Returns the value of attribute policy_group.



35
36
37
# File 'lib/chef-dk/policyfile_services/push.rb', line 35

def policy_group
  @policy_group
end

#root_dirObject (readonly)

Returns the value of attribute root_dir.



33
34
35
# File 'lib/chef-dk/policyfile_services/push.rb', line 33

def root_dir
  @root_dir
end

#storage_configObject (readonly)

Returns the value of attribute storage_config.



37
38
39
# File 'lib/chef-dk/policyfile_services/push.rb', line 37

def storage_config
  @storage_config
end

#uiObject (readonly)

Returns the value of attribute ui.



36
37
38
# File 'lib/chef-dk/policyfile_services/push.rb', line 36

def ui
  @ui
end

Instance Method Details

#http_clientObject



53
54
55
56
57
# File 'lib/chef-dk/policyfile_services/push.rb', line 53

def http_client
  @http_client ||= Chef::ServerAPI.new(config.chef_server_url,
    signing_key_filename: config.client_key,
    client_name: config.node_name)
end

#policy_dataObject



59
60
61
62
63
# File 'lib/chef-dk/policyfile_services/push.rb', line 59

def policy_data
  @policy_data ||= FFI_Yajl::Parser.parse(IO.read(policyfile_lock_expanded_path))
rescue => error
  raise PolicyfilePushError.new("Error reading lockfile #{policyfile_lock_expanded_path}", error)
end

#policyfile_lockObject



82
83
84
# File 'lib/chef-dk/policyfile_services/push.rb', line 82

def policyfile_lock
  @policyfile_lock || validate_lockfile
end

#runObject



72
73
74
75
76
77
78
79
80
# File 'lib/chef-dk/policyfile_services/push.rb', line 72

def run
  unless File.exist?(policyfile_lock_expanded_path)
    raise LockfileNotFound, "No lockfile at #{policyfile_lock_expanded_path} - you need to run `install` before `push`"
  end

  validate_lockfile
  write_updated_lockfile
  upload_policy
end

#uploaderObject



65
66
67
68
69
70
# File 'lib/chef-dk/policyfile_services/push.rb', line 65

def uploader
  ChefDK::Policyfile::Uploader.new(policyfile_lock, policy_group,
    ui: ui,
    http_client: http_client,
    policy_document_native_api: config.policy_document_native_api)
end