diff --git a/.goreleaser.yaml b/.goreleaser.yaml index d8552b6..bafc299 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -14,15 +14,15 @@ builds: # export GO_VERSION=$(go version | awk '{print $3}') # export BUILD_USER=$(whoami) ldflags: - - "-X github.com/OpenCHAMI/magellan/internal/version.GitCommit={{ .Commit }} \ - -X github.com/OpenCHAMI/magellan/internal/version.BuildTime={{ .Timestamp }} \ - -X github.com/OpenCHAMI/magellan/internal/version.Version={{ .Version }} \ - -X github.com/OpenCHAMI/magellan/internal/version.GitBranch={{ .Branch }} \ - -X github.com/OpenCHAMI/magellan/internal/version.GitTag={{ .Tag }} \ - -X github.com/OpenCHAMI/magellan/internal/version.GitState={{ .Env.GIT_STATE }} \ - -X github.com/OpenCHAMI/magellan/internal/version.BuildHost={{ .Env.BUILD_HOST }} \ - -X github.com/OpenCHAMI/magellan/internal/version.GoVersion={{ .Env.GO_VERSION }} \ - -X github.com/OpenCHAMI/magellan/internal/version.BuildUser={{ .Env.BUILD_USER }} " + - "-X github.com/davidallendj/magellan/internal/version.GitCommit={{ .Commit }} \ + -X github.com/davidallendj/magellan/internal/version.BuildTime={{ .Timestamp }} \ + -X github.com/davidallendj/magellan/internal/version.Version={{ .Version }} \ + -X github.com/davidallendj/magellan/internal/version.GitBranch={{ .Branch }} \ + -X github.com/davidallendj/magellan/internal/version.GitTag={{ .Tag }} \ + -X github.com/davidallendj/magellan/internal/version.GitState={{ .Env.GIT_STATE }} \ + -X github.com/davidallendj/magellan/internal/version.BuildHost={{ .Env.BUILD_HOST }} \ + -X github.com/davidallendj/magellan/internal/version.GoVersion={{ .Env.GO_VERSION }} \ + -X github.com/davidallendj/magellan/internal/version.BuildUser={{ .Env.BUILD_USER }} " tags: - version goos: diff --git a/CHANGELOG.md b/CHANGELOG.md index a6a8e92..bb3abf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -271,7 +271,7 @@ Tidied up CLI flag names * Ability to update firmware * Refactored connection handling for faster scanning - * Updated to reflect home at github.com/OpenCHAMI + * Updated to reflect home at github.com/davidallendj * Updated to reflect ghcr.io as container home ## [Unreleased] diff --git a/Makefile b/Makefile index 8b5f3cb..5495893 100644 --- a/Makefile +++ b/Makefile @@ -100,9 +100,9 @@ diff: ## git diff .PHONY: docs docs: ## go docs $(call print-target) - go doc github.com/OpenCHAMI/magellan/cmd - go doc github.com/OpenCHAMI/magellan/internal - go doc github.com/OpenCHAMI/magellan/pkg/crawler + go doc github.com/davidallendj/magellan/cmd + go doc github.com/davidallendj/magellan/internal + go doc github.com/davidallendj/magellan/pkg/crawler .PHONY: emulator emulator: diff --git a/README.md b/README.md index 6cb34be..bcbc566 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# OpenCHAMI Magellan +# Magellan -The `magellan` CLI tool is a Redfish-based, board management controller (BMC) discovery tool designed to scan networks and is written in Go. The tool collects information from BMC nodes using the provided Redfish RESTful API with [`gofish`](https://github.com/stmcginnis/gofish) and loads the queried data into an [SMD](https://github.com/OpenCHAMI/smd/tree/master) instance. The tool strives to be more flexible by implementing multiple methods of discovery to work for a wider range of systems (WIP) and is capable of using independently of other tools or services. +The `magellan` CLI tool is a Redfish-based, board management controller (BMC) discovery tool designed to scan networks and is written in Go. The tool collects information from BMC nodes using the provided Redfish RESTful API with [`gofish`](https://github.com/stmcginnis/gofish) and loads the queried data into an [SMD](https://github.com/davidallendj/smd/tree/master) instance. The tool strives to be more flexible by implementing multiple methods of discovery to work for a wider range of systems (WIP) and is capable of using independently of other tools or services. **Note: `magellan` v0.1.0 is incompatible with SMD v2.15.3 and earlier.** @@ -25,7 +25,7 @@ See the [TODO](#todo) section for a list of soon-ish goals planned. The `magellan` tool can be built to run on bare metal. Install the required Go tools, clone the repo, and then build the binary in the root directory with the following: ```bash -git clone https://github.com/OpenCHAMI/magellan +git clone https://github.com/davidallendj/magellan cd magellan go mod tidy && go build ``` @@ -58,10 +58,10 @@ This might take some time to complete initially because of the `go-sqlite3` driv ### Docker -The tool can also run using Docker. To build the Docker container, run `docker build -t magellan:testing .` in the project's directory. This is useful if you to run `magellan` on a different system through Docker desktop without having to install and build with Go (or if you can't do so for some reason). [Prebuilt images](https://github.com/OpenCHAMI/magellan/pkgs/container/magellan) are available as well on `ghcr`. Images can be pulled directly from the repository: +The tool can also run using Docker. To build the Docker container, run `docker build -t magellan:testing .` in the project's directory. This is useful if you to run `magellan` on a different system through Docker desktop without having to install and build with Go (or if you can't do so for some reason). [Prebuilt images](https://github.com/davidallendj/magellan/pkgs/container/magellan) are available as well on `ghcr`. Images can be pulled directly from the repository: ```bash -docker pull ghcr.io/openchami/magellan:latest +docker pull ghcr.io/davidallendj/magellan:latest ``` See the ["Running with Docker"](#running-with-docker) section below about running with the Docker container. @@ -195,7 +195,7 @@ watch -n 1 "./magellan update 172.16.0.110 --status --username $USERNAME --passw ### Getting an Access Token (WIP) -The `magellan` tool has a `login` subcommand that works with the [`opaal`](https://github.com/OpenCHAMI/opaal) service to obtain a token needed to access the SMD service. If the SMD instance requires authentication, set the `ACCESS_TOKEN` environment variable to have `magellan` include it in the header for HTTP requests to SMD. +The `magellan` tool has a `login` subcommand that works with the [`opaal`](https://github.com/davidallendj/opaal) service to obtain a token needed to access the SMD service. If the SMD instance requires authentication, set the `ACCESS_TOKEN` environment variable to have `magellan` include it in the header for HTTP requests to SMD. ```bash # must have a running OPAAL instance @@ -205,7 +205,7 @@ The `magellan` tool has a `login` subcommand that works with the [`opaal`](https export ACCESS_TOKEN=eyJhbGciOiJIUzI1NiIs... ``` -Alternatively, if you are running the OpenCHAMI quickstart in the [deployment recipes](https://github.com/OpenCHAMI/deployment-recipes), you can run the provided script to generate a token and set the environment variable that way. +Alternatively, if you are running the OpenCHAMI quickstart in the [deployment recipes](https://github.com/davidallendj/deployment-recipes), you can run the provided script to generate a token and set the environment variable that way. ```bash quickstart_dir=path/to/deployment/recipes/quickstart @@ -218,8 +218,7 @@ export ACCESS_TOKEN=$(gen_access_token) The `magellan` tool can be ran in a Docker container after pulling the latest image: ```bash -docker pull ghcr.io/openchami/magellan:latest - +docker pull ghcr.io/davidallendj/magellan:latest ``` Then, run either with the helper script found in `bin/magellan.sh` or the binary in the container: @@ -250,7 +249,7 @@ In summary, `magellan` needs at minimum the following configured to work on each ## TODO -See the [issue list](https://github.com/OpenCHAMI/magellan/issues) for plans for `magellan`. Here is a list of other features left to add, fix, or do (and some ideas!): +See the [issue list](https://github.com/davidallendj/magellan/issues) for plans for `magellan`. Here is a list of other features left to add, fix, or do (and some ideas!): * [X] Confirm loading different components into SMD * [X] Add ability to set subnet mask for scanning diff --git a/cmd/cache.go b/cmd/cache.go new file mode 100644 index 0000000..11c87a5 --- /dev/null +++ b/cmd/cache.go @@ -0,0 +1,96 @@ +package cmd + +import ( + "fmt" + "net/url" + "os" + "strconv" + + magellan "github.com/davidallendj/magellan/internal" + "github.com/davidallendj/magellan/internal/cache/sqlite" + "github.com/rs/zerolog/log" + "github.com/spf13/cobra" +) + +var ( + withHosts []string + withPorts []int +) + +var cacheCmd = &cobra.Command{ + Use: "cache", + Short: "Manage found assets in cache.", + Run: func(cmd *cobra.Command, args []string) { + // show the help for cache and exit + if len(args) <= 0 { + cmd.Help() + os.Exit(0) + } + }, +} + +var cacheRemoveCmd = &cobra.Command{ + Use: "remove", + Short: "Remove a host from a scanned cache list.", + Run: func(cmd *cobra.Command, args []string) { + assets := []magellan.RemoteAsset{} + + // add all assets directly from positional args + for _, arg := range args { + var ( + port int + uri *url.URL + err error + ) + uri, err = url.ParseRequestURI(arg) + if err != nil { + log.Error().Err(err).Msg("failed to parse arg") + } + + // convert port to its "proper" type + if uri.Port() == "" { + uri.Host += ":443" + } + port, err = strconv.Atoi(uri.Port()) + if err != nil { + log.Error().Err(err).Msg("failed to convert port to integer type") + } + asset := magellan.RemoteAsset{ + Host: fmt.Sprintf("%s://%s", uri.Scheme, uri.Hostname()), + Port: port, + } + assets = append(assets, asset) + } + + // Add all assets with specified hosts (same host different different ports) + // This should produce the following SQL: + // DELETE FROM magellan_scanned_assets WHERE host=:host + for _, host := range withHosts { + assets = append(assets, magellan.RemoteAsset{ + Host: host, + Port: -1, + }) + } + // Add all assets with specified ports (same port different hosts) + // This should produce the following SQL: + // DELETE FROM magellan_scanned_assets WHERE port=:port + for _, port := range withPorts { + assets = append(assets, magellan.RemoteAsset{ + Host: "", + Port: port, + }) + } + if len(assets) <= 0 { + log.Error().Msg("nothing to do") + os.Exit(1) + } + sqlite.DeleteScannedAssets(cachePath, assets...) + }, +} + +func init() { + cacheRemoveCmd.Flags().StringSliceVar(&withHosts, "with-hosts", []string{}, "Remove all assets with specified hosts") + cacheRemoveCmd.Flags().IntSliceVar(&withPorts, "with-ports", []int{}, "Remove all assets with specified ports") + cacheCmd.AddCommand(cacheRemoveCmd) + rootCmd.AddCommand(cacheCmd) +} diff --git a/cmd/collect.go b/cmd/collect.go index 1f3288a..53807c3 100644 --- a/cmd/collect.go +++ b/cmd/collect.go @@ -4,11 +4,11 @@ import ( "fmt" "os/user" - magellan "github.com/OpenCHAMI/magellan/internal" - "github.com/OpenCHAMI/magellan/internal/cache/sqlite" - urlx "github.com/OpenCHAMI/magellan/internal/url" - "github.com/OpenCHAMI/magellan/pkg/auth" "github.com/cznic/mathutil" + magellan "github.com/davidallendj/magellan/internal" + "github.com/davidallendj/magellan/internal/cache/sqlite" + urlx "github.com/davidallendj/magellan/internal/url" + "github.com/davidallendj/magellan/pkg/auth" "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -17,7 +17,7 @@ import ( // The `collect` command fetches data from a collection of BMC nodes. // This command should be ran after the `scan` to find available hosts // on a subnet. -var collectCmd = &cobra.Command{ +var CollectCmd = &cobra.Command{ Use: "collect", Short: "Collect system information by interrogating BMC node", Long: "Send request(s) to a collection of hosts running Redfish services found stored from the 'scan' in cache.\n" + @@ -75,28 +75,28 @@ var collectCmd = &cobra.Command{ func init() { currentUser, _ = user.Current() - collectCmd.PersistentFlags().StringVar(&host, "host", "", "Set the URI to the SMD root endpoint") - collectCmd.PersistentFlags().StringVar(&username, "username", "", "Set the BMC user") - collectCmd.PersistentFlags().StringVar(&password, "password", "", "Set the BMC password") - collectCmd.PersistentFlags().StringVar(&scheme, "scheme", "https", "Set the scheme used to query") - collectCmd.PersistentFlags().StringVar(&protocol, "protocol", "tcp", "Set the protocol used to query") - collectCmd.PersistentFlags().StringVarP(&outputPath, "output", "o", fmt.Sprintf("/tmp/%smagellan/inventory/", currentUser.Username+"/"), "Set the path to store collection data") - collectCmd.PersistentFlags().BoolVar(&forceUpdate, "force-update", false, "Set flag to force update data sent to SMD") - collectCmd.PersistentFlags().StringVar(&cacertPath, "cacert", "", "Path to CA cert. (defaults to system CAs)") + CollectCmd.PersistentFlags().StringVar(&host, "host", "", "Set the URI to the SMD root endpoint") + CollectCmd.PersistentFlags().StringVar(&username, "username", "", "Set the BMC user") + CollectCmd.PersistentFlags().StringVar(&password, "password", "", "Set the BMC password") + CollectCmd.PersistentFlags().StringVar(&scheme, "scheme", "https", "Set the scheme used to query") + CollectCmd.PersistentFlags().StringVar(&protocol, "protocol", "tcp", "Set the protocol used to query") + CollectCmd.PersistentFlags().StringVarP(&outputPath, "output", "o", fmt.Sprintf("/tmp/%smagellan/inventory/", currentUser.Username+"/"), "Set the path to store collection data") + CollectCmd.PersistentFlags().BoolVar(&forceUpdate, "force-update", false, "Set flag to force update data sent to SMD") + CollectCmd.PersistentFlags().StringVar(&cacertPath, "cacert", "", "Path to CA cert. (defaults to system CAs)") // set flags to only be used together - collectCmd.MarkFlagsRequiredTogether("username", "password") + CollectCmd.MarkFlagsRequiredTogether("username", "password") // bind flags to config properties - checkBindFlagError(viper.BindPFlag("collect.host", collectCmd.Flags().Lookup("host"))) - checkBindFlagError(viper.BindPFlag("collect.username", collectCmd.Flags().Lookup("username"))) - checkBindFlagError(viper.BindPFlag("collect.password", collectCmd.Flags().Lookup("password"))) - checkBindFlagError(viper.BindPFlag("collect.scheme", collectCmd.Flags().Lookup("scheme"))) - checkBindFlagError(viper.BindPFlag("collect.protocol", collectCmd.Flags().Lookup("protocol"))) - checkBindFlagError(viper.BindPFlag("collect.output", collectCmd.Flags().Lookup("output"))) - checkBindFlagError(viper.BindPFlag("collect.force-update", collectCmd.Flags().Lookup("force-update"))) - checkBindFlagError(viper.BindPFlag("collect.cacert", collectCmd.Flags().Lookup("cacert"))) - checkBindFlagError(viper.BindPFlags(collectCmd.Flags())) + checkBindFlagError(viper.BindPFlag("collect.host", CollectCmd.Flags().Lookup("host"))) + checkBindFlagError(viper.BindPFlag("collect.username", CollectCmd.Flags().Lookup("username"))) + checkBindFlagError(viper.BindPFlag("collect.password", CollectCmd.Flags().Lookup("password"))) + checkBindFlagError(viper.BindPFlag("collect.scheme", CollectCmd.Flags().Lookup("scheme"))) + checkBindFlagError(viper.BindPFlag("collect.protocol", CollectCmd.Flags().Lookup("protocol"))) + checkBindFlagError(viper.BindPFlag("collect.output", CollectCmd.Flags().Lookup("output"))) + checkBindFlagError(viper.BindPFlag("collect.force-update", CollectCmd.Flags().Lookup("force-update"))) + checkBindFlagError(viper.BindPFlag("collect.cacert", CollectCmd.Flags().Lookup("cacert"))) + checkBindFlagError(viper.BindPFlags(CollectCmd.Flags())) - rootCmd.AddCommand(collectCmd) + rootCmd.AddCommand(CollectCmd) } diff --git a/cmd/crawl.go b/cmd/crawl.go index 2611ed3..f6ee9a9 100644 --- a/cmd/crawl.go +++ b/cmd/crawl.go @@ -5,8 +5,8 @@ import ( "fmt" "log" - urlx "github.com/OpenCHAMI/magellan/internal/url" - "github.com/OpenCHAMI/magellan/pkg/crawler" + urlx "github.com/davidallendj/magellan/internal/url" + "github.com/davidallendj/magellan/pkg/crawler" "github.com/spf13/cobra" "github.com/spf13/viper" ) diff --git a/cmd/list.go b/cmd/list.go index e09299f..9fc81cd 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -6,7 +6,7 @@ import ( "strings" "time" - "github.com/OpenCHAMI/magellan/internal/cache/sqlite" + "github.com/davidallendj/magellan/internal/cache/sqlite" "github.com/rs/zerolog/log" "github.com/spf13/cobra" diff --git a/cmd/login.go b/cmd/login.go index 47aec06..5811d9b 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -6,8 +6,8 @@ import ( "net/http" "os" - magellan "github.com/OpenCHAMI/magellan/internal" - "github.com/OpenCHAMI/magellan/pkg/auth" + magellan "github.com/davidallendj/magellan/internal" + "github.com/davidallendj/magellan/pkg/auth" "github.com/lestrrat-go/jwx/jwt" "github.com/rs/zerolog/log" "github.com/spf13/cobra" diff --git a/cmd/root.go b/cmd/root.go index 3b0d4f0..778e37f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -20,7 +20,7 @@ import ( "os" "os/user" - magellan "github.com/OpenCHAMI/magellan/internal" + magellan "github.com/davidallendj/magellan/internal" "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/spf13/viper" diff --git a/cmd/scan.go b/cmd/scan.go index fedc691..d2cbaf8 100644 --- a/cmd/scan.go +++ b/cmd/scan.go @@ -7,12 +7,12 @@ import ( "os" "path" - magellan "github.com/OpenCHAMI/magellan/internal" - "github.com/OpenCHAMI/magellan/internal/cache/sqlite" + magellan "github.com/davidallendj/magellan/internal" + "github.com/davidallendj/magellan/internal/cache/sqlite" "github.com/rs/zerolog/log" - urlx "github.com/OpenCHAMI/magellan/internal/url" "github.com/cznic/mathutil" + urlx "github.com/davidallendj/magellan/internal/url" "github.com/spf13/cobra" "github.com/spf13/viper" ) @@ -32,7 +32,7 @@ var ( // // See the `ScanForAssets()` function in 'internal/scan.go' for details // related to the implementation. -var scanCmd = &cobra.Command{ +var ScanCmd = &cobra.Command{ Use: "scan urls...", Short: "Scan to discover BMC nodes on a network", Long: "Perform a net scan by attempting to connect to each host and port specified and getting a response.\n" + @@ -174,24 +174,24 @@ var scanCmd = &cobra.Command{ } func init() { - // scanCmd.Flags().StringSliceVar(&hosts, "host", []string{}, "set additional hosts to scan") - scanCmd.Flags().StringSliceVar(&hosts, "host", nil, "Add individual hosts to scan. (example: https://my.bmc.com:5000; same as using positional args)") - scanCmd.Flags().IntSliceVar(&ports, "port", nil, "Adds additional ports to scan for each host with unspecified ports.") - scanCmd.Flags().StringVar(&scheme, "scheme", "https", "Set the default scheme to use if not specified in host URI. (default is 'https')") - scanCmd.Flags().StringVar(&protocol, "protocol", "tcp", "Set the default protocol to use in scan. (default is 'tcp')") - scanCmd.Flags().StringSliceVar(&subnets, "subnet", nil, "Add additional hosts from specified subnets to scan.") - scanCmd.Flags().IPMaskVar(&subnetMask, "subnet-mask", net.IPv4Mask(255, 255, 255, 0), "Set the default subnet mask to use for with all subnets not using CIDR notation.") - scanCmd.Flags().BoolVar(&disableProbing, "disable-probing", false, "Disable probing found assets for Redfish service(s) running on BMC nodes") - scanCmd.Flags().BoolVar(&disableCache, "disable-cache", false, "Disable saving found assets to a cache database specified with 'cache' flag") - - checkBindFlagError(viper.BindPFlag("scan.hosts", scanCmd.Flags().Lookup("host"))) - checkBindFlagError(viper.BindPFlag("scan.ports", scanCmd.Flags().Lookup("port"))) - checkBindFlagError(viper.BindPFlag("scan.scheme", scanCmd.Flags().Lookup("scheme"))) - checkBindFlagError(viper.BindPFlag("scan.protocol", scanCmd.Flags().Lookup("protocol"))) - checkBindFlagError(viper.BindPFlag("scan.subnets", scanCmd.Flags().Lookup("subnet"))) - checkBindFlagError(viper.BindPFlag("scan.subnet-masks", scanCmd.Flags().Lookup("subnet-mask"))) - checkBindFlagError(viper.BindPFlag("scan.disable-probing", scanCmd.Flags().Lookup("disable-probing"))) - checkBindFlagError(viper.BindPFlag("scan.disable-cache", scanCmd.Flags().Lookup("disable-cache"))) - - rootCmd.AddCommand(scanCmd) + // ScanCmd.Flags().StringSliceVar(&hosts, "host", []string{}, "set additional hosts to scan") + ScanCmd.Flags().StringSliceVar(&hosts, "host", nil, "Add individual hosts to scan. (example: https://my.bmc.com:5000; same as using positional args)") + ScanCmd.Flags().IntSliceVar(&ports, "port", nil, "Adds additional ports to scan for each host with unspecified ports.") + ScanCmd.Flags().StringVar(&scheme, "scheme", "https", "Set the default scheme to use if not specified in host URI. (default is 'https')") + ScanCmd.Flags().StringVar(&protocol, "protocol", "tcp", "Set the default protocol to use in scan. (default is 'tcp')") + ScanCmd.Flags().StringSliceVar(&subnets, "subnet", nil, "Add additional hosts from specified subnets to scan.") + ScanCmd.Flags().IPMaskVar(&subnetMask, "subnet-mask", net.IPv4Mask(255, 255, 255, 0), "Set the default subnet mask to use for with all subnets not using CIDR notation.") + ScanCmd.Flags().BoolVar(&disableProbing, "disable-probing", false, "Disable probing found assets for Redfish service(s) running on BMC nodes") + ScanCmd.Flags().BoolVar(&disableCache, "disable-cache", false, "Disable saving found assets to a cache database specified with 'cache' flag") + + checkBindFlagError(viper.BindPFlag("scan.hosts", ScanCmd.Flags().Lookup("host"))) + checkBindFlagError(viper.BindPFlag("scan.ports", ScanCmd.Flags().Lookup("port"))) + checkBindFlagError(viper.BindPFlag("scan.scheme", ScanCmd.Flags().Lookup("scheme"))) + checkBindFlagError(viper.BindPFlag("scan.protocol", ScanCmd.Flags().Lookup("protocol"))) + checkBindFlagError(viper.BindPFlag("scan.subnets", ScanCmd.Flags().Lookup("subnet"))) + checkBindFlagError(viper.BindPFlag("scan.subnet-masks", ScanCmd.Flags().Lookup("subnet-mask"))) + checkBindFlagError(viper.BindPFlag("scan.disable-probing", ScanCmd.Flags().Lookup("disable-probing"))) + checkBindFlagError(viper.BindPFlag("scan.disable-cache", ScanCmd.Flags().Lookup("disable-cache"))) + + rootCmd.AddCommand(ScanCmd) } diff --git a/cmd/update.go b/cmd/update.go index d5f9a50..57f99b8 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -4,7 +4,7 @@ import ( "os" "strings" - magellan "github.com/OpenCHAMI/magellan/internal" + magellan "github.com/davidallendj/magellan/internal" "github.com/rs/zerolog/log" "github.com/spf13/cobra" "github.com/spf13/viper" diff --git a/cmd/version.go b/cmd/version.go index 87b7596..921ae81 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -1,7 +1,7 @@ package cmd import ( - "github.com/OpenCHAMI/magellan/internal/version" + "github.com/davidallendj/magellan/internal/version" "github.com/spf13/cobra" ) diff --git a/go.mod b/go.mod index e153625..1a2e948 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/OpenCHAMI/magellan +module github.com/davidallendj/magellan go 1.21 diff --git a/internal/cache/sqlite/sqlite.go b/internal/cache/sqlite/sqlite.go index 594fd92..fa0ae0b 100644 --- a/internal/cache/sqlite/sqlite.go +++ b/internal/cache/sqlite/sqlite.go @@ -2,9 +2,10 @@ package sqlite import ( "fmt" + "strings" - magellan "github.com/OpenCHAMI/magellan/internal" - "github.com/OpenCHAMI/magellan/internal/util" + magellan "github.com/davidallendj/magellan/internal" + "github.com/davidallendj/magellan/internal/util" "github.com/jmoiron/sqlx" ) @@ -59,20 +60,40 @@ func InsertScannedAssets(path string, assets ...magellan.RemoteAsset) error { return nil } -func DeleteScannedAssets(path string, results ...magellan.RemoteAsset) error { - if results == nil { +func DeleteScannedAssets(path string, assets ...magellan.RemoteAsset) error { + var ( + db *sqlx.DB + tx *sqlx.Tx + err error + ) + if assets == nil { return fmt.Errorf("no assets found") } - db, err := sqlx.Open("sqlite3", path) + db, err = sqlx.Open("sqlite3", path) if err != nil { return fmt.Errorf("failed to open database: %v", err) } - tx := db.MustBegin() - for _, state := range results { - sql := fmt.Sprintf(`DELETE FROM %s WHERE host = :host, port = :port;`, TABLE_NAME) - _, err := tx.NamedExec(sql, &state) + tx = db.MustBegin() + for _, asset := range assets { + // skip if neither host nor port are specified + if asset.Host == "" && asset.Port <= 0 { + continue + } + sql := fmt.Sprintf(`DELETE FROM %s`, TABLE_NAME) + where := []string{} + if asset.Port > 0 { + where = append(where, "port=:port") + } + if asset.Host != "" { + where = append(where, "host=:host") + } + if len(where) <= 0 { + continue + } + sql += fmt.Sprintf(" WHERE %s;", strings.Join(where, " AND ")) + _, err := tx.NamedExec(sql, &asset) if err != nil { - fmt.Printf("failed to execute transaction: %v\n", err) + fmt.Printf("failed to execute DELETE transaction: %v\n", err) } } diff --git a/internal/collect.go b/internal/collect.go index e52bc60..2f2c863 100644 --- a/internal/collect.go +++ b/internal/collect.go @@ -10,13 +10,13 @@ import ( "net/http" "os" "path" - "strings" "path/filepath" + "strings" "sync" "time" - "github.com/OpenCHAMI/magellan/pkg/client" - "github.com/OpenCHAMI/magellan/pkg/crawler" + "github.com/davidallendj/magellan/pkg/client" + "github.com/davidallendj/magellan/pkg/crawler" "github.com/rs/zerolog/log" diff --git a/internal/config.go b/internal/config.go index 4059269..ab26dcc 100644 --- a/internal/config.go +++ b/internal/config.go @@ -3,7 +3,7 @@ package magellan import ( "fmt" - "github.com/OpenCHAMI/magellan/internal/util" + "github.com/davidallendj/magellan/internal/util" "github.com/spf13/viper" ) diff --git a/internal/scan.go b/internal/scan.go index a88116d..99b4904 100644 --- a/internal/scan.go +++ b/internal/scan.go @@ -10,17 +10,17 @@ import ( "sync" "time" - urlx "github.com/OpenCHAMI/magellan/internal/url" - "github.com/OpenCHAMI/magellan/pkg/client" + urlx "github.com/davidallendj/magellan/internal/url" + "github.com/davidallendj/magellan/pkg/client" "github.com/rs/zerolog/log" ) type RemoteAsset struct { - Host string `json:"host"` - Port int `json:"port"` - Protocol string `json:"protocol"` - State bool `json:"state"` - Timestamp time.Time `json:"timestamp"` + Host string `db:"host" json:"host"` + Port int `db:"port" json:"port"` + Protocol string `db:"protocol" json:"protocol"` + State bool `db:"state" json:"state"` + Timestamp time.Time `db:"timestamp" json:"timestamp"` } // ScanParams is a collection of commom parameters passed to the CLI diff --git a/internal/update.go b/internal/update.go index 9191818..464b0b9 100644 --- a/internal/update.go +++ b/internal/update.go @@ -6,7 +6,7 @@ import ( "net/http" "net/url" - "github.com/OpenCHAMI/magellan/pkg/client" + "github.com/davidallendj/magellan/pkg/client" ) type UpdateParams struct { diff --git a/internal/version/version.go b/internal/version/version.go index 7d9d231..b7dae64 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -5,40 +5,40 @@ import ( ) // GitCommit stores the latest Git commit hash. -// Set via -ldflags "-X github.com/OpenCHAMI/magellan/internal/version.GitCommit=$(git rev-parse HEAD)" +// Set via -ldflags "-X github.com/davidallendj/magellan/internal/version.GitCommit=$(git rev-parse HEAD)" var GitCommit string // BuildTime stores the build timestamp in UTC. -// Set via -ldflags "-X github.com/OpenCHAMI/magellan/internal/version.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)" +// Set via -ldflags "-X github.com/davidallendj/magellan/internal/version.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)" var BuildTime string // Version indicates the version of the binary, such as a release number or semantic version. -// Set via -ldflags "-X github.com/OpenCHAMI/magellan/internal/version.Version=v1.0.0" +// Set via -ldflags "-X github.com/davidallendj/magellan/internal/version.Version=v1.0.0" var Version string // GitBranch holds the name of the Git branch from which the build was created. -// Set via -ldflags "-X github.com/OpenCHAMI/magellan/internal/version.GitBranch=$(git rev-parse --abbrev-ref HEAD)" +// Set via -ldflags "-X github.com/davidallendj/magellan/internal/version.GitBranch=$(git rev-parse --abbrev-ref HEAD)" var GitBranch string // GitTag represents the most recent Git tag at build time, if any. -// Set via -ldflags "-X github.com/OpenCHAMI/magellan/internal/version.GitTag=$(git describe --tags --abbrev=0)" +// Set via -ldflags "-X github.com/davidallendj/magellan/internal/version.GitTag=$(git describe --tags --abbrev=0)" var GitTag string // GitState indicates whether the working directory was "clean" or "dirty" (i.e., with uncommitted changes). -// Set via -ldflags "-X github.com/OpenCHAMI/magellan/internal/version.GitState=$(if git diff-index --quiet HEAD --; then echo 'clean'; else echo 'dirty'; fi)" +// Set via -ldflags "-X github.com/davidallendj/magellan/internal/version.GitState=$(if git diff-index --quiet HEAD --; then echo 'clean'; else echo 'dirty'; fi)" var GitState string // BuildHost stores the hostname of the machine where the binary was built. -// Set via -ldflags "-X github.com/OpenCHAMI/magellan/internal/version.BuildHost=$(hostname)" +// Set via -ldflags "-X github.com/davidallendj/magellan/internal/version.BuildHost=$(hostname)" var BuildHost string // GoVersion captures the Go version used to build the binary. // Typically, this can be obtained automatically with runtime.Version(), but you can set it manually. -// Set via -ldflags "-X github.com/OpenCHAMI/magellan/internal/version.GoVersion=$(go version | awk '{print $3}')" +// Set via -ldflags "-X github.com/davidallendj/magellan/internal/version.GoVersion=$(go version | awk '{print $3}')" var GoVersion string // BuildUser is the username of the person or system that initiated the build process. -// Set via -ldflags "-X github.com/OpenCHAMI/magellan/internal/version.BuildUser=$(whoami)" +// Set via -ldflags "-X github.com/davidallendj/magellan/internal/version.BuildUser=$(whoami)" var BuildUser string // PrintVersionInfo outputs all versioning information for troubleshooting or version checks. diff --git a/main.go b/main.go index ebe2d95..f0e9e5d 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,7 @@ package main import ( - "github.com/OpenCHAMI/magellan/cmd" + "github.com/davidallendj/magellan/cmd" ) func main() { diff --git a/pkg/client/smd.go b/pkg/client/smd.go index 499a72c..4551245 100644 --- a/pkg/client/smd.go +++ b/pkg/client/smd.go @@ -1,8 +1,8 @@ package client // See ref for API docs: -// https://github.com/OpenCHAMI/hms-smd/blob/master/docs/examples.adoc -// https://github.com/OpenCHAMI/hms-smd +// https://github.com/davidallendj/hms-smd/blob/master/docs/examples.adoc +// https://github.com/davidallendj/hms-smd import ( "fmt" "net/http" diff --git a/tests/api_test.go b/tests/api_test.go index e823bfa..d46a312 100644 --- a/tests/api_test.go +++ b/tests/api_test.go @@ -22,9 +22,9 @@ import ( "flag" - magellan "github.com/OpenCHAMI/magellan/internal" - "github.com/OpenCHAMI/magellan/internal/util" - "github.com/OpenCHAMI/magellan/pkg/client" + magellan "github.com/davidallendj/magellan/internal" + "github.com/davidallendj/magellan/internal/util" + "github.com/davidallendj/magellan/pkg/client" "github.com/rs/zerolog/log" ) diff --git a/tests/compatibility_test.go b/tests/compatibility_test.go index ce2e876..c947e17 100644 --- a/tests/compatibility_test.go +++ b/tests/compatibility_test.go @@ -14,8 +14,8 @@ import ( "net/http" "testing" - "github.com/OpenCHAMI/magellan/pkg/client" - "github.com/OpenCHAMI/magellan/pkg/crawler" + "github.com/davidallendj/magellan/pkg/client" + "github.com/davidallendj/magellan/pkg/crawler" ) var (