Dist branding for plugins/inspec-habitat

Signed-off-by: Artem Sidorenko <artem.sidorenko@t-systems.com>
This commit is contained in:
Artem Sidorenko 2019-05-24 13:08:58 +02:00
parent 4c0260aedd
commit e468c592ca
4 changed files with 23 additions and 17 deletions

View file

@ -1,8 +1,11 @@
require_relative 'profile'
require 'inspec/dist'
module InspecPlugins
module Habitat
class ProfileCLI < Inspec.plugin(2, :cli_command)
include Inspec::Dist
# Override banner method to correct missing subcommand.
# @see https://github.com/erikhuda/thor/issues/261
def self.banner(command, _namespace = nil, _subcommand = false)
@ -28,10 +31,10 @@ module InspecPlugins
end
class CLI < Inspec.plugin(2, :cli_command)
subcommand_desc 'habitat SUBCOMMAND', 'Manage Habitat with InSpec'
subcommand_desc 'habitat SUBCOMMAND', "Manage Habitat with #{PRODUCT_NAME}"
namespace 'habitat'
desc 'profile', 'Manage InSpec profiles as Habitat artifacts'
desc 'profile', "Manage #{PRODUCT_NAME} profiles as Habitat artifacts"
subcommand 'profile', ProfileCLI
end
end

View file

@ -3,10 +3,13 @@ require 'inspec/profile_vendor'
require 'mixlib/shellout'
require 'tomlrb'
require 'ostruct'
require 'inspec/dist'
module InspecPlugins
module Habitat
class Profile
include Inspec::Dist
attr_reader :logger
def initialize(path, options = {})
@path = path
@ -72,7 +75,7 @@ module InspecPlugins
create_file_from_template(default_toml, 'default.toml.erb')
config = File.join(path, 'habitat', 'config', 'inspec_exec_config.json')
logger.info("Generating #{config} for `inspec exec`...")
logger.info("Generating #{config} for `#{EXEC_NAME} exec`...")
create_file_from_template(config, 'config/inspec_exec_config.json.erb')
end

View file

@ -10,13 +10,13 @@ PROFILE_PATH="{{pkg.path}}/{{pkg.name}}-{{pkg.version}}.tar.gz"
while true; do
echo "Executing ${PROFILE_IDENT}"
exec inspec exec ${PROFILE_PATH} --json-config ${CONFIG} 2>&1 | tee ${LOG_FILE}
exec <%= Inspec::Dist::EXEC_NAME %> exec ${PROFILE_PATH} --json-config ${CONFIG} 2>&1 | tee ${LOG_FILE}
exit_code=$?
if [ $exit_code -eq 1 ]; then
echo "InSpec run failed."
echo "<%= Inspec::Dist::PRODUCT_NAME %> run failed."
else
echo "InSpec run completed successfully."
echo "<%= Inspec::Dist::PRODUCT_NAME %> run completed successfully."
if [ $exit_code -eq 0 ]; then
echo "No controls failed or were skipped."
elif [ $exit_code -eq 100 ]; then

View file

@ -18,7 +18,7 @@ do_before() {
return 1
fi
# Execute an 'inspec compliance login' if a profile needs to be fetched from
# Execute an '<%= Inspec::Dist::EXEC_NAME %> compliance login' if a profile needs to be fetched from
# the Automate server
if [ "$(grep "compliance: " "$PLAN_CONTEXT/../inspec.yml")" ]; then
_do_compliance_login;
@ -29,10 +29,10 @@ do_setup_environment() {
set_buildtime_env PROFILE_CACHE_DIR "$HAB_CACHE_SRC_PATH/$pkg_dirname"
set_buildtime_env ARCHIVE_NAME "$pkg_name-$pkg_version.tar.gz"
# InSpec loads `pry` which tries to expand `~`. This fails if HOME isn't set.
# <%= Inspec::Dist::PRODUCT_NAME %> loads `pry` which tries to expand `~`. This fails if HOME isn't set.
set_runtime_env HOME "$pkg_svc_var_path"
# InSpec will create a `.inspec` directory in the user's home directory.
# <%= Inspec::Dist::PRODUCT_NAME %> will create a `.inspec` directory in the user's home directory.
# This overrides that to write to a place within the running service's path.
# NOTE: Setting HOME does the same currently. This is here to be explicit.
set_runtime_env INSPEC_CONFIG_DIR "$pkg_svc_var_path"
@ -52,9 +52,9 @@ do_unpack() {
}
do_build() {
inspec archive "$PROFILE_CACHE_DIR" \
--overwrite \
-o "$PROFILE_CACHE_DIR/$ARCHIVE_NAME"
<%= Inspec::Dist::EXEC_NAME %> archive "$PROFILE_CACHE_DIR" \
--overwrite \
-o "$PROFILE_CACHE_DIR/$ARCHIVE_NAME"
}
do_install() {
@ -63,7 +63,7 @@ do_install() {
_do_compliance_login() {
if [ -z $COMPLIANCE_CREDS ]; then
message="ERROR: Please perform an 'inspec compliance login' and set"
message="ERROR: Please perform an '<%= Inspec::Dist::EXEC_NAME %> compliance login' and set"
message="$message \$HAB_STUDIO_SECRET_COMPLIANCE_CREDS to the contents of"
message="$message '~/.inspec/compliance/config.json'"
build_line "$message"
@ -78,8 +78,8 @@ _do_compliance_login() {
sed 's/"//g'
)
insecure=$(echo $COMPLIANCE_CREDS | jq .insecure)
inspec compliance login --insecure $insecure \
--user $user \
--token $token \
$automate_server
<%= Inspec::Dist::EXEC_NAME %> compliance login --insecure $insecure \
--user $user \
--token $token \
$automate_server
}