session

package
v0.0.0-...-7bac0ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMaxReports     = 5
	DefaultConfigFileName = "config.yaml"
)

Variables

View Source
var (
	ErrLoggerNotSet = errors.New("logger not set")
	ErrStatsNotSet  = errors.New("stats not set")
	ErrCacheNotSet  = errors.New("cache not set")
)
View Source
var DefaultConfig string

Functions

func CreateConfigPathStructure

func CreateConfigPathStructure(configRoot string) error

CreateConfigPathStructure creates all the necessary paths under session root if they don't exist and returns an error if it fails to create the directory, or the session root does not exist

func CreateDefaultConfigIfMissing

func CreateDefaultConfigIfMissing(path string) (bool, error)

CreateDefaultConfigIfMissing creates a default session configuration file if it does not exist and returns true if it was created, or false if it already exists

func GetConfigRoot

func GetConfigRoot(root string, homeDir string, appName string) string

GetConfigRoot returns the root path for the app's session directory if root is specified, it will use that, otherwise it will use the user's home directory

Types

type Config

type Config struct {
	Global GlobalConfig `mapstructure:"global"`
	Rating RatingConfig `mapstructure:"rating"`
}

type GlobalConfig

type GlobalConfig struct {
	LogLevel            string `mapstructure:"log-level"`
	Output              string `mapstructure:"output"`
	HomeDir             string
	IndentSpaces        int      `mapstructure:"indent-spaces"`
	Ports               []string `mapstructure:"ports"`
	MaxValueChars       int32    `mapstructure:"max-value-chars"`
	MaxAge              string   `mapstructure:"max-age"`
	MaxReports          int      `mapstructure:"max-reports"`
	DisableCache        bool     `mapstructure:"disable-cache"`
	Style               string   `mapstructure:"style"`
	InitialiseCacheOnly bool
	FilterProviders     []string `mapstructure:"filter-providers"`
}

type Messages

type Messages struct {
	Mu      sync.Mutex
	Info    []string
	Warning []string
	Error   []string
}

func (*Messages) AddError

func (m *Messages) AddError(msg string)

func (*Messages) AddInfo

func (m *Messages) AddInfo(msg string)

func (*Messages) AddWarn

func (m *Messages) AddWarn(msg string)

type Providers

type Providers struct {
	AbuseIPDB struct {
		APIKey         string
		Enabled        *bool  `mapstructure:"enabled"`
		ResultCacheTTL int64  `mapstructure:"result_cache_ttl"`
		MaxAge         int    `mapstructure:"max-age"`
		OutputPriority *int32 `mapstructure:"output_priority"`
	} `mapstructure:"abuseipdb"`
	Alibaba struct {
		Enabled          *bool  `mapstructure:"enabled"`
		DocumentCacheTTL int64  `mapstructure:"document_cache_ttl"`
		URL              string `mapstructure:"url"`
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"alibaba"`
	Annotated struct {
		Enabled          *bool    `mapstructure:"enabled"`
		DocumentCacheTTL int64    `mapstructure:"document_cache_ttl"`
		Paths            []string `mapstructure:"paths"`
		OutputPriority   *int32   `mapstructure:"output_priority"`
	} `mapstructure:"annotated"`
	AWS struct {
		Enabled          *bool  `mapstructure:"enabled"`
		DocumentCacheTTL int64  `mapstructure:"document_cache_ttl"`
		URL              string `mapstructure:"url"`
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"aws"`
	Azure struct {
		Enabled          *bool  `mapstructure:"enabled"`
		DocumentCacheTTL int64  `mapstructure:"document_cache_ttl"`
		URL              string `mapstructure:"url"`
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"azure"`
	AzureWAF struct {
		Enabled          *bool    `mapstructure:"enabled"`
		ResourceIDs      []string `mapstructure:"resource_ids"`
		DocumentCacheTTL int64    `mapstructure:"document_cache_ttl"`
		OutputPriority   *int32   `mapstructure:"output_priority"`
	} `mapstructure:"azure"`
	Bingbot struct {
		Enabled          *bool  `mapstructure:"enabled"`
		DocumentCacheTTL int64  `mapstructure:"document_cache_ttl"`
		URL              string `mapstructure:"url"`
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"bingbot"`
	CriminalIP struct {
		APIKey         string
		ResultCacheTTL int64  `mapstructure:"result_cache_ttl"`
		Enabled        *bool  `mapstructure:"enabled"`
		OutputPriority *int32 `mapstructure:"output_priority"`
	} `mapstructure:"criminalip"`
	DigitalOcean struct {
		Enabled          *bool `mapstructure:"enabled"`
		DocumentCacheTTL int64 `mapstructure:"document_cache_ttl"`
		URL              string
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"digitalocean"`
	GCP struct {
		Enabled          *bool `mapstructure:"enabled"`
		DocumentCacheTTL int64 `mapstructure:"document_cache_ttl"`
		URL              string
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"gcp"`
	Google struct {
		Enabled          *bool `mapstructure:"enabled"`
		DocumentCacheTTL int64 `mapstructure:"document_cache_ttl"`
		URL              string
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"google"`
	Googlebot struct {
		Enabled          *bool `mapstructure:"enabled"`
		DocumentCacheTTL int64 `mapstructure:"document_cache_ttl"`
		URL              string
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"googlebot"`
	GoogleSC struct {
		Enabled          *bool `mapstructure:"enabled"`
		DocumentCacheTTL int64 `mapstructure:"document_cache_ttl"`
		URL              string
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"googlesc"`
	Hetzner struct {
		Enabled          *bool `mapstructure:"enabled"`
		DocumentCacheTTL int64 `mapstructure:"document_cache_ttl"`
		URL              string
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"hetzner"`
	ICloudPR struct {
		Enabled          *bool  `mapstructure:"enabled"`
		DocumentCacheTTL int64  `mapstructure:"document_cache_ttl"`
		URL              string `mapstructure:"url"`
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"icloudpr"`
	IPAPI struct {
		APIKey         string
		Enabled        *bool  `mapstructure:"enabled"`
		ResultCacheTTL int64  `mapstructure:"result_cache_ttl"`
		OutputPriority *int32 `mapstructure:"output_priority"`
	} `mapstructure:"ipapi"`
	IPQS struct {
		APIKey         string
		Enabled        *bool  `mapstructure:"enabled"`
		ResultCacheTTL int64  `mapstructure:"result_cache_ttl"`
		OutputPriority *int32 `mapstructure:"output_priority"`
	} `mapstructure:"ipqs"`
	IPURL struct {
		Enabled          *bool    `mapstructure:"enabled"`
		DocumentCacheTTL int64    `mapstructure:"document_cache_ttl"`
		URLs             []string `mapstructure:"urls"`
		OutputPriority   *int32   `mapstructure:"output_priority"`
	} `mapstructure:"ipurl"`
	Linode struct {
		Enabled          *bool `mapstructure:"enabled"`
		DocumentCacheTTL int64 `mapstructure:"document_cache_ttl"`
		URL              string
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"linode"`
	M247 struct {
		Enabled          *bool  `mapstructure:"enabled"`
		DocumentCacheTTL int64  `mapstructure:"document_cache_ttl"`
		URL              string `mapstructure:"url"`
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"m247"`
	OVH struct {
		Enabled          *bool  `mapstructure:"enabled"`
		DocumentCacheTTL int64  `mapstructure:"document_cache_ttl"`
		URL              string `mapstructure:"url"`
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"ovh"`
	Scaleway struct {
		Enabled          *bool  `mapstructure:"enabled"`
		DocumentCacheTTL int64  `mapstructure:"document_cache_ttl"`
		URL              string `mapstructure:"url"`
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"scaleway"`
	Shodan struct {
		APIKey         string
		ResultCacheTTL int64  `mapstructure:"result_cache_ttl"`
		Enabled        *bool  `mapstructure:"enabled"`
		OutputPriority *int32 `mapstructure:"output_priority"`
	} `mapstructure:"shodan"`
	PTR struct {
		Enabled        *bool    `mapstructure:"enabled"`
		ResultCacheTTL int64    `mapstructure:"result_cache_ttl"`
		Nameservers    []string `mapstructure:"nameservers"`
		OutputPriority *int32   `mapstructure:"output_priority"`
	} `mapstructure:"ptr"`
	VirusTotal struct {
		APIKey         string
		ResultCacheTTL int64  `mapstructure:"result_cache_ttl"`
		ShowProviders  *bool  `mapstructure:"show_providers"`
		ShowUnrated    *bool  `mapstructure:"show_unrated"`
		ShowHarmless   *bool  `mapstructure:"show_harmless"`
		ShowClean      *bool  `mapstructure:"show_clean"`
		Enabled        *bool  `mapstructure:"enabled"`
		OutputPriority *int32 `mapstructure:"output_priority"`
	} `mapstructure:"virustotal"`
	Vultr struct {
		Enabled          *bool  `mapstructure:"enabled"`
		DocumentCacheTTL int64  `mapstructure:"document_cache_ttl"`
		URL              string `mapstructure:"url"`
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"vultr"`
	Zscaler struct {
		Enabled          *bool  `mapstructure:"enabled"`
		DocumentCacheTTL int64  `mapstructure:"document_cache_ttl"`
		URL              string `mapstructure:"url"`
		OutputPriority   *int32 `mapstructure:"output_priority"`
	} `mapstructure:"zscaler"`
}

type RatingConfig

type RatingConfig struct {
	ConfigPath   string `mapstructure:"config-path"`
	UseAI        bool   `mapstructure:"use-ai"`
	OpenAIAPIKey string `mapstructure:"openai-api-key"`
}

type Session

type Session struct {
	App struct {
		Version string
		SemVer  string
	}
	Logger   *slog.Logger
	Stats    *Stats
	Target   *os.File
	Output   string
	Messages *Messages
	Cache    *badger.DB
	Config   Config

	HTTPClient   *retryablehttp.Client
	Host         netip.Addr
	Providers    Providers `mapstructure:"providers"`
	HideProgress bool      `mapstructure:"hide-progress"`

	UseTestData bool
}

func New

func New() *Session

func (*Session) Validate

func (c *Session) Validate() error

type Stats

type Stats struct {
	Mu                  sync.Mutex
	InitialiseDuration  map[string]time.Duration
	InitialiseUsedCache map[string]bool
	FindHostDuration    map[string]time.Duration
	FindHostUsedCache   map[string]bool
	CreateTableDuration map[string]time.Duration
}

func CreateStats

func CreateStats() *Stats

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL