8000 NOISSUE - Certs service refactor by mteodor · Pull Request #1369 · absmach/supermq · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

NOISSUE - Certs service refactor #1369

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

Merged
merged 25 commits into from
Mar 15, 2021
Merged

Conversation

mteodor
Copy link
Contributor
@mteodor mteodor commented Feb 23, 2021

What does this do?

Some code refactoring, fix endpoints and openapi,
create another implementation of PKI agent along with Vault wrapper agent implementation ( vault.go)
list certificates by thing id

List any changes that modify/break current functionality

Have you included tests for your changes?

Did you document any new/modified functionality?

Notes

Copy link
Contributor
@drasko drasko left a comment

Choose a reason for hiding this comment

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

@mteodor
Copy link
Contributor Author
mteodor commented Feb 27, 2021

no not a duplicate, notice the description

@mteodor mteodor marked this pull request as ready for review March 8, 2021 14:51
@mteodor mteodor requested a review from a team as a code owner March 8, 2021 14:51
@codecov-io
Copy link
codecov-io commented Mar 8, 2021
10000

Codecov Report

Merging #1369 (d41fb9f) into master (30ba38c) will increase coverage by 0.10%.
The diff coverage is 90.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1369      +/-   ##
==========================================
+ Coverage   67.56%   67.67%   +0.10%     
==========================================
  Files         121      122       +1     
  Lines        8420     8467      +47     
==========================================
+ Hits         5689     5730      +41     
- Misses       2215     2218       +3     
- Partials      516      519       +3     
Impacted Files Coverage Δ
certs/postgres/certs.go 0.00% <ø> (ø)
certs/service.go 87.23% <89.47%> (ø)
certs/postgres/init.go 75.86% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30ba38c...d41fb9f. Read the comment docs.

defer func(begin time.Time) {
message := fmt.Sprintf("Method list_certs for token: %s took %s to complete", token, time.Since(begin))
message := fmt.Sprintf("Method list_certs for token: %s and thing ID:%s took %s to complete", token, thingID, time.Since(begin))
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a white space after : or it will be hard to read. Also, I think that we don't use capital letters in logs.

certs/certs.go Outdated
@@ -19,7 +19,7 @@ type Repository interface {
Save(ctx context.Context, cert Cert) (string, error)

// RetrieveAll retrieve all issued certificates for given owner
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is still correct?

conns := make(map[string][]string)
for k, v := range svc.connections {
i := findIndex(v, id)
if i != -1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

What are all these magic numbers? Either add comments or move them to constants (or both).

}

var tmp []string
if i != len(ids)-2 {
10000 Copy link
Contributor

Choose a reason for hiding this comment

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

Magic numbers, add comments or use constants.


ids := svc.connections[chanID]
i := 0
for _, t := range ids {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this doing? Probably some comments are needed here.

Also, can this search be improved?

Copy link
Contributor Author
@mteodor mteodor Mar 9, 2021

Choose a reason for hiding this comment

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

this file things.go is copied from other service, there is opened issue for refactoring mocks so that we don't copy in each service same code, so this could be part of that PR https://github.com/mainflux/mainflux/issues/1382 as basically it is not related to changes in this PR

manuio
manuio previously approved these changes Mar 9, 2021
Copy link
Contributor
@manuio manuio left a comment

Choose a reason for hiding this comment

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

LGTM

manuio
manuio previously approved these changes Mar 9, 2021
Copy link
Contributor
@manuio manuio left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -18,9 +18,15 @@ func issueCert(svc certs.Service) endpoint.Endpoint {
}
res, err := svc.IssueCert(ctx, req.token, req.ThingID, req.Valid, req.KeyBits, req.KeyType)
if err != nil {
return certsResponse{Error: err.Error()}, nil
return thingCertsRes{Error: err.Error()}, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

What else it can be than things certs?

@@ -51,14 +51,14 @@ func MakeHandler(svc certs.Service) http.Handler {
opts...,
))

r.Get("/certs", kithttp.NewServer(
r.Get("/certs/:id", kithttp.NewServer(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Which ID is this?

blokovi
blokovi previously approved these changes Mar 10, 2021
@mteodor mteodor dismissed stale reviews from blokovi and manuio via 58c1db8 March 10, 2021 09:21
blokovi
blokovi previously approved these changes Mar 10, 2021
nmarcetic
nmarcetic previously approved these changes Mar 10, 2021
// ErrNotImplemented indicate that method called is not implemented
ErrNotImplemented = errors.New("method not implemented for certs")

// ErrMissingCACertificate indicates missing CA certificate.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove punctuation to align with the other comments.

certs/service.go Outdated
errFailedToRemoveCertFromDB = errors.New("failed to remove cert serial from db")
errFailedCertCreation = errors.New("failed to create client certificate")
errFailedCertRevocation = errors.New("failed to revoke certificate")
// ErrFailedCertCreation failed to create certificate.
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can put a single comment explanation above this var block to avoid writing unnecessary comments just to satisfy linter.

)

func newService(tokens map[string]string) (certs.Service, error) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove the empty line.

certs/certs.go Outdated
@@ -18,8 +18,8 @@ type Repository interface {
// Save saves cert for thing into database
Save(ctx context.Context, cert Cert) (string, error)

// RetrieveAll retrieve all issued certificates for given owner
RetrieveAll(ctx context.Context, ownerID string, offset, limit uint64) (Page, error)
// RetrieveAll retrieve all issued certificates for given owner adn thing id
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo and.

mteodor added 10 commits March 12, 2021 09:12
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
@mteodor mteodor dismissed stale reviews from nmarcetic and blokovi via edd5648 March 12, 2021 09:25
blokovi
blokovi previously approved these changes Mar 12, 2021
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
manuio
manuio previously approved these changes Mar 12, 2021
Copy link
Contributor
@manuio manuio left a comment

Choose a reason for hiding this comment

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

LGTM

nmarcetic
nmarcetic previously approved these changes Mar 12, 2021
blokovi
blokovi previously approved these changes Mar 12, 2021
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
@mteodor mteodor dismissed stale reviews from blokovi, nmarcetic, and manuio via ab5c117 March 12, 2021 10:48
Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
@@ -18,9 +18,15 @@ func issueCert(svc certs.Service) endpoint.Endpoint {
}
res, err := svc.IssueCert(ctx, req.token, req.ThingID, req.Valid, req.KeyBits, req.KeyType)
if err != nil {
return certsResponse{Error: err.Error()}, nil
return certsRes{Error: err.Error()}, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why both return error and error inside response?

@@ -171,17 +150,17 @@ func (cs *certsService) RevokeCert(ctx context.Context, token, thingID string) (
}
thing, err := cs.sdk.Thing(thingID, token)
if err != nil {
return revoke, errors.Wrap(errFailedCertRevocation, err)
return revoke, errors.Wrap(ErrFailedCertRevocation, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Revoke seems to be a simple wrapper around time.Time. Since it's unlikely its content will ever change, this wrapper seems to be unnecessary; you can return time directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

more or less I copied response from vault https://www.vaultproject.io/api/secret/pki#sample-request-14

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can (and need) to wrap time in API layer, but there is no need to wrap it in the service method.

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
errFailedVaultCertIssue = errors.New("failed to issue vault certificate")
errFailedCertDecoding = errors.New("failed to decode response from vault service")
)

type Revoke struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this struct be removed?

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
dborovcanin
dborovcanin previously approved these changes Mar 12, 2021
Copy link
Contributor
@manuio manuio left a comment

Choose a reason for hiding this comment

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

LGTM

blokovi
blokovi previously approved these changes Mar 12, 2021
Comment on lines 21 to 25
type certsRes struct {
ID string `json:"thing_id"`
Cert string `json:"thing_cert"`
Key string `json:"thing_cert_key"`
Serial string `json:"thing_cert_serial"`
Copy link
Contributor
@manuio manuio Mar 12, 2021

Choose a reason for hiding this comment

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

tags should follow field name

Signed-off-by: Mirko Teodorovic <mirko.teodorovic@gmail.com>
@mteodor mteodor dismissed stale reviews from blokovi and dborovcanin via c408925 March 12, 2021 19:42
Copy link
Contributor
@manuio manuio left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor
@drasko drasko left a comment

Choose a reason for hiding this comment

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

LGTM

@drasko drasko merged commit 74aa93f into absmach:master Mar 15, 2021
@mteodor mteodor deleted the refactor-certs branch September 13, 2021 12:28
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.

7 participants
0