database

package
v0.0.0-...-e8f671e Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

Close closes the manager database and attempts all maintenance and cleanup steps

func CreateAgentEntries

func CreateAgentEntries(agentEntries []T_scan_agent) error

CreateAgentEntries persists new scan agent entries

func DeleteAgent

func DeleteAgent(agentId uint64) error

DeleteAgent removes a scan agent from the manager database

func GetScopeEntryIds

func GetScopeEntryIds() ([]uint64, error)

GetScopeEntryIds retrieves a list of remaining scan scope IDs. It returns an empty slice and NO error if no entry is found.

func Open

func Open() error

Open initializes the manager database

func RemoveDatabaseEntry

func RemoveDatabaseEntry(dbServerId uint64) error

RemoveDatabaseEntry removes a database server from the manager database

func UpdateDatabaseEntry

func UpdateDatabaseEntry(dbServerEntry *T_db_server) error

UpdateDatabaseEntry updates data of existing database servers in the database or creates new ones. None will be removed.

func UpdateScanAgents

func UpdateScanAgents(scopeId uint64, agentEntries []T_scan_agent) error

UpdateScanAgents updates data of existing scan agents in the database or creates new ones. None will be removed

func UpdateScopeInstances

func UpdateScopeInstances(scanScopeId uint64, instances map[string]uint32) error

UpdateScopeInstances updates the maximum module instances per scan agent of a scan scope. It returns gorm.ErrRecordNotFound if no entry is found.

func ViewExists

func ViewExists(scanScopeId uint64, viewName string) (bool, error)

ViewExists checks whether a given view name on a scan scope does already exist.

func WithTransaction

func WithTransaction(action func(*Transaction) error) error

WithTransaction executes manager database operations atomically

Types

type T_db_server

type T_db_server struct {
	Id         uint64 `gorm:"column:id;primaryKey" json:"id"`                                                 // Id autoincrement
	Name       string `gorm:"column:name;type:text" json:"name"`                                              // Name of the database as a note for administrators
	Dialect    string `gorm:"column:dialect;type:text;uniqueIndex:uix_db_server_multi_column" json:"dialect"` // DB connection details...
	Host       string `gorm:"column:host;type:text;uniqueIndex:uix_db_server_multi_column" json:"host"`       // ...
	HostPublic string `gorm:"column:host_public;type:text" json:"host_public"`                                // Public endpoint for user access (might be different to the internally used one, e.g. load balancer)
	Port       int    `gorm:"column:port;uniqueIndex:uix_db_server_multi_column" json:"port"`                 // ...
	Admin      string `gorm:"column:admin;type:text" json:"admin"`                                            // ...
	Password   string `gorm:"column:password;type:text" json:"-"`                                             // ...
	Args       string `gorm:"column:args;type:text" json:"args"`                                              // Additional connection arguments

	ScanScopes []T_scan_scope `gorm:"foreignKey:IdTDbServer"`
}

T_db_server contains connection details and credentials to a database hosting one or multiple scan scopes

func CreateDatabaseEntry

func CreateDatabaseEntry(
	dbName string,
	dbDialect string,
	dbServer string,
	dbPort int,
	dbUser string,
	dbPassword string,
	dbHostPublic string,
	dbArgs string,
) (*T_db_server, error)

CreateDatabaseEntry creates a new database server entry in the manager database

func GetDatabaseEntries

func GetDatabaseEntries() ([]T_db_server, error)

GetDatabaseEntries queries the manager database for all database servers

func GetDatabaseEntry

func GetDatabaseEntry(dbServerId uint64) (*T_db_server, error)

GetDatabaseEntry queries the manager database for the database server by ID. If no entry is found, a nil pointer is returned, make sure to check it!

func GetDatabaseEntryByName

func GetDatabaseEntryByName(name string) (*T_db_server, error)

GetDatabaseEntryByName queries the manager database for the database server entry by name. If no entry is found, a nil pointer is returned, make sure to check it!

func (*T_db_server) BeforeSave

func (dbServer *T_db_server) BeforeSave(tx *gorm.DB) error

BeforeSave is a GORM hook that's executed every time the user object is written to the DB. This should be used to do some data sanitization, e.g. to strip illegal HTML tags in user attributes or to convert values to a certain format.

func (*T_db_server) Delete

func (dbServer *T_db_server) Delete() error

Delete a user

type T_scan_agent

type T_scan_agent struct {
	Id           uint64 `gorm:"column:id;primary_key" json:"id"`                                                    // Id autoincrement
	IdTScanScope uint64 `gorm:"column:id_t_scan_scope;type:int;not null;uniqueIndex:idx_agent_identifier" json:"-"` // Unique index (across columns) to make sure the same view name only exists once per scan scope!

	Name string `gorm:"column:name;type:text;not null;uniqueIndex:idx_agent_identifier" json:"name"`
	Host string `gorm:"column:host;type:text;not null;uniqueIndex:idx_agent_identifier" json:"host"`
	Ip   string `gorm:"column:ip;type:text;not null" json:"ip"`

	BuildCommit    string `gorm:"column:build_commit;type:text;" json:"build_commit"`
	BuildTimestamp string `gorm:"column:build_timestamp;type:text;" json:"build_timestamp"`
	ApiVersion     string `gorm:"column:api_version;type:text;" json:"api_version"`

	Shared   bool          `gorm:"column:shared;type:bool;default:false" json:"shared"`
	Limits   bool          `gorm:"column:limits;type:bool;default:false" json:"limits"`
	LastSeen time.Time     `gorm:"column:last_seen;default:CURRENT_TIMESTAMP" json:"last_seen"`
	Tasks    utils.JsonMap `gorm:"column:tasks;default:'{}'" json:"tasks"`

	Platform        string  `gorm:"column:platform;type:text;" json:"platform"`
	PlatformFamily  string  `gorm:"column:platform_family;type:text;" json:"platform_family"`
	PlatformVersion string  `gorm:"column:platform_version;type:text;" json:"platform_version"`
	CpuCores        int     `gorm:"column:cpu_cores;type:int;default:0" json:"cpu_cores"`
	CpuMhz          float64 `gorm:"column:cpu_mhz;type:float;default:0" json:"cpu_mhz"`
	CpuRate         float64 `gorm:"column:cpu_rate;type:float;default:0" json:"cpu_rate"` // Usage in %
	MemoryBytes     uint64  `gorm:"column:memory_bytes;type:bigint;default:0" json:"memory_bytes"`
	MemoryRate      float64 `gorm:"column:memory_rate;type:float;default:0" json:"memory_rate"` // Usage in %

	VersionNmap   string `gorm:"column:version_nmap;type:text;" json:"version_nmap"`
	VersionNpcap  string `gorm:"column:version_npcap;type:text;" json:"version_npcap"`
	VersionSslyze string `gorm:"column:version_sslyze;type:text;" json:"version_sslyze"`
	VersionPython string `gorm:"column:version_python;type:text;" json:"version_python"`

	ScanScope T_scan_scope `gorm:"foreignKey:IdTScanScope" json:"-"` // Can be empty if the ID is set in turn
}

func GetAgentEntries

func GetAgentEntries() ([]T_scan_agent, error)

GetAgentEntries queries the manager database for all scan agents, grouped by scan scope. It returns an empty slice and NO error if no entry is found.

func (*T_scan_agent) BeforeSave

func (scanAgent *T_scan_agent) BeforeSave(tx *gorm.DB) error

BeforeSave is a GORM hook that's executed every time the user object is written to the DB. This should be used to do some data sanitization, e.g. to strip illegal HTML tags in user attributes or to convert values to a certain format.

func (*T_scan_agent) Delete

func (scanAgent *T_scan_agent) Delete() error

Delete a user

func (*T_scan_agent) Save

func (scanAgent *T_scan_agent) Save(columns ...string) (int64, error)

Save updates defined columns of a user entry in the database. It updates defined columns, to the currently set values, even if the values are empty ones, such as 0, false or "". ATTENTION: Only update required columns to avoid overwriting changes of parallel processes (with data in memory)

type T_scan_scope

type T_scan_scope struct {
	Id          uint64 `gorm:"column:id;primaryKey" json:"id"`                         // Id autoincrement
	IdTDbServer uint64 `gorm:"column:id_t_db_server;type:int;not null;index" json:"-"` // Index recommended on foreign keys for efficient update/delete cascaded actions
	IdTGroup    uint64 `gorm:"column:id_t_group;type:int;not null;index" json:"-"`     // Group reference this scan scope belongs to. Table "t_groups" is maintained by the web backend and not known to the manager.

	Name            string        `gorm:"column:name;type:text" json:"name"`                                   // Name of the scope selected by the user
	DbName          string        `gorm:"column:db_name;type:text;uniqueIndex" json:"-"`                       // Database name (UID) to connect to on respective DB server. Unique across all DB servers to avoid future conflicts.
	Created         time.Time     `gorm:"column:created;default:CURRENT_TIMESTAMP" json:"created"`             // Timestamp of creation
	CreatedBy       string        `gorm:"column:created_by;type:text;not null" json:"created_by"`              // User who created this scope
	Secret          string        `gorm:"column:secret;type:text;unique" json:"-"`                             // Random none-guessable scope secret used by agents to authenticate/associate. Value may change.
	Enabled         bool          `gorm:"column:enabled;default:true" json:"enabled"`                          // Whether new target should be fed to scan agents for this scan scope
	Type            string        `gorm:"column:type;type:text" json:"type"`                                   // The kind of scope, there might be different ones initialized via different mechanisms. E.g. custom, remote repository,...
	LastSync        time.Time     `gorm:"column:last_sync" json:"last_sync"`                                   // Timestamp when the scan scope targets were set/updated/synchronized the last time
	Size            uint          `gorm:"column:size;type:int;default:0" json:"size"`                          // Amount of IPs currently within this scan scope. Needs to be calculated/updated during population of the actual scan scope's t_discovery table.
	Cycles          bool          `gorm:"column:cycles" json:"cycles"`                                         // Scan in cycles
	CyclesRetention int           `gorm:"column:cycles_retention;type:int;default:-1" json:"cycles_retention"` // Amount of previous scan cycles to keep. Older ones will be cleaned up.
	SplitSize       uint32        `gorm:"column:split_size;type:int;not null;default:2048" json:"split_size"`  // Maximum amount of IPs contained in one scan target after large networks are split
	Attributes      utils.JsonMap `gorm:"column:attributes;type:json;not null" json:"attributes"`              // Scope arguments that can be arbitrary to your deployment environment, e.g., describing how to populate, import, refresh, synchronize scan inputs...

	Cycle        uint          `gorm:"column:cycle;type:int;default:1" json:"cycle"`                        // The current cycle the scan is in. Relevant, if scanning in cycles is enabled
	CycleStarted time.Time     `gorm:"column:cycle_started;default:CURRENT_TIMESTAMP" json:"cycle_started"` // Timestamp of last cycle start
	CycleDone    float64       `gorm:"column:cycle_done;type:float;default:0" json:"cycle_done"`            // Percentage of completed input scan tasks. Is updated in intervals and not a 100% current.
	CycleActive  float64       `gorm:"column:cycle_active;type:float;default:0" json:"cycle_active"`        // Percentage of active input scan tasks. Is updated in intervals and not a 100% current.
	CycleFailed  float64       `gorm:"column:cycle_failed;type:float;default:0" json:"cycle_failed"`        // Percentage of failed input scan tasks. Is updated in intervals and not a 100% current.
	CycleQueue   utils.JsonMap `gorm:"column:cycle_queue;type:json;not null" json:"cycle_queue"`            // Per-module counts of queued scan tasks. Is updated in intervals and not a 100% current.

	DbServer     T_db_server    `gorm:"foreignKey:IdTDbServer" json:"-"` // Database server connection details to connect to
	ScanSettings T_scan_setting `gorm:"foreignKey:IdTScanScope;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"`
	ScanAgents   []T_scan_agent `gorm:"foreignKey:IdTScanScope;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"` // Scan agent data (cached data)
	ScopeViews   []T_scope_view `gorm:"foreignKey:IdTScanScope;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"`
}

T_scan_scope contains available scan scopes and their configuration

func CreateScopeEntry

func CreateScopeEntry(
	dbServerEntry *T_db_server,
	name string,
	dbName string,
	groupId uint64,
	createdBy string,
	secret string,
	scopeType string,
	cycles bool,
	cyclesRetention int,
	splitSize uint32,
	attributes utils.JsonMap,
	size uint,
	settingsEntry T_scan_setting,
) (*T_scan_scope, error)

CreateScopeEntry creates a scan scope entry in the manager database to track a scope database

func GetScopeEntries

func GetScopeEntries() ([]T_scan_scope, error)

GetScopeEntries queries the manager database for all available scan scopes including their database server details and scan settings. It returns an empty slice and NO error if no entry is found.

func GetScopeEntriesOf

func GetScopeEntriesOf(groupIds []uint64) ([]T_scan_scope, error)

GetScopeEntriesOf queries the manager database for scope entries of a given group by group ID. It returns an empty slice and NO error if no entry is found.

func GetScopeEntry

func GetScopeEntry(scopeId uint64) (*T_scan_scope, error)

GetScopeEntry queries the manager database for the scope entry by ID. If no entry is found, a nil pointer is returned, make sure to check it!

func GetScopeEntryByName

func GetScopeEntryByName(dbName string) (*T_scan_scope, error)

GetScopeEntryByName returns the scan scope including its database server for a given scan scope database name. If no entry is found, a nil pointer is returned, make sure to check it!

func GetScopeEntryBySecret

func GetScopeEntryBySecret(secret string) (*T_scan_scope, error)

GetScopeEntryBySecret queries the manager database for the scope entry by secret. If no entry is found, a nil pointer is returned, make sure to check it!

func (*T_scan_scope) BeforeSave

func (scopeEntry *T_scan_scope) BeforeSave(tx *gorm.DB) error

BeforeSave is a GORM hook that's executed every time the user object is written to the DB. This should be used to do some data sanitization, e.g. to strip illegal HTML tags in user attributes or to convert values to a certain format.

func (*T_scan_scope) Save

func (scopeEntry *T_scan_scope) Save(columns ...string) (int64, error)

Save updates defined columns of a user entry in the database. It updates defined columns, to the currently set values, even if the values are empty ones, such as 0, false or "". ATTENTION: Only update required columns to avoid overwriting changes of parallel processes (with data in memory)

type T_scan_setting

type T_scan_setting struct {
	Id           uint64 `gorm:"column:id;primaryKey" json:"-"`                                 // Id autoincrement
	IdTScanScope uint64 `gorm:"column:id_t_scan_scope;type:int;not null;uniqueIndex" json:"-"` // Index recommended on foreign keys for efficient update/delete cascaded actions

	Ot bool `gorm:"column:ot;default:false" json:"ot"` // Enable OT discovery mode (PROFINET DCP, EtherCAT, LLDP, NDP, mDNS) with OT-optimized Nmap timing. Agent auto-detects scan targets based on local configuration.

	MaxInstancesDiscovery        uint32          `gorm:"column:max_instances_discovery;type:int" json:"max_instances_discovery"`   // Maximum parallel instances of discovery scans per agent.
	MaxInstancesBanner           uint32          `gorm:"column:max_instances_banner;type:int" json:"max_instances_banner"`         // Maximum parallel instances of banner scans per agent.
	MaxInstancesNfs              uint32          `gorm:"column:max_instances_nfs;type:int" json:"max_instances_nfs"`               // Maximum parallel instances of nfs scans per agent.
	MaxInstancesNuclei           uint32          `gorm:"column:max_instances_nuclei;type:int" json:"max_instances_nuclei"`         // Maximum parallel instances of nuclei scans per agent.
	MaxInstancesSmb              uint32          `gorm:"column:max_instances_smb;type:int" json:"max_instances_smb"`               // Maximum parallel instances of smb scans per agent.
	MaxInstancesSsh              uint32          `gorm:"column:max_instances_ssh;type:int" json:"max_instances_ssh"`               // Maximum parallel instances of ssh scans per agent.
	MaxInstancesSsl              uint32          `gorm:"column:max_instances_ssl;type:int" json:"max_instances_ssl"`               // Maximum parallel instances of ssl scans per agent.
	MaxInstancesWebcrawler       uint32          `gorm:"column:max_instances_webcrawler;type:int" json:"max_instances_webcrawler"` // Maximum parallel instances of webcrawler scans per agent.
	MaxInstancesWebenum          uint32          `gorm:"column:max_instances_webenum;type:int" json:"max_instances_webenum"`       // Maximum parallel instances of webenum scans per agent.
	SensitivePorts               string          `gorm:"column:sensitive_ports;type:text" json:"-"`                                // Comma separated list of sensitive ports that shall not be scanned with submodules
	SensitivePortsSlice          []int           `gorm:"-" json:"sensitive_ports"`                                                 //
	NetworkTimeoutSeconds        int             `gorm:"column:network_timeout_seconds;type:int" json:"network_timeout_seconds"`   //
	HttpUserAgent                string          `gorm:"column:http_user_agent;type:text" json:"http_user_agent"`                  //
	DiscoveryTimespans           string          `gorm:"column:discovery_timespans;type:text" json:"-"`
	DiscoveryTimespansSlice      utils.Timespans `gorm:"-" json:"discovery_timespans"`
	DiscoveryNmapArgs            string          `gorm:"column:discovery_nmap_args;type:text" json:"discovery_nmap_args"`
	DiscoveryNmapArgsPrescan     string          `gorm:"column:discovery_nmap_args_prescan;type:text" json:"discovery_nmap_args_prescan"` // A smaller scan executed before the main scan to at least retrieve some scan results, before a potential IDS kicks in
	DiscoveryNmapArgsOt          string          `gorm:"-" json:"discovery_nmap_args_ot"`                                                 // A safer scan executed in OT discovery scans. Field is just required as a JSON field to load default settings from the manager.conf. Not required in the manager database, because it will be copied into the normal nmap args field.
	DiscoveryExcludeDomains      string          `gorm:"column:discovery_exclude_domains;type:text" json:"discovery_exclude_domains"`
	NfsScanTimeoutMinutes        int             `gorm:"column:nfs_scan_timeout_minutes;type:int" json:"nfs_scan_timeout_minutes"`
	NfsDepth                     int             `gorm:"column:nfs_depth;type:int" json:"nfs_depth"`
	NfsThreads                   int             `gorm:"column:nfs_threads;type:int" json:"nfs_threads"`
	NfsExcludeShares             string          `gorm:"column:nfs_exclude_shares;type:text" json:"nfs_exclude_shares"`
	NfsExcludeFolders            string          `gorm:"column:nfs_exclude_folders;type:text" json:"nfs_exclude_folders"`
	NfsExcludeExtensions         string          `gorm:"column:nfs_exclude_extensions;type:text" json:"nfs_exclude_extensions"`
	NfsExcludeFileSizeBelow      int             `gorm:"column:nfs_exclude_file_size_below;type:int" json:"nfs_exclude_file_size_below"`
	NfsExcludeLastModifiedBelow  time.Time       `gorm:"column:nfs_exclude_last_modified_below;type:datetime" json:"nfs_exclude_last_modified_below"`
	NfsAccessibleOnly            bool            `gorm:"column:nfs_accessible_only;type:bool" json:"nfs_accessible_only"`
	NucleiScanTimeoutMinutes     int             `gorm:"column:nuclei_scan_timeout_minutes;type:int" json:"nuclei_scan_timeout_minutes"`
	NucleiIncludeSeverities      string          `gorm:"column:nuclei_include_severities;type:text" json:"nuclei_include_severities"`
	NucleiExcludeSeverities      string          `gorm:"column:nuclei_exclude_severities;type:text" json:"nuclei_exclude_severities"`
	NucleiIncludeTags            string          `gorm:"column:nuclei_include_tags;type:text" json:"nuclei_include_tags"`
	NucleiExcludeTags            string          `gorm:"column:nuclei_exclude_tags;type:text" json:"nuclei_exclude_tags"`
	NucleiIncludeIds             string          `gorm:"column:nuclei_include_ids;type:text" json:"nuclei_include_ids"`
	NucleiExcludeIds             string          `gorm:"column:nuclei_exclude_ids;type:text" json:"nuclei_exclude_ids"`
	NucleiIncludeProtocols       string          `gorm:"column:nuclei_include_protocols;type:text" json:"nuclei_include_protocols"`
	NucleiExcludeProtocols       string          `gorm:"column:nuclei_exclude_protocols;type:text" json:"nuclei_exclude_protocols"`
	SmbScanTimeoutMinutes        int             `gorm:"column:smb_scan_timeout_minutes;type:int" json:"smb_scan_timeout_minutes"`
	SmbDepth                     int             `gorm:"column:smb_depth;type:int" json:"smb_depth"`
	SmbThreads                   int             `gorm:"column:smb_threads;type:int" json:"smb_threads"`
	SmbForcedShares              string          `gorm:"column:smb_forced_shares;type:text" json:"smb_forced_shares"`
	SmbExcludeShares             string          `gorm:"column:smb_exclude_shares;type:text" json:"smb_exclude_shares"`
	SmbExcludeFolders            string          `gorm:"column:smb_exclude_folders;type:text" json:"smb_exclude_folders"`
	SmbExcludeExtensions         string          `gorm:"column:smb_exclude_extensions;type:text" json:"smb_exclude_extensions"`
	SmbExcludeFileSizeBelow      int             `gorm:"column:smb_exclude_file_size_below;type:int" json:"smb_exclude_file_size_below"`
	SmbExcludeLastModifiedBelow  time.Time       `gorm:"column:smb_exclude_last_modified_below;type:datetime" json:"smb_exclude_last_modified_below"`
	SmbAccessibleOnly            bool            `gorm:"column:smb_accessible_only;type:bool" json:"smb_accessible_only"`
	SslScanTimeoutMinutes        int             `gorm:"column:ssl_scan_timeout_minutes;type:int" json:"ssl_scan_timeout_minutes"`
	SshScanTimeoutMinutes        int             `gorm:"column:ssh_scan_timeout_minutes;type:int" json:"ssh_scan_timeout_minutes"`
	WebcrawlerScanTimeoutMinutes int             `gorm:"column:webcrawler_scan_timeout_minutes;type:int" json:"webcrawler_scan_timeout_minutes"`
	WebcrawlerDepth              int             `gorm:"column:webcrawler_depth;type:int" json:"webcrawler_depth"`
	WebcrawlerMaxThreads         int             `gorm:"column:webcrawler_max_threads;type:int" json:"webcrawler_max_threads"`
	WebcrawlerFollowQueryStrings bool            `gorm:"column:webcrawler_follow_query_strings;type:bool" json:"webcrawler_follow_query_strings"`
	WebcrawlerAlwaysStoreRoot    bool            `gorm:"column:webcrawler_always_store_root;type:bool" json:"webcrawler_always_store_root"`
	WebcrawlerFollowTypes        string          `gorm:"column:webcrawler_follow_types;type:text" json:"webcrawler_follow_types"`
	WebenumScanTimeoutMinutes    int             `gorm:"column:webenum_scan_timeout_minutes;type:int" json:"webenum_scan_timeout_minutes"`
	WebenumProbeRobots           bool            `gorm:"column:webenum_probe_robots;type:bool" json:"webenum_probe_robots"`

	ScanScope *T_scan_scope `gorm:"foreignKey:IdTScanScope" json:"-"` // Has to be a pointer in order to prevent an invalid recursion. Can be nil if the id has been set
}

func (*T_scan_setting) AfterFind

func (scanSettings *T_scan_setting) AfterFind(tx *gorm.DB) (err error)

AfterFind updates yet empty struct fields with the derived values. Some setting values are not stored in the database but derived from other fields in the database.

func (*T_scan_setting) BeforeSave

func (scanSettings *T_scan_setting) BeforeSave(tx *gorm.DB) error

BeforeSave is a GORM hook that's executed every time the user object is written to the DB. This should be used to do some data sanitization, e.g. to strip illegal HTML tags in user attributes or to convert values to a certain format.

func (*T_scan_setting) MaxInstances

func (scanSettings *T_scan_setting) MaxInstances(label string) (int, error)

MaxInstances extracts the set amount of maximum instances from a scan scope for a given scan module label

func (*T_scan_setting) SaveAll

func (scanSettings *T_scan_setting) SaveAll(settingsEntry *T_scan_setting) (int64, error)

SaveAll updates *all* columns of a user entry in the database. It overwrites existing values with the ones passed in

func (*T_scan_setting) UnmarshalJSON

func (scanSettings *T_scan_setting) UnmarshalJSON(b []byte) error

type T_scope_view

type T_scope_view struct {
	// Unique index on IdTScanScope and Name to make sure the same view name only exists once per scan scope!
	// Otherwise, they couldn't be created on the database!
	Id           uint64 `gorm:"column:id;primaryKey" json:"id"`                                               // Id autoincrement
	IdTScanScope uint64 `gorm:"column:id_t_scan_scope;type:int;not null;uniqueIndex:idx_scope_name" json:"-"` // Unique index (across columns) to make sure the same view name only exists once per scan scope!

	Name      string        `gorm:"column:name;type:text;not null;uniqueIndex:idx_scope_name" json:"name"` // Name of the view to show to the user
	Created   time.Time     `gorm:"column:created;default:CURRENT_TIMESTAMP" json:"created"`               // Timestamp of creation
	CreatedBy string        `gorm:"column:created_by;type:text;not null" json:"created_by"`                // User who created this view
	Filters   utils.JsonMap `gorm:"column:filters;type:json;default:'{}'" json:"filters"`                  // Applied filters restricting view on original data
	ViewNames string        `gorm:"column:view_names;type:text" json:"view_names"`                         // Comma separated list of view table names as created in the scope database

	ScanScope T_scan_scope   `gorm:"foreignKey:IdTScanScope" json:"-"`
	Grants    []T_view_grant `gorm:"foreignKey:IdTScopeView;constraint:OnUpdate:CASCADE,OnDelete:CASCADE" json:"-"`
}

func CreateViewEntry

func CreateViewEntry(
	scopeEntry *T_scan_scope,
	name string,
	createdBy string,
	filters map[string][]string,
	viewTableNames []string,
) (*T_scope_view, error)

CreateViewEntry creates a scope view entry in the manager database, to track scope database views

func GetViewEntries

func GetViewEntries() ([]T_scope_view, error)

GetViewEntries queries the manager database for all view entries. It returns an empty slice and NO error if no view entry is found at all. ATTENTION: Contains sensitive information (e.g. DbServer details) which may not be yielded to clients!

func GetViewEntriesOf

func GetViewEntriesOf(groupIds []uint64) ([]T_scope_view, error)

GetViewEntriesOf queries the manager database for all view entries of a given list of group IDs. It returns an empty slice and NO error if no view entry is found.

func GetViewEntry

func GetViewEntry(viewId uint64) (*T_scope_view, error)

GetViewEntry queries the manager database for the view entry by ID. If no entry is found, a nil pointer is returned, make sure to check it! ATTENTION: Contains sensitive information (e.g. DbServer details) which may not be yielded to clients!

func GetViewsGranted

func GetViewsGranted(username string) ([]T_scope_view, error)

GetViewsGranted queries the manager database for all view entries a user has granted access. It returns an empty slice and NO error if no view entry is found. ATTENTION: Contains sensitive information (e.g. DbServer details) which may not be yielded to clients!

func (*T_scope_view) BeforeSave

func (scopeView *T_scope_view) BeforeSave(tx *gorm.DB) error

BeforeSave is a GORM hook that's executed every time the user object is written to the DB. This should be used to do some data sanitization, e.g. to strip illegal HTML tags in user attributes or to convert values to a certain format.

func (*T_scope_view) Save

func (scopeView *T_scope_view) Save(columns ...string) (int64, error)

Save updates defined columns of a user entry in the database. It updates defined columns, to the currently set values, even if the values are empty ones, such as 0, false or "". ATTENTION: Only update required columns to avoid overwriting changes of parallel processes (with data in memory)

type T_view_grant

type T_view_grant struct {
	// A view grant is representing an access right to a certain scope view. It may represent a user specific
	// access right, or a generic not user bound access token access right.
	Id           uint64 `gorm:"column:id;primaryKey;uniqueIndex" json:"-"`               // Id autoincrement
	IdTScopeView uint64 `gorm:"column:id_t_scope_view;type:int;not null;index" json:"-"` // Index recommended on foreign keys for efficient update/delete cascaded actions

	IsUser      bool      `gorm:"column:is_user;type:bool" json:"is_user"`                 // Flag indicating whether this entry is for a dedicated user, rather than a not user bound access token
	Username    string    `gorm:"column:username;type:text" json:"username"`               // The database user name this grant references. May be an e-mail address to reference certain user or random string for access tokens
	Created     time.Time `gorm:"column:created;default:CURRENT_TIMESTAMP" json:"created"` // Timestamp of grant creation
	CreatedBy   string    `gorm:"column:created_by;type:text;not null" json:"created_by"`  // User who created this grant
	Expiry      time.Time `gorm:"column:expiry;not null" json:"expiry"`                    // Timestamp when this access grant is scheduled to expire, should equal the values set on the database servers
	Description string    `gorm:"column:description;type:text" json:"description"`         // Set by the creator, only necessary for access tokens

	ScopeView T_scope_view `gorm:"foreignKey:IdTScopeView" json:"-"`
}

func CreateGrantEntry

func CreateGrantEntry(
	viewEntry *T_scope_view,
	isUser bool,
	username string,
	createdBy string,
	expiry time.Time,
	description string,
) (*T_view_grant, error)

CreateGrantEntry creates a grant entry in the manager database, to track scope database access rights. A grant entry can either represent access rights for a dedicated user or for a not user bound access token.

func (*T_view_grant) BeforeSave

func (grantEntry *T_view_grant) BeforeSave(tx *gorm.DB) error

BeforeSave is a GORM hook that's executed every time the user object is written to the DB. This should be used to do some data sanitization, e.g. to strip illegal HTML tags in user attributes or to convert values to a certain format.

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

Transaction provides domain-specific manager database operations without exposing the underlying GORM handle

func (*Transaction) CreateDatabaseEntry

func (transaction *Transaction) CreateDatabaseEntry(
	dbName string,
	dbDialect string,
	dbServer string,
	dbPort int,
	dbUser string,
	dbPassword string,
	dbHostPublic string,
	dbArgs string,
) (*T_db_server, error)

CreateDatabaseEntry creates a database server entry within the transaction

func (*Transaction) CreateGrantEntry

func (transaction *Transaction) CreateGrantEntry(
	viewEntry *T_scope_view,
	isUser bool,
	username string,
	createdBy string,
	expiry time.Time,
	description string,
) (*T_view_grant, error)

CreateGrantEntry creates a view grant entry within the transaction

func (*Transaction) CreateScopeEntry

func (transaction *Transaction) CreateScopeEntry(
	dbServerEntry *T_db_server,
	name string,
	dbName string,
	groupId uint64,
	createdBy string,
	secret string,
	scopeType string,
	cycles bool,
	cyclesRetention int,
	splitSize uint32,
	attributes utils.JsonMap,
	size uint,
	settingsEntry T_scan_setting,
) (*T_scan_scope, error)

CreateScopeEntry creates a scan scope entry within the transaction

func (*Transaction) CreateViewEntry

func (transaction *Transaction) CreateViewEntry(
	scopeEntry *T_scan_scope,
	name string,
	createdBy string,
	filters map[string][]string,
	viewTableNames []string,
) (*T_scope_view, error)

CreateViewEntry creates a scope view entry within the transaction

func (*Transaction) DeleteAgentEntry

func (transaction *Transaction) DeleteAgentEntry(agentEntry *T_scan_agent) error

DeleteAgentEntry removes a scan agent entry within the transaction

func (*Transaction) DeleteGrantEntry

func (transaction *Transaction) DeleteGrantEntry(grantEntry *T_view_grant) error

DeleteGrantEntry removes a view grant entry within the transaction

func (*Transaction) DeleteScopeEntry

func (transaction *Transaction) DeleteScopeEntry(scopeEntry *T_scan_scope) error

DeleteScopeEntry removes a scan scope entry within the transaction

func (*Transaction) DeleteScopeSettings

func (transaction *Transaction) DeleteScopeSettings(settingsEntry *T_scan_setting) error

DeleteScopeSettings removes scan scope settings within the transaction

func (*Transaction) DeleteViewEntry

func (transaction *Transaction) DeleteViewEntry(viewEntry *T_scope_view) error

DeleteViewEntry removes a scope view entry within the transaction

func (*Transaction) UpdateViewEntry

func (transaction *Transaction) UpdateViewEntry(viewEntry *T_scope_view) error

UpdateViewEntry persists a scope view update within the transaction

Jump to

Keyboard shortcuts

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