-
Notifications
You must be signed in to change notification settings - Fork 66
fix(kafka update): broken preview #1311
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,7 @@ import ( | |||||
| "fmt" | ||||||
| "reflect" | ||||||
| "strconv" | ||||||
| "strings" | ||||||
|
|
||||||
| "github.com/AlecAivazis/survey/v2" | ||||||
| kafkamgmtclient "github.com/redhat-developer/app-services-sdk-go/kafkamgmt/apiv1/client" | ||||||
|
|
@@ -281,6 +282,7 @@ func promptConfirmUpdate(opts *options) (bool, error) { | |||||
| // creates a summary of what values will be changed in this update | ||||||
| // returns a formatted string. Example: | ||||||
| // owner: foo_user ➡️ bar_user | ||||||
| // to do: Needs update once reauthentication_enabled is incorporated | ||||||
| func generateUpdateSummary(new reflect.Value, current reflect.Value) string { | ||||||
| var summary string | ||||||
|
|
||||||
|
|
@@ -291,10 +293,14 @@ func generateUpdateSummary(new reflect.Value, current reflect.Value) string { | |||||
| fieldTag := field.Tag.Get("json") | ||||||
| fieldName := field.Name | ||||||
|
|
||||||
| oldVal := getElementValue(current.FieldByName(fieldName)).String() | ||||||
| newVal := getElementValue(new.FieldByName(fieldName)).String() | ||||||
| oldVal := getElementValue(current.FieldByName(fieldName)) | ||||||
| newVal := getUpdateObjValue(new.FieldByName(fieldName)) | ||||||
|
|
||||||
| summary += fmt.Sprintf("%v: %v %v %v\n", color.Bold(fieldTag), oldVal, icon.Emoji("\u27A1", "=>"), newVal) | ||||||
| fieldTagDisp := strings.Split(fieldTag, ",")[0] | ||||||
|
|
||||||
| if newVal != reflect.ValueOf(nil) { | ||||||
| summary += fmt.Sprintf("%v: %v %v %v\n", color.Bold(fieldTagDisp), oldVal, icon.Emoji("\u27A1", "=>"), newVal) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return summary | ||||||
|
|
@@ -308,3 +314,13 @@ func getElementValue(v reflect.Value) reflect.Value { | |||||
| } | ||||||
| return v | ||||||
| } | ||||||
|
|
||||||
| // get the true value from a reflect.Value for KafkaUpdateRequest struct | ||||||
| // to do: Needs update once reauthentication_enabled is incorporated | ||||||
| func getUpdateObjValue(v reflect.Value) reflect.Value { | ||||||
| if v.Kind() == reflect.Struct { | ||||||
| vstruct := v.Field(0) | ||||||
|
||||||
| vstruct := v.Field(0) | |
| vstruct := v.FieldByName("value") |
This should suffice, no need to iterate.
Though I'm starting to think going forward with reflection on this is a bad idea, as we are making assumptions that are tightly coupled with the SDK, which could introduce breaking changes in the future by changing the name from "value" and since this is not strongly typed, we would not catch it..
For now, once you update with the suggestion above, we can merge as it is blocking any releases. Could you create a follow up issue to address this? We can simplify it by operating directly on the SDK model properties instead.
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!
Ready for review.
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.
How reauthentication_enabled affects this preview?
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 methods generating preview iterate through the entire update struct, the broken preview did display
reauthentication_enabledtoo.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. That iteration thru all elements of struct is core issue IMHO
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.
We need to filter out the nil properties of the update object.