diff --git a/.docker/alpine.docker b/.docker/alpine.docker index 8467d8b..755d9ab 100644 --- a/.docker/alpine.docker +++ b/.docker/alpine.docker @@ -4,14 +4,13 @@ ARG REGISTRY="docker.io" ## BUILDER ##################################################################### -FROM golang:alpine3.18 as builder +FROM ${REGISTRY}/essentialkaos/golang:alpine3.18 as builder WORKDIR /go/src/github.com/essentialkaos/sslcli COPY . . -# hadolint ignore=DL3018 -RUN apk add --no-cache git make && make deps && make all +RUN make deps && make all ## FINAL IMAGE ################################################################# diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fc51337..d0ad1de 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -14,6 +14,12 @@ updates: - "andyone" reviewers: - "andyone" + groups: + all: + applies-to: version-updates + update-types: + - "minor" + - "patch" - package-ecosystem: "github-actions" directory: "/" diff --git a/.github/images/card.svg b/.github/images/card.svg new file mode 100644 index 0000000..25d6942 --- /dev/null +++ b/.github/images/card.svg @@ -0,0 +1,4 @@ + + + + diff --git a/.github/images/license.svg b/.github/images/license.svg new file mode 100644 index 0000000..8990e77 --- /dev/null +++ b/.github/images/license.svg @@ -0,0 +1 @@ +license: Apache-2.0licenseApache-2.0 \ No newline at end of file diff --git a/.github/images/usage.svg b/.github/images/usage.svg new file mode 100644 index 0000000..68342b1 --- /dev/null +++ b/.github/images/usage.svg @@ -0,0 +1,88 @@ + + + + SSL CLI Usage + + + + + + + + + + + + + + + + + + + Terminal + + Usage: sslcli {options} host… + Options + --email, -e email ........ User account email (required) + --format, -f format ...... Output result in different formats (text/json/yaml/xml) + --detailed, -d ........... Show detailed info for each endpoint + --ignore-mismatch, -i .... Proceed with assessments on certificate mismatch + --avoid-cache, -c ........ Disable cache usage + --public, -p ............. Publish results on sslscan.com + --perfect, -P ............ Return non-zero exit code if not A+ + --max-left, -M duration .. Check expiry date (num + d/w/m/y) + --notify, -n ............. Notify when check is done + --quiet, -q .............. Don't show any output + --pager, -G .............. Use pager for long output + --no-color, -nc .......... Disable colors in output + --help, -h ............... Show this help message + --version, -v ............ Show version + Examples + sslcli --register --email john@domain.com --org 'Some Organization' --name 'John Doe' + Register new user account for scanning + sslcli google.com + Check google.com + sslcli -P google.com + Check google.com and return zero exit code only if result is perfect (A+) + sslcli -p -c google.com + Check google.com, publish results, disable cache usage + sslcli -M 3m -q google.com + Check google.com in quiet mode and return error if cert expire in 3 months + sslcli hosts.txt + Check all hosts defined in hosts.txt file + + + diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml index 758de78..5980e6b 100644 --- a/.github/workflows/docker-push.yml +++ b/.github/workflows/docker-push.yml @@ -135,7 +135,7 @@ jobs: - name: Build and push Docker images (Docker) if: ${{ steps.build_check.outputs.build == 'true' }} - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: push: true context: . @@ -148,7 +148,7 @@ jobs: - name: Build and push Docker images (GHCR) if: ${{ steps.build_check.outputs.build == 'true' }} - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: push: true context: . diff --git a/Makefile b/Makefile index 3fa4367..d80d41c 100644 --- a/Makefile +++ b/Makefile @@ -1,39 +1,40 @@ ################################################################################ -# This Makefile generated by GoMakeGen 2.3.0 using next command: +# This Makefile generated by GoMakeGen 3.0.2 using next command: # gomakegen --mod . # # More info: https://kaos.sh/gomakegen ################################################################################ -export GO111MODULE=on - ifdef VERBOSE ## Print verbose information (Flag) VERBOSE_FLAG = -v endif -COMPAT ?= 1.18 +COMPAT ?= 1.19 MAKEDIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) GITREV ?= $(shell test -s $(MAKEDIR)/.git && git rev-parse --short HEAD) ################################################################################ .DEFAULT_GOAL := help -.PHONY = fmt vet all clean deps update init vendor mod-init mod-update mod-download mod-vendor help +.PHONY = fmt vet all install uninstall clean deps update init vendor mod-init mod-update mod-download mod-vendor help ################################################################################ all: sslcli ## Build all binaries sslcli: - go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" sslcli.go + @echo "Building sslcli…" + @go build $(VERBOSE_FLAG) -ldflags="-X main.gitrev=$(GITREV)" sslcli.go install: ## Install all binaries - cp sslcli /usr/bin/sslcli + @echo "Installing binaries…" + @cp sslcli /usr/bin/sslcli uninstall: ## Uninstall all binaries - rm -f /usr/bin/sslcli + @echo "Removing installed binaries…" + @rm -f /usr/bin/sslcli init: mod-init ## Initialize new module @@ -44,57 +45,70 @@ update: mod-update ## Update dependencies to the latest versions vendor: mod-vendor ## Make vendored copy of dependencies mod-init: + @echo "[1/2] Modules initialization…" ifdef MODULE_PATH ## Module path for initialization (String) - go mod init $(MODULE_PATH) + @go mod init $(MODULE_PATH) else - go mod init + @go mod init endif + @echo "[2/2] Dependencies cleanup…" ifdef COMPAT ## Compatible Go version (String) - go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT) + @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) -go=$(COMPAT) else - go mod tidy $(VERBOSE_FLAG) + @go mod tidy $(VERBOSE_FLAG) endif mod-update: + @echo "[1/4] Updating dependencies…" ifdef UPDATE_ALL ## Update all dependencies (Flag) - go get -u $(VERBOSE_FLAG) all + @go get -u $(VERBOSE_FLAG) all else - go get -u $(VERBOSE_FLAG) ./... + @go get -u $(VERBOSE_FLAG) ./... endif + @echo "[2/4] Stripping toolchain info…" + @grep -q 'toolchain ' go.mod && go mod edit -toolchain=none || : + + @echo "[3/4] Dependencies cleanup…" ifdef COMPAT - go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) + @go mod tidy $(VERBOSE_FLAG) -compat=$(COMPAT) else - go mod tidy $(VERBOSE_FLAG) + @go mod tidy $(VERBOSE_FLAG) endif - test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : + @echo "[4/4] Updating vendored dependencies…" + @test -d vendor && rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : mod-download: - go mod download + @echo "Downloading dependencies…" + @go mod download mod-vendor: - rm -rf vendor && go mod vendor $(VERBOSE_FLAG) + @echo "Vendoring dependencies…" + @rm -rf vendor && go mod vendor $(VERBOSE_FLAG) || : fmt: ## Format source code with gofmt - find . -name "*.go" -exec gofmt -s -w {} \; + @echo "Formatting sources…" + @find . -name "*.go" -exec gofmt -s -w {} \; vet: ## Runs 'go vet' over sources - go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./... + @echo "Running 'go vet' over sources…" + @go vet -composites=false -printfuncs=LPrintf,TLPrintf,TPrintf,log.Debug,log.Info,log.Warn,log.Error,log.Critical,log.Print ./... clean: ## Remove generated files - rm -f sslcli + @echo "Removing built binaries…" + @rm -f sslcli help: ## Show this info @echo -e '\n\033[1mTargets:\033[0m\n' @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ - | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-14s\033[0m %s\n", $$1, $$2}' + | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[33m%-9s\033[0m %s\n", $$1, $$2}' @echo -e '\n\033[1mVariables:\033[0m\n' @grep -E '^ifdef [A-Z_]+ .*?## .*$$' $(abspath $(lastword $(MAKEFILE_LIST))) \ | sed 's/ifdef //' \ - | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}' + | awk 'BEGIN {FS = " .*?## "}; {printf " \033[32m%-11s\033[0m %s\n", $$1, $$2}' @echo -e '' - @echo -e '\033[90mGenerated by GoMakeGen 2.3.0\033[0m\n' + @echo -e '\033[90mGenerated by GoMakeGen 3.0.2\033[0m\n' ################################################################################ diff --git a/README.md b/README.md index 9dcb6b4..5f8b000 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ -

+

GitHub Actions CI Status GoReportCard codebeat badge GitHub Actions CodeQL Status - +

-

Usage demo • Installation • Feature list • Usage • Build Status • Contributing • Terms of Use • License

+

Usage demo • Installation • Feature list • Usage • CI Status • Contributing • Terms of Use • License


@@ -67,48 +67,9 @@ docker run --rm -it ghcr.io/essentialkaos/sslcli:latest mydomain.com ### Usage -``` -Usage: sslcli {options} host… - -Options - - --email, -e email User account email (required) - --format, -f format Output result in different formats (text/json/yaml/xml) - --detailed, -d Show detailed info for each endpoint - --ignore-mismatch, -i Proceed with assessments on certificate mismatch - --avoid-cache, -c Disable cache usage - --public, -p Publish results on sslscan.com - --perfect, -P Return non-zero exit code if not A+ - --max-left, -M duration Check expiry date (num + d/w/m/y) - --notify, -n Notify when check is done - --quiet, -q Don't show any output - --pager, -G Use pager for long output - --no-color, -nc Disable colors in output - --help, -h Show this help message - --version, -v Show version - -Examples - - sslcli --register --email john@domain.com --org 'Some Organization' --name 'John Doe' - Register new user account for scanning - - sslcli google.com - Check google.com - - sslcli -P google.com - Check google.com and return zero exit code only if result is perfect (A+) - - sslcli -p -c google.com - Check google.com, publish results, disable cache usage - - sslcli -M 3m -q google.com - Check google.com in quiet mode and return error if cert expire in 3 months - - sslcli hosts.txt - Check all hosts defined in hosts.txt file -``` + -### Build Status +### CI Status | Branch | Status | |------------|--------| diff --git a/cli/cli.go b/cli/cli.go index f115f27..6a166ed 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -24,6 +24,7 @@ import ( "github.com/essentialkaos/ek/v12/strutil" "github.com/essentialkaos/ek/v12/support" "github.com/essentialkaos/ek/v12/support/deps" + "github.com/essentialkaos/ek/v12/terminal" "github.com/essentialkaos/ek/v12/timeutil" "github.com/essentialkaos/ek/v12/usage" "github.com/essentialkaos/ek/v12/usage/completion/bash" @@ -39,7 +40,7 @@ import ( const ( APP = "SSLScan Client" - VER = "3.0.0" + VER = "3.0.1" DESC = "Command-line client for the SSL Labs API" ) @@ -156,8 +157,9 @@ func Run(gitRev string, gomod []byte) { args, errs := options.Parse(optMap) - if len(errs) != 0 { - printError(errs[0].Error()) + if !errs.IsEmpty() { + terminal.Error("Options parsing errors:") + terminal.Error(errs.String()) os.Exit(1) } @@ -189,7 +191,7 @@ func Run(gitRev string, gomod []byte) { err = prepare() if err != nil { - printError(err.Error()) + terminal.Error(err) os.Exit(1) } @@ -201,7 +203,7 @@ func Run(gitRev string, gomod []byte) { } if err != nil { - printError(err.Error()) + terminal.Error(err) } if !ok { @@ -253,8 +255,8 @@ func checkForEmail() { return } - printError("You must provide an email address to make requests to the API.") - printError( + terminal.Error("You must provide an email address to make requests to the API.") + terminal.Error( "You can provide it using %s option, or using SSLLABS_EMAIL environment variable.", options.Format(OPT_EMAIL), ) @@ -684,11 +686,6 @@ func getNormGrade(grade string) string { } } -// printError prints error message to console -func printError(f string, a ...interface{}) { - fmtc.Fprintf(os.Stderr, "{r}"+f+"{!}\n", a...) -} - // ////////////////////////////////////////////////////////////////////////////////// // // checkAPIAvailability checks SSLLabs API availability @@ -735,12 +732,7 @@ func printCompletion() int { // printMan prints man page func printMan() { - fmt.Println( - man.Generate( - genUsage(), - genAbout(""), - ), - ) + fmt.Println(man.Generate(genUsage(), genAbout(""))) } // genUsage generates usage info diff --git a/cli/details.go b/cli/details.go index a117202..9ce317d 100644 --- a/cli/details.go +++ b/cli/details.go @@ -18,6 +18,7 @@ import ( "github.com/essentialkaos/ek/v12/pluralize" "github.com/essentialkaos/ek/v12/sliceutil" "github.com/essentialkaos/ek/v12/strutil" + "github.com/essentialkaos/ek/v12/terminal" "github.com/essentialkaos/ek/v12/timeutil" sslscan "github.com/essentialkaos/sslscan/v14" @@ -63,12 +64,12 @@ func printDetailedInfo(ap *sslscan.AnalyzeProgress, fromCache bool) { info, err := ap.Info(true, fromCache) if err != nil { - printError("\nCan't fetch full analyze info: %v\n", err) + terminal.Error("\nCan't fetch full analyze info: %v\n", err) return } if strings.ToUpper(info.Status) != "READY" { - printError("\n%s\n", info.StatusMessage) + terminal.Error("\n%s\n", info.StatusMessage) return } diff --git a/common/sslcli.spec b/common/sslcli.spec index 0751cb1..40f8c18 100644 --- a/common/sslcli.spec +++ b/common/sslcli.spec @@ -10,7 +10,7 @@ Summary: Pretty awesome command-line client for public SSLLabs API Name: sslcli -Version: 3.0.0 +Version: 3.0.1 Release: 0%{?dist} Group: Applications/System License: Apache License, Version 2.0 @@ -22,7 +22,7 @@ Source100: checksum.sha512 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) -BuildRequires: golang >= 1.20 +BuildRequires: golang >= 1.21 Provides: %{name} = %{version}-%{release} @@ -37,13 +37,15 @@ Pretty awesome command-line client for public SSLLabs API. %{crc_check} %setup -q - -%build if [[ ! -d "%{name}/vendor" ]] ; then - echo "This package requires vendored dependencies" + echo -e "----\nThis package requires vendored dependencies\n----" + exit 1 +elif [[ -f "%{name}/%{name}" ]] ; then + echo -e "----\nSources must not contain precompiled binaries\n----" exit 1 fi +%build pushd %{name} go build %{name}.go cp LICENSE .. @@ -101,6 +103,10 @@ fi ################################################################################ %changelog +* Mon Jun 24 2024 Anton Novojilov - 3.0.1-0 +- Code refactoring +- Dependencies update + * Sat Mar 30 2024 Anton Novojilov - 3.0.0-0 - sslscan package update to v14 - Added account registration feature diff --git a/go.mod b/go.mod index a5b646b..b1e82a3 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,11 @@ module github.com/essentialkaos/sslcli go 1.19 require ( - github.com/essentialkaos/ek/v12 v12.113.1 - github.com/essentialkaos/sslscan/v14 v14.0.0 + github.com/essentialkaos/ek/v12 v12.127.0 + github.com/essentialkaos/sslscan/v14 v14.0.1 ) require ( - github.com/essentialkaos/depsy v1.1.0 // indirect - golang.org/x/sys v0.18.0 // indirect + github.com/essentialkaos/depsy v1.3.0 // indirect + golang.org/x/sys v0.21.0 // indirect ) diff --git a/go.sum b/go.sum index 7ff94a7..a4739d3 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,12 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk= -github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI= -github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= -github.com/essentialkaos/ek/v12 v12.113.1 h1:3opV9dwRpIQq1fqg5mkaSEt6ogECL4VLzrH/829qeYg= -github.com/essentialkaos/ek/v12 v12.113.1/go.mod h1:SslW97Se34YQKc08Ume2V/8h/HPTgLS1+Iok64cNF/U= -github.com/essentialkaos/sslscan/v14 v14.0.0 h1:b5Mob+7Dl7JsaZ/3Bl2cba9cyPwdtdCd+fWv/9JCE5k= -github.com/essentialkaos/sslscan/v14 v14.0.0/go.mod h1:pAaJOxGKRrxmVHnTbtOS7ks+yTSF86mzS7OojcUbJPE= +github.com/essentialkaos/depsy v1.3.0 h1:CN7bRgBU2jGTHSkg/Sh38eDUn7cvmaTp2sxFt2HpFeU= +github.com/essentialkaos/depsy v1.3.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8= +github.com/essentialkaos/ek/v12 v12.127.0 h1:fU5A+QbIZ7NTq1K5jGVwAWwuLtBUhsIKuRWYT78hE+Q= +github.com/essentialkaos/ek/v12 v12.127.0/go.mod h1:71IJ7m82hgjrvWnhL+z0vIhguxz47/rfVma5/CeI5Fw= +github.com/essentialkaos/sslscan/v14 v14.0.1 h1:vzf3vQ4/Odc7Cah7q+jOPwrVDQdNBdWMuNT+d8tRvm8= +github.com/essentialkaos/sslscan/v14 v14.0.1/go.mod h1:s83oY+H7TDwgZuA1VkA8F8g/GMQu2yV5E0+KpvIBwcg= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= +golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=