-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: Create/Get Profile Endpoint and store the profile data #10
Conversation
to be replaced by getting profile IDThis comment was generated by todo based on a
|
Codecov Report
@@ Coverage Diff @@
## master #10 +/- ##
==========================================
- Coverage 94.59% 89.65% -4.94%
==========================================
Files 4 5 +1
Lines 74 145 +71
==========================================
+ Hits 70 130 +60
- Misses 2 8 +6
- Partials 2 7 +5
Continue to review full report at Codecov.
|
pkg/internal/mock/vc/mock_vc.go
Outdated
"github.com/trustbloc/edge-service/pkg/storage" | ||
) | ||
|
||
// MockVC mock did exchange service |
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 mock is referencing exchange service and protocols, lets discuss this
pkg/storage/memstore/memstore.go
Outdated
@@ -0,0 +1,90 @@ | |||
/* |
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 this memory store reused from other projects?
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.
Firas, Sandra and I just talked - I am going to ask @troyronda if we can make another repo for just storage, since it looks like we're going to be using the same storage in the edv repo and this one
When couchdb support is ready, it'll go into that new repo as well
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.
Yes i reused it from aries-framework-go, agree it would make more sense to put that in separate project. I have pointed to edv for now.
@@ -111,11 +181,61 @@ func createCredential(data *CreateCrendential) (*verifiable.Credential, error) { | |||
return validatedCred, nil | |||
} | |||
|
|||
func (c *Operation) createProfile(pr *ProfileRequest) (*ProfileResponse, error) { | |||
if pr.DID == "" || pr.URI == "" { | |||
return nil, fmt.Errorf("profile request is bad") |
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.
error should be more informative: missing DID and/or URI information
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
25d05ba
to
6e04d74
Compare
) | ||
|
||
// MockStoreProvider mock store provider. | ||
type MockStoreProvider struct { |
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.
Are mocks from edv too?
pkg/internal/mock/vc/mock_vc.go
Outdated
// Name return service name | ||
func (m *MockVC) Name() string { | ||
if m.ProtocolName != "" { | ||
return m.ProtocolName |
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.
What is protocol name?
00e321e
to
4169a4f
Compare
_, err = rw.Write([]byte(fmt.Sprintf("Received invalid request: %s", err.Error()))) | ||
|
||
if err != nil { | ||
log.Errorf("Failed to write response for credential profile failure (unable to read request): %s", err.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.
Change this log error to "Failed to write response for invalid request received" or something similar so it matches the pattern of the other log error messages in this 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.
It would be better to have common function for error response - it will make your unit-testing easier.
func (c *Operation) writeErrorResponse(rw http.ResponseWriter, status int, msg string) { rw.WriteHeader(status) if _, err := rw.Write([]byte(msg)); err != nil { log.Errorf("Unable to send error message, %s", err) } }
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
// | ||
// Args: | ||
// | ||
// | ||
// Returns: | ||
// | ||
// error: 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.
don't need this part of the comment. Or perhaps expand on it so it provides some more useful info if you think it's needed
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
// | ||
// Args: | ||
// | ||
// id: profile id | ||
// | ||
// Returns: | ||
// | ||
// profile found | ||
// error: 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.
Don't need this part of the comment. Or perhaps expand on it so it provides some more useful info if you think it's needed
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
cmd/vc-rest/startcmd/start.go
Outdated
@@ -89,7 +93,7 @@ func startEdgeService(parameters *vcRestParameters) error { | |||
router.HandleFunc(handler.Path(), handler.Handle()).Methods(handler.Method()) | |||
} | |||
|
|||
err := parameters.srv.ListenAndServe(parameters.hostURL, router) | |||
err = parameters.srv.ListenAndServe(parameters.hostURL, router) |
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.
you can return here
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
_, err = rw.Write([]byte(fmt.Sprintf("Received invalid request: %s", err.Error()))) | ||
|
||
if err != nil { | ||
log.Errorf("Failed to write response for credential profile failure (unable to read request): %s", err.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.
It would be better to have common function for error response - it will make your unit-testing easier.
func (c *Operation) writeErrorResponse(rw http.ResponseWriter, status int, msg string) { rw.WriteHeader(status) if _, err := rw.Write([]byte(msg)); err != nil { log.Errorf("Unable to send error message, %s", err) } }
closes: trustbloc#1 Signed-off-by: talwinder.kaur <talwinder.kaur@securekey.com>
430e000
to
dbcf514
Compare
to be replaced by getting profile ID issue-47This comment was generated by todo based on a
|
if err != nil { | ||
log.Errorf("Unable to send error response, %s", err) | ||
if err == errProfileNotFound { | ||
rw.WriteHeader(http.StatusNotFound) |
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.
header is also written in write error response, no need to write twice
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
return | ||
} | ||
|
||
rw.WriteHeader(http.StatusBadRequest) |
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.
no need to write header
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
} | ||
|
||
func getIssueDate() time.Time { | ||
issueDate := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), |
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.
no need to call time.Now() this many times
also, can you use time.Now().UTC()
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.
i have tried time.Now().UTC() and it worked. I remember it didn't work before, so i have updated now.
@@ -111,11 +158,65 @@ func createCredential(data *CreateCrendential) (*verifiable.Credential, error) { | |||
return validatedCred, nil | |||
} | |||
|
|||
func (c *Operation) createProfile(pr *ProfileRequest) (*ProfileResponse, error) { | |||
if pr.DID == "" && pr.URI == "" { |
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 pr.DID is blank but pr.URI isn't, is any error thrown? If not, you'll probably want to catch that.
closes trustbloc#2 Signed-off-by: talwinder.kaur <talwinder.kaur@securekey.com>
closes #2
Signed-off-by: talwinder.kaur talwinder.kaur@securekey.com