...

Source file src/edge-infra.dev/pkg/edge/iam/barcode/storage.go

Documentation: edge-infra.dev/pkg/edge/iam/barcode

     1  //nolint:revive
     2  package barcode
     3  
     4  import (
     5  	"context"
     6  	"time"
     7  )
     8  
     9  type Code struct {
    10  	// Subject is the user this barcode is issued to
    11  	Subject string `bson:"subject" json:"subject" xml:"subject"`
    12  	// IssuedBy is used to indicate who issued this
    13  	IssuedBy string `bson:"iby" json:"iby" xml:"iby"`
    14  	// ClientID is used to make sure that the same client is the one exchanging the code for the actual barcode
    15  	ClientID string `bson:"clientId" json:"clientId" xml:"clientId"`
    16  	// Challenge is used to map the barcode key to the session
    17  	Challenge string `bson:"challenge" json:"challenge" xml:"challenge"`
    18  	// Used tells whether this barcode is used previously or not
    19  	Used bool `bson:"used" json:"used" xml:"used"`
    20  	// CreatedAt refers to the timestamp when the barcode is generated as per user request.
    21  	CreatedAt time.Time `bson:"createdAt" json:"createdAt" xml:"createdAt"`
    22  	// Type refers to QR or 128A.
    23  	Type string `bson:"type" json:"type" xml:"type"`
    24  }
    25  
    26  type Barcode struct {
    27  	// Subject is the user this barcode is issued to
    28  	Subject string `bson:"subject" json:"subject" xml:"subject"`
    29  	// Secret is a unique generated credential for a barcode generation request.
    30  	Secret string `bson:"secret" json:"secret" xml:"secret"`
    31  	// CreatedAt refers to the timestamp when the barcode is generated as per user request.
    32  	CreatedAt time.Time `bson:"createdAt" json:"createdAt" xml:"createdAt"`
    33  }
    34  
    35  type BarcodeKey struct {
    36  	// BarcodeKey is used to map barcode to a barcode user
    37  	BarcodeKey string `bson:"barcodeKey" json:"barcodeKey" xml:"barcodeKey"`
    38  }
    39  
    40  type Storage interface {
    41  	CreateBarcodeCode(ctx context.Context, code string, subject string, issuedBy string, clientID string, barcodeType string, challenge string) (err error)
    42  	InvalidateBarcodeCode(ctx context.Context, code string, subject string, issuedBy string, clientID string, barcodeType string, challenge string) (err error)
    43  	CreateBarcodeKey(ctx context.Context, challenge string, barcodeKey string) (err error)
    44  	GetBarcodeKey(ctx context.Context, challenge string) (barcodeKey *BarcodeKey, err error)
    45  	DeleteBarcodeKey(ctx context.Context, challenge string) (err error)
    46  	GetBarcodeCode(ctx context.Context, code string) (barcodeCode *Code, err error)
    47  	GetBarcodeUser(ctx context.Context, barCodeUser string) (string, error)
    48  	CreateBarcodeUser(ctx context.Context, subject, barcodeKey string) (err error)
    49  	DeleteBarcodeCode(ctx context.Context, code string) (err error)
    50  	CreateBarcode(ctx context.Context, key, secret, subject string) (err error)
    51  	GetBarcode(ctx context.Context, key string) (barcode *Barcode, err error)
    52  	DeleteBarcode(ctx context.Context, barcode string) (err error)
    53  	IsOffline() bool
    54  	RunOfflineDetection()
    55  }
    56  

View as plain text