-
Notifications
You must be signed in to change notification settings - Fork 55
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #216 +/- ##
==========================================
+ Coverage 22.67% 23.07% +0.39%
==========================================
Files 26 25 -1
Lines 2293 2254 -39
==========================================
Hits 520 520
+ Misses 1691 1652 -39
Partials 82 82 ☔ View full report in Codecov by Sentry. |
const ParentResource = "/presentations/submissions" | ||
|
||
// Status indicates the current state of a submission. | ||
type Status uint8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why a uint8 and not define a type for status
type (
Status string
)
const (
StatusPending Status = "pending"
StatusDenied Status = "denied"
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Synced offline. We're storing uints, and exposing strings.
pkg/service/operation/bolt.go
Outdated
db *storage.BoltDB | ||
} | ||
|
||
func (b BoltOperationStorage) CancelOperation(id string) (opstorage.StoredOperation, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (b BoltOperationStorage) CancelOperation(id string) (opstorage.StoredOperation, error) { | |
func (b BoltOperationStorage) CancelOperation(id string) (*opstorage.StoredOperation, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
_, opData, err := b.db.UpdateValueAndOperation( | ||
submission.Namespace, submission.ResourceID(id), storage.NewUpdater(map[string]any{ | ||
"status": submission.StatusCancelled, | ||
"reason": cancelledReason, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when is this reason ever used/surfaced?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetSubmission
returns an object that has a reason
field. It's meant to be a simple record and can be empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think it'll be useful for auditing purposes
pkg/service/operation/bolt.go
Outdated
if err != nil { | ||
return util.LoggingErrorMsgf(err, "marshalling operation with id: %s", id) | ||
} | ||
return b.db.Write(namespace.FromID(id), id, jsonBytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it worth pulling this off as a separate value to be able to wrap the error with a log in case it fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was actually moved only. That said, I've updated this to wrap and log.
pkg/service/operation/bolt.go
Outdated
if err != nil { | ||
stored = append(stored, nextOp) | ||
continue | ||
} | ||
if include { | ||
stored = append(stored, nextOp) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if err != nil { | |
stored = append(stored, nextOp) | |
continue | |
} | |
if include { | |
stored = append(stored, nextOp) | |
} | |
if err != nil || include { | |
stored = append(stored, nextOp) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pkg/service/operation/bolt.go
Outdated
return nil | ||
} | ||
|
||
func NewBoltOperationStorage(db *storage.BoltDB) (*BoltOperationStorage, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I usually put the constructors at the top of the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pkg/service/operation/service.go
Outdated
@@ -102,8 +103,20 @@ func (s Service) GetOperation(request GetOperationRequest) (Operation, error) { | |||
return serviceModel(storedOp) | |||
} | |||
|
|||
func (s Service) CancelOperation(request CancelOperationRequest) (Operation, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (s Service) CancelOperation(request CancelOperationRequest) (Operation, error) { | |
func (s Service) CancelOperation(request CancelOperationRequest) (*Operation, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
const Namespace = "presentation_submission" | ||
|
||
// ParentResource is the prefix of the submission parent resource. | ||
const ParentResource = "/presentations/submissions" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit could put these in the same const ()
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
DefinitionID: definition.PresentationDefinition.ID, | ||
}, | ||
}, | ||
{ | ||
Status: "pending", | ||
PresentationSubmission: &exchange.PresentationSubmission{ | ||
ID: operation.SubmissionID(op2.ID), | ||
ID: submission.ResourceID(op2.ID), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why resource over submission? submission is more meaningful in context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to ID
, as submission is already in the package name.
pkg/service/operation/service.go
Outdated
@@ -102,8 +103,20 @@ func (s Service) GetOperation(request GetOperationRequest) (Operation, error) { | |||
return serviceModel(storedOp) | |||
} | |||
|
|||
func (s Service) CancelOperation(request CancelOperationRequest) (Operation, error) { | |||
if err := request.Validate(); err != nil { | |||
return Operation{}, errors.Wrap(err, "invalid request") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Operation{}, errors.Wrap(err, "invalid request") | |
return nil, errors.Wrap(err, "invalid request") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pkg/service/operation/service.go
Outdated
|
||
storedOp, err := s.storage.CancelOperation(request.ID) | ||
if err != nil { | ||
return Operation{}, errors.Wrap(err, "marking as done") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return Operation{}, errors.Wrap(err, "marking as done") | |
return nil, errors.Wrap(err, "marking as done") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving pending few small comments
* modity storage * modify tests * modify service storage * change module name * update * fix warnings * [OSE-176] Operations can be cancelled (#216) * Initial draft of cancellation * Linters * Moving a constant. * Better homes for many methods and variables. * PR comments * Lets make pointers. * Rename func * add schema caching (#219) Co-authored-by: Andres Uribe <[email protected]> * modity storage * modify tests * modify service storage * change module name * update * fix warnings * fix server test * Fixes to the merge problems. * Small fixes * Lint Co-authored-by: Andres Uribe <[email protected]> Co-authored-by: Gabe <[email protected]> Co-authored-by: Andres Uribe Gonzalez <[email protected]>
Overview
This PR implements the
CancelOperation
endpoint.Description
After an operation is cancelled, the associated resource's status must be recorded. We currently only support operations related to
Submission
resources. In order to do so, this PR moved a number of methods around so there are no dependency cycles. The rule I followed was: submissions can depend on operations, but not the other way around.Happy to hear feedback about better organizing packages.
How Has This Been Tested?
See added unit tests.
Checklist
Before submitting this PR, please make sure:
References
SIP6