Class: ChefDK::PolicyfileServices::PushArchive

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-dk/policyfile_services/push_archive.rb

Constant Summary collapse

USTAR_INDICATOR =
"ustar\0".force_encoding(Encoding::ASCII_8BIT).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive_file: nil, policy_group: nil, root_dir: nil, ui: nil, config: nil) ⇒ PushArchive

Returns a new instance of PushArchive.



41
42
43
44
45
46
47
48
49
# File 'lib/chef-dk/policyfile_services/push_archive.rb', line 41

def initialize(archive_file: nil, policy_group: nil, root_dir: nil, ui: nil, config: nil)
  @archive_file = archive_file
  @policy_group = policy_group
  @root_dir = root_dir || Dir.pwd
  @ui = ui
  @config = config

  @policyfile_lock = nil
end

Instance Attribute Details

#archive_fileObject (readonly)

Returns the value of attribute archive_file.



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

def archive_file
  @archive_file
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#policy_groupObject (readonly)

Returns the value of attribute policy_group.



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

def policy_group
  @policy_group
end

#policyfile_lockObject (readonly)

Returns the value of attribute policyfile_lock.



39
40
41
# File 'lib/chef-dk/policyfile_services/push_archive.rb', line 39

def policyfile_lock
  @policyfile_lock
end

#root_dirObject (readonly)

Returns the value of attribute root_dir.



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

def root_dir
  @root_dir
end

#uiObject (readonly)

Returns the value of attribute ui.



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

def ui
  @ui
end

Instance Method Details

#archive_file_pathObject



51
52
53
# File 'lib/chef-dk/policyfile_services/push_archive.rb', line 51

def archive_file_path
  File.expand_path(archive_file, root_dir)
end

#http_clientObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
82
83
# File 'lib/chef-dk/policyfile_services/push_archive.rb', line 79

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

#runObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/chef-dk/policyfile_services/push_archive.rb', line 55

def run
  unless File.exist?(archive_file_path)
    raise InvalidPolicyArchive, "Archive file #{archive_file_path} not found"
  end

  stage_unpacked_archive do |staging_dir|
    read_policyfile_lock(staging_dir)

    uploader.upload
  end

rescue => e
  raise PolicyfilePushArchiveError.new("Failed to publish archived policy", e)
end

#uploaderObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



71
72
73
74
75
76
# File 'lib/chef-dk/policyfile_services/push_archive.rb', line 71

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