How to use archive method of Inspec Package

Best Inspec_ruby code snippet using Inspec.archive

profile.rb

Source:profile.rb Github

copy

Full Screen

...259 end260 def controls_count261 params[:controls].values.length262 end263 # generates a archive of a folder profile264 # assumes that the profile was checked before265 def archive(opts)266 # check if file exists otherwise overwrite the archive267 dst = archive_name(opts)268 if dst.exist? && !opts[:overwrite]269 @logger.info "Archive #{dst} exists already. Use --overwrite."270 return false271 end272 # remove existing archive273 File.delete(dst) if dst.exist?274 @logger.info "Generate archive #{dst}."275 # filter files that should not be part of the profile276 # TODO ignore all .files, but add the files to debug output277 # display all files that will be part of the archive278 @logger.debug 'Add the following files to archive:'279 files.each { |f| @logger.debug ' ' + f }280 if opts[:zip]281 # generate zip archive282 require 'inspec/archive/zip'283 zag = Inspec::Archive::ZipArchiveGenerator.new284 zag.archive(root_path, files, dst)285 else286 # generate tar archive287 require 'inspec/archive/tar'288 tag = Inspec::Archive::TarArchiveGenerator.new289 tag.archive(root_path, files, dst)290 end291 @logger.info 'Finished archive generation.'292 true293 end294 def locked_dependencies295 @locked_dependencies ||= load_dependencies296 end297 def lockfile_exists?298 @source_reader.target.files.include?('inspec.lock')299 end300 def lockfile_path301 File.join(cwd, 'inspec.lock')302 end303 def root_path304 @source_reader.target.prefix305 end306 def files307 @source_reader.target.files308 end309 #310 # TODO(ssd): Relative path handling really needs to be carefully311 # thought through, especially with respect to relative paths in312 # tarballs.313 #314 def cwd315 @target.is_a?(String) && File.directory?(@target) ? @target : './'316 end317 def lockfile318 @lockfile ||= if lockfile_exists?319 Inspec::Lockfile.from_content(@source_reader.target.read('inspec.lock'))320 else321 generate_lockfile322 end323 end324 #325 # Generate an in-memory lockfile. This won't render the lock file326 # to disk, it must be explicitly written to disk by the caller.327 #328 # @param vendor_path [String] Path to the on-disk vendor dir329 # @return [Inspec::Lockfile]330 #331 def generate_lockfile332 res = Inspec::DependencySet.new(cwd, @cache, nil, @backend)333 res.vendor(metadata.dependencies)334 Inspec::Lockfile.from_dependency_set(res)335 end336 def load_dependencies337 Inspec::DependencySet.from_lockfile(lockfile, cwd, @cache, @backend, { attributes: @attr_values })338 end339 # Calculate this profile's SHA256 checksum. Includes metadata, dependencies,340 # libraries, data files, and controls.341 #342 # @return [Type] description of returned object343 def sha256344 # get all dependency checksums345 deps = Hash[locked_dependencies.list.map { |k, v| [k, v.profile.sha256] }]346 res = Digest::SHA256.new347 files = source_reader.tests.to_a + source_reader.libraries.to_a +348 source_reader.data_files.to_a +349 [['inspec.yml', source_reader.metadata.content]] +350 [['inspec.lock.deps', YAML.dump(deps)]]351 files.sort { |a, b| a[0] <=> b[0] }352 .map { |f| res << f[0] << "\0" << f[1] << "\0" }353 res.hexdigest354 end355 private356 # Create an archive name for this profile and an additional options357 # configuration. Either use :output or generate the name from metadata.358 #359 # @param [Hash] configuration options360 # @return [Pathname] path for the archive361 def archive_name(opts)362 if (name = opts[:output])363 return Pathname.new(name)364 end365 name = params[:name] ||366 raise('Cannot create an archive without a profile name! Please '\367 'specify the name in metadata or use --output to create the archive.')368 version = params[:version] ||369 raise('Cannot create an archive without a profile version! Please '\370 'specify the version in metadata or use --output to create the archive.')371 ext = opts[:zip] ? 'zip' : 'tar.gz'372 slug = name.downcase.strip.tr(' ', '-').gsub(/[^\w-]/, '_')373 Pathname.new(Dir.pwd).join("#{slug}-#{version}.#{ext}")374 end375 def load_params376 params = @source_reader.metadata.params377 params[:name] = @profile_id unless @profile_id.nil?378 load_checks_params(params)379 @profile_id ||= params[:name]380 params381 end382 def load_checks_params(params)383 load_libraries384 tests = collect_tests...

Full Screen

Full Screen

run_lambda_locally.rb

Source:run_lambda_locally.rb Github

copy

Full Screen

...7#8require_relative 'lambda_function'9lambda_handler(10 event: {11 'command' => 'inspec exec https://github.com/mitre/redhat-enterprise-linux-7-stig-baseline/archive/master.tar.gz'\12 ' -t ssh://ssm-user@i-00f1868f8f3b4eb03'\13 ' --sudo'\14 ' -i /tmp/tmp_ssh_key'\15 ' --input=\'disable_slow_controls=true\''\16 ' --proxy-command=\'sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=%p"\'',17 'results_name' => 'redhat-enterprise-linux-7-stig-baseline-inspec-rhel7-test',18 'results_buckets' => [19 'inspec-results-bucket-dev'20 ],21 'eval_tags' => 'ServerlessInspec,RHEL7,inspec-rhel7-test,SSH-SSM',22 'tmp_ssm_ssh_key' => {23 'host' => 'i-00f1868f8f3b4eb03',24 'user' => 'ssm-user',25 'key_name' => 'tmp_ssh_key'26 }27 },28 context: nil29)30# SSH command31_ = {32 'command' => 'inspec exec /tmp/redhat-enterprise-linux-7-stig-baseline-2.6.6.tar.gz'\33 ' -t ssh://ec2-user@ec2-15-200-235-74.us-gov-west-1.compute.amazonaws.com'\34 ' --sudo'\35 ' --input=disable_slow_controls=true',36 'results_name' => 'redhat-enterprise-linux-7-stig-baseline-inspec-rhel7-test',37 'results_buckets' => [38 'inspec-results-bucket-dev'39 ],40 'eval_tags' => 'ServerlessInspec,RHEL7,inspec-rhel7-test,SSH',41 'resources' => [42 {43 'local_file_path' => '/tmp/redhat-enterprise-linux-7-stig-baseline-2.6.6.tar.gz',44 'source_aws_s3_bucket' => 'inspec-profiles-bucket-dev',45 'source_aws_s3_key' => 'redhat-enterprise-linux-7-stig-baseline-2.6.6.tar.gz'46 }47 ]48}49# SSH via SSM command (with tmp key)50_ = {51 'command' => 'inspec exec https://github.com/mitre/redhat-enterprise-linux-7-stig-baseline/archive/master.tar.gz'\52 ' -t ssh://ssm-user@i-00f1868f8f3b4eb03'\53 ' --sudo'\54 ' -i /tmp/tmp_ssh_key'\55 ' --input=\'disable_slow_controls=true\''\56 ' --proxy-command=\'sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=%p"\'',57 'results_name' => 'redhat-enterprise-linux-7-stig-baseline-inspec-rhel7-test',58 'results_buckets' => [59 'inspec-results-bucket-dev'60 ],61 'eval_tags' => 'ServerlessInspec,RHEL7,inspec-rhel7-test,SSH-SSM',62 'tmp_ssm_ssh_key' => {63 'host' => 'i-00f1868f8f3b4eb03',64 'user' => 'ssm-user',65 'key_name' => 'tmp_ssh_key'66 }67}68# AWSSSM command69_ = {70 'command' => 'inspec exec https://github.com/mitre/redhat-enterprise-linux-7-stig-baseline/archive/master.tar.gz'\71 ' -t awsssm://i-00f1868f8f3b4eb03'\72 ' --input=\'disable_slow_controls=true\'',73 'results_name' => 'redhat-enterprise-linux-7-stig-baseline-inspec-rhel7-test',74 'results_buckets' => [75 'inspec-results-bucket-dev'76 ],77 'eval_tags' => 'ServerlessInspec,RHEL7,inspec-rhel7-test,AWSSSM'78}79# WinRM command80_ = {81 'command' => 'inspec exec /tmp/microsoft-windows-server-2019-stig-baseline-1.3.10.tar.gz'\82 ' -t winrm://localhost'\83 ' --password $WIN_PASS',84 'results_name' => 'windows-server-2019-stig-baseline-inspec-win2019-test',85 'results_buckets' => [86 'inspec-results-bucket-dev'87 ],88 'eval_tags' => 'ServerlessInspec,WinSvr2019,inspec-win2019-test,WinRM',89 'resources' => [90 {91 'local_file_path' => '/tmp/microsoft-windows-server-2019-stig-baseline-1.3.10.tar.gz',92 'source_aws_s3_bucket' => 'inspec-profiles-bucket-dev',93 'source_aws_s3_key' => 'microsoft-windows-server-2019-stig-baseline-1.3.10.tar.gz'94 },95 {96 'env_variable' => 'WIN_PASS',97 'source_aws_ssm_parameter_key' => '/inspec/inspec-win2019-test/password'98 }99 ],100 'ssm_port_forward' => {101 'instance_id' => 'i-0e35ab216355084ee',102 'ports' => [5985, 5986]103 }104}105# AWS CIS Baseline command106_ = {107 'command' => 'inspec exec /tmp/aws-foundations-cis-baseline-1.2.2.tar.gz'\108 ' -t aws://',109 'results_name' => 'aws-foundations-cis-baseline-6756-0937-9314',110 'results_buckets' => [111 'inspec-results-bucket-dev'112 ],113 'eval_tags' => 'ServerlessInspec,AwsCisBaseline,6756-0937-9314,AWS',114 'resources' => [115 {116 'local_file_path' => '/tmp/aws-foundations-cis-baseline-1.2.2.tar.gz',117 'source_aws_s3_bucket' => 'inspec-profiles-bucket-dev',118 'source_aws_s3_key' => 'aws-foundations-cis-baseline-1.2.2.tar.gz'119 }120 ]121}122# k8s command123_ = {124 'command' => 'inspec exec https://gitlab.dsolab.io/scv-content/inspec/kubernetes/baselines/k8s-cluster-stig-baseline/-/archive/master/k8s-cluster-stig-baseline-master.tar.gz'\125 ' -t k8s://',126 'results_name' => 'k8s-cluster-stig-baseline-dev-cluster',127 'results_buckets' => [128 'inspec-results-bucket-dev'129 ],130 'eval_tags' => 'ServerlessInspec,k8s',131 'resources' => [132 {133 'local_file_path' => '/tmp/kube/config',134 'source_aws_s3_bucket' => 'inspec-profiles-bucket-dev',135 'source_aws_s3_key' => 'kube-dev/config'136 },137 {138 'local_file_path' => '/tmp/kube/client.crt',...

Full Screen

Full Screen

inspec_archive_test.rb

Source:inspec_archive_test.rb Github

copy

Full Screen

2# author: Dominik Richter3# author: Christoph Hartmann4require 'functional/helper'5require 'tmpdir'6describe 'inspec archive' do7 include FunctionalHelper8 it 'archive is successful' do9 out = inspec('archive ' + example_profile + ' --overwrite')10 out.exit_status.must_equal 011 out.stdout.must_match(/Generate archive [^ ]*profile-1.0.0.tar.gz/)12 out.stdout.must_include 'Finished archive generation.'13 end14 it 'archives to output file' do15 out = inspec('archive ' + example_profile + ' --output ' + dst.path)16 out.stderr.must_equal ''17 out.stdout.must_include 'Generate archive '+dst.path18 out.stdout.must_include 'Finished archive generation.'19 out.exit_status.must_equal 020 File.exist?(dst.path).must_equal true21 end22 it 'auto-archives when no --output is given' do23 auto_dst = File.join(repo_path, 'profile-1.0.0.tar.gz')24 out = inspec('archive ' + example_profile + ' --overwrite')25 out.stderr.must_equal ''26 out.stdout.must_include 'Generate archive '+auto_dst27 out.stdout.must_include 'Finished archive generation.'28 out.exit_status.must_equal 029 File.exist?(auto_dst).must_equal true30 end31 it 'archive on invalid archive' do32 Dir.tmpdir do |target_dir|33 out = inspec('archive #{target_dir} --output ' + dst.path)34 # out.stdout.must_equal '' => we have partial stdout output right now35 out.stderr.must_include "Don't understand inspec profile in \"#{target_dir}\""36 out.exit_status.must_equal 137 File.exist?(dst.path).must_equal false38 end39 end40 it 'archive wont overwrite existing files' do41 x = rand.to_s42 File.write(dst.path, x)43 out = inspec('archive ' + example_profile + ' --output ' + dst.path)44 out.stderr.must_equal '' # uh...45 out.stdout.must_include "Archive #{dst.path} exists already. Use --overwrite."46 out.exit_status.must_equal 147 File.read(dst.path).must_equal x48 end49 it 'archive will overwrite files if necessary' do50 x = rand.to_s51 File.write(dst.path, x)52 out = inspec('archive ' + example_profile + ' --output ' + dst.path + ' --overwrite')53 out.stderr.must_equal ''54 out.stdout.must_include 'Generate archive '+dst.path55 out.exit_status.must_equal 056 File.read(dst.path).wont_equal x57 end58 it 'creates valid tar.gz archives' do59 out = inspec('archive ' + example_profile + ' --output ' + dst.path + ' --tar')60 out.stderr.must_equal ''61 out.stdout.must_include 'Generate archive '+dst.path62 out.exit_status.must_equal 063 t = Zlib::GzipReader.open(dst.path)64 Gem::Package::TarReader.new(t).entries.map(&:header).map(&:name).must_include 'inspec.yml'65 end66 it 'creates valid zip archives' do67 out = inspec('archive ' + example_profile + ' --output ' + dst.path + ' --zip')68 out.stderr.must_equal ''69 out.stdout.must_include 'Generate archive '+dst.path70 out.exit_status.must_equal 071 Zip::File.new(dst.path).entries.map(&:name).must_include 'inspec.yml'72 end73end...

Full Screen

Full Screen

archive

Using AI Code Generation

copy

Full Screen

1 describe archive('path/to/archive') do2 it { should exist }3 its('type') { should eq 'tar' }4 its('files') { should include 'README.md' }5 describe archive('path/to/archive') do6 it { should exist }7 its('type') { should eq 'zip' }8 its('files') { should include 'README.md' }9 describe archive('path/to/archive') do10 it { should exist }11 its('type') { should eq 'zip' }12 its('files') { should include 'README.md' }require 'inspec/resources/archive'13 describe archive('path/to/archive') do14 it { hould exist }15 its('ty') { should eq 'zip' }16 its('files') { should inlude 'README.md' }17 describe archive('path/to/archive') do18 it { should exist }19 its('type') { should eq 'zip' }20 its('files') { should include 'README.md' }21 describe archive('path/to/archive') do22 it { should exist }23 its('type') { should eq 'zip' }24 its('files') { should include 'README.md' }25 describe archive('path/to/archive') do26 it { should exist }27 its('type') { should eq 'zip' }28 its('files') { should include 'README.md' }

Full Screen

Full Screen

archive

Using AI Code Generation

copy

Full Screen

1describe archive('/tmp/archive.zip') do2 its('files') { should include 'archive.txt' }3describe archive('/tmp/archive.zip') do4 its('files') { should include 'archive.txt' }5describe archive('/tmp/archive.zip') do6 its('files') { should include 'archive.txt' }

Full Screen

Full Screen

archive

Using AI Code Generation

copy

Full Screen

1describe archive('/tmp/archive.zip') do2 its('files') { should include 'archive.txt' }3describe archive('/tmp/archive.zip') do4 its('files') { should include 'archive.txt' }5describe archive('/tmp/archive.zip') do6 its('files') { should include 'archive.txt' }

Full Screen

Full Screen

archive

Using AI Code Generation

copy

Full Screen

1archive = Inspec::Archive.new('/home/inspec_user/inspec_test.tar.gz')2archive.extract('/home/inspec_user/inspec_test')3archive = Inspec::Archive.new('/home/inspec_user/inspec_test.tar.gz')4archive.extract('/home/inspec_user/inspec_test')5archive = Inspec::Archive.new('/home/inspec_user/inspec_test.tar.gz')6archive.extract('/home/inspec_user/inspec_test')7archive = Inspec::Archive.new('/home/inspec_user/inspec_test.tar.gz')8archive.extract('/home/inspec_user/inspec_test')9archive = Inspec::Archive.new('/home/inspec_user/inspec_test.tar.gz')10archive.extract('/home/inspec_user/inspec_test')11archive = Inspec::Archive.new('/home/inspec_user/inspec_test.tar.gz')12archive.extract('/home/inspec_user/inspec_test')13archive = Inspec::Archive.new('/home/inspec_user/inspec_test.tar.gz')14archive.extract('/home/inspec_user/inspec_test')15archive = Inspec::Archive.new('/home/inspec_user/inspec_test.tar.gz')16archive.extract('/home/inspec_user/

Full Screen

Full Screen

archive

Using AI Code Generation

copy

Full Screen

1inspec.archive('my-archive.tar.gz')2inspec.archive('my-archive.tar.oz', 'gz')3inspec.archive('my-archive.tar.gz', 'gz', '/tmp')4inspec.arciv('my-archive.tar.gz','gz', '/tmp', 'my-proe')5inspec.archive('my-archive.tar.gz', 'gz', '/tmp', 'my-profile', '0.1.0')6inspec.archie('my-chve.tr.gz', 'gz', '/tmp', 'my-profile', '0.1.0', 'My Profile')7inspec.archive('my-archive.tar.gz', 'gz', '/tmp', 'my-profile', '0.1.0', 'My Profile', 'My Profile Summary')8inspec.archive('my-archive.tar.gz', 'gz', '/tmp', 'my-profile', '0.1.0', 'My Profile', 'My Profile Summary', 'My Profile Maintainer')9inspec.archive('my-archive.tar.gz', 'gz', '/tmp', 'my-profile', '0.1.0',

Full Screen

Full Screen

archive

Using AI Code Generation

copy

Full Screen

1Inspec::Log.logger = Logger.new('/tmp/inspec.log')2profile = Inspec::Profile.for_target('.', {}, :archive)3profile.archive('/tmp/inspec.tar.gz')

Full Screen

Full Screen

archive

Using AI Code Generation

copy

Full Screen

1describe archive('test.zip') do2 its('content') { should include 'test.txt' }3describe archive('test.zip') do4 its('co.rb

Full Screen

Full Screen

archive

Using AI Code Generation

copy

Full Screen

1Inspec::Input.archive('/tmp/file1', '/tmp/file1.tgz', 'gzip')2Inspec::Input.archive('/tmp/dir1', '/tmp/dir1.tgz', 'gzip')nt') { should include 'test.txt' }3Inspec::Input.archive('/tmp/file1', '/tmp/file1.zip', 'none')4Inspec::Input.archive('/tmp/ir1', '/tmp/dir1.zip', 'non')5Inspec::Input.archive('/tmp/file1', '/tmp/file1.bz2', 'bzip2')6Inpec::Input.archive('/tmp/dir1', '/tmp/dir1.bz2', 'bzip2')7Inspc::Inpu.arcive('/tmp/file1', '/tmp/file1.xz', 'xz')8Inspec::Input.archive('/tmp/dir1', '/tmp/ir1.xz', 'xz')9c::Input.arhive('/tmp/file1','/tmp/file1.lzma', 'lzma')10Inspec::Input.archive('/tmp/dir1', '/tmp/dir1.lzma', 'zma')11Inspec::Input.archive('/tmp/file1', '/tmp/file1.lzip', 'lzip')12Inspec::Input.archive('/tmp/dir1', '/tmp/dir113describe archive('test.zip') do14 its('content') { should include 'test.txt' }15describe archive('test.zip') do16 its('content') { should include 'test.txt' }17describe archive('test.zip') do18 its('content') { should include 'test.txt' }19describe archive('test.zip') do20 its('content') { should include 'test.txt' }21describe archive('test.zip') do22 its('content') { should include 'test.txt' }23describe archive('test.zip') do24 its('content') { should include 'test.txt' }

Full Screen

Full Screen

archive

Using AI Code Generation

copy

Full Screen

1Inspec::Input.archive('/tmp/file1', '/tmp/file1.tgz', 'gzip')2Inspec::Input.archive('/tmp/dir1', '/tmp/dir1.tgz', 'gzip')3Inspec::Input.archive('/tmp/file1', '/tmp/file1.zip', 'none')4Inspec::Input.archive('/tmp/dir1', '/tmp/dir1.zip', 'none')5Inspec::Input.archive('/tmp/file1', '/tmp/file1.bz2', 'bzip2')6Inspec::Input.archive('/tmp/dir1', '/tmp/dir1.bz2', 'bzip2')7Inspec::Input.archive('/tmp/file1', '/tmp/file1.xz', 'xz')8Inspec::Input.archive('/tmp/dir1', '/tmp/dir1.xz', 'xz')9Inspec::Input.archive('/tmp/file1', '/tmp/file1.lzma', 'lzma')10Inspec::Input.archive('/tmp/dir1', '/tmp/dir1.lzma', 'lzma')11Inspec::Input.archive('/tmp/file1', '/tmp/file1.lzip', 'lzip')12Inspec::Input.archive('/tmp/dir1', '/tmp/dir1

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Inspec_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful