@@ -13,11 +13,11 @@ version_command() {
1313
1414c8l_usage () {
1515 if [[ -n $long_usage ]]; then
16- printf " c8l - [EXPERIMENTAL] Chainloop (c8) Labs CLI\n"
16+ printf " c8l - [EXPERIMENTAL] (c8l) Chainloop Labs CLI\n"
1717 echo
1818
1919 else
20- printf " c8l - [EXPERIMENTAL] Chainloop (c8) Labs CLI\n"
20+ printf " c8l - [EXPERIMENTAL] (c8l) Chainloop Labs CLI\n"
2121 echo
2222
2323 fi
@@ -32,6 +32,7 @@ c8l_usage() {
3232 printf " %s Show help about a command\n" " help "
3333 printf " %s [i] Inspect.\n" " inspect"
3434 printf " %s Show the content of c8l script ready for sourcing.\n" " source "
35+ printf " %s Run a command in the c8l environment.\n" " cmd "
3536 printf " %s Chainloop CLI UX improved\n" " cli "
3637 echo
3738
@@ -132,6 +133,41 @@ c8l_source_usage() {
132133 fi
133134}
134135
136+ c8l_cmd_usage () {
137+ if [[ -n $long_usage ]]; then
138+ printf " c8l cmd - Run a command in the c8l environment.\n"
139+ echo
140+
141+ else
142+ printf " c8l cmd - Run a command in the c8l environment.\n"
143+ echo
144+
145+ fi
146+
147+ printf " Alias: r\n"
148+ echo
149+
150+ printf " %s\n" " Usage:"
151+ printf " c8l cmd COMMAND\n"
152+ printf " c8l cmd --help | -h\n"
153+ echo
154+
155+ if [[ -n $long_usage ]]; then
156+ printf " %s\n" " Options:"
157+
158+ printf " %s\n" " --help, -h"
159+ printf " Show this help\n"
160+ echo
161+
162+ printf " %s\n" " Arguments:"
163+
164+ printf " %s\n" " COMMAND"
165+ printf " Command to run in the c8l environment.\n"
166+ echo
167+
168+ fi
169+ }
170+
135171c8l_cli_usage () {
136172 if [[ -n $long_usage ]]; then
137173 printf " c8l cli - Chainloop CLI UX improved\n"
@@ -560,7 +596,7 @@ normalize_input() {
560596 done
561597}
562598
563- export CHAINLOOP_BIN_PATH=" ${CHAINLOOP_BIN_PATH:-/ usr/ local/ bin/ chainloop } "
599+ export CHAINLOOP_BIN_PATH=" ${CHAINLOOP_BIN_PATH:-/ usr/ local/ bin/ chainloop_bin } "
564600
565601is_chainloop_in_path () {
566602 if command -v chainloop & > /dev/null; then
@@ -605,11 +641,11 @@ prepare_tmp_file() {
605641 file_name=$1
606642 mkdir -p " ${tmp_dir} "
607643 t=" ${tmp_dir} /${file_name} "
608- if [ -f $t ]; then
644+ if [ -f " $t " ]; then
609645 echo " Temporary file file $t already exists"
610646 return 1
611647 fi
612- echo $t
648+ echo " $t "
613649}
614650
615651# chainloop_bin_cache_in_dir - it takes a path and copy there the CHAINLOOP_BIN_PATH
@@ -632,6 +668,7 @@ chainloop_recreate_env_from_file() {
632668 file=$( basename $path )
633669 if [[ $file =~ ^\. env_.* $ ]]; then
634670 export $( echo $file | sed ' s/\.env_//' ) =$( cat $path )
671+ echo export $( echo $file | sed ' s/\.env_//' ) =$( cat $path )
635672 else
636673 log_error " File $file is not in the format .env_NAME"
637674 return 1
@@ -761,6 +798,7 @@ generic_install() {
761798 mkdir -p $CHAINLOOP_BIN_PATH
762799 log " Installing $file "
763800 curl -sfL $url -o $file_path
801+
764802 if [ $? -ne 0 ]; then
765803 log_error " $file installation failed"
766804 return 1
@@ -820,25 +858,32 @@ chainloop_attestation_push() {
820858 export COSIGN_PASSWORD=" $CHAINLOOP_SIGNING_PASSWORD "
821859 cosign generate-key-pair
822860 fi
823- if [ -z " ${CHAINLOOP_SIGNING_KEY_PATH+x } " ]; then
861+ if [ -n " ${CHAINLOOP_SIGNING_KEY } " ]; then
824862 log " with CHAINLOOP_SIGNING_KEY"
825863 tmp_key=" ${CHAINLOOP_TMP_DIR} /key"
826864 mkdir -p " ${CHAINLOOP_TMP_DIR} "
827- echo " ${CHAINLOOP_SIGNING_KEY} " > $tmp_key
828- else
865+ echo " ${CHAINLOOP_SIGNING_KEY} " > " $tmp_key "
866+ fi
867+ if [ -n " ${CHAINLOOP_SIGNING_KEY_PATH} " ]; then
829868 log " with CHAINLOOP_SIGNING_KEY_PATH"
830869 tmp_key=" ${CHAINLOOP_SIGNING_KEY_PATH} "
831870 fi
871+
872+ tmp_key_value=" "
873+ if [ -n " $tmp_key " ]; then
874+ tmp_key_value=" --key $tmp_key "
875+ fi
876+
832877 # chainloop attestation push --key env://CHAINLOOP_SIGNING_KEY
833- if chainloop attestation push --key $tmp_key --remote-state --attestation-id " ${CHAINLOOP_ATTESTATION_ID} " & > c8-push.txt; then
878+ if chainloop attestation push " $tmp_key_value " --output json --remote-state --attestation-id " ${CHAINLOOP_ATTESTATION_ID} " > c8-push.txt; then
834879 log " Attestation Process Completed Successfully"
835880 cat c8-push.txt
836- rm $tmp_key
881+ rm -f " $tmp_key "
837882 else
838883 exit_code=$?
839884 log_error " Attestation Process Failed"
840885 cat c8-push.txt
841- rm $tmp_key
886+ rm -f " $tmp_key "
842887 return $exit_code
843888 fi
844889}
@@ -849,20 +894,24 @@ chainloop_summary() {
849894 log $tmpfile
850895 return 1
851896 fi
852- echo -e " ## Great job!\n\nYou are making SecOps and Compliance teams really happy. Keep up the good work!\n" >> $tmpfile
897+ echo -e " ## Great job!\n\nYou are making SecOps and Compliance teams really happy. Keep up the good work!\n" >> $tmpfile
853898
854899 digest=" "
855900 if [ -f c8-push.txt ]; then
856- digest=$( cat c8-push.txt | grep " Digest: " | awk -F' sha256:' ' {print $2}' )
857- echo " **[Chainloop Trust Report]( https://app.chainloop.dev/attestation/sha256:${digest} )**" >> $tmpfile
858- echo " \`\`\` " >> $tmpfile
901+ digest=$( cat c8-push.txt | jq -r ' .digest' )
902+ if [ $? -ne 0 ]; then
903+ log_error " Failed to get digest from c8-push.txt"
904+ return 1
905+ fi
906+ echo " **[Chainloop Trust Report]( https://app.chainloop.dev/attestation/${digest} )**" >> " $tmpfile "
859907 fi
860- if [ -f c8-status.txt ]; then
861- cat c8-status.txt >> $tmpfile
862- echo " \`\`\` " >> $tmpfile
908+ if [ -f c8-status.txt ] ; then
909+ echo " \`\`\` " >> " $tmpfile "
910+ cat c8-status.txt >> " $tmpfile "
911+ echo " \`\`\` " >> " $tmpfile "
863912 fi
864- cat $tmpfile
865- rm $tmpfile
913+ cat " $tmpfile "
914+ rm " $tmpfile "
866915}
867916
868917chainloop_summary_on_failure () {
@@ -1076,6 +1125,11 @@ c8l_source_command() {
10761125
10771126}
10781127
1128+ c8l_cmd_command () {
1129+ eval " ${args['command']} "
1130+
1131+ }
1132+
10791133c8l_cli_install_tools_command () {
10801134 validate_env
10811135 install_chainloop_tools
@@ -1272,6 +1326,13 @@ parse_requirements() {
12721326 shift $#
12731327 ;;
12741328
1329+ cmd | r)
1330+ action=" cmd"
1331+ shift
1332+ c8l_cmd_parse_requirements " $@ "
1333+ shift $#
1334+ ;;
1335+
12751336 cli | c)
12761337 action=" cli"
12771338 shift
@@ -1432,6 +1493,56 @@ c8l_source_parse_requirements() {
14321493
14331494}
14341495
1496+ c8l_cmd_parse_requirements () {
1497+
1498+ while [[ $# -gt 0 ]]; do
1499+ case " ${1:- } " in
1500+ --help | -h)
1501+ long_usage=yes
1502+ c8l_cmd_usage
1503+ exit
1504+ ;;
1505+
1506+ * )
1507+ break
1508+ ;;
1509+
1510+ esac
1511+ done
1512+
1513+ action=" cmd"
1514+
1515+ while [[ $# -gt 0 ]]; do
1516+ key=" $1 "
1517+ case " $key " in
1518+
1519+ -?* )
1520+ printf " invalid option: %s\n" " $key " >&2
1521+ exit 1
1522+ ;;
1523+
1524+ * )
1525+
1526+ if [[ -z ${args['command']+x} ]]; then
1527+ args[' command' ]=$1
1528+ shift
1529+ else
1530+ printf " invalid argument: %s\n" " $key " >&2
1531+ exit 1
1532+ fi
1533+
1534+ ;;
1535+
1536+ esac
1537+ done
1538+
1539+ if [[ -z ${args['command']+x} ]]; then
1540+ printf " missing required argument: COMMAND\nusage: c8l cmd COMMAND\n" >&2
1541+ exit 1
1542+ fi
1543+
1544+ }
1545+
14351546c8l_cli_parse_requirements () {
14361547
14371548 while [[ $# -gt 0 ]]; do
@@ -2044,6 +2155,7 @@ run() {
20442155 " help" ) c8l_help_command ;;
20452156 " inspect" ) c8l_inspect_command ;;
20462157 " source" ) c8l_source_command ;;
2158+ " cmd" ) c8l_cmd_command ;;
20472159 " cli" ) c8l_cli_command ;;
20482160 " cli install-tools" ) c8l_cli_install_tools_command ;;
20492161 " cli attestation-add-from-yaml" ) c8l_cli_attestation_add_from_yaml_command ;;
0 commit comments