Class: ChefDK::PolicyfileServices::ExportRepo
- Inherits:
-
Object
- Object
- ChefDK::PolicyfileServices::ExportRepo
- Defined in:
- lib/chef-dk/policyfile_services/export_repo.rb
Constant Summary collapse
- POLICY_GROUP =
Policy groups provide namespaces for policies so that a Chef Server can have multiple active iterations of a policy at once, but we don’t need this when serving a single exported policy via Chef Zero, so hardcode it to a “well known” value:
'local'.freeze
Instance Attribute Summary collapse
-
#export_dir ⇒ Object
readonly
Returns the value of attribute export_dir.
-
#root_dir ⇒ Object
readonly
Returns the value of attribute root_dir.
-
#storage_config ⇒ Object
readonly
Returns the value of attribute storage_config.
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(policyfile: nil, export_dir: nil, root_dir: nil, force: false) ⇒ ExportRepo
constructor
A new instance of ExportRepo.
- #policy_data ⇒ Object
- #policy_name ⇒ Object
- #policyfile_lock ⇒ Object
- #run ⇒ Object
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, export_dir: nil, root_dir: nil, force: false) ⇒ ExportRepo
Returns a new instance of ExportRepo.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/chef-dk/policyfile_services/export_repo.rb', line 41 def initialize(policyfile: nil, export_dir: nil, root_dir: nil, force: false) @root_dir = root_dir @export_dir = File.(export_dir) @force_export = force @policy_data = nil @policyfile_lock = nil policyfile_rel_path = policyfile || "Policyfile.rb" policyfile_full_path = File.(policyfile_rel_path, root_dir) @storage_config = Policyfile::StorageConfig.new.use_policyfile(policyfile_full_path) end |
Instance Attribute Details
#export_dir ⇒ Object (readonly)
Returns the value of attribute export_dir.
39 40 41 |
# File 'lib/chef-dk/policyfile_services/export_repo.rb', line 39 def export_dir @export_dir end |
#root_dir ⇒ Object (readonly)
Returns the value of attribute root_dir.
38 39 40 |
# File 'lib/chef-dk/policyfile_services/export_repo.rb', line 38 def root_dir @root_dir end |
#storage_config ⇒ Object (readonly)
Returns the value of attribute storage_config.
37 38 39 |
# File 'lib/chef-dk/policyfile_services/export_repo.rb', line 37 def storage_config @storage_config end |
Instance Method Details
#export ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/chef-dk/policyfile_services/export_repo.rb', line 77 def export create_repo_structure copy_cookbooks create_policyfile_data_item rescue => error msg = "Failed to export policy (in #{policyfile_filename}) to #{export_dir}" raise PolicyfileExportRepoError.new(msg, error) end |
#policy_data ⇒ Object
67 68 69 70 71 |
# File 'lib/chef-dk/policyfile_services/export_repo.rb', line 67 def policy_data @policy_data ||= FFI_Yajl::Parser.parse(IO.read()) rescue => error raise PolicyfileExportRepoError.new("Error reading lockfile #{}", error) end |
#policy_name ⇒ Object
54 55 56 |
# File 'lib/chef-dk/policyfile_services/export_repo.rb', line 54 def policy_name policyfile_lock.name end |
#policyfile_lock ⇒ Object
73 74 75 |
# File 'lib/chef-dk/policyfile_services/export_repo.rb', line 73 def policyfile_lock @policyfile_lock || validate_lockfile end |
#run ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/chef-dk/policyfile_services/export_repo.rb', line 58 def run assert_lockfile_exists! assert_export_dir_clean! validate_lockfile write_updated_lockfile export end |