scanner

package
v0.0.0-...-e417875 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// RetrieveCapFailMsg the message indicate failed to retrieve the scanner capabilities
	RetrieveCapFailMsg = "failed to retrieve scanner capabilities, error %v"
)

Variables

View Source
var DefaultController = New()

DefaultController is a singleton api controller for plug scanners

Functions

This section is empty.

Types

type Controller

type Controller interface {
	// ListRegistrations returns a list of currently configured scanner registrations.
	// Query parameters are optional
	//
	//  Arguments:
	//    ctx context.Context : the context for this method
	//    query *q.Query : query parameters
	//
	//  Returns:
	//    []*scanner.Registration : scanner list of all the matched ones
	//    error                   : non nil error if any errors occurred
	ListRegistrations(ctx context.Context, query *q.Query) ([]*scanner.Registration, error)

	// GetTotalOfRegistrations returns the total count of scanner registrations according to the query.
	GetTotalOfRegistrations(ctx context.Context, query *q.Query) (int64, error)

	// CreateRegistration creates a new scanner registration with the given data.
	// Returns the scanner registration identifier.
	//
	//  Arguments:
	//    ctx context.Context : the context for this method
	//    registration *scanner.Registration : scanner registration to create
	//
	//  Returns:
	//    string : the generated UUID of the new scanner
	//    error  : non nil error if any errors occurred
	CreateRegistration(ctx context.Context, registration *scanner.Registration) (string, error)

	// GetRegistration returns the details of the specified scanner registration.
	//
	//  Arguments:
	//    ctx context.Context : the context for this method
	//    registrationUUID string : the UUID of the given scanner
	//
	//  Returns:
	//    *scanner.Registration : the required scanner
	//    error                 : non nil error if any errors occurred
	GetRegistration(ctx context.Context, registrationUUID string) (*scanner.Registration, error)

	// RegistrationExists checks if the provided registration is there.
	//
	//  Arguments:
	//    ctx context.Context : the context for this method
	//    registrationUUID string : the UUID of the given scanner
	//
	//  Returns:
	//    true for existing or false for not existing
	RegistrationExists(ctx context.Context, registrationUUID string) bool

	// UpdateRegistration updates the specified scanner registration.
	//
	//  Arguments:
	//    ctx context.Context : the context for this method
	//    registration *scanner.Registration : scanner registration to update
	//
	//  Returns:
	//    error  : non nil error if any errors occurred
	UpdateRegistration(ctx context.Context, registration *scanner.Registration) error

	// DeleteRegistration deletes the specified scanner registration.
	//
	//  Arguments:
	//    ctx context.Context : the context for this method
	//    registrationUUID string : the UUID of the given scanner which is going to be deleted
	//
	//  Returns:
	//    *scanner.Registration : the deleted scanner
	//    error                 : non nil error if any errors occurred
	DeleteRegistration(ctx context.Context, registrationUUID string) (*scanner.Registration, error)

	// SetDefaultRegistration marks the specified scanner registration as default.
	// The implementation is supposed to unset any registration previously set as default.
	//
	//  Arguments:
	//    ctx context.Context : the context for this method
	//    registrationUUID string : the UUID of the given scanner which is marked as default
	//
	//  Returns:
	//    error : non nil error if any errors occurred
	SetDefaultRegistration(ctx context.Context, registrationUUID string) error

	// SetRegistrationByProject sets scanner for the given project.
	//
	//  Arguments:
	//    ctx context.Context : the context.Context for this method
	//    projectID int64  : the ID of the given project
	//    scannerID string : the UUID of the scanner
	//
	//  Returns:
	//    error : non nil error if any errors occurred
	SetRegistrationByProject(ctx context.Context, projectID int64, scannerID string) error

	// GetRegistrationByProject returns the configured scanner registration of the given project or
	// the system default registration if exists or `nil` if no system registrations set.
	//
	//   Arguments:
	//     ctx context.Context : the context.Context for this method
	//     projectID int64 : the ID of the given project
	//
	//   Returns:
	//     *scanner.Registration : the default scanner registration
	//     error                 : non nil error if any errors occurred
	GetRegistrationByProject(ctx context.Context, projectID int64, options ...Option) (*scanner.Registration, error)

	// Ping pings Scanner Adapter to test EndpointURL and Authorization settings.
	// The implementation is supposed to call the GetMetadata method on scanner.Client.
	// Returns `nil` if connection succeeded, a non `nil` error otherwise.
	//
	//  Arguments:
	//    ctx context.Context : the context for this method
	//    registration *scanner.Registration : scanner registration to ping
	//
	//  Returns:
	//    *v1.ScannerAdapterMetadata : metadata returned by the scanner if successfully ping
	//    error                      : non nil error if any errors occurred
	Ping(ctx context.Context, registration *scanner.Registration) (*v1.ScannerAdapterMetadata, error)

	// GetMetadata returns the metadata of the given scanner.
	//
	//  Arguments:
	//    ctx context.Context : the context for this method
	//    registrationUUID string : the UUID of the given scanner which is marked as default
	//
	//  Returns:
	//    *v1.ScannerAdapterMetadata : metadata returned by the scanner if successfully ping
	//    error                      : non nil error if any errors occurred
	GetMetadata(ctx context.Context, registrationUUID string) (*v1.ScannerAdapterMetadata, error)

	// RetrieveCap retrieve scanner capabilities
	RetrieveCap(ctx context.Context, r *scanner.Registration) error
}

Controller provides the related operations of scanner for the upper API. All the capabilities of the scanner are defined here.

func New

func New() Controller

New a basic controller

type MetadataResult

type MetadataResult struct {
	Metadata *v1.ScannerAdapterMetadata
	Error    string
}

MetadataResult metadata or error saved in cache

func (*MetadataResult) Unpack

Unpack get ScannerAdapterMetadata and error from the result

type Option

type Option func(options *Options) error

Option represents an option item by func template. The validation result of the options are marked by nil/non-nil error. e.g: If the option is required and the input arg is empty, then a non nil error should be returned at then.

func WithPing

func WithPing(ping bool) Option

WithPing sets the requester option.

type Options

type Options struct {
	// Mark the scan triggered by who.
	// Identified by the UUID.
	Ping bool
}

Options keep the settings/configurations for scanner.

type Registration

type Registration = scanner.Registration

Registration ...

Jump to

Keyboard shortcuts

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