2020-01-17 08:58:12 +01:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
)
|
|
|
|
|
|
|
|
type contextKey string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// manifestInfoKey the context key for manifest info
|
|
|
|
manifestInfoKey = contextKey("ManifestInfo")
|
2020-01-20 03:29:37 +01:00
|
|
|
// ScannerPullCtxKey the context key for robot account to bypass the pull policy check.
|
|
|
|
ScannerPullCtxKey = contextKey("ScannerPullCheck")
|
2020-01-17 08:58:12 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// ManifestInfo ...
|
|
|
|
type ManifestInfo struct {
|
|
|
|
ProjectID int64
|
|
|
|
Repository string
|
|
|
|
Tag string
|
|
|
|
Digest string
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewManifestInfoContext returns context with manifest info
|
|
|
|
func NewManifestInfoContext(ctx context.Context, info *ManifestInfo) context.Context {
|
|
|
|
return context.WithValue(ctx, manifestInfoKey, info)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ManifestInfoFromContext returns manifest info from context
|
|
|
|
func ManifestInfoFromContext(ctx context.Context) (*ManifestInfo, bool) {
|
|
|
|
info, ok := ctx.Value(manifestInfoKey).(*ManifestInfo)
|
|
|
|
return info, ok
|
|
|
|
}
|
2020-01-20 03:29:37 +01:00
|
|
|
|
|
|
|
// NewScannerPullContext returns context with policy check info
|
|
|
|
func NewScannerPullContext(ctx context.Context, scannerPull bool) context.Context {
|
|
|
|
return context.WithValue(ctx, ScannerPullCtxKey, scannerPull)
|
|
|
|
}
|