mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
Minor changes
This commit is contained in:
parent
f1a8a067d4
commit
dc8addf062
2 changed files with 22 additions and 6 deletions
20
cmd/cache.go
20
cmd/cache.go
|
|
@ -13,8 +13,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
withAllHosts bool
|
withHosts []string
|
||||||
withAllPorts bool
|
withPorts []int
|
||||||
)
|
)
|
||||||
|
|
||||||
var cacheCmd = &cobra.Command{
|
var cacheCmd = &cobra.Command{
|
||||||
|
|
@ -34,6 +34,8 @@ var cacheRemoveCmd = &cobra.Command{
|
||||||
Short: "Remove a host from a scanned cache list.",
|
Short: "Remove a host from a scanned cache list.",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
assets := []magellan.RemoteAsset{}
|
assets := []magellan.RemoteAsset{}
|
||||||
|
|
||||||
|
// add all assets directly from positional args
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
var (
|
var (
|
||||||
port int
|
port int
|
||||||
|
|
@ -46,6 +48,9 @@ var cacheRemoveCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert port to its "proper" type
|
// convert port to its "proper" type
|
||||||
|
if uri.Port() == "" {
|
||||||
|
uri.Host += ":443"
|
||||||
|
}
|
||||||
port, err = strconv.Atoi(uri.Port())
|
port, err = strconv.Atoi(uri.Port())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("failed to convert port to integer type")
|
log.Error().Err(err).Msg("failed to convert port to integer type")
|
||||||
|
|
@ -54,16 +59,21 @@ var cacheRemoveCmd = &cobra.Command{
|
||||||
Host: fmt.Sprintf("%s://%s", uri.Scheme, uri.Hostname()),
|
Host: fmt.Sprintf("%s://%s", uri.Scheme, uri.Hostname()),
|
||||||
Port: port,
|
Port: port,
|
||||||
}
|
}
|
||||||
fmt.Printf("%s:%d\n", asset.Host, asset.Port)
|
|
||||||
assets = append(assets, asset)
|
assets = append(assets, asset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add all assets with specified hosts (same host different different ports)
|
||||||
|
for _, host := range withHosts {
|
||||||
|
|
||||||
|
}
|
||||||
|
// add all assets with specified ports (same port different hosts)
|
||||||
sqlite.DeleteScannedAssets(cachePath, assets...)
|
sqlite.DeleteScannedAssets(cachePath, assets...)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cacheRemoveCmd.Flags().BoolVar(&withAllHosts, "--all-hosts", false, "Remove all assets with specified hosts")
|
cacheRemoveCmd.Flags().StringSliceVar(&withHosts, "with-hosts", []string{}, "Remove all assets with specified hosts")
|
||||||
cacheRemoveCmd.Flags().BoolVar(&withAllPorts, "--all-ports", false, "Remove all assets with specified ports")
|
cacheRemoveCmd.Flags().IntSliceVar(&withPorts, "with-ports", []int{}, "Remove all assets with specified ports")
|
||||||
cacheCmd.AddCommand(cacheRemoveCmd)
|
cacheCmd.AddCommand(cacheRemoveCmd)
|
||||||
rootCmd.AddCommand(cacheCmd)
|
rootCmd.AddCommand(cacheCmd)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
8
internal/cache/sqlite/sqlite.go
vendored
8
internal/cache/sqlite/sqlite.go
vendored
|
|
@ -72,7 +72,13 @@ func DeleteScannedAssets(path string, assets ...magellan.RemoteAsset) error {
|
||||||
}
|
}
|
||||||
tx := db.MustBegin()
|
tx := db.MustBegin()
|
||||||
for _, asset := range assets {
|
for _, asset := range assets {
|
||||||
sql := fmt.Sprintf(`DELETE FROM %s WHERE host=:host AND port=:port;`, TABLE_NAME)
|
if asset.Host == "" && asset.Port <= 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sql := fmt.Sprintf(`DELETE FROM %s WHERE port=:port;`, TABLE_NAME)
|
||||||
|
if asset.Host != "" {
|
||||||
|
sql += "AND host=:host"
|
||||||
|
}
|
||||||
_, err := tx.NamedExec(sql, &asset)
|
_, err := tx.NamedExec(sql, &asset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("failed to execute DELETE transaction: %v\n", err)
|
fmt.Printf("failed to execute DELETE transaction: %v\n", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue