Improve the code to print the secrets using printTable#464
Improve the code to print the secrets using printTable#464cmoulliard merged 13 commits intocnoe-io:mainfrom
Conversation
cmoulliard
commented
Dec 19, 2024
- Improve the code to print the secrets using the cli-runtime line and printTable.
- Refactor the code to use the print functions from the util package
- See: [Suggestion] Enhance how we print the secret to show them using as format: Table, Yaml or JSON #463
This comment was marked as resolved.
This comment was marked as resolved.
…printTable. cnoe-io#463 Signed-off-by: cmoulliard <cmoulliard@redhat.com>
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
497a15a to
666bfc7
Compare
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
|
Question: Should we for the core package secrets display the information as such ? OR |
|
We should review in a seperate PR how we will display the k=v data of the secrets labelized with |
…r: isCore to make the distinction betweek the core secrets and secrets having the CNOE label Signed-off-by: cmoulliard <cmoulliard@redhat.com>
Fixed |
…rmats supported Signed-off-by: cmoulliard <cmoulliard@redhat.com>
I vote for 1st option. This way we can have flexibility for complex fields. |
punkwalker
left a comment
There was a problem hiding this comment.
nit: I suggest that we create a separate Printer package and Printer Interface.
pkg/cmd/get/root.go
Outdated
| GetCmd.AddCommand(SecretsCmd) | ||
| GetCmd.PersistentFlags().StringSliceVarP(&packages, "packages", "p", []string{}, "names of packages.") | ||
| GetCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "", "Output format. json or yaml.") | ||
| GetCmd.PersistentFlags().StringVarP(&outputFormat, "output", "o", "", "Output format: table (default if not specified), json or yaml.") |
There was a problem hiding this comment.
let's name the default as "table" instead of "".
pkg/cmd/get/clusters.go
Outdated
| func printClustersOutput(outWriter io.Writer, clusters []Cluster, format string) error { | ||
| switch format { | ||
| case "json": | ||
| return util.PrintDataAsJson(clusters, outWriter) | ||
| case "yaml": | ||
| return util.PrintDataAsYaml(clusters, outWriter) | ||
| case "": | ||
| return util.PrintTable(generateClusterTable(clusters), outWriter) | ||
| default: | ||
|
|
||
| return fmt.Errorf("output format %s is not supported", format) |
There was a problem hiding this comment.
Can we combine this function for secret and cluster both and add it in utils package to avoid duplicate code?
There was a problem hiding this comment.
Can we combine this function for secret and cluster both and add it in utils package to avoid duplicate code?
Here is what I did which is still a WIP: 580042f, 13b4ad9
Improvements are welcome ;-) @punkwalker
pkg/cmd/get/secrets.go
Outdated
| func generateSecret(s v1.Secret, isCoreSecret bool) Secret { | ||
| secret := Secret{ | ||
| Name: s.Name, | ||
| Namespace: s.Namespace, |
There was a problem hiding this comment.
We should name this populateSecrets instead of generateSecret. I felt we are creating a new secret.
pkg/cmd/get/secrets.go
Outdated
| } | ||
|
|
||
| type Secret struct { | ||
| isCore bool |
There was a problem hiding this comment.
Is the use of isCore field just to control the printing of core package fields? Can we do that without this?
There was a problem hiding this comment.
Is the use of
isCorefield just to control the printing of core package fields?
It is used to figure out when we have a core package secret containing as values: username, password and token (for gitea)
There was a problem hiding this comment.
Can we do that without this?
Not really
This is what I did |
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
Great idea. Fixed: 771fd89 |
Why ? Can you elaborate ? |
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
… Node, etc. and created printer methods. WIP Signed-off-by: cmoulliard <cmoulliard@redhat.com>
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
I prefer the second format but like you said, we can discuss that in another PR / issue. |
We can address this later. As of now, we can merge this PR |
|
Should we wait an approval from @nabuskey @blakeromano ? @punkwalker |