Skip to content

Improve the code to print the secrets using printTable#464

Merged
cmoulliard merged 13 commits intocnoe-io:mainfrom
ch007m:new-secret-print-table
Dec 24, 2024
Merged

Improve the code to print the secrets using printTable#464
cmoulliard merged 13 commits intocnoe-io:mainfrom
ch007m:new-secret-print-table

Conversation

@cmoulliard
Copy link
Copy Markdown
Contributor

@cmoulliard

This comment was marked as resolved.

…printTable. cnoe-io#463

Signed-off-by: cmoulliard <cmoulliard@redhat.com>
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
@cmoulliard cmoulliard force-pushed the new-secret-print-table branch from 497a15a to 666bfc7 Compare December 19, 2024 14:38
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
@cmoulliard
Copy link
Copy Markdown
Contributor Author

Question: Should we for the core package secrets display the information as such ?

[
  {
    "name": "argocd-initial-admin-secret",
    "namespace": "argocd",
    "data": {
      "password": "cP0HzmKo8vbzpa5L",
      "username": "admin"
    }
  }
]

OR

[
  {
    "name": "argocd-initial-admin-secret",
    "namespace": "argocd",
    "username": "admin",
    "password": "cP0HzmKo8vbzpa5L",
    }
  }
]

@cmoulliard
Copy link
Copy Markdown
Contributor Author

We should review in a seperate PR how we will display the k=v data of the secrets labelized with cnoe.io/cli-secret: "true" as currently I do simply

❯ ./idpbuilder get secrets
NAME                          NAMESPACE   USERNAME     PASSWORD                                   TOKEN                                      DATA
argocd-initial-admin-secret   argocd      admin        cP0HzmKo8vbzpa5L                                                                      
gitea-credential              gitea       giteaAdmin   8./6=O(C7{Vy|]I%V!#]]_/7+,j>/WGXgrX?64rf   6ff17d317da8ef57e45bb4f9a91ab99bfe5d9c72   
cnoe                          default                                                                                                        user1=charles, user2=Manabu...

…r: isCore to make the distinction betweek the core secrets and secrets having the CNOE label

Signed-off-by: cmoulliard <cmoulliard@redhat.com>
@cmoulliard
Copy link
Copy Markdown
Contributor Author

To be investigated as test is failing.

Fixed

…rmats supported

Signed-off-by: cmoulliard <cmoulliard@redhat.com>
@punkwalker
Copy link
Copy Markdown
Contributor

punkwalker commented Dec 19, 2024

Question: Should we for the core package secrets display the information as such ?

[
  {
    "name": "argocd-initial-admin-secret",
    "namespace": "argocd",
    "data": {
      "password": "cP0HzmKo8vbzpa5L",
      "username": "admin"
    }
  }
]

OR

[
  {
    "name": "argocd-initial-admin-secret",
    "namespace": "argocd",
    "username": "admin",
    "password": "cP0HzmKo8vbzpa5L",
    }
  }
]

I vote for 1st option. This way we can have flexibility for complex fields.

Copy link
Copy Markdown
Contributor

@punkwalker punkwalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I suggest that we create a separate Printer package and Printer Interface.

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.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's name the default as "table" instead of "".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Fixed: 288284e

Comment on lines +87 to +97
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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we combine this function for secret and cluster both and add it in utils package to avoid duplicate code?

Copy link
Copy Markdown
Contributor Author

@cmoulliard cmoulliard Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines 219 to 222
func generateSecret(s v1.Secret, isCoreSecret bool) Secret {
secret := Secret{
Name: s.Name,
Namespace: s.Namespace,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should name this populateSecrets instead of generateSecret. I felt we are creating a new secret.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: 813c0cd

}

type Secret struct {
isCore bool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the use of isCore field just to control the printing of core package fields? Can we do that without this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the use of isCore field 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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do that without this?

Not really

@cmoulliard
Copy link
Copy Markdown
Contributor Author

I vote for 1st option. This way we can have flexibility for complex fields.

This is what I did

Signed-off-by: cmoulliard <cmoulliard@redhat.com>
Signed-off-by: cmoulliard <cmoulliard@redhat.com>
@cmoulliard
Copy link
Copy Markdown
Contributor Author

cmoulliard commented Dec 20, 2024

I suggest that we create a separate Printer package

Great idea. Fixed: 771fd89

@cmoulliard
Copy link
Copy Markdown
Contributor Author

and Printer Interface.

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>
@nabuskey
Copy link
Copy Markdown
Collaborator

Question: Should we for the core package secrets display the information as such ?

[
  {
    "name": "argocd-initial-admin-secret",
    "namespace": "argocd",
    "data": {
      "password": "cP0HzmKo8vbzpa5L",
      "username": "admin"
    }
  }
]

OR

[
  {
    "name": "argocd-initial-admin-secret",
    "namespace": "argocd",
    "username": "admin",
    "password": "cP0HzmKo8vbzpa5L",
    }
  }
]

I prefer the second format but like you said, we can discuss that in another PR / issue.

@punkwalker
Copy link
Copy Markdown
Contributor

and Printer Interface.

Why ? Can you elaborate ?

We can address this later. As of now, we can merge this PR

@cmoulliard
Copy link
Copy Markdown
Contributor Author

Should we wait an approval from @nabuskey @blakeromano ? @punkwalker

@cmoulliard cmoulliard merged commit 6f834bc into cnoe-io:main Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants