swagger

package
v0.0.0-...-fd430d6 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

README

Go API Server for swagger

This is a simple backend API to allow a user to configure repositories for scanning, trigger a scan of those repositories, and retrieve the results.

Overview

This server was generated by the [swagger-codegen] (https://github.com/swagger-api/swagger-codegen) project.
By using the OpenAPI-Spec from a remote server, you can easily generate a server stub.

To see how to make this your own, look here:

README

  • API version: 0.0.1
  • Build date: 2022-06-17T07:28:26.566Z
Running the server

To run the server, follow these simple steps:

go run main.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeScanId

func EncodeScanId(v uint64) string

Helper function to convert a numeric value into a base64 string value that can be used as an id

func Logger

func Logger(inner http.Handler, name string) http.Handler

func ValidScanId

func ValidScanId(s string) bool

Helper function to validate that the given string is a proper base64 string value

Types

type App

type App struct {
	Router           HttpRouter
	DBType           string
	DB               *PsqlDB
	RepoStore        RepoStore
	ScanStore        ScanStore
	EngineController engine.Controller
	EngineScanner    engine.Scanner
	ActiveJobs       map[string]*ScanJob
	ActiveJobsLock   sync.RWMutex
}

func (*App) AddRepository

func (a *App) AddRepository(w http.ResponseWriter, r *http.Request)

func (*App) AddScan

func (a *App) AddScan(w http.ResponseWriter, r *http.Request)

func (*App) AddScanRequest

func (a *App) AddScanRequest(ri *models.RepositoryInfo, sr *models.ScanRecord)

func (*App) CleanUp

func (a *App) CleanUp()

func (*App) ClearStores

func (a *App) ClearStores()

func (*App) DeleteRepository

func (a *App) DeleteRepository(w http.ResponseWriter, r *http.Request)

func (*App) DeleteScan

func (a *App) DeleteScan(w http.ResponseWriter, r *http.Request)

func (*App) GetRepository

func (a *App) GetRepository(w http.ResponseWriter, r *http.Request)

func (*App) GetScan

func (a *App) GetScan(w http.ResponseWriter, r *http.Request)

func (*App) Initialize

func (a *App) Initialize(noop bool)

func (*App) ListRepositories

func (a *App) ListRepositories(w http.ResponseWriter, r *http.Request)

func (*App) ListScans

func (a *App) ListScans(w http.ResponseWriter, r *http.Request)

func (*App) ModifyRepository

func (a *App) ModifyRepository(w http.ResponseWriter, r *http.Request)

func (*App) NewRouter

func (a *App) NewRouter() HttpRouter

func (*App) RemoveScanRequest

func (a *App) RemoveScanRequest(id string)

func (*App) Run

func (a *App) Run()

func (*App) ScanRequestHandler

func (a *App) ScanRequestHandler(id string)

type HttpRouter

type HttpRouter interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

type PsqlDB

type PsqlDB struct {
	Host     string
	Port     int
	User     string
	Password string
	DBname   string
	DB       *sql.DB
}

func GetPsqlDBInstance

func GetPsqlDBInstance() *PsqlDB

func (*PsqlDB) Initialize

func (db *PsqlDB) Initialize()

type RepoStore

type RepoStore interface {
	Insert(ri *models.RepositoryInfo) (*models.RepositoryRecord, error)
	Retrieve(id int64) (*models.RepositoryRecord, error)
	Delete(id int64) error
	Update(rr *models.RepositoryRecord) error
	List(pp *models.PaginationParams) (*models.RepositoryList, error)
}

func NewRepoStore

func NewRepoStore(dbtype string) (RepoStore, error)

Create and return a pointer to a new repository data store. Returns nil and an error on failure

func NewRepoStoreMemDB

func NewRepoStoreMemDB() (RepoStore, error)

func NewRepoStorePsqlDB

func NewRepoStorePsqlDB() (RepoStore, error)

type RepoStoreMemDB

type RepoStoreMemDB struct {
	DB *memdb.MemDB
	// contains filtered or unexported fields
}

func (*RepoStoreMemDB) Delete

func (rs *RepoStoreMemDB) Delete(id int64) error

Delete an existing repository record from the data store. Returns nil on success or an error on failure.

func (*RepoStoreMemDB) Insert

Add a new repository record to the data store. Returns a pointer to the newly added repository record or nil and an error on failure.

func (*RepoStoreMemDB) List

List returns a repository list based on the provided pagination parameters. It will return a maximum of page size repository records while skipping offset-1 records from the start of the data store.

func (*RepoStoreMemDB) NextId

func (rs *RepoStoreMemDB) NextId() int64

Helper function to auto-generate the next unique id value that can be used for new repository records.

func (*RepoStoreMemDB) Retrieve

func (rs *RepoStoreMemDB) Retrieve(id int64) (*models.RepositoryRecord, error)

Retrieve an existing repository record from the data store. Returns a pointer to a copy of the retrieved repository record or nil and an error on failure.

func (*RepoStoreMemDB) Update

func (rs *RepoStoreMemDB) Update(rr *models.RepositoryRecord) error

Update an existing repository record in the data store. Returns nil on success or an error on failure.

type RepoStorePsql

type RepoStorePsql struct {
	DB *sql.DB
}

func (*RepoStorePsql) Delete

func (rs *RepoStorePsql) Delete(id int64) error

Delete an existing repository record from the data store. Returns nil on success or an error on failure.

func (*RepoStorePsql) Insert

Add a new repository record to the data store. Returns a pointer to the newly added repository record or nil and an error on failure.

func (*RepoStorePsql) List

List returns a repository list based on the provided pagination parameters. It will return a maximum of page size repository records while skipping offset-1 records from the start of the data store.

func (*RepoStorePsql) Retrieve

func (rs *RepoStorePsql) Retrieve(id int64) (*models.RepositoryRecord, error)

Retrieve an existing repository record from the data store. Returns a pointer to a copy of the retrieved repository record or nil and an error on failure.

func (*RepoStorePsql) Update

func (rs *RepoStorePsql) Update(rr *models.RepositoryRecord) error

Update an existing repository record in the data store. Returns nil on success or an error on failure.

type Route

type Route struct {
	Name        string
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

type Routes

type Routes []Route

type ScanJob

type ScanJob struct {
	Job        *engine.Job
	CancelFlag chan bool
}

type ScanStore

type ScanStore interface {
	Insert(si *models.ScanInfo) (*models.ScanRecord, error)
	Retrieve(id string) (*models.ScanRecord, error)
	Delete(id string) error
	Update(sr *models.ScanRecord) error
	List(pp *models.PaginationParams) (*models.ScanList, error)
	InsertFindings(scanId string, findings []*models.FindingsInfo) error
	ListFindings(scanId string) ([]*models.FindingsInfo, error)
	DeleteFindings(scanId string) (int, error)
}

func NewScanStore

func NewScanStore(dbtype string) (ScanStore, error)

Create and return a pointer to a new scan data store. Returns nil and an error on failure

func NewScanStoreMemDB

func NewScanStoreMemDB() (ScanStore, error)

func NewScanStorePsqlDB

func NewScanStorePsqlDB() (ScanStore, error)

type ScanStoreMemDB

type ScanStoreMemDB struct {
	DB *memdb.MemDB
	// contains filtered or unexported fields
}

func (*ScanStoreMemDB) Delete

func (ss *ScanStoreMemDB) Delete(id string) error

Delete an existing scan record from the data store. Returns nil on success or an error on failure.

func (*ScanStoreMemDB) DeleteFindings

func (ss *ScanStoreMemDB) DeleteFindings(scanId string) (int, error)

DeleteFindings deletes all of the findings from the data store indexed by scanId. All operations related to findings are done in bulk. It returns the number of deleted records on success, or zero and an error on failure, at which point none of the findings will be deleted.

func (*ScanStoreMemDB) Insert

func (ss *ScanStoreMemDB) Insert(si *models.ScanInfo) (*models.ScanRecord, error)

Add a new scan record to the data store. Returns a pointer to the newly added scan record or nil and an error on failure.

func (*ScanStoreMemDB) InsertFindings

func (ss *ScanStoreMemDB) InsertFindings(scanId string, findings []*models.FindingsInfo) error

InsertFindings stores all of the contents of the findings list into the data store, indexed by scanId. All operations related to findings are done in bulk. It returns nil on success or an error on failure, at which point none of the findings will be stored.

func (*ScanStoreMemDB) List

List returns a scan list based on the provided pagination parameters. It will return a maximum of page size repository records while skipping offset-1 records from the start of the data store.

func (*ScanStoreMemDB) ListFindings

func (ss *ScanStoreMemDB) ListFindings(scanId string) ([]*models.FindingsInfo, error)

ListFindings retrieves all of the findings from the data store indexed by scanId. All operations related to findings are done in bulk. It returns a list of findings on success, or nil and an error on failure.

func (*ScanStoreMemDB) NextFindingsId

func (ss *ScanStoreMemDB) NextFindingsId() int

Helper function to auto-generate the next unique id value that can be used for new findings records.

func (*ScanStoreMemDB) NextId

func (ss *ScanStoreMemDB) NextId() string

Helper function to auto-generate the next unique id value that can be used for new scan records.

func (*ScanStoreMemDB) Retrieve

func (ss *ScanStoreMemDB) Retrieve(id string) (*models.ScanRecord, error)

Retrieve an existing scan record from the data store. Returns a pointer to a copy of the retrieved scan record or nil and an error on failure.

func (*ScanStoreMemDB) Update

func (ss *ScanStoreMemDB) Update(sr *models.ScanRecord) error

Update an existing scan record in the data store. Returns nil on success or an error on failure.

type ScanStorePsqlDB

type ScanStorePsqlDB struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

func (*ScanStorePsqlDB) Delete

func (ss *ScanStorePsqlDB) Delete(id string) error

Delete an existing scan record from the data store. Returns nil on success or an error on failure.

func (*ScanStorePsqlDB) DeleteFindings

func (ss *ScanStorePsqlDB) DeleteFindings(scanId string) (int, error)

DeleteFindings deletes all of the findings from the data store indexed by scanId. All operations related to findings are done in bulk. It returns the number of deleted records on success, or zero and an error on failure, at which point none of the findings will be deleted.

func (*ScanStorePsqlDB) Insert

func (ss *ScanStorePsqlDB) Insert(si *models.ScanInfo) (*models.ScanRecord, error)

Add a new scan record to the data store. Returns a pointer to the newly added scan record or nil and an error on failure.

func (*ScanStorePsqlDB) InsertFindings

func (ss *ScanStorePsqlDB) InsertFindings(scanId string, findings []*models.FindingsInfo) error

InsertFindings stores all of the contents of the findings list into the data store, indexed by scanId. All operations related to findings are done in bulk. It returns nil on success or an error on failure, at which point none of the findings will be stored.

func (*ScanStorePsqlDB) List

List returns a scan list based on the provided pagination parameters. It will return a maximum of page size repository records while skipping offset-1 records from the start of the data store.

func (*ScanStorePsqlDB) ListFindings

func (ss *ScanStorePsqlDB) ListFindings(scanId string) ([]*models.FindingsInfo, error)

ListFindings retrieves all of the findings from the data store indexed by scanId. All operations related to findings are done in bulk. It returns a list of findings on success, or nil and an error on failure.

func (*ScanStorePsqlDB) NextId

func (ss *ScanStorePsqlDB) NextId() string

Helper function to auto-generate the next unique id value that can be used for new scan records.

func (*ScanStorePsqlDB) Retrieve

func (ss *ScanStorePsqlDB) Retrieve(id string) (*models.ScanRecord, error)

Retrieve an existing scan record from the data store. Returns a pointer to a copy of the retrieved scan record or nil and an error on failure.

func (*ScanStorePsqlDB) Update

func (ss *ScanStorePsqlDB) Update(sr *models.ScanRecord) error

Update an existing scan record in the data store. Returns nil on success or an error on failure.

Jump to

Keyboard shortcuts

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