db

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: MPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDB

func NewDB(driverName string, dataSourceName string, logger log.Logger) (store.DB, error)

Types

type DB

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

func (*DB) DeleteDevice

func (db *DB) DeleteDevice(ctx context.Context, id string) error

func (*DB) InsertDevice

func (db *DB) InsertDevice(ctx context.Context, alias string, deviceID string, dmsID string, description string, tags []string, iconName string, iconColor string) error

func (*DB) InsertDeviceCertHistory

func (db *DB) InsertDeviceCertHistory(ctx context.Context, certHistory device.DeviceCertHistory) error

func (*DB) InsertLog

func (db *DB) InsertLog(ctx context.Context, logDev device.DeviceLog) error

func (*DB) SelectAllDevices

func (db *DB) SelectAllDevices(ctx context.Context, queryParameters device.QueryParameters) ([]device.Device, int, error)

func (*DB) SelectAllDevicesByDmsId

func (db *DB) SelectAllDevicesByDmsId(ctx context.Context, dms_id string) ([]device.Device, error)

func (*DB) SelectDeviceById

func (db *DB) SelectDeviceById(ctx context.Context, id string) (device.Device, error)

func (*DB) SelectDeviceCertHistory

func (db *DB) SelectDeviceCertHistory(ctx context.Context, deviceId string) ([]device.DeviceCertHistory, error)

func (*DB) SelectDeviceCertHistoryBySerialNumber

func (db *DB) SelectDeviceCertHistoryBySerialNumber(ctx context.Context, serialNumber string) (device.DeviceCertHistory, error)

func (*DB) SelectDeviceCertHistoryLastThirtyDays

func (db *DB) SelectDeviceCertHistoryLastThirtyDays(ctx context.Context, queryParameters device.QueryParameters) ([]device.DeviceCertHistory, error)

func (*DB) SelectDeviceLogs

func (db *DB) SelectDeviceLogs(ctx context.Context, deviceId string) ([]device.DeviceLog, error)

func (*DB) SelectDmssLastIssuedCert

func (db *DB) SelectDmssLastIssuedCert(ctx context.Context, queryParameters device.QueryParameters) ([]device.DMSLastIssued, error)
func (db *DB) UpdateDeviceCertHistory(ctx context.Context, deviceId string, serialNumber string, newStatus string) error {
	db.logger = ctx.Value(utils.LamassuLoggerContextKey).(log.Logger)
	parentSpan := opentracing.SpanFromContext(ctx)
	sqlStatement := `
	UPDATE device_certificates_history
	SET status = $2, revocation_ts = $3
	WHERE serial_number = $1
	`
	span := opentracing.StartSpan("lamassu-device-manager: updated Devices Cert History with ID "+serialNumber+" to "+newStatus+" status", opentracing.ChildOf(parentSpan.Context()))
	res, err := db.Exec(sqlStatement, serialNumber, newStatus, time.Now())
	span.Finish()
	if err != nil {
		level.Debug(db.logger).Log("err", err, "msg", "Could not updated Devices Cert History with ID "+serialNumber+" to "+newStatus+" status")
		return err
	}
	count, err := res.RowsAffected()
	if err != nil {
		return err
	}
	if count <= 0 {
		err = errors.New("no rows have been updated in database")
		level.Debug(db.logger).Log("err", err)
		return err
	}
	level.Debug(db.logger).Log("err", err, "msg", "Updated Devices Cert History with ID "+serialNumber+" to "+newStatus+" status")
	return nil
}

func (*DB) UpdateByID added in v0.0.10

func (db *DB) UpdateByID(ctx context.Context, alias string, deviceID string, dmsID string, description string, tags []string, iconName string, iconColor string) error

func (*DB) UpdateDeviceCertificateSerialNumberByID

func (db *DB) UpdateDeviceCertificateSerialNumberByID(ctx context.Context, id string, serialNumber string) error

func (*DB) UpdateDeviceStatusByID

func (db *DB) UpdateDeviceStatusByID(ctx context.Context, id string, newStatus string) error

Jump to

Keyboard shortcuts

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