mirror of
https://github.com/inspec/inspec
synced 2024-11-27 07:00:39 +00:00
CFINSPEC-183: Rename artifact commands to inspec sign
Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
parent
967dbfca56
commit
c7d902875a
6 changed files with 35 additions and 61 deletions
|
@ -1,12 +0,0 @@
|
|||
module InspecPlugins
|
||||
module Artifact
|
||||
class Plugin < Inspec.plugin(2)
|
||||
plugin_name :'inspec-artifact'
|
||||
|
||||
cli_command :artifact do
|
||||
require_relative "inspec-artifact/cli"
|
||||
InspecPlugins::Artifact::CLI
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@
|
|||
# These specs are used in plugin list and search command
|
||||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "inspec-artifact"
|
||||
spec.name = "inspec-sign"
|
||||
spec.summary = ""
|
||||
spec.description = "Plugin to generate asymmetrical keys that you can use to encrypt profiles"
|
||||
spec.license = "Apache-2.0"
|
12
lib/plugins/inspec-sign/lib/inspec-sign.rb
Normal file
12
lib/plugins/inspec-sign/lib/inspec-sign.rb
Normal file
|
@ -0,0 +1,12 @@
|
|||
module InspecPlugins
|
||||
module Sign
|
||||
class Plugin < Inspec.plugin(2)
|
||||
plugin_name :'inspec-sign'
|
||||
|
||||
cli_command :sign do
|
||||
require_relative "inspec-sign/cli"
|
||||
InspecPlugins::Sign::CLI
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -8,7 +8,7 @@ require "inspec/dist"
|
|||
require "inspec/utils/json_profile_summary"
|
||||
|
||||
module InspecPlugins
|
||||
module Artifact
|
||||
module Sign
|
||||
class Base
|
||||
include Inspec::Dist
|
||||
|
||||
|
@ -74,7 +74,7 @@ module InspecPlugins
|
|||
|
||||
def self.profile_verify(options)
|
||||
artifact = new
|
||||
file_to_verifiy = options["infile"]
|
||||
file_to_verifiy = options["signed_profile"]
|
||||
puts "Verifying #{file_to_verifiy}"
|
||||
|
||||
artifact.verify(file_to_verifiy) do ||
|
||||
|
@ -82,23 +82,6 @@ module InspecPlugins
|
|||
end
|
||||
end
|
||||
|
||||
def self.profile_install(options)
|
||||
artifact = new
|
||||
puts "Installing profile"
|
||||
file_to_verifiy = options["infile"]
|
||||
dest_dir = options["destdir"]
|
||||
artifact.verify(file_to_verifiy) do |content|
|
||||
Dir.mktmpdir do |workdir|
|
||||
tmpfile = Pathname.new(workdir).join("artifact_to_install.tar.gz")
|
||||
File.open(tmpfile, "wb") do |f|
|
||||
f.write content
|
||||
end
|
||||
puts "Installing to #{dest_dir}"
|
||||
`tar xzf #{tmpfile} -C #{dest_dir}`
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def read_profile_metadata(path_to_profile)
|
||||
begin
|
||||
p = Pathname.new(path_to_profile)
|
|
@ -70,46 +70,39 @@ require "inspec/dist"
|
|||
# To extract the raw content from a .iaf:
|
||||
# sed '1,/^$/d' foo.iaf
|
||||
|
||||
# inspec artifact is renamed to inspec sign
|
||||
|
||||
module InspecPlugins
|
||||
module Artifact
|
||||
module Sign
|
||||
class CLI < Inspec.plugin(2, :cli_command)
|
||||
include Inspec::Dist
|
||||
|
||||
subcommand_desc "artifact SUBCOMMAND", "Manage #{PRODUCT_NAME} Artifacts"
|
||||
subcommand_desc "sign SUBCOMMAND", "Manage #{PRODUCT_NAME} profile signing."
|
||||
|
||||
desc "generate", "Generate a RSA key pair for signing and verification"
|
||||
desc "generate-keys", "Generate a RSA key pair for signing and verification"
|
||||
option :keyname, type: :string, required: true,
|
||||
desc: "Desriptive name of key"
|
||||
option :keydir, type: :string, default: "./",
|
||||
desc: "Directory to search for keys"
|
||||
def generate_keys
|
||||
puts "Generating keys"
|
||||
InspecPlugins::Artifact::Base.keygen(options)
|
||||
InspecPlugins::Sign::Base.keygen(options)
|
||||
end
|
||||
|
||||
desc "sign-profile", "Create a signed .iaf artifact"
|
||||
desc "profile", "Create a signed .iaf artifact"
|
||||
option :profile, type: :string, required: true,
|
||||
desc: "Path to profile directory"
|
||||
option :keyname, type: :string, required: true,
|
||||
desc: "Desriptive name of key"
|
||||
def sign_profile
|
||||
InspecPlugins::Artifact::Base.profile_sign(options)
|
||||
def profile
|
||||
InspecPlugins::Sign::Base.profile_sign(options)
|
||||
end
|
||||
|
||||
desc "verify-profile", "Verify a signed .iaf artifact"
|
||||
option :infile, type: :string, required: true,
|
||||
desc "verify", "Verify a signed .iaf artifact"
|
||||
option :signed_profile, type: :string, required: true,
|
||||
desc: ".iaf file to verify"
|
||||
def verify_profile
|
||||
InspecPlugins::Artifact::Base.profile_verify(options)
|
||||
end
|
||||
|
||||
desc "install-profile", "Verify and install a signed .iaf artifact"
|
||||
option :infile, type: :string, required: true,
|
||||
desc: ".iaf file to install"
|
||||
option :destdir, type: :string, required: true,
|
||||
desc: "Installation directory"
|
||||
def install_profile
|
||||
InspecPlugins::Artifact::Base.profile_install(options)
|
||||
def verify
|
||||
InspecPlugins::Sign::Base.profile_verify(options)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@ require "fileutils" unless defined?(FileUtils)
|
|||
require "plugins/shared/core_plugin_test_helper"
|
||||
require "securerandom" unless defined?(SecureRandom)
|
||||
|
||||
class ArtifactCli < Minitest::Test
|
||||
class SignCli < Minitest::Test
|
||||
include CorePluginFunctionalHelper
|
||||
|
||||
def test_generating_archive_keys
|
||||
|
@ -10,7 +10,7 @@ class ArtifactCli < Minitest::Test
|
|||
skip_windows! # Breakage confirmed, only on CI: https://buildkite.com/chef-oss/inspec-inspec-master-verify/builds/2355#2c9d032e-4a24-4e7c-aef2-1c9e2317d9e2
|
||||
|
||||
unique_key_name = SecureRandom.uuid
|
||||
out = run_inspec_process("artifact generate --keyname #{unique_key_name}", prefix: "cd #{dir};")
|
||||
out = run_inspec_process("sign generate-keys --keyname #{unique_key_name}", prefix: "cd #{dir};")
|
||||
|
||||
stdout = out.stdout.force_encoding(Encoding::UTF_8)
|
||||
assert_includes stdout, "Generating private key"
|
||||
|
@ -32,10 +32,10 @@ class ArtifactCli < Minitest::Test
|
|||
profile = File.join(dir, "artifact-profile")
|
||||
run_inspec_process("init profile artifact-profile", prefix: "cd #{dir};")
|
||||
|
||||
out = run_inspec_process("artifact generate --keyname #{unique_key_name}", prefix: "cd #{dir};")
|
||||
out = run_inspec_process("sign generate-keys --keyname #{unique_key_name}", prefix: "cd #{dir};")
|
||||
assert_exit_code 0, out
|
||||
|
||||
out = run_inspec_process("artifact sign-profile --profile #{profile} --keyname #{unique_key_name}", prefix: "cd #{dir};")
|
||||
out = run_inspec_process("sign profile --profile #{profile} --keyname #{unique_key_name}", prefix: "cd #{dir};")
|
||||
assert_exit_code 0, out
|
||||
|
||||
# The archive install commands do not currently support windows
|
||||
|
@ -43,12 +43,10 @@ class ArtifactCli < Minitest::Test
|
|||
# still experimental we are skipping it for now.
|
||||
return if is_windows?
|
||||
|
||||
out = run_inspec_process("artifact install-profile --infile artifact-profile-0.1.0.iaf --destdir #{install_dir}", prefix: "cd #{dir};")
|
||||
out = run_inspec_process("sign verify --signed-profile artifact-profile-0.1.0.iaf", prefix: "cd #{dir};")
|
||||
assert_exit_code 0, out
|
||||
|
||||
assert_includes out.stdout.force_encoding(Encoding::UTF_8), "Installing to #{install_dir}"
|
||||
assert_includes Dir.entries(install_dir).join, "inspec.yml"
|
||||
assert_includes Dir.entries(install_dir).join, "inspec.json"
|
||||
assert_includes out.stdout.force_encoding(Encoding::UTF_8), "Verifying artifact-profile-0.1.0.iaf"
|
||||
assert_exit_code 0, out
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue