Class: ChefCLI::PolicyfileServices::PushArchive

Inherits:
Object
  • Object
show all
Defined in:
lib/chef-cli/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.



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

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.



32
33
34
# File 'lib/chef-cli/policyfile_services/push_archive.rb', line 32

def archive_file
  @archive_file
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#policy_groupObject (readonly)

Returns the value of attribute policy_group.



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

def policy_group
  @policy_group
end

#policyfile_lockObject (readonly)

Returns the value of attribute policyfile_lock.



38
39
40
# File 'lib/chef-cli/policyfile_services/push_archive.rb', line 38

def policyfile_lock
  @policyfile_lock
end

#root_dirObject (readonly)

Returns the value of attribute root_dir.



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

def root_dir
  @root_dir
end

#uiObject (readonly)

Returns the value of attribute ui.



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

def ui
  @ui
end

Instance Method Details

#archive_file_pathObject



50
51
52
# File 'lib/chef-cli/policyfile_services/push_archive.rb', line 50

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.



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

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



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

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.



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

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