diff --git a/internal/workflow/hari_activity.go b/internal/workflow/hari_activity.go index 9cf3e829..3ed8e73e 100644 --- a/internal/workflow/hari_activity.go +++ b/internal/workflow/hari_activity.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io/ioutil" "net" @@ -35,9 +36,13 @@ func NewUpdateHARIActivity(m *Manager) *UpdateHARIActivity { } func (a UpdateHARIActivity) Execute(ctx context.Context, tinfo *TransferInfo) error { + if err := validateKind(tinfo.Bundle.Kind); err != nil { + return nonRetryableError(fmt.Errorf("error validating kind attribute: %v", err)) + } + apiURL, err := a.url() if err != nil { - return nonRetryableError(fmt.Errorf("error in URL construction: %w", err)) + return nonRetryableError(fmt.Errorf("error in URL construction: %v", err)) } mock, _ := hookAttrBool(a.manager.Hooks, "hari", "mock") @@ -149,3 +154,32 @@ type avlRequest struct { Timestamp time.Time `json:"timestamp"` // RFC3339. E.g. "2006-01-02T15:04:05Z07:00". AIPID string `json:"aip_id"` } + +var knownKinds = []string{ + "DPJ", "EPJ", "AVLXML", "OTHER", +} + +func validateKind(kind string) error { + if kind == "" { + return errors.New("empty") + } + + const suffix = "-SIP" + if !strings.HasSuffix(kind, suffix) { + return fmt.Errorf("attribute (%s) does not containt suffix (\"-SIP\")", kind) + } + kind = strings.TrimSuffix(kind, "-SIP") + + var known bool + for _, k := range knownKinds { + if k == kind { + known = true + break + } + } + if !known { + return fmt.Errorf("attribute (%s) is unexpected/unknown", kind) + } + + return nil +} diff --git a/internal/workflow/prod_activity.go b/internal/workflow/prod_activity.go index 51384958..52f63543 100644 --- a/internal/workflow/prod_activity.go +++ b/internal/workflow/prod_activity.go @@ -30,6 +30,10 @@ func (a *UpdateProductionSystemActivity) Execute(ctx context.Context, tinfo *Tra return nonRetryableError(errors.New("unknown originalID")) } + if err := validateKind(tinfo.Bundle.Kind); err != nil { + return nonRetryableError(fmt.Errorf("error validating kind attribute: %v", err)) + } + // We expect tinfo.StoredAt to have the zero value when the ingestion // has failed. Here we set a new value as it is a required field. if tinfo.StoredAt.IsZero() {