-
Notifications
You must be signed in to change notification settings - Fork 18
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 trigger sync and save #230
Conversation
df907e7
to
72a6616
Compare
Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com> Signed-off-by: Eddy Babetto <eddy.babetto@gmail.com>
ddb1c41
to
8a4814a
Compare
Refactor of functions with pre-existing ones in order to save lines of code Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Add command triggers validate for validate json payload Signed-off-by: Eddy Babetto <eddy.babetto@gmail.com>
cmd/realm/triggers.go
Outdated
@@ -69,111 +71,372 @@ var triggersDeleteCmd = &cobra.Command{ | |||
Aliases: []string{"del"}, | |||
} | |||
|
|||
var triggersSaveCmd = &cobra.Command{ | |||
Use: "save [destination-path]", |
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.
Let's keep consistency with other commands
Use: "save [destination-path]", | |
Use: "save <destination-path>", |
cmd/realm/triggers.go
Outdated
Use: "save [destination-path]", | ||
Short: "Save triggers to a local folder", | ||
Long: `Save each trigger in a realm to a local folder. Each trigger will | ||
be saved in a dedicated file whose name will be in the form '<trigger_name>_v<version>.json'. |
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.
Triggers are not versioned
be saved in a dedicated file whose name will be in the form '<trigger_name>_v<version>.json'. | |
be saved in a dedicated file whose name will be in the form '<trigger_name>.json'. |
cmd/realm/triggers.go
Outdated
} | ||
|
||
var triggersSyncCmd = &cobra.Command{ | ||
Use: "sync <interface_files> [...]", |
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.
Use: "sync <interface_files> [...]", | |
Use: "sync <trigger_files> [...]", |
cmd/realm/triggers.go
Outdated
} | ||
|
||
func triggersShowF(command *cobra.Command, args []string) 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.
Remove newline
cmd/realm/triggers.go
Outdated
|
||
fmt.Printf("\n") | ||
fmt.Printf("The following new triggers will be installed: %+q \n", list) | ||
fmt.Printf("\n") |
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.
There's a \n
at the end of the above print, no need for another
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.
up
cmd/realm/triggers.go
Outdated
return err | ||
} | ||
|
||
var astarteTrigger map[string]interface{} |
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.
Note: once astarte-go offers utilities for triggers, this will be something like map[string]triggers.Trigger{}
cmd/realm/triggers.go
Outdated
triggerDefinition, _ := getTriggerRes.Parse() | ||
respJSON, _ := json.MarshalIndent(triggerDefinition, "", " ") | ||
fmt.Println(string(respJSON)) | ||
triggerToInstall := []map[string]interface{}{} |
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.
triggerToInstall := []map[string]interface{}{} | |
triggersToInstall := []map[string]interface{}{} |
cmd/realm/triggers.go
Outdated
respJSON, _ := json.MarshalIndent(triggerDefinition, "", " ") | ||
fmt.Println(string(respJSON)) | ||
triggerToInstall := []map[string]interface{}{} | ||
triggerToUpdate := []map[string]interface{}{} |
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.
triggerToUpdate := []map[string]interface{}{} | |
triggersToUpdate := []map[string]interface{}{} |
cmd/realm/triggers.go
Outdated
fmt.Println(string(respJSON)) | ||
triggerToInstall := []map[string]interface{}{} | ||
triggerToUpdate := []map[string]interface{}{} | ||
invalidtrigger := []string{} |
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.
invalidtrigger := []string{} | |
invalidTriggers := []string{} |
2f9c28b
to
9197109
Compare
fec6e1a
to
da15c68
Compare
cmd/realm/triggers.go
Outdated
|
||
RealmManagementCmd.AddCommand(triggersCmd) | ||
triggersSyncCmd.Flags().Lookup("force").NoOptDefVal = "false" |
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 that the flag should have NoOptDefVal
set to true, so that one could write astartectl realm-management triggers sync ... --force
(note the missing =true
) and force the trigger synchronization
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.
Also, if you set the NoOptDefVal
here rather than in the sync function, I think that the lookup is redundant: something like this could work, too:
tiggersSyncCmd.PersistentFlags().BoolVar(...)
tiggersSyncCmd.Flag("force").NoOptDefVal = "true"
cmd/realm/triggers.go
Outdated
} | ||
|
||
// var astarteTrigger map[string]triggers.Trigger{} | ||
var astarteTrigger map[string]interface{} |
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 this should be a triggers.AstarteTrigger{}
as your above comment suggests
cmd/realm/triggers.go
Outdated
return err | ||
} | ||
|
||
if _, err := getTriggerDefinition(realm, astarteTrigger["name"].(string)); err != nil { |
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 _, err := getTriggerDefinition(realm, astarteTrigger["name"].(string)); err != nil { | |
if _, err := getTriggerDefinition(realm, astarteTrigger.name); err != nil { |
cmd/realm/triggers.go
Outdated
|
||
fmt.Printf("\n") | ||
fmt.Printf("The following new triggers will be installed: %+q \n", list) | ||
fmt.Printf("\n") |
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.
up
cmd/realm/triggers.go
Outdated
return nil | ||
} | ||
|
||
for _, v := range triggersToInstall { |
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.
Since one of the fileds is used in the for body, give a meaningful name to v
(e.g. trigger
)
cmd/realm/triggers.go
Outdated
return nil | ||
} | ||
|
||
func updateTrigger(realm string, triggername string, newtrig map[string]interface{}) 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.
func updateTrigger(realm string, triggername string, newtrig map[string]interface{}) error { | |
func updateTrigger(realm string, triggerName string, newTrigger triggers.AstarteTrigger) error { |
cmd/realm/triggers.go
Outdated
|
||
_, _ = deleteTriggerRes.Parse() | ||
func getTriggerDefinition(realm, triggerName string) (map[string]interface{}, 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.
func getTriggerDefinition(realm, triggerName string) (map[string]interface{}, error) { | |
func getTriggerDefinition(realm, triggerName string) (triggers.AstarteTrigger, error) { |
cmd/realm/triggers.go
Outdated
for _, v := range triggersToInstall { | ||
list = append(list, v["name"].(string)) | ||
} |
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.
for _, v := range triggersToInstall { | |
list = append(list, v["name"].(string)) | |
} | |
for _, trigger := range triggersToInstall { | |
list = append(list, trigger.name) | |
} |
cmd/realm/triggers.go
Outdated
triggersToInstall := []map[string]interface{}{} | ||
triggersToUpdate := []map[string]interface{}{} | ||
invalidTriggers := []string{} |
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.
triggersToInstall := []map[string]interface{}{} | |
triggersToUpdate := []map[string]interface{}{} | |
invalidTriggers := []string{} | |
triggersToInstall := []triggers.AstarteTrigger{} | |
triggersToUpdate := []triggers.AstarteTrigger{} | |
invalidTriggers := []string{} |
cmd/realm/triggers.go
Outdated
for _, v := range triggersToUpdate { | ||
list_existing = append(list_existing, v["name"].(string)) | ||
} |
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.
See above comment
f1170a9
to
b8d5f59
Compare
1e359d0
to
9114d2a
Compare
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.
Some nitpicking, but the PR is good!
@@ -5,6 +5,7 @@ astartectl_* | |||
.gobuild | |||
dist/ | |||
/result | |||
.idea/ |
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 this line is used, put this change in a separate commit
github.com/Azure/go-autorest/autorest/adal v0.9.13/go.mod h1:W/MM4U6nLxnIskrw4UwWzlHfGjwUS50aOsc/I3yuU8M= | ||
github.com/Azure/go-autorest/autorest/adal v0.9.23 h1:Yepx8CvFxwNKpH6ja7RZ+sKX+DWYNldbLiALMC3BTz8= | ||
github.com/Azure/go-autorest/autorest/adal v0.9.23/go.mod h1:5pcMqFkdPhviJdlEy3kC/v1ZLnQl0MH6XA5YCcMhy4c= |
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.
Put dependency update in a different commit, too
cmd/realm/triggers.go
Outdated
list = append(list, trigger.Name) | ||
} | ||
|
||
list_existing := []string{} |
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.
Let's keep naming consistency
list_existing := []string{} | |
listExisting := []string{} |
Add trigger validation on sync, removing invalid payload from process queue Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Edit .gitignore file to remove ide temp folder Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Update project dependencies to latest Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
Add command to sync local trigger to remote astarte cluster, after validation
Add command to save remote astarte trigger to local json files
Depends on astarte-platform/astarte-go#59