Skip to content
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

Improve the code to print the secrets using printTable #464

Merged
merged 13 commits into from
Dec 24, 2024

Conversation

cmoulliard
Copy link
Contributor

@cmoulliard

This comment was marked as resolved.

@cmoulliard cmoulliard force-pushed the new-secret-print-table branch from 497a15a to 666bfc7 Compare December 19, 2024 14:38
@cmoulliard
Copy link
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
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 <[email protected]>
@cmoulliard
Copy link
Contributor Author

To be investigated as test is failing.

Fixed

@punkwalker
Copy link
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
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.

@@ -22,7 +22,7 @@ func init() {
GetCmd.AddCommand(ClustersCmd)
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
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
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
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
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
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
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 TemplateData struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Data map[string]string `json:"data"`
}

type Secret struct {
isCore bool
Copy link
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
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
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
Contributor Author

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

This is what I did

@cmoulliard
Copy link
Contributor Author

cmoulliard commented Dec 20, 2024

I suggest that we create a separate Printer package

Great idea. Fixed: 771fd89

@cmoulliard
Copy link
Contributor Author

and Printer Interface.

Why ? Can you elaborate ?

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

and Printer Interface.

Why ? Can you elaborate ?

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

@cmoulliard
Copy link
Contributor Author

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

@cmoulliard cmoulliard merged commit 6f834bc into cnoe-io:main Dec 24, 2024
5 checks passed
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