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

MF-1699 - Enrich SDK and CLI #1719

Merged
merged 14 commits into from
May 24, 2023
Merged

MF-1699 - Enrich SDK and CLI #1719

merged 14 commits into from
May 24, 2023

Conversation

rodneyosodo
Copy link
Member

@rodneyosodo rodneyosodo commented Feb 7, 2023

What does this do?

Enriches SDK and CLI. Also it updated the api docs swagger files.

Which issue(s) does this PR fix/relate to?

Resolves #1699
Duplicate of #1711

List any changes that modify/break current functionality

N/A

Have you included tests for your changes?

Yes

Did you document any new/modified functionality?

No

Notes

N/A

@rodneyosodo rodneyosodo marked this pull request as ready for review February 7, 2023 10:04
@rodneyosodo rodneyosodo requested a review from a team as a code owner February 7, 2023 10:04
@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2023

Codecov Report

Merging #1719 (797dc4d) into master (12a3214) will decrease coverage by 0.48%.
The diff coverage is 25.82%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master    #1719      +/-   ##
==========================================
- Coverage   70.29%   69.82%   -0.48%     
==========================================
  Files         146      149       +3     
  Lines       11518    11697     +179     
==========================================
+ Hits         8097     8167      +70     
- Misses       2765     2865     +100     
- Partials      656      665       +9     
Impacted Files Coverage Δ
certs/service.go 83.13% <0.00%> (ø)
pkg/sdk/go/bootstrap.go 0.00% <0.00%> (ø)
pkg/sdk/go/policies.go 0.00% <0.00%> (ø)
pkg/sdk/go/responses.go 0.00% <ø> (ø)
pkg/sdk/go/sdk.go 72.30% <ø> (ø)
pkg/sdk/go/things.go 41.55% <0.00%> (-31.17%) ⬇️
pkg/sdk/go/consumers.go 48.64% <48.64%> (ø)
pkg/sdk/go/certs.go 76.19% <77.77%> (+76.19%) ⬆️
certs/certs.go 83.33% <83.33%> (ø)
auth/api/http/groups/transport.go 45.79% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@dborovcanin dborovcanin left a comment

Choose a reason for hiding this comment

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

Please update the PR.

@@ -169,9 +237,65 @@ func (sdk mfSDK) Connect(connIDs ConnectionIDs, token string) errors.SDKError {
return sdkerr
}

func (sdk mfSDK) DisConnect(connIDs ConnectionIDs, token string) errors.SDKError {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not Disconnect?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

certs/certs.go Outdated
@@ -30,3 +39,46 @@ type Repository interface {
// RetrieveBySerial retrieves a certificate for a given serial ID
RetrieveBySerial(ctx context.Context, ownerID, serialID string) (Cert, error)
}

func LoadCertificates(caPath, caKeyPath string) (tls.Certificate, *x509.Certificate, error) {
var tlsCert tls.Certificate
Copy link
Contributor

Choose a reason for hiding this comment

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

unnecessary initialization of tlsCert and caCert considering they're assigned in LoadX509KeyPair and ReadCert. Suggest removal

Copy link
Member Author

Choose a reason for hiding this comment

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

They are used before LoadX509KeyPair. When caPath and caKeyPath is == ""

Copy link
Contributor

Choose a reason for hiding this comment

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

you can return an empty struct and nill, for that case

Copy link
Member Author

Choose a reason for hiding this comment

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

at b, err := ioutil.ReadFile(caPath) on error handling should we return an empty tlsCert yet is was created or not?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also prefer Sammy's approach. I find explicit return tls.Certificate{}, nil, nil in case of error just as fine and a bit more precise and efficient (when reading return tlsCert, caCert, nil you do not know what are actual values; but you also do not care). This is a matter of personal preference.

cli/consumers.go Outdated
},
},
{
Use: "remove <thing_id> <user_auth_token>",
Copy link
Contributor

Choose a reason for hiding this comment

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

did you mean remove <sub_id>

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

cli/consumers.go Show resolved Hide resolved
cli/policies.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

a lot of shared code between create and remove commands, consider refactoring

Copy link
Member Author

Choose a reason for hiding this comment

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

That would make it spaghetti code

Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps with a modifier such as a flag, policy --create and --remove

Copy link
Contributor

Choose a reason for hiding this comment

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

Or a root command policy and sub commands create and remove

certs/certs.go Outdated
@@ -30,3 +39,46 @@ type Repository interface {
// RetrieveBySerial retrieves a certificate for a given serial ID
RetrieveBySerial(ctx context.Context, ownerID, serialID string) (Cert, error)
}

func LoadCertificates(caPath, caKeyPath string) (tls.Certificate, *x509.Certificate, error) {
var tlsCert tls.Certificate
Copy link
Collaborator

Choose a reason for hiding this comment

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

I also prefer Sammy's approach. I find explicit return tls.Certificate{}, nil, nil in case of error just as fine and a bit more precise and efficient (when reading return tlsCert, caCert, nil you do not know what are actual values; but you also do not care). This is a matter of personal preference.

certs/certs.go Outdated
Comment on lines 51 to 58
if _, err := os.Stat(caPath); os.IsNotExist(err) {
return tlsCert, caCert, err
}

if _, err := os.Stat(caKeyPath); os.IsNotExist(err) {
return tlsCert, caCert, err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we also care about other errors besides NotExists (such as insufficient privilege)?

certs/certs.go Outdated
Comment on lines 51 to 58
if _, err := os.Stat(caPath); os.IsNotExist(err) {
return tlsCert, caCert, err
}

if _, err := os.Stat(caKeyPath); os.IsNotExist(err) {
return tlsCert, caCert, err
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we also care about other errors besides NotExists (such as insufficient privilege)?

cli/consumers.go Show resolved Hide resolved
certs/certs.go Show resolved Hide resolved
certs/certs.go Show resolved Hide resolved
Comment on lines +40 to +64
Use: "get [all | <thing_id>] <user_auth_token>",
Short: "Get config",
Long: `Get Thing Config with given ID belonging to the user identified by the given key`,
Long: `Get Thing Config with given ID belonging to the user identified by the given key.
all - lists all config
<thing_id> - view config of <thing_id>`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 2 {
logUsage(cmd.Use)
return
}
pageMetadata := mfxsdk.PageMetadata{
Offset: uint64(Offset),
Limit: uint64(Limit),
State: State,
Name: Name,
}
if args[0] == "all" {
l, err := sdk.Bootstraps(pageMetadata, args[1])
if err != nil {
logError(err)
return
}
logJSON(l)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

mainflux-cli bootstrap get all this command will return with limit 10
How to view all things

Copy link
Member Author

Choose a reason for hiding this comment

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

You increase using the -l or -limit flag

pkg/sdk/go/bootstrap.go Show resolved Hide resolved
@@ -98,15 +146,25 @@ var cmdBootstrap = []cobra.Command{
},
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

I tired to test the bootstrap
But I got not found

In CLI bootstrap url is not configured http://localhost
In nginx there is not route for bootstrap

Copy link
Member Author

Choose a reason for hiding this comment

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

The URL is provided by the -bootstrap-url or -b flag

Copy link
Contributor

Choose a reason for hiding this comment

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

I think for the longer form of flags, they should have double dashes --

Copy link
Contributor

Choose a reason for hiding this comment

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

I think for the longer form of flags, they should have double dashes --

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this one resolved, @arvindh123 can you test and confirm?

Copy link
Contributor

Choose a reason for hiding this comment

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

tested , It works perfect !!

Copy link
Contributor

@arvindh123 arvindh123 left a comment

Choose a reason for hiding this comment

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

LGTM

arvindh123
arvindh123 previously approved these changes May 17, 2023
)

func TestLoadCertificates(t *testing.T) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the empty line.

rodneyosodo and others added 11 commits May 24, 2023 10:24
Signed-off-by: rodneyosodo <socials@rodneyosodo.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <socials@rodneyosodo.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <socials@rodneyosodo.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <socials@rodneyosodo.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <socials@rodneyosodo.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <socials@rodneyosodo.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
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 408eaba into absmach:master May 24, 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.

Inconsistency Between API Documentation and Service Implementation
6 participants