Skip to content

Commit

Permalink
Implement auto-approval bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed May 18, 2024
1 parent 2ae68b2 commit 9ccaf43
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 69 deletions.
31 changes: 22 additions & 9 deletions hack/ccp/internal/controller/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ type iterator struct {

p *Package

startAt uuid.UUID
startAtChainID uuid.UUID

startAtLinkID uuid.UUID

chain *chain

Expand All @@ -71,12 +73,13 @@ type iterator struct {

func NewIterator(logger logr.Logger, gearman *gearmin.Server, wf *workflow.Document, p *Package) *iterator {
iter := &iterator{
logger: logger,
gearman: gearman,
wf: wf,
p: p,
startAt: p.startAt,
waitCh: make(chan waitSignal, 10),
logger: logger,
gearman: gearman,
wf: wf,
p: p,
startAtChainID: p.startAtChainID,
startAtLinkID: p.startAtLinkID,
waitCh: make(chan waitSignal, 10),
}

return iter
Expand All @@ -93,7 +96,12 @@ func (i *iterator) Process(ctx context.Context) (err error) {
}
}()

next := i.startAt
next := i.startAtChainID

// The package indicates that we should start from a specific chain link
// within the chain. Needed by transfer submission with auto-approval
// enabled, otherwise uuid.Nil.
bypassLink := i.startAtLinkID

for {
if err := ctx.Err(); err != nil {
Expand All @@ -109,7 +117,12 @@ func (i *iterator) Process(ctx context.Context) (err error) {
} else {
i.chain.pCtx = pCtx
}
next = ch.LinkID
if bypassLink != uuid.Nil {
next = bypassLink // Bypass in place.
bypassLink = uuid.Nil // Do this only once.
} else {
next = ch.LinkID
}
continue
}

Expand Down
12 changes: 9 additions & 3 deletions hack/ccp/internal/controller/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ type Package struct {
path string

// Identifier of the chain where the iterator must start processing.
startAt uuid.UUID
startAtChainID uuid.UUID

// Identifier of the link where the iterator must start processing.
startAtLinkID uuid.UUID

// User decisinon manager
decision decision
Expand All @@ -68,7 +71,7 @@ func NewPackage(ctx context.Context, logger logr.Logger, store store.Store, shar

pkg := newPackage(logger, store, sharedDir)
pkg.path = path
pkg.startAt = wd.ChainID
pkg.startAtChainID = wd.ChainID

switch {
case wd.UnitType == "Transfer":
Expand Down Expand Up @@ -130,7 +133,10 @@ func NewTransferPackage(
pkg := newPackage(logger, store, sharedDir)
pkg.id = uuid.New()
pkg.unit = &Transfer{pkg: pkg}
pkg.startAt = Transfers.WithType(req.Type).Chain

transferType := Transfers.WithType(req.Type)
pkg.startAtChainID = transferType.BypassChainID
pkg.startAtLinkID = transferType.BypassLinkID

var msID uuid.UUID
if req.MetadataSetId != nil {
Expand Down
112 changes: 55 additions & 57 deletions hack/ccp/internal/controller/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,32 @@ import (
"github.com/google/uuid"

adminv1 "github.com/artefactual/archivematica/hack/ccp/internal/api/gen/archivematica/ccp/admin/v1beta1"
"github.com/artefactual/archivematica/hack/ccp/internal/workflow"
)

// TransferType represents a known type of transfer in Archivematica.
type TransferType struct {
// Name of the transfer type.
// Name of the transfer type, e.g. "standard", "zipfile", etc...
Name string

// Type in the transfer type enum.
// Type enum value as described by the adminv1 proto.
Type adminv1.TransferType

// WatcheDir is the watched directory used to trigger this type of transfer.
WatchedDir string

// Chain is the chain used to start processing if approval is omitted.
Chain uuid.UUID
// BypassChainID is the chain bypass used to start a new transfer of this
// type with auto-approval.
BypassChainID uuid.UUID

// Link is the link used to start processing if approval is omitted.
Link uuid.UUID
// BypassLinkID is the specific chain link within the bypass chain where
// we want to start processing when using auto-approval.
BypassLinkID uuid.UUID

// DecisionLink is the chain link used to require user approval.
// DecisionLink is the chain link used to prompt the user for approval.
// Decision is the chain that we have to choose to accept the transfer.
// TODO: remove these two once we implement the Decision API.
DecisionLink uuid.UUID

// Decision is the approved chain.
Decision uuid.UUID
}

func (t TransferType) WatchedDirDoc(wf *workflow.Document) *workflow.WatchedDirectory {
return nil
Decision uuid.UUID
}

type TransferTypes []TransferType
Expand Down Expand Up @@ -69,61 +67,61 @@ func (t TransferTypes) WithType(tt adminv1.TransferType) *TransferType {
// List of transfer types supported by Archivematica.
var Transfers TransferTypes = []TransferType{
{
Name: "standard",
Type: adminv1.TransferType_TRANSFER_TYPE_STANDARD,
WatchedDir: "activeTransfers/standardTransfer",
Chain: uuid.MustParse("6953950b-c101-4f4c-a0c3-0cd0684afe5e"),
Link: uuid.MustParse("045c43ae-d6cf-44f7-97d6-c8a602748565"),
DecisionLink: uuid.MustParse("0c94e6b5-4714-4bec-82c8-e187e0c04d77"),
Decision: uuid.MustParse("b4567e89-9fea-4256-99f5-a88987026488"),
Name: "standard",
Type: adminv1.TransferType_TRANSFER_TYPE_STANDARD,
WatchedDir: "activeTransfers/standardTransfer",
BypassChainID: uuid.MustParse("6953950b-c101-4f4c-a0c3-0cd0684afe5e"),
BypassLinkID: uuid.MustParse("045c43ae-d6cf-44f7-97d6-c8a602748565"),
DecisionLink: uuid.MustParse("0c94e6b5-4714-4bec-82c8-e187e0c04d77"),
Decision: uuid.MustParse("b4567e89-9fea-4256-99f5-a88987026488"),
},
{
Name: "zipfile",
Type: adminv1.TransferType_TRANSFER_TYPE_ZIP_FILE,
WatchedDir: "activeTransfers/zippedDirectory",
Chain: uuid.MustParse("f3caceff-5ad5-4bad-b98c-e73f8cd03450"),
Link: uuid.MustParse("541f5994-73b0-45bb-9cb5-367c06a21be7"),
Name: "zipfile",
Type: adminv1.TransferType_TRANSFER_TYPE_ZIP_FILE,
WatchedDir: "activeTransfers/zippedDirectory",
BypassChainID: uuid.MustParse("f3caceff-5ad5-4bad-b98c-e73f8cd03450"),
BypassLinkID: uuid.MustParse("541f5994-73b0-45bb-9cb5-367c06a21be7"),
},
{
Name: "unzipped bag",
Type: adminv1.TransferType_TRANSFER_TYPE_UNZIPPED_BAG,
WatchedDir: "activeTransfers/baggitDirectory",
Chain: uuid.MustParse("c75ef451-2040-4511-95ac-3baa0f019b48"),
Link: uuid.MustParse("154dd501-a344-45a9-97e3-b30093da35f5"),
Name: "unzipped bag",
Type: adminv1.TransferType_TRANSFER_TYPE_UNZIPPED_BAG,
WatchedDir: "activeTransfers/baggitDirectory",
BypassChainID: uuid.MustParse("c75ef451-2040-4511-95ac-3baa0f019b48"),
BypassLinkID: uuid.MustParse("154dd501-a344-45a9-97e3-b30093da35f5"),
},
{
Name: "zipped bag",
Type: adminv1.TransferType_TRANSFER_TYPE_ZIPPED_BAG,
WatchedDir: "activeTransfers/baggitZippedDirectory",
Chain: uuid.MustParse("167dc382-4ab1-4051-8e22-e7f1c1bf3e6f"),
Link: uuid.MustParse("3229e01f-adf3-4294-85f7-4acb01b3fbcf"),
Name: "zipped bag",
Type: adminv1.TransferType_TRANSFER_TYPE_ZIPPED_BAG,
WatchedDir: "activeTransfers/baggitZippedDirectory",
BypassChainID: uuid.MustParse("167dc382-4ab1-4051-8e22-e7f1c1bf3e6f"),
BypassLinkID: uuid.MustParse("3229e01f-adf3-4294-85f7-4acb01b3fbcf"),
},
{
Name: "dspace",
Type: adminv1.TransferType_TRANSFER_TYPE_DSPACE,
WatchedDir: "activeTransfers/Dspace",
Chain: uuid.MustParse("1cb2ef0e-afe8-45b5-8d8f-a1e120f06605"),
Link: uuid.MustParse("bda96b35-48c7-44fc-9c9e-d7c5a05016c1"),
Name: "dspace",
Type: adminv1.TransferType_TRANSFER_TYPE_DSPACE,
WatchedDir: "activeTransfers/Dspace",
BypassChainID: uuid.MustParse("1cb2ef0e-afe8-45b5-8d8f-a1e120f06605"),
BypassLinkID: uuid.MustParse("bda96b35-48c7-44fc-9c9e-d7c5a05016c1"),
},
{
Name: "maildir",
Type: adminv1.TransferType_TRANSFER_TYPE_MAILDIR,
WatchedDir: "activeTransfers/maildir",
Chain: uuid.MustParse("d381cf76-9313-415f-98a1-55c91e4d78e0"),
Link: uuid.MustParse("da2d650e-8ce3-4b9a-ac97-8ca4744b019f"),
Name: "maildir",
Type: adminv1.TransferType_TRANSFER_TYPE_MAILDIR,
WatchedDir: "activeTransfers/maildir",
BypassChainID: uuid.MustParse("d381cf76-9313-415f-98a1-55c91e4d78e0"),
BypassLinkID: uuid.MustParse("da2d650e-8ce3-4b9a-ac97-8ca4744b019f"),
},
{
Name: "TRIM",
Type: adminv1.TransferType_TRANSFER_TYPE_TRIM,
WatchedDir: "activeTransfers/TRIM",
Chain: uuid.MustParse("e4a59e3e-3dba-4eb5-9cf1-c1fb3ae61fa9"),
Link: uuid.MustParse("2483c25a-ade8-4566-a259-c6c37350d0d6"),
Name: "TRIM",
Type: adminv1.TransferType_TRANSFER_TYPE_TRIM,
WatchedDir: "activeTransfers/TRIM",
BypassChainID: uuid.MustParse("e4a59e3e-3dba-4eb5-9cf1-c1fb3ae61fa9"),
BypassLinkID: uuid.MustParse("2483c25a-ade8-4566-a259-c6c37350d0d6"),
},
{
Name: "dataverse",
Type: adminv1.TransferType_TRANSFER_TYPE_DATAVERSE,
WatchedDir: "activeTransfers/dataverseTransfer",
Chain: uuid.MustParse("10c00bc8-8fc2-419f-b593-cf5518695186"),
Link: uuid.MustParse("0af6b163-5455-4a76-978b-e35cc9ee445f"),
Name: "dataverse",
Type: adminv1.TransferType_TRANSFER_TYPE_DATAVERSE,
WatchedDir: "activeTransfers/dataverseTransfer",
BypassChainID: uuid.MustParse("10c00bc8-8fc2-419f-b593-cf5518695186"),
BypassLinkID: uuid.MustParse("0af6b163-5455-4a76-978b-e35cc9ee445f"),
},
}

0 comments on commit 9ccaf43

Please sign in to comment.