Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add self update option #314

Merged
merged 3 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: 🔨 Build Test

on:
pull_request:
paths:
- '**.go'
- '**.mod'
workflow_dispatch:

jobs:
Expand All @@ -10,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
go-version: [1.18.x, 1.19.x]
go-version: [1.19.x]
os: [ubuntu-latest, windows-latest, macOS-12]
steps:
- name: Set up Go
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ name: 🚨 CodeQL Analysis
on:
workflow_dispatch:
pull_request:
branches:
- dev
paths:
- '**.go'
- '**.mod'

jobs:
analyze:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: 🙏🏻 Lint Test

on:
pull_request:
paths:
- '**.go'
- '**.mod'
workflow_dispatch:

jobs:
Expand All @@ -12,7 +15,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19
- name: Checkout code
uses: actions/checkout@v3
- name: Run golangci-lint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19

- uses: goreleaser/goreleaser-action@v4
with:
Expand Down
34 changes: 0 additions & 34 deletions .github/workflows/sonarcloud.yml

This file was deleted.

4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ require (
github.com/pkg/errors v0.9.1
github.com/projectdiscovery/goflags v0.1.8
github.com/projectdiscovery/gologger v1.1.8
github.com/projectdiscovery/utils v0.0.4-0.20221214110533-9f95ee986a54
github.com/projectdiscovery/utils v0.0.15-0.20230312150239-2528d5ff811d
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.14
github.com/stretchr/testify v1.8.1
golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783
golang.org/x/oauth2 v0.5.0
google.golang.org/api v0.109.0
gopkg.in/yaml.v2 v2.4.0
)
89 changes: 77 additions & 12 deletions go.sum

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions internal/runner/banner.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package runner

import "github.com/projectdiscovery/gologger"
import (
"github.com/projectdiscovery/gologger"
updateutils "github.com/projectdiscovery/utils/update"
)

const banner = `
________ _____ __
Expand All @@ -10,8 +13,8 @@ const banner = `
\____/_/\____/\__,_/\__,_/_/_/____/\__/ v1.0.2
`

// Version is the current version of nuclei
const Version = `1.0.2`
// version is the current version of cloudlist
const version = `1.0.2`

// showBanner is used to show the banner to the user
func showBanner() {
Expand All @@ -21,3 +24,11 @@ func showBanner() {
gologger.Print().Msgf("Use with caution. You are responsible for your actions\n")
gologger.Print().Msgf("Developers assume no liability and are not responsible for any misuse or damage.\n")
}

// GetUpdateCallback returns a callback function that updates cloudlist
func GetUpdateCallback() func() {
return func() {
showBanner()
updateutils.GetUpdateToolCallback("cloudlist", version)()
}
}
48 changes: 32 additions & 16 deletions internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@ import (
"github.com/projectdiscovery/gologger"
"github.com/projectdiscovery/gologger/levels"
fileutil "github.com/projectdiscovery/utils/file"
updateutils "github.com/projectdiscovery/utils/update"
"gopkg.in/yaml.v2"
)

// Options contains the configuration options for cloudlist.
type Options struct {
JSON bool // JSON returns JSON output
Silent bool // Silent Display results only
Version bool // Version returns the version of the tool.
Verbose bool // Verbose prints verbose output.
Hosts bool // Hosts specifies to fetch only DNS Names
IPAddress bool // IPAddress specifes to fetch only IP Addresses
Config string // Config is the location of the config file.
Output string // Output is the file to write found results too.
ExcludePrivate bool // ExcludePrivate excludes private IPs from results
Provider goflags.StringSlice // Provider specifies what providers to fetch assets for.
Id goflags.StringSlice // Id specifies what id's to fetch assets for.
ProviderConfig string // ProviderConfig is the location of the provider config file.
JSON bool // JSON returns JSON output
Silent bool // Silent Display results only
Version bool // Version returns the version of the tool.
Verbose bool // Verbose prints verbose output.
Hosts bool // Hosts specifies to fetch only DNS Names
IPAddress bool // IPAddress specifes to fetch only IP Addresses
Config string // Config is the location of the config file.
Output string // Output is the file to write found results too.
ExcludePrivate bool // ExcludePrivate excludes private IPs from results
Provider goflags.StringSlice // Provider specifies what providers to fetch assets for.
Id goflags.StringSlice // Id specifies what id's to fetch assets for.
ProviderConfig string // ProviderConfig is the location of the provider config file.
DisableUpdateCheck bool // DisableUpdateCheck disable automatic update check
}

var (
Expand All @@ -39,8 +41,6 @@ var (

// ParseOptions parses the command line flags provided by a user
func ParseOptions() *Options {
showBanner()

// Migrate config to provider config
if fileutil.FileExists(defaultConfigLocation) && !fileutil.FileExists(defaultProviderConfigLocation) {
if _, err := readProviderConfig(defaultConfigLocation); err == nil {
Expand Down Expand Up @@ -68,6 +68,10 @@ func ParseOptions() *Options {
flagSet.BoolVar(&options.IPAddress, "ip", false, "display only ips in results"),
flagSet.BoolVarP(&options.ExcludePrivate, "exclude-private", "ep", false, "exclude private ips in cli output"),
)
flagSet.CreateGroup("update", "Update",
flagSet.CallbackVarP(GetUpdateCallback(), "update", "up", "update cloudlist to latest version"),
flagSet.BoolVarP(&options.DisableUpdateCheck, "disable-update-check", "duc", false, "disable automatic cloudlist update check"),
)
flagSet.CreateGroup("output", "Output",
flagSet.StringVarP(&options.Output, "output", "o", "", "output file to write results"),
flagSet.BoolVar(&options.JSON, "json", false, "write output in json format"),
Expand All @@ -79,11 +83,23 @@ func ParseOptions() *Options {
_ = flagSet.Parse()

options.configureOutput()

showBanner()
if options.Version {
gologger.Info().Msgf("Current Version: %s\n", Version)
gologger.Info().Msgf("Current Version: %s\n", version)
os.Exit(0)
}

if !options.DisableUpdateCheck {
latestVersion, err := updateutils.GetVersionCheckCallback("cloudlist")()
if err != nil {
if options.Verbose {
gologger.Error().Msgf("cloudlist version check failed: %v", err.Error())
}
} else {
gologger.Info().Msgf("Current cloudlist version %v %v", version, updateutils.GetVersionDescription(version, latestVersion))
}
}

checkAndCreateProviderConfigFile(options)
return options
}
Expand Down
16 changes: 0 additions & 16 deletions sonar-project.properties

This file was deleted.