Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added batch update for statuses #658

Merged
merged 4 commits into from
Aug 17, 2023

Conversation

andresuribe87
Copy link
Contributor

Overview

This PR adds a batch endpoint for updating statuses of credentials. It is the last PR that fixes #347

Description

Added the v1/credentials/status/batch endpoint. See the swagger spec file for documentation on the request/response schemas.

How Has This Been Tested?

Unit and integration tests.

@@ -339,6 +339,72 @@ type UpdateCredentialStatusResponse struct {
Suspended bool `json:"suspended"`
}

type SingleUpdateCredentialStatusRequest struct {
// ID of the credential who's status should be updated.
ID string `json:"id"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be required

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

serviceReq := routerReq.toServiceRequest(routerReq.ID)
req.Requests = append(req.Requests, serviceReq)
}
return &req
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why return a ptr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason. Shouldn't make a difference. Changes to non-ptr.

@@ -218,6 +218,7 @@ func CredentialAPI(rg *gin.RouterGroup, service svcframework.Service, webhookSer
// Credential Status
credentialAPI.GET("/:id"+StatusPrefix, credRouter.GetCredentialStatus)
credentialAPI.PUT("/:id"+StatusPrefix, credRouter.UpdateCredentialStatus)
credentialAPI.PUT(StatusPrefix+"/batch", credRouter.BatchUpdateCredentialStatus)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change /batch to a const which can be used elsewhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -31,6 +31,109 @@ func TestCredentialAPI(t *testing.T) {

for _, test := range testutil.TestDatabases {
t.Run(test.Name, func(tt *testing.T) {
tt.Run("Batch Update Credential Status", func(ttt *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a few different test cases here

  1. batch of 0
  2. batch of 1-n (all valid)
  3. batch of 1-n (mixed invalid and valid credentials, invalid = cred doesn't exist, cred status already set)

Another test we might need here and elsewhere is performing an update where the key no longer exists (revoked/deleted)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for all batch behaviors.

Another test we might need here and elsewhere is performing an update where the key no longer exists (revoked/deleted)

I'm unsure about some of the details of the behavior you're trying to test. Mind creating an issue and we can discuss?


type Status struct {
// ID of the credentials who's status this object represents.
ID string `json:"id,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the usage in UpdateCredentialStatusResponse is optional.

return nil, errors.Wrap(err, "reading credential")
}

if gotCred.Credential.CredentialStatus == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend a new helper like HasCredentialStatus which can also check that gotCred is not nil and gotCred.Credential is not nil, or else we're at risk for NPEs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return nil, sdkutil.LoggingNewErrorf("credential %q has no credentialStatus field", gotCred.LocalCredentialID)
}

statusPurpose := gotCred.Credential.CredentialStatus.(map[string]any)["statusPurpose"].(string)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetStatusPurpose method would be helpful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Member

@decentralgabe decentralgabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments

Copy link
Contributor Author

@andresuribe87 andresuribe87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL

@@ -339,6 +339,72 @@ type UpdateCredentialStatusResponse struct {
Suspended bool `json:"suspended"`
}

type SingleUpdateCredentialStatusRequest struct {
// ID of the credential who's status should be updated.
ID string `json:"id"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

serviceReq := routerReq.toServiceRequest(routerReq.ID)
req.Requests = append(req.Requests, serviceReq)
}
return &req
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason. Shouldn't make a difference. Changes to non-ptr.

@@ -218,6 +218,7 @@ func CredentialAPI(rg *gin.RouterGroup, service svcframework.Service, webhookSer
// Credential Status
credentialAPI.GET("/:id"+StatusPrefix, credRouter.GetCredentialStatus)
credentialAPI.PUT("/:id"+StatusPrefix, credRouter.UpdateCredentialStatus)
credentialAPI.PUT(StatusPrefix+"/batch", credRouter.BatchUpdateCredentialStatus)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -31,6 +31,109 @@ func TestCredentialAPI(t *testing.T) {

for _, test := range testutil.TestDatabases {
t.Run(test.Name, func(tt *testing.T) {
tt.Run("Batch Update Credential Status", func(ttt *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests for all batch behaviors.

Another test we might need here and elsewhere is performing an update where the key no longer exists (revoked/deleted)

I'm unsure about some of the details of the behavior you're trying to test. Mind creating an issue and we can discuss?

return nil, errors.Wrap(err, "reading credential")
}

if gotCred.Credential.CredentialStatus == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return nil, sdkutil.LoggingNewErrorf("credential %q has no credentialStatus field", gotCred.LocalCredentialID)
}

statusPurpose := gotCred.Credential.CredentialStatus.(map[string]any)["statusPurpose"].(string)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.


type Status struct {
// ID of the credentials who's status this object represents.
ID string `json:"id,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the usage in UpdateCredentialStatusResponse is optional.

@codecov-commenter
Copy link

Codecov Report

Merging #658 (d486ace) into main (1955573) will decrease coverage by 0.17%.
The diff coverage is 4.34%.

@@            Coverage Diff             @@
##             main     #658      +/-   ##
==========================================
- Coverage   25.72%   25.55%   -0.17%     
==========================================
  Files          56       56              
  Lines        6254     6299      +45     
==========================================
+ Hits         1609     1610       +1     
- Misses       4369     4413      +44     
  Partials      276      276              
Files Changed Coverage Δ
config/config.go 30.40% <ø> (ø)
integration/common.go 2.15% <0.00%> (-0.06%) ⬇️
pkg/server/router/credential.go 11.93% <0.00%> (-1.38%) ⬇️
pkg/server/server.go 71.37% <100.00%> (+0.11%) ⬆️

@andresuribe87 andresuribe87 merged commit f1ac3f8 into TBD54566975:main Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Batch Operations
3 participants