storage

package
v0.0.0-...-f44e450 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2023 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Copyright 2023 Meta Platforms, Inc. and affiliates.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright 2023 Meta Platforms, Inc. and affiliates.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright 2023 Meta Platforms, Inc. and affiliates.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright 2023 Meta Platforms, Inc. and affiliates.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright 2023 Meta Platforms, Inc. and affiliates.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright 2023 Meta Platforms, Inc. and affiliates.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright 2023 Meta Platforms, Inc. and affiliates.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright 2023 Meta Platforms, Inc. and affiliates.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright 2023 Meta Platforms, Inc. and affiliates.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalyzeReportFindFilter

type AnalyzeReportFindFilter struct {
	ID          *uint64
	JobID       *types.JobID
	AssetID     *int32
	ProcessedAt *sql.NullTime

	// Firmware image referenced in the report.
	ActualFirmware FindFirmwareFilter
}

AnalyzeReportFindFilter is a set of values to look for (concatenated through "AND"-s).

If a field has a nil-value then it is not included to filter conditions.

type BlobStorage

type BlobStorage interface {
	io.Closer
	Get(ctx context.Context, key []byte) ([]byte, error)
	Replace(ctx context.Context, key []byte, blob []byte) error
	Delete(ctx context.Context, key []byte) error
}

type Cache

type Cache interface {
	// Get returns an object, given its cache key.
	//
	// Returns an untyped nil if there is no such entry in the cache.
	Get(ctx context.Context, objectKey objhash.ObjHash) any

	// Set tries to set an object with its cache key. It is up to implementation
	// to decide whether to actually store the object.
	//
	// objectSize is only notifies the implementation (of Cache) about how
	// much memory the object consumes (rough estimation).
	Set(ctx context.Context, objectKey objhash.ObjHash, object any, objectSize uint64)
}

Cache is used to avoid repeating queries to the backends

type ErrAlreadyExists

type ErrAlreadyExists struct {
	Err *mysql.MySQLError
	// contains filtered or unexported fields
}

ErrAlreadyExists implements "error", for the description see Error.

func (ErrAlreadyExists) Error

func (err ErrAlreadyExists) Error() string

func (ErrAlreadyExists) Unwrap

func (err ErrAlreadyExists) Unwrap() error

type ErrDownload

type ErrDownload struct {
	Err error
}

ErrDownload implements "error", for the description see Error.

func (ErrDownload) Error

func (err ErrDownload) Error() string

func (ErrDownload) Unwrap

func (err ErrDownload) Unwrap() error

type ErrEmptyFilters

type ErrEmptyFilters struct{}

ErrEmptyFilters signals that search filters are empty and effectively the request requires to select all the data, which is forbidden.

func (ErrEmptyFilters) Error

func (err ErrEmptyFilters) Error() string

type ErrGetData

type ErrGetData struct {
	Err error
}

ErrGetData implements "error", for the description see Error.

func (ErrGetData) Error

func (err ErrGetData) Error() string

func (ErrGetData) Unwrap

func (err ErrGetData) Unwrap() error

type ErrGetMeta

type ErrGetMeta struct {
	Err error
}

ErrGetMeta implements "error", for the description see Error.

func (ErrGetMeta) Error

func (err ErrGetMeta) Error() string

func (ErrGetMeta) Unwrap

func (err ErrGetMeta) Unwrap() error

type ErrInitMySQL

type ErrInitMySQL struct {
	Err error
	DSN string
}

ErrInitMySQL implements "error", for the description see Error.

func (ErrInitMySQL) Error

func (err ErrInitMySQL) Error() string

func (ErrInitMySQL) Unwrap

func (err ErrInitMySQL) Unwrap() error

type ErrMySQLPing

type ErrMySQLPing struct {
	Err error
}

ErrMySQLPing implements "error", for the description see Error.

func (ErrMySQLPing) Error

func (err ErrMySQLPing) Error() string

func (ErrMySQLPing) Unwrap

func (err ErrMySQLPing) Unwrap() error

type ErrNotFound

type ErrNotFound struct {
	Query string
}

ErrNotFound implements "error", for the description see Error.

func (ErrNotFound) Error

func (err ErrNotFound) Error() string

type ErrSelect

type ErrSelect struct {
	Err error
}

ErrSelect implements "error", for the description see Error.

func (ErrSelect) Error

func (err ErrSelect) Error() string

func (ErrSelect) Unwrap

func (err ErrSelect) Unwrap() error

type ErrTooManyEntries

type ErrTooManyEntries struct {
	Count uint
}

ErrTooManyEntries implements "error", for the description see Error.

func (ErrTooManyEntries) Error

func (err ErrTooManyEntries) Error() string

type ErrUnableToInsert

type ErrUnableToInsert struct {
	Err error
	// contains filtered or unexported fields
}

ErrUnableToInsert implements "error", for the description see Error.

func (ErrUnableToInsert) Error

func (err ErrUnableToInsert) Error() string

func (ErrUnableToInsert) Unwrap

func (err ErrUnableToInsert) Unwrap() error

type ErrUnableToUpdate

type ErrUnableToUpdate struct {
	Err error
	// contains filtered or unexported fields
}

ErrUnableToUpdate implements "error", for the description see Error.

func (ErrUnableToUpdate) Error

func (err ErrUnableToUpdate) Error() string

func (ErrUnableToUpdate) Unwrap

func (err ErrUnableToUpdate) Unwrap() error

type ErrUnableToUpdateMetadata

type ErrUnableToUpdateMetadata struct {
	Err error
}

ErrUnableToUpdateMetadata implements "error", for the description see Error.

func (ErrUnableToUpdateMetadata) Error

func (err ErrUnableToUpdateMetadata) Error() string

func (ErrUnableToUpdateMetadata) Unwrap

func (err ErrUnableToUpdateMetadata) Unwrap() error

type ErrUnableToUpload

type ErrUnableToUpload struct {
	Key []byte
	Err error
}

ErrUnableToUpload implements "error", for the description see Error.

func (ErrUnableToUpload) Error

func (err ErrUnableToUpload) Error() string

func (ErrUnableToUpload) Unwrap

func (err ErrUnableToUpload) Unwrap() error

type FindFirmwareFilter

type FindFirmwareFilter struct {
	ImageID         *types.ImageID
	HashSHA2_512    types.HashValue
	HashBlake3_512  types.HashValue
	HashStable      types.HashValue
	Filename        *string
	FirmwareVersion *string

	ImageIDPrefix []byte
}

FindFirmwareFilter is a set of values to look for (concatenated through "AND"-s).

If a field has a nil-value then it is not included to filter conditions.

func (FindFirmwareFilter) IsEmpty

func (f FindFirmwareFilter) IsEmpty() bool

IsEmpty returns true if no filters are set

type Storage

type Storage struct {
	DB                       *sqlx.DB
	BlobStorage              BlobStorage
	Cache                    Cache
	CacheLockMap             *lockmap.LockMap
	Logger                   logger.Logger
	RetryDefaultInitialDelay time.Duration
	RetryTimeout             time.Duration
	// contains filtered or unexported fields
}

Storage is the implementation of firmware images storage (which handles both: metadata and the image itself).

func New

func New(
	rdbmsDriver string,
	rdbmsDSN string,
	blobStorage BlobStorage,
	cache Cache,
	log logger.Logger,
) (*Storage, error)

NewStorage returns an instance of Storage.

func (*Storage) Close

func (stor *Storage) Close() error

Close stops the instance of the Storage.

func (*Storage) FindAnalyzeReports

func (stor *Storage) FindAnalyzeReports(
	ctx context.Context,
	filterInput AnalyzeReportFindFilter,
	tx *sqlx.Tx,
	limit uint,
) (
	[]*models.AnalyzeReport,
	error,
)

FindAnalyzeReports finds and locks existing AnalyzeReports including the related AnalyzerReports.

The rows are write-locks as part of `tx` transaction. To unlock the rows either Commit or Rollback the transaction.

TODO: Remove these functions from `Storage`. The initial purpose of storage is combine together

management of metadata in MySQL and data in BlobStorage for firmware images. All the rest
entities should not be accessed through Storage. Otherwise locking, transactions and other
usual stuff is pretty cludgy (e.g. see the `tx` which semantically partially duplicates `stor.DB`).

func (*Storage) FindAnalyzerReport

func (stor *Storage) FindAnalyzerReport(
	tx *sqlx.Tx,
	analyzerReportID int64,
) (*models.AnalyzerReport, error)

FindAnalyzerReport finds and locks an AnalyzerReport, given its ID.

The rows are write-locks as part of `tx` transaction. To unlock the rows either Commit or Rollback the transaction.

TODO: Remove these functions from `Storage`. The initial purpose of storage is combine together

management of metadata in MySQL and data in BlobStorage for firmware images. All the rest
entities should not be accessed through Storage. Otherwise locking, transactions and other
usual stuff is pretty cludgy (e.g. see the `tx` which semantically partially duplicates `stor.DB`).

func (*Storage) FindFirmware

func (stor *Storage) FindFirmware(ctx context.Context, filter FindFirmwareFilter) (imageMetas []*models.FirmwareImageMetadata, unlockFn context.CancelFunc, err error)

FindFirmware locks (with a shared lock) the rows and returns image metadata.

Second returned variable is a function to release the lock on the row.

func (*Storage) FindFirmwareOne

FindFirmwareOne locks (with a shared lock) the row and returns image metadata.

Second returned variable is a function to release the lock on the row.

func (*Storage) FindReproducedPCRsOne

func (stor *Storage) FindReproducedPCRsOne(ctx context.Context, key models.UniqueKey) (models.ReproducedPCRs, error)

FindReproducedPCRsOne returns reproduced single PCRs item by unique search key

TODO: Remove these functions from `Storage`. The initial purpose of storage is combine together

management of metadata in MySQL and data in BlobStorage for firmware images. All the rest
entities should not be accessed through Storage. Otherwise locking, transactions and other
usual stuff is pretty cludgy.

func (*Storage) GetAnalyzeReportGroup

func (stor *Storage) GetAnalyzeReportGroup(
	ctx context.Context,
	key models.AnalyzeReportGroupKey,
	tx *sqlx.Tx,
	fetchAnalyzeReports bool,
) (
	*models.AnalyzeReportGroup,
	error,
)

GetAnalyzeReportGroup finds and locks an existing AnalyzeReportGroup.

The rows are write-locks as part of `tx` transaction. To unlock the rows either Commit or Rollback the transaction.

if `fetchAnalyzeReports` is true then also fetches related AnalyzeReports into field AnalyzeReports.

Returns (nil, nil) if such group is was not found.

TODO: Remove these functions from `Storage`. The initial purpose of storage is combine together

management of metadata in MySQL and data in BlobStorage for firmware images. All the rest
entities should not be accessed through Storage. Otherwise locking, transactions and other
usual stuff is pretty cludgy (e.g. see the `tx` which semantically partially duplicates `stor.DB`).

func (*Storage) GetFirmware

func (stor *Storage) GetFirmware(ctx context.Context, imageID types.ImageID) ([]byte, *models.FirmwareImageMetadata, error)

GetFirmware returns an image and the metadata by ImageID (basically combines FindFirmwareOne and GetFirmwareBytes).

func (*Storage) GetFirmwareBytes

func (stor *Storage) GetFirmwareBytes(ctx context.Context, imageID types.ImageID) (firmwareImage []byte, err error)

GetFirmwareBytes returns an image itself only by ImageID.

func (*Storage) GetFirmwareBytesByBlobStoreKey

func (stor *Storage) GetFirmwareBytesByBlobStoreKey(ctx context.Context, blobStoreKey []byte) (firmwareImage []byte, err error)

GetFirmwareBytesByPath returns an image itself only by its path in the BlobStorage

func (*Storage) GetOrCreateAnalyzeReportGroup

func (stor *Storage) GetOrCreateAnalyzeReportGroup(
	ctx context.Context,
	key models.AnalyzeReportGroupKey,
	tx *sqlx.Tx,
	fetchAnalyzeReports bool,
) (
	*models.AnalyzeReportGroup,
	error,
)

GetOrCreateAnalyzeReportGroup is similar to GetAnalyzeReportGroup, but it also creates an entry if one not exist in the table.

The rows are write-locks as part of `tx` transaction. To unlock the rows either Commit or Rollback the transaction.

TODO: Remove these functions from `Storage`. The initial purpose of storage is combine together

management of metadata in MySQL and data in BlobStorage for firmware images. All the rest
entities should not be accessed through Storage. Otherwise locking, transactions and other
usual stuff is pretty cludgy (e.g. see the `tx` which semantically partially duplicates `stor.DB`).

func (*Storage) InsertAnalyzeReport

func (stor *Storage) InsertAnalyzeReport(ctx context.Context, report *models.AnalyzeReport) (retErr error)

InsertAnalyzeReport adds information about performed analysis.

`report` should be not-nil, but `ID` field should be zero.

On success also: * `ID` is set. * `report.Reports` are also saved and: `ID` and `AnalyzerReportID` are also set.

TODO: Remove these functions from `Storage`. The initial purpose of storage is combine together

management of metadata in MySQL and data in BlobStorage for firmware images. All the rest
entities should not be accessed through Storage. Otherwise locking, transactions and other
usual stuff is pretty cludgy.

func (*Storage) InsertFirmware

func (stor *Storage) InsertFirmware(ctx context.Context, imageMeta models.FirmwareImageMetadata, imageData []byte) (err error)

InsertFirmware adds an image to the storage (saves the images itself and it's metadata).

func (*Storage) SelectReproducedPCRs

func (stor *Storage) SelectReproducedPCRs(ctx context.Context) ([]models.ReproducedPCRs, error)

SelectReproducedPCRs selects all reproduced PCR values

TODO: Remove these functions from `Storage`. The initial purpose of storage is combine together

management of metadata in MySQL and data in BlobStorage for firmware images. All the rest
entities should not be accessed through Storage. Otherwise locking, transactions and other
usual stuff is pretty cludgy.

func (*Storage) SelectReproducedPCRsWithImageMetadata

func (stor *Storage) SelectReproducedPCRsWithImageMetadata(ctx context.Context) ([]models.ReproducedPCRs, []models.FirmwareImageMetadata, error)

SelectReproducedPCRsWithImageMetadata selects an INNER JOIN of reproduced PCRs with image metadatas. The indexes of both returned slices corresponds to each other.

TODO: Remove these functions from `Storage`. The initial purpose of storage is combine together

management of metadata in MySQL and data in BlobStorage for firmware images. All the rest
entities should not be accessed through Storage. Otherwise locking, transactions and other
usual stuff is pretty cludgy.

func (*Storage) UpsertReproducedPCRs

func (stor *Storage) UpsertReproducedPCRs(ctx context.Context, reproducedPCRs models.ReproducedPCRs) error

UpsertReproducedPCRs inserts ReproducedPCRs or updates reproduced pcr values if item already exists structure

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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