Class: InspecPlugins::Habitat::Profile
- Inherits:
-
Object
- Object
- InspecPlugins::Habitat::Profile
- Defined in:
- lib/plugins/inspec-habitat/lib/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.
32 33 34 35 36 37 38 39 40 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 32 def initialize(path, = {}) @path = path @options = @cli_config = nil log_level = .fetch('log_level', 'info') @log = Inspec::Log @log.level(log_level.to_sym) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 11 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 11 def path @path end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
11 12 13 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 11 def profile @profile end |
Class Method Details
.create(path, options = {}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 13 def self.create(path, = {}) creator = new(path, ) hart_file = creator.create creator.copy(hart_file) ensure creator.delete_work_dir end |
.setup(path) ⇒ Object
21 22 23 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 21 def self.setup(path) new(path).setup end |
.upload(path, options = {}) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 25 def self.upload(path, = {}) uploader = new(path, ) uploader.upload ensure uploader.delete_work_dir end |
Instance Method Details
#copy(hart_file) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 66 def copy(hart_file) validate_output_dir @log.info("Copying artifact to #{output_dir}...") copy_hart(hart_file) end |
#create ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 42 def create @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_default_config(work_dir) # returns the path to the .hart file in the work directory build_hart rescue => e @log.debug(e.backtrace.join("\n")) exit_with_error( 'Unable to generate Habitat artifact.', "#{e.class} -- #{e.}", ) end |
#delete_work_dir ⇒ Object
85 86 87 88 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 85 def delete_work_dir @log.debug("Deleting work directory #{work_dir}") FileUtils.rm_rf(work_dir) if Dir.exist?(work_dir) end |
#setup ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 90 def setup @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_default_config(path) end |
#upload ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb', line 73 def upload validate_habitat_auth_token hart_file = create upload_hart(hart_file) rescue => e @log.debug(e.backtrace.join("\n")) exit_with_error( 'Unable to upload Habitat artifact.', "#{e.class} -- #{e.}", ) end |