-
Notifications
You must be signed in to change notification settings - Fork 86
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
refactor: extract inspect rendering logic to be display handlers #1150
base: main
Are you sure you want to change the base?
refactor: extract inspect rendering logic to be display handlers #1150
Conversation
Signed-off-by: Junjie Gao <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1150 +/- ##
==========================================
+ Coverage 73.30% 74.71% +1.41%
==========================================
Files 53 59 +6
Lines 3240 3338 +98
==========================================
+ Hits 2375 2494 +119
+ Misses 671 651 -20
+ Partials 194 193 -1 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
// Common option struct. | ||
type Common struct { | ||
Printer *output.Printer | ||
} |
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.
Will you refactor --debug
in later PRs?
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, it is part of this issue #1151
cmd/notation/inspect.go
Outdated
if err := opts.Format.Parse(cmd); err != nil { | ||
return err | ||
} | ||
if err := opts.Common.Parse(cmd); err != nil { | ||
return 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.
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, I noticed that, but I chose to include it in future PRs. It is part of this issue: #1151
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
@@ -61,21 +61,21 @@ func ValidatePayloadContentType(payload *signature.Payload) error { | |||
|
|||
// DescriptorFromPayload parses a signature payload and returns the descriptor | |||
// that was signed. Note: the descriptor was signed but may not be trusted | |||
func DescriptorFromSignaturePayload(payload *signature.Payload) (*ocispec.Descriptor, error) { | |||
func DescriptorFromSignaturePayload(payload *signature.Payload) (ocispec.Descriptor, 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.
Any reason to make this change? It seems not related to this PR though.
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.
It was suggested here: #1150 (comment). I think this is a convention of ORAS.
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.
OK, I removed the update to envelope.go
as it is not closely related to this refactor work.
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.
@Two-Hearts ocispec.Descriptor
should be used as a structure is a convention start from image-spec
. We should follow the same patten: https://pkg.go.dev/github.com/opencontainers/[email protected]/specs-go/v1#Manifest
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
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
Signed-off-by: Junjie Gao <[email protected]>
limitations under the License. | ||
*/ | ||
|
||
package output |
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.
Now we have a folder called display
, then another folder called output
.
I have a feeling that we are making the code structure more and more complicated. And this may bring in difficulty for other developers to read through and understand such complicity in the future.
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.
Refactored and moved output
to display/output
internal/tree/tree.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.
Same here. We have a folder called tree
, then another folder with the same name under cmd/notation/internal/display/metadata
. Can we try to reduce such complicity during the design phase?
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.
Refactored.
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
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 noticed that handlers are grouped by command names instead of format types. Although both are acceptable, grouping by format types can have more benefits in the long run, especially we have growing commands but fixed set of format types.
One important point is that grouping by format types make developers easier to have consistent output for a certain format type across all commands.
Also, it is easier to have common utility functions without creating a utility package, which is discouraged.
Signed-off-by: Junjie Gao <[email protected]>
Updated to group the handlers by format types. |
func NewInpsectHandler(printer *output.Printer, format option.Format) (metadata.InspectHandler, error) { | ||
// NewMetadataInpsectHandler creates a new InspectHandler based on the output | ||
// format. | ||
func NewMetadataInpsectHandler(printer *output.Printer, format option.Format) (metadata.InspectHandler, 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.
Let's call it NewInpsectHandler
.
In the package display
, the function name is intended to be
func New{{.CommandName}}Handler({{.parameters}}) (status.{{.CommandName}}Handler, metadata.{{.CommandName}}Handler, error)
although we dont have status support yet.
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.
Updated to NewInpsectHandler
Signed-off-by: Junjie Gao <[email protected]>
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
Signed-off-by: Junjie Gao <[email protected]>
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
Depends on spec change: #1156
Refactor:
json
andtree
inspect handlers.Fix:
tree
output, make the key names with multiple words separated by space characters rather than capitalizing the words, which is defined in the inspect command spec.json
output, default to rendering time in RFC3339 with nanoseconds (Notation expiry, signing time and certificate expiry are accurate to 1 second. Timestamp RFC 3161 can have fraction-of-second time value).E2E Test:
-o
shorthand.Resolves part of #1151