-
Notifications
You must be signed in to change notification settings - Fork 674
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
Conversation
Codecov Report
❗ 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
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
Please update the PR.
pkg/sdk/go/things.go
Outdated
@@ -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 { |
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 not Disconnect?
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.
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 |
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.
unnecessary initialization of tlsCert and caCert considering they're assigned in LoadX509KeyPair and ReadCert. Suggest removal
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.
They are used before LoadX509KeyPair
. When caPath
and caKeyPath
is ==
""
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 an empty struct and nill, for that case
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.
at b, err := ioutil.ReadFile(caPath)
on error handling should we return an empty tlsCert
yet is was created or not?
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 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>", |
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.
did you mean remove <sub_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.
Yes
cli/policies.go
Outdated
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.
a lot of shared code between create and remove commands, consider refactoring
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.
That would make it spaghetti code
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.
perhaps with a modifier such as a flag, policy --create and --remove
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.
Or a root command policy and sub commands create and remove
7d784d6
to
4a2b295
Compare
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 |
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 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
if _, err := os.Stat(caPath); os.IsNotExist(err) { | ||
return tlsCert, caCert, err | ||
} | ||
|
||
if _, err := os.Stat(caKeyPath); os.IsNotExist(err) { | ||
return tlsCert, caCert, 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.
Do we also care about other errors besides NotExists
(such as insufficient privilege)?
certs/certs.go
Outdated
if _, err := os.Stat(caPath); os.IsNotExist(err) { | ||
return tlsCert, caCert, err | ||
} | ||
|
||
if _, err := os.Stat(caKeyPath); os.IsNotExist(err) { | ||
return tlsCert, caCert, 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.
Do we also care about other errors besides NotExists
(such as insufficient privilege)?
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 | ||
} |
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.
mainflux-cli bootstrap get all
this command will return with limit 10
How to view all things
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 increase using the -l
or -limit
flag
@@ -98,15 +146,25 @@ var cmdBootstrap = []cobra.Command{ | |||
}, | |||
}, | |||
{ |
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 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
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.
The URL is provided by the -bootstrap-url
or -b
flag
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 think for the longer form of flags, they should have double dashes --
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 think for the longer form of flags, they should have double dashes --
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 one resolved, @arvindh123 can you test and confirm?
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.
tested , It works perfect !!
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.
LGTM
certs/certs_test.go
Outdated
) | ||
|
||
func TestLoadCertificates(t *testing.T) { | ||
|
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.
Remove the empty line.
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>
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.
LGTM
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