From cbfd152ae35bffb7e5c461cba09c2f8455d2a8f9 Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Tue, 31 Oct 2023 22:03:45 -0500 Subject: [PATCH 01/13] Add dependabot. --- .github/dependabot.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..6ea84a2 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" \ No newline at end of file From 6d4d1966224090950538b7432e399d7a79fb35ed Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Tue, 31 Oct 2023 22:58:01 -0500 Subject: [PATCH 02/13] ADd GolangCI-lint. --- .github/workflows/golangci-lint.yml | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..5bdd5ea --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,55 @@ +name: golangci-lint +on: + push: + branches: + - master + - main + pull_request: + +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: '1.21' + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + # Require: The version of golangci-lint to use. + # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. + # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. + version: v1.54 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # + # Note: By default, the `.golangci.yml` file should be at the root of the repository. + # The location of the configuration file can be changed by using `--config=` + # args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true, then all caching functionality will be completely disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true, then the action won't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true, then the action won't cache or restore ~/.cache/go-build. + # skip-build-cache: true + + # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. + # install-mode: "goinstall" \ No newline at end of file From c5eda445c7446d7bfda6ed38965630842e1cffb8 Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Tue, 31 Oct 2023 23:20:32 -0500 Subject: [PATCH 03/13] Update golangci-lint.yml Remove "master" of branches. Change "ubuntu-latest" to "ubuntu-20.04". Add timeout in args. --- .github/workflows/golangci-lint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 5bdd5ea..92e9268 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -2,7 +2,6 @@ name: golangci-lint on: push: branches: - - master - main pull_request: @@ -14,7 +13,7 @@ permissions: jobs: golangci: name: lint - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v4 @@ -37,6 +36,7 @@ jobs: # Note: By default, the `.golangci.yml` file should be at the root of the repository. # The location of the configuration file can be changed by using `--config=` # args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 + args: --timeout=3m -v # Optional: show only new issues if it's a pull request. The default value is `false`. # only-new-issues: true From d44c3252623520ca63b85ea4a05ceef238e03a16 Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Tue, 31 Oct 2023 23:21:06 -0500 Subject: [PATCH 04/13] Changes "ubuntu-latest" to "ubuntu-20.04" --- .github/workflows/release-binary.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-binary.yml b/.github/workflows/release-binary.yml index 6accd90..b93506a 100644 --- a/.github/workflows/release-binary.yml +++ b/.github/workflows/release-binary.yml @@ -7,7 +7,7 @@ on: jobs: release-binary: name: Release Go Binary - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: matrix: # build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64 From be7ad39d51091d363718b985aa098da9162d57c3 Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Tue, 31 Oct 2023 23:59:19 -0500 Subject: [PATCH 05/13] Add Test report to .gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c57100a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +coverage.txt From 2ba693c6c38005210c4a1242db25de837ac8b8f7 Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Wed, 1 Nov 2023 00:00:15 -0500 Subject: [PATCH 06/13] Add test workflow of codecov. --- .github/workflows/test.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ee99e6b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,34 @@ +name: codecov + +on: + push: + branches: + - main + pull_request: + +jobs: + codecov: + strategy: + matrix: + go-version: [1.21.x] + platform: [ubuntu-20.04] + + runs-on: ${{ matrix.platform }} + + steps: + - name: Install GO + uses: actions/setup-go@v4 + with: + ${{ matrix.go-version }} + + - name: checkout code + uses: actions/checkout@v3 + + - name: Test + run: go test -shuffle=on -race -coverprofile=coverage.txt -covermode=atomic ./... + + - name: Vet + run: go vet ./... + + - name: Codecov + run: bash <(curl -s https://codecov.io/bash) \ No newline at end of file From 856d58534b6c5677c2cfeb77a950601661668c98 Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Wed, 1 Nov 2023 00:02:37 -0500 Subject: [PATCH 07/13] Changes "ubuntu-20.04" to "ubuntu-latest". --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ee99e6b..1c49a9e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: go-version: [1.21.x] - platform: [ubuntu-20.04] + platform: [ubuntu-latest] runs-on: ${{ matrix.platform }} From fc64e783759f9d9fb60d866be2726ac5615fed59 Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Wed, 1 Nov 2023 00:06:13 -0500 Subject: [PATCH 08/13] Changes "1.21.x" version to "1.21" version. --- .github/workflows/test.yml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c49a9e..43a0826 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,19 +10,16 @@ jobs: codecov: strategy: matrix: - go-version: [1.21.x] + go-version: [1.21] platform: [ubuntu-latest] runs-on: ${{ matrix.platform }} steps: - - name: Install GO - uses: actions/setup-go@v4 + - uses: actions/setup-go@v4 with: ${{ matrix.go-version }} - - - name: checkout code - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - name: Test run: go test -shuffle=on -race -coverprofile=coverage.txt -covermode=atomic ./... From 18dc4003552e82726cf3c17bdc5ec892a3a1883c Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Wed, 1 Nov 2023 00:09:10 -0500 Subject: [PATCH 09/13] Refactoring. --- .github/workflows/test.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 43a0826..c69f005 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,17 +8,14 @@ on: jobs: codecov: - strategy: - matrix: - go-version: [1.21] - platform: [ubuntu-latest] - - runs-on: ${{ matrix.platform }} + name: Test + runs-on: ubuntu-20.04 steps: - uses: actions/setup-go@v4 with: - ${{ matrix.go-version }} + go-version: '1.21' + cache: false - uses: actions/checkout@v3 - name: Test From 4dc54f76a5be2b9dd42202223b815f7002fd1c0a Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Wed, 1 Nov 2023 00:40:57 -0500 Subject: [PATCH 10/13] Refactoring Codecov --- .github/workflows/test.yml | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c69f005..b3c6c6f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,22 +7,16 @@ on: pull_request: jobs: - codecov: - name: Test - runs-on: ubuntu-20.04 - + build: + runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: '1.21' - cache: false - - uses: actions/checkout@v3 - - - name: Test - run: go test -shuffle=on -race -coverprofile=coverage.txt -covermode=atomic ./... - - - name: Vet - run: go vet ./... - - - name: Codecov - run: bash <(curl -s https://codecov.io/bash) \ No newline at end of file + go-version: 'stable' + - name: Run coverage + run: go test -race -coverprofile=coverage.txt -covermode=atomic + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} \ No newline at end of file From cfe0ef3329cf514847709250531f4d85f050bd10 Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Wed, 1 Nov 2023 15:48:00 -0500 Subject: [PATCH 11/13] Add .golangci --- .golangci.yml | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..268e208 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,175 @@ +### Config GolangCI + +# Options for analysis running. +run: + # The default concurrency value is the number of available CPU. + concurrency: 2 + + # Timeout for analysis, e.g. 30s, 5m. + # Default: 1m + timeout: 5m + + # Exit code when at least one issue was found. + # Default: 1 + issues-exit-code: 2 + + # Include test files or not. + # Default: true + tests: false + + # If set we pass it to "go list -mod={option}". From "go help modules": + # If invoked with -mod=readonly, the go command is disallowed from the implicit + # automatic updating of go.mod described above. Instead, it fails when any changes + # to go.mod are needed. This setting is most useful to check that go.mod does + # not need updates, such as in a continuous integration and testing system. + # If invoked with -mod=vendor, the go command assumes that the vendor + # directory holds the correct copies of dependencies and ignores + # the dependency descriptions in go.mod. + # + # Allowed values: readonly|vendor|mod + # By default, it isn't set. + modules-download-mode: readonly + + # Allow multiple parallel golangci-lint instances running. + # If false (default) - golangci-lint acquires file lock on start. + allow-parallel-runners: false + + # Define the Go version limit. + # Mainly related to generics support since go1.18. + # Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.18 + go: '1.18' + + +# output configuration options +output: + # Format: colored-line-number|line-number|json|colored-tab|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity + # + # Multiple can be specified by separating them by comma, output can be provided + # for each of them by separating format name and path by colon symbol. + # Output path can be either `stdout`, `stderr` or path to the file to write to. + # Example: "checkstyle:report.xml,json:stdout,colored-line-number" + # + # Default: colored-line-number + format: json + + # Print lines of code with issue. + # Default: true + print-issued-lines: false + # Print linter name in the end of issue text. + # Default: true + print-linter-name: false + # Make issues output unique by line. + # Default: true + uniq-by-line: false + # Add a prefix to the output file references. + # Default is no prefix. + path-prefix: "" + # Sort results by: filepath, line and column. + sort-results: false + +linters: + # Disable all linters. + # Default: false + disable-all: false + + # Enable all available linters. + # Default: false + enable-all: false + + enable: + - errcheck + - gosimple + - govet + - ineffassign + - unused + - asciicheck + - bidichk + - containedctx + - cyclop + - decorder + - depguard + - dupl + - dupword + - execinquery + - exhaustruct + - goconst + - gosec + - interfacebloat + - misspell + - sqlclosecheck + - unconvert + - unparam + - usestdlibvars + + # Run only fast linters from enabled linters set (first run won't be fast) + # Default: false + fast: true + + +linters-settings: + cyclop: + # The maximal average package complexity. + # If it's higher than 0.0 (float) the check is enabled + # Default: 0.0 + package-average: 0.5 + # Should ignore tests. + # Default: false + skip-tests: true + + decorder: + # Required order of `type`, `const`, `var` and `func` declarations inside a file. + # Default: types before constants before variables before functions. + dec-order: + - type + - const + - var + - func + # If true, underscore vars (vars with "_" as the name) will be ignored at all checks + # Default: false (underscore vars are not ignored) + ignore-underscore-vars: false + # If true, order of declarations is not checked at all. + # Default: true (disabled) + disable-dec-order-check: false + # If true, `init` func can be anywhere in file (does not have to be declared before all other functions). + # Default: true (disabled) + disable-init-func-first-check: false + # If true, multiple global `type`, `const` and `var` declarations are allowed. + # Default: true (disabled) + disable-dec-num-check: false + # If true, type declarations will be ignored for dec num check + # Default: false (type statements are not ignored) + disable-type-dec-num-check: false + # If true, const declarations will be ignored for dec num check + # Default: false (const statements are not ignored) + disable-const-dec-num-check: false + # If true, var declarations will be ignored for dec num check + # Default: false (var statements are not ignored) + disable-var-dec-num-check: false + + dupl: + # Tokens count to trigger issue. + # Default: 150 + threshold: 150 + + dupword: + # Keywords for detecting duplicate words. + # If this list is not empty, only the words defined in this list will be detected. + # Default: [] + keywords: + - "the" + - "and" + - "a" + # Keywords used to ignore detection. + # Default: [] + ignore: + - "0C0C" + + exhaustivestruct: + # Struct Patterns is list of expressions to match struct packages and names. + # The struct packages have the form `example.com/package.ExampleStruct`. + # The matching patterns can use matching syntax from https://pkg.go.dev/path#Match. + # If this list is empty, all structs are tested. + # Default: [] + struct-patterns: + - '*.Test' + - 'example.com/package.ExampleStruct' \ No newline at end of file From 3fd4d48c70961fa769fec1b4477a4c194208fb0c Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Wed, 1 Nov 2023 16:26:49 -0500 Subject: [PATCH 12/13] Bugfix "go test". --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b3c6c6f..71cbb75 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,7 +15,7 @@ jobs: with: go-version: 'stable' - name: Run coverage - run: go test -race -coverprofile=coverage.txt -covermode=atomic + run: go test -race -coverprofile=coverage.txt -covermode=atomic ./... - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 env: From 1e9cf6231cae02652c68961ba156b7a793d2dd21 Mon Sep 17 00:00:00 2001 From: AxzelBC Date: Mon, 13 Nov 2023 19:51:41 -0500 Subject: [PATCH 13/13] Fixing of linter alerts (goconst, gosec, unused) string `windows` has 3 occurrences, make it a constant (goconst) ssh.go file: field `dummyCommand` is unused (unused) db.go file: field `dummyCommand` is unused (unused) G107: Potential HTTP request made with variable url (gosec) --- pkg/command/db.go | 2 -- pkg/command/shell.go | 16 +++++++++++----- pkg/command/ssh.go | 2 -- pkg/command/summary.go | 11 +++++++++-- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/pkg/command/db.go b/pkg/command/db.go index 7bdf5b3..77e90d6 100644 --- a/pkg/command/db.go +++ b/pkg/command/db.go @@ -16,8 +16,6 @@ func init() { } type DB struct { - dummyCommand - dbType string db *sql.DB isFinished bool diff --git a/pkg/command/shell.go b/pkg/command/shell.go index eb108ba..8d2fc3a 100644 --- a/pkg/command/shell.go +++ b/pkg/command/shell.go @@ -11,6 +11,12 @@ import ( "syscall" ) +const ( + WINDOWS_OS = "windows" + LINUX_OS = "linux" + MAC_OS = "darwin" +) + func init() { commands["shell"] = &Shell{} } @@ -57,7 +63,7 @@ func ExecShell(command string) { fmt.Println(command) fmt.Println() var cmd *exec.Cmd - if runtime.GOOS == "windows" { + if runtime.GOOS == WINDOWS_OS { cmd = exec.Command("cmd", "/C", command) } else { cmd = exec.Command("bash", "-c", command) @@ -80,7 +86,7 @@ func ExecShell(command string) { case <-done: return case <-sigChan: - if runtime.GOOS == "windows" { + if runtime.GOOS == WINDOWS_OS { _ = cmd.Process.Signal(os.Kill) } else { _ = syscall.Kill(cmd.Process.Pid, syscall.SIGINT) @@ -92,11 +98,11 @@ func ExecShell(command string) { func getOSInfo() string { var version string switch runtime.GOOS { - case "darwin": + case MAC_OS: version = darwinVersion() - case "linux": + case LINUX_OS: version = linuxVersion() - case "windows": + case WINDOWS_OS: version = windowsVersion() } return fmt.Sprintf("%s %s", runtime.GOOS, version) diff --git a/pkg/command/ssh.go b/pkg/command/ssh.go index b976023..a74d1a5 100644 --- a/pkg/command/ssh.go +++ b/pkg/command/ssh.go @@ -17,8 +17,6 @@ func init() { } type Ssh struct { - dummyCommand - client *ssh.Client host string osInfo string diff --git a/pkg/command/summary.go b/pkg/command/summary.go index 344b2e4..bd8cae3 100644 --- a/pkg/command/summary.go +++ b/pkg/command/summary.go @@ -3,6 +3,7 @@ package command import ( "fmt" "net/http" + "net/url" "regexp" "strings" @@ -44,8 +45,14 @@ func (c *Summary) Prompts(input string) []string { return []string{prompt} } -func crawl(url string) string { - resp, err := http.Get(url) +func crawl(url_input string) string { + // Validate the URL + if _, err := url.ParseRequestURI(url_input); err != nil { + fmt.Println("Invalid URL: ", err) + return "" + } + + resp, err := http.Get(url_input) if err != nil { fmt.Println("Error fetching URL: ", err) return ""