utils

package
v0.0.0-...-a87dae0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTaskMaxRetries = 3

	Q_CRITICAL = "critical"
	Q_DEFAULT  = "default"
	Q_LOW      = "low"
)
View Source
const (
	AUDIT_LOGS                   = "audit-logs"
	VULNERABILITY_SCAN           = "vulnerability-scan"
	VULNERABILITY_SCAN_STATUS    = "vulnerability-scan-status"
	SECRET_SCAN                  = "secret-scan"
	SECRET_SCAN_STATUS           = "secret-scan-status"
	MALWARE_SCAN                 = "malware-scan"
	MALWARE_SCAN_STATUS          = "malware-scan-status"
	SBOM_ARTIFACTS               = "sbom-artifact"
	SBOM_CVE_SCAN                = "sbom-cve-scan"
	CLOUD_COMPLIANCE_SCAN        = "cloud-compliance-scan"
	CLOUD_COMPLIANCE_SCAN_STATUS = "cloud-compliance-scan-status"
	COMPLIANCE_SCAN              = "compliance-scan"
	COMPLIANCE_SCAN_STATUS       = "compliance-scan-status"
	CLOUD_TRAIL_ALERTS           = "cloudtrail-alert"
	CLOUD_RESOURCE               = "cloud-resource"
)

kafka topics

View Source
const (
	CleanUpGraphDBTask                = "clean_up_graph_db"
	CleanUpPostgresqlTask             = "clean_up_postgresql"
	CleanupDiagnosisLogs              = "clean_up_diagnosis_logs"
	RetryFailedScansTask              = "retry_failed_scans"
	RetryFailedUpgradesTask           = "retry_failed_upgrades"
	ScanSBOMTask                      = "tasks_scan_sbom"
	GenerateSBOMTask                  = "tasks_generate_sbom"
	CheckAgentUpgradeTask             = "tasks_check_agent_upgrade"
	SyncRegistryTask                  = "task_sync_registry"
	TriggerConsoleActionsTask         = "trigger_console_actions"
	ScheduledTasks                    = "scheduled_tasks"
	SecretScanTask                    = "task_secret_scan"
	MalwareScanTask                   = "task_malware_scan"
	ReportGeneratorTask               = "tasks_generate_report"
	ComputeThreatTask                 = "compute_threat"
	SendNotificationTask              = "tasks_send_notification"
	CloudComplianceTask               = "cloud_compliance"
	CachePostureProviders             = "cache_posture_providers"
	ReportCleanUpTask                 = "tasks_cleanup_reports"
	LinkCloudResourceTask             = "link_cloud_resource"
	LinkNodesTask                     = "link_nodes"
	StopSecretScanTask                = "task_stop_secret_scan"
	StopMalwareScanTask               = "task_stop_malware_scan"
	StopVulnerabilityScanTask         = "task_stop_vulnerability_scan"
	UpdateCloudResourceScanStatusTask = "update_cloud_resource_scan_status"
	UpdatePodScanStatusTask           = "update_pod_scan_status"
)

task names

View Source
const (
	SCAN_STATUS_SUCCESS        = "COMPLETE"
	SCAN_STATUS_STARTING       = "STARTING"
	SCAN_STATUS_INPROGRESS     = "IN_PROGRESS"
	SCAN_STATUS_FAILED         = "ERROR"
	SCAN_STATUS_CANCEL_PENDING = "CANCEL_PENDING"
	SCAN_STATUS_CANCELLING     = "CANCELLING"
	SCAN_STATUS_CANCELLED      = "CANCELLED"
)
View Source
const (
	NodeTypeCloudProvider     = "CloudProvider"
	NodeTypeCloudRegion       = "CloudRegion"
	NodeTypeKubernetesCluster = "KubernetesCluster"
	NodeTypeContainerImage    = "ContainerImage"
	NodeTypeHost              = "Node"
	NodeTypeContainer         = "Container"
	NodeTypePod               = "Pod"
	NodeTypeProcess           = "Process"
	NodeTypeCloudNode         = "CloudNode"
	NodeTypeCloudResource     = "CloudResource"
	NodeTypeRegistryAccount   = "RegistryAccount"
)

Neo4j Node Labels

View Source
const (
	MASK_GLOBAL        = "mask_global"
	MASK_ALL_IMAGE_TAG = "mask_all_image_tag"
	MASK_ENTITY        = "mask_entity"
	MASK_IMAGE_TAG     = "mask_image_tag"
)
View Source
const (
	ErrorUserNotFound = "user not found"
)
View Source
const (
	Project = "ThreatMapper"
)

Variables

View Source
var (
	ScanTypeDetectedNode = map[Neo4jScanType]string{
		NEO4J_VULNERABILITY_SCAN:    "Vulnerability",
		NEO4J_SECRET_SCAN:           "Secret",
		NEO4J_MALWARE_SCAN:          "Malware",
		NEO4J_COMPLIANCE_SCAN:       "Compliance",
		NEO4J_CLOUD_COMPLIANCE_SCAN: "CloudCompliance",
	}
	DetectedNodeScanType = map[string]Neo4jScanType{
		"Vulnerability":   NEO4J_VULNERABILITY_SCAN,
		"Secret":          NEO4J_SECRET_SCAN,
		"Malware":         NEO4J_MALWARE_SCAN,
		"Compliance":      NEO4J_COMPLIANCE_SCAN,
		"CloudCompliance": NEO4J_CLOUD_COMPLIANCE_SCAN,
	}
)

kafka client logger

View Source
var ScanIdReplacer = strings.NewReplacer("/", "_", ":", "_", ".", "_")

list of task names to create topics

Functions

func BoolArrayToInterfaceArray

func BoolArrayToInterfaceArray(a []bool) []interface{}

func CheckKafkaConn

func CheckKafkaConn(kafkaBrokers []string) error

func CreateMissingTopics

func CreateMissingTopics(
	kafkaBrokers []string,
	topics []string,
	partitions int32,
	replicas int16,
	retention_ms string,
) error

func CritialTaskOpts

func CritialTaskOpts(opts ...asynq.Option) []asynq.Option

func DefaultTaskOpts

func DefaultTaskOpts(opts ...asynq.Option) []asynq.Option

func ExecuteCommand

func ExecuteCommand(commandStr string, envVars map[string]string) (string, error)

func FileExists

func FileExists(name string) bool

func FromMap

func FromMap(bb map[string]interface{}, c interface{})

FromMap Convert map[string]interface{} into structs e.g:

type Titi struct {
	Tata string `json:"tata"`
}

type Toto struct {
	Foo  string   `json:"foo"`
	Bar  int      `json:"bar"`
	Ta   Titi     `json:"ta"`
	Tas  []Titi   `json:"tas"`
	Tass []string `json:"tass"`
}

m := map[string]interface{}{
	"foo": "toto",
	"bar": 42,
	"ta": map[string]interface{}{"tata": "ok"},
	"tas": []map[string]interface{}{{"tata": "ok2"}, {"tata": "ok1"}},
	"tass": []string{"a"},
}

var t Toto FromMap(m, &t)

func GenerateHashFromString

func GenerateHashFromString(s string) string

func GenerateRandomNumber

func GenerateRandomNumber(numberOfDigits int) (int64, error)

func GetCurrentDatetime

func GetCurrentDatetime() time.Time

func GetCustomerNamespace

func GetCustomerNamespace(s string) (string, error)

func GetDatetimeNow

func GetDatetimeNow() string

func GetEmailDomain

func GetEmailDomain(email string) (string, error)

func GetEnvOrDefault

func GetEnvOrDefault(envVar string, defaultValue string) string

func GetEnvOrDefaultInt

func GetEnvOrDefaultInt(envVar string, defaultValue int) int

func GetErrorRedirectUrl

func GetErrorRedirectUrl(consoleUrl, errorMessage string) string

func GetHttpClient

func GetHttpClient() *http.Client

func GetInfoRedirectUrl

func GetInfoRedirectUrl(consoleUrl, message string) string

func GetInsecureHttpClient

func GetInsecureHttpClient() *http.Client

func GetInt64ValueFromInterfaceMap

func GetInt64ValueFromInterfaceMap(claims map[string]interface{}, key string) (int64, error)

func GetScheduledJobHash

func GetScheduledJobHash(schedule postgresqlDb.Scheduler) string

func GetStringValueFromInterfaceMap

func GetStringValueFromInterfaceMap(claims map[string]interface{}, key string) (string, error)

func GetTimestamp

func GetTimestamp() int64

func InSlice

func InSlice[T comparable](e T, s []T) bool

func InterfaceToInt

func InterfaceToInt(a interface{}) (int64, error)

func IsJWTExpired

func IsJWTExpired(token string) bool

func IsUUIDValid

func IsUUIDValid(uuidStr string) bool

func LowTaskOpts

func LowTaskOpts(opts ...asynq.Option) []asynq.Option

func MapKeys

func MapKeys(input map[string]string) []int32

func NewHTTPClient

func NewHTTPClient() (*http.Client, error)

func NewUUID

func NewUUID() uuid.UUID

func NewUUIDString

func NewUUIDString() string

func RandomString

func RandomString(nByte int) (string, error)

func RecursiveZip

func RecursiveZip(pathsToZip []string, excludePathPrefixes []string, destinationPath string) error

func RemoveURLPath

func RemoveURLPath(inUrl string) (string, error)

func ResourceTypeToNeo4jLabel

func ResourceTypeToNeo4jLabel(t CloudProvider) string

func SHA256sum

func SHA256sum(data []byte) string

func SetCookie

func SetCookie(w http.ResponseWriter, r *http.Request, name, value, path string)

func SplitFullName

func SplitFullName(name string) (string, string)

func StartKafkaProducer

func StartKafkaProducer(
	ctx context.Context,
	brokers []string,
	ingestChan chan *kgo.Record,
)

func StringArrayToInterfaceArray

func StringArrayToInterfaceArray(a []string) []interface{}

func StripAnsi

func StripAnsi(str []byte) []byte

StripAnsi remove ansi color from log lines

func StripAnsiStr

func StripAnsiStr(str string) string

StripAnsiStr remove ansi color from log lines

func StructToMap

func StructToMap[T any](c T) map[string]interface{}

func TaskOptions

func TaskOptions(queue string, opts ...asynq.Option) []asynq.Option

func TasksMaxRetries

func TasksMaxRetries() asynq.Option

func ToMap

func ToMap[T any](c T) map[string]interface{}

TODO: check if StructToMap can replace ToMap

func ToSnakeCase

func ToSnakeCase(str string) string

func URLDecode

func URLDecode(s string) (string, error)

func URLEncode

func URLEncode(s string) string

func UUIDFromString

func UUIDFromString(uuidStr string) (uuid.UUID, error)

func UploadFile

func UploadFile(url string, fileName string) ([]byte, int, error)

func ValidateEmail

func ValidateEmail(email string) bool

func WaitServiceTcpConn

func WaitServiceTcpConn(host string, port string, timeout time.Duration) error

Types

type AdvancedReportFilters

type AdvancedReportFilters struct {
	Masked                []bool   `json:"masked,omitempty"`
	ScanStatus            []string `json:"scan_status,omitempty"`
	PodName               []string `json:"pod_name,omitempty"`
	ContainerName         []string `json:"container_name,omitempty"`
	ImageName             []string `json:"image_name,omitempty"`
	HostName              []string `json:"host_name,omitempty"`
	AccountId             []string `json:"account_id,omitempty"`
	KubernetesClusterName []string `json:"kubernetes_cluster_name,omitempty"`
}

type AgentID

type AgentID struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type CloudProvider

type CloudProvider int
const (
	AWS CloudProvider = iota
	GCP
	Azure
	DO
	AWSOrg
	GCPOrg
)

func StringToCloudProvider

func StringToCloudProvider(s string) CloudProvider

type MalwareScanParameters

type MalwareScanParameters struct {
	ImageName             string `json:"image_name"`
	ImageId               string `json:"image_id"`
	ScanId                string `json:"scan_id" required:"true"`
	KubernetesClusterName string `json:"kubernetes_cluster_name"`
	HostName              string `json:"host_name"`
	NodeId                string `json:"node_id"`
	NodeType              string `json:"node_type"`
	ScanType              string `json:"scan_type"`
	ContainerName         string `json:"container_name"`
	Mode                  string `json:"mode,omitempty"`
	RegistryId            string `json:"registry_id,omitempty"`
}

type MinioError

type MinioError struct {
	XMLName    xml.Name `xml:"Error"`
	Text       string   `xml:",chardata"`
	Code       string   `xml:"Code"`
	Message    string   `xml:"Message"`
	Key        string   `xml:"Key"`
	BucketName string   `xml:"BucketName"`
	Resource   string   `xml:"Resource"`
	RequestId  string   `xml:"RequestId"`
	HostId     string   `xml:"HostId"`
}

type Neo4jScanType

type Neo4jScanType string
const (
	NEO4J_SECRET_SCAN           Neo4jScanType = "SecretScan"
	NEO4J_VULNERABILITY_SCAN    Neo4jScanType = "VulnerabilityScan"
	NEO4J_MALWARE_SCAN          Neo4jScanType = "MalwareScan"
	NEO4J_COMPLIANCE_SCAN       Neo4jScanType = "ComplianceScan"
	NEO4J_CLOUD_COMPLIANCE_SCAN Neo4jScanType = "CloudComplianceScan"
)

func StringToNeo4jScanType

func StringToNeo4jScanType(s string) Neo4jScanType

type RegistrySyncParams

type RegistrySyncParams struct {
	PgID int32 `json:"pg_id"`
}

type ReportFilters

type ReportFilters struct {
	ScanId                string                `json:"scan_id"`
	ScanType              string                `json:"scan_type" validate:"required" required:"true" enum:"vulnerability,secret,malware,compliance,cloud_compliance"`
	NodeType              string                `json:"node_type" validate:"required" required:"true" enum:"host,container,container_image,linux,cluster,aws,gcp,azure"`
	SeverityOrCheckType   []string              `json:"severity_or_check_type" enum:"critical,high,medium,low,cis,gdpr,nist,hipaa,pci,soc_2"`
	IncludeDeadNode       bool                  `json:"include_dead_nodes"`
	MostExploitableReport bool                  `json:"most_exploitable_report"`
	AdvancedReportFilters AdvancedReportFilters `json:"advanced_report_filters,omitempty"`
}

func (ReportFilters) String

func (r ReportFilters) String() string

type ReportParams

type ReportParams struct {
	ReportID   string        `json:"report_id"`
	ReportType string        `json:"report_type"`
	Duration   int           `json:"duration"`
	Filters    ReportFilters `json:"filters"`
}

type ReportType

type ReportType string
const (
	ReportXLSX ReportType = "xlsx"
	ReportPDF  ReportType = "pdf"
)

type SbomBody

type SbomBody struct {
	SBOM string `json:"sbom" required:"true"`
}

type SbomParameters

type SbomParameters struct {
	ImageName             string `json:"image_name"`
	ImageId               string `json:"image_id"`
	ScanId                string `json:"scan_id" required:"true"`
	KubernetesClusterName string `json:"kubernetes_cluster_name"`
	HostName              string `json:"host_name"`
	NodeId                string `json:"node_id"`
	NodeType              string `json:"node_type"`
	ScanType              string `json:"scan_type"`
	ContainerName         string `json:"container_name"`
	SBOMFilePath          string `json:"sbom_file_path"`
	Mode                  string `json:"mode,omitempty"`
	RegistryId            string `json:"registry_id,omitempty"`
	SkipScan              bool   `json:"skip_scan,omitempty"`
}

type ScanSbomRequest

type ScanSbomRequest struct {
	SbomParameters
	SbomBody
}

type SecretScanParameters

type SecretScanParameters struct {
	ImageName             string `json:"image_name"`
	ImageId               string `json:"image_id"`
	ScanId                string `json:"scan_id" required:"true"`
	KubernetesClusterName string `json:"kubernetes_cluster_name"`
	HostName              string `json:"host_name"`
	NodeId                string `json:"node_id"`
	NodeType              string `json:"node_type"`
	ScanType              string `json:"scan_type"`
	ContainerName         string `json:"container_name"`
	Mode                  string `json:"mode,omitempty"`
	RegistryId            string `json:"registry_id,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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