github.com/RedHatInsights/insights-content-service@v1.0.0/gosec.sh (about)

     1  #!/bin/bash
     2  # Copyright 2020, 2021, 2022 Red Hat, Inc
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #      http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  RED_BG=$(tput setab 1)
    17  GREEN_BG=$(tput setab 2)
    18  BLUE=$(tput setaf 4)
    19  NC=$(tput sgr0) # No Color
    20  
    21  GO_SEC_ARGS=""
    22  
    23  if [[ $* != *verbose* ]] && [[ -z "${VERBOSE}" ]]; then
    24      GO_SEC_ARGS="-quiet"
    25  fi
    26  
    27  cd "$(dirname "$0")" || exit
    28  
    29  echo -e "${BLUE}Security issues detection${NC}"
    30  
    31  if ! [ -x "$(command -v gosec)" ]
    32  then
    33      echo -e "${BLUE}Installing ${NC}"
    34      curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b "$(go env GOPATH)/bin"
    35      # shellcheck disable=SC2181
    36      if [ $? -eq 0 ]
    37      then
    38          echo -e "${BLUE}Installed ${NC}"
    39      else
    40          echo -e "${RED_BG}[FAIL]${NC} Installation failure"
    41          exit 2
    42      fi
    43  fi
    44  
    45  if ! gosec $GO_SEC_ARGS ./...
    46  then
    47      echo -e "${RED_BG}[FAIL]${NC} Potential security issues detected!"
    48      exit 1
    49  else
    50      echo -e "${GREEN_BG}[OK]${NC} No potential security issues has been detected"
    51      exit 0
    52  fi