Class: Habitat::Profile
- Inherits:
-
Object
- Object
- Habitat::Profile
- Defined in:
- lib/bundles/inspec-habitat/profile.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
Class Method Summary collapse
Instance Method Summary collapse
- #copy(hart_file) ⇒ Object
- #create ⇒ Object
- #delete_work_dir ⇒ Object
-
#initialize(path, options = {}) ⇒ Profile
constructor
A new instance of Profile.
- #setup ⇒ Object
- #upload ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Profile
Returns a new instance of Profile.
31 32 33 34 35 36 37 38 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 31 def initialize(path, = {}) @path = path @options = @cli_config = nil log_level = .fetch('log_level', 'info') Habitat::Log.level(log_level.to_sym) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 10 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 10 def path @path end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
10 11 12 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 10 def profile @profile end |
Class Method Details
.create(path, options = {}) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 12 def self.create(path, = {}) creator = new(path, ) hart_file = creator.create creator.copy(hart_file) ensure creator.delete_work_dir end |
.setup(path) ⇒ Object
20 21 22 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 20 def self.setup(path) new(path).setup end |
.upload(path, options = {}) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 24 def self.upload(path, = {}) uploader = new(path, ) uploader.upload ensure uploader.delete_work_dir end |
Instance Method Details
#copy(hart_file) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 65 def copy(hart_file) validate_output_dir Habitat::Log.info("Copying artifact to #{output_dir}...") copy_hart(hart_file) end |
#create ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 40 def create Habitat::Log.info("Creating a Habitat artifact for profile: #{path}") validate_habitat_installed validate_habitat_origin create_profile_object verify_profile vendor_profile_dependencies copy_profile_to_work_dir create_habitat_directories(work_dir) create_plan(work_dir) create_run_hook(work_dir) create_settings_file(work_dir) create_default_config(work_dir) # returns the path to the .hart file in the work directory build_hart rescue => e Habitat::Log.debug(e.backtrace.join("\n")) exit_with_error( 'Unable to generate Habitat artifact.', "#{e.class} -- #{e.}", ) end |
#delete_work_dir ⇒ Object
84 85 86 87 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 84 def delete_work_dir Habitat::Log.debug("Deleting work directory #{work_dir}") FileUtils.rm_rf(work_dir) if Dir.exist?(work_dir) end |
#setup ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 89 def setup Habitat::Log.info("Setting up profile at #{path} for Habitat...") create_profile_object verify_profile vendor_profile_dependencies create_habitat_directories(path) create_plan(path) create_run_hook(path) create_settings_file(path) create_default_config(path) end |
#upload ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bundles/inspec-habitat/profile.rb', line 72 def upload validate_habitat_auth_token hart_file = create upload_hart(hart_file) rescue => e Habitat::Log.debug(e.backtrace.join("\n")) exit_with_error( 'Unable to upload Habitat artifact.', "#{e.class} -- #{e.}", ) end |