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

List secrets with last updated, input bugfix, create/update instructions update #177

Merged
10 commits merged into from
Sep 25, 2023

Conversation

ghost
Copy link

@ghost ghost commented Sep 25, 2023

Ticket

#159

Changelog

  • Show last updated when listing secrets
  • Fix creating/updating secrets input reading and instructions

Tophatting

Create a secret using interactive input:

~/repos/cli/src secrets-date !1 ❯ opslevel create secret --alias typed-secret-2 -f -                           х INT Ruby 3.0.0 12:51:39 pm
12:52PM INF Reading input directly from command line... Press CTRL+D to stop typing
owner:
  alias: "platform"
value: "made by typing directly"
&{Owner:{Id: Alias:platform} Value:made by typing directly}
Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzY3

Create a secret using heredoc:

~/repos/cli/src secrets-date !1 ❯ cat << EOF | opslevel create secret --alias heredoc-secret-2 -f -               3s Ruby 3.0.0 12:50:35 pm
pipe heredoc> owner:
pipe heredoc>   alias: "platform"
pipe heredoc> value: "made by heredoc"
pipe heredoc> EOF
&{Owner:{Id: Alias:platform} Value:made by heredoc}
Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzY2

Create a secret using a file:

~/repos/cli/src secrets-date !1 ❯ opslevel create secret --alias file-secret-2 -f ~/secret.yaml                  23s Ruby 3.0.0 12:50:25 pm
here: /Users/taimoorahmad/secret.yaml
&{Owner:{Id: Alias:platform} Value:this was made using dash f}
Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzY1

Updated a secret using interactive input:

~/repos/cli/src secrets-date ❯ opslevel update secret Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzY1 -f -      Ruby 3.0.0 12:58:32 pm
12:58PM INF Reading input directly from command line... Press CTRL+D to stop typing
owner:
  alias: "platform"
value: "updated this by typing"
Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzY1

Finally, list secrets to see last updated time:

~/repos/cli/src secrets-date ❯ opslevel list secrets                                                           х INT Ruby 3.0.0 12:59:47 pm
ALIAS                  ID                                                    OWNER     UPDATED_AT
direct-secret          Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzYz  platform  2023-09-25 16:37:01.128483 +0000 UTC
file-secret-2          Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzY1  platform  2023-09-25 16:59:04.213883 +0000 UTC
heredoc-secret         Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzY0  platform  2023-09-25 16:46:25.341093 +0000 UTC
heredoc-secret-2       Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzY2  platform  2023-09-25 16:51:34.104404 +0000 UTC
new-platform-secret    Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzYx  platform  2023-09-25 16:08:53.943065 +0000 UTC
stdin-platform-secret  Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzYy  platform  2023-09-25 16:11:28.950098 +0000 UTC
typed-secret-2         Z2lkOi8vb3BzbGV2ZWwvU2VjcmV0c1ZhdWx0czo6U2VjcmV0LzY3  platform  2023-09-25 16:52:25.989577 +0000 UTC

@ghost ghost self-assigned this Sep 25, 2023
@ghost ghost changed the title List secrets along with List secrets with last updated, input bugfix Sep 25, 2023
@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

Merging #177 (995b921) into main (afd4d11) will not change coverage.
The diff coverage is n/a.

@@          Coverage Diff          @@
##            main    #177   +/-   ##
=====================================
  Coverage   6.22%   6.22%           
=====================================
  Files          5       5           
  Lines        257     257           
=====================================
  Hits          16      16           
  Misses       241     241           

@@ -11,14 +11,16 @@ import (
var dataFile string

func readInputConfig() {
viper.SetConfigType("yaml")
Copy link
Author

Choose a reason for hiding this comment

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

IIRC -f filename.yaml wasn't working until I moved this up here from outside of the case "-" block.

Copy link
Author

Choose a reason for hiding this comment

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

can't think of a reason for this to not be applied in certain conditions vs others, so it makes sense to move to the top.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is explicitly set to yaml below since viper has no way to infer the filetype from the stdin input.

viper.SetConfigFile() defines the path, name and extension of the config file. Then viper.ReadInConfig() will know how to read it later.

If somebody is using a .json file I would assume viper would internally reset the configType below?

In any case, @rocktavious has mentioned that we should look into a better solution for reading user input in place of viper

Copy link
Collaborator

Choose a reason for hiding this comment

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

ya we need to fix this reading from input problems globally

@ghost ghost marked this pull request as ready for review September 25, 2023 17:05
@ghost ghost requested review from davidbloss and rocktavious September 25, 2023 17:05
@ghost ghost changed the title List secrets with last updated, input bugfix List secrets with last updated, input bugfix, create/update instructions update Sep 25, 2023
switch dataFile {
case ".":
// TODO: does this block ever actually ever run?
Copy link
Contributor

Choose a reason for hiding this comment

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

Somebody could be using this case.
Setting -f to . is called out in the command help docs for opslevel create --help (create.go) and opslevel update --help (update.go).

Copy link
Author

Choose a reason for hiding this comment

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

I could not find a way to get it to trigger though, at least on bash/zsh. IIRC I ran into this problem before, passing . as an argument in CLI's is a bad idea 😅

I don't think we should remove it immediately, but we should look into it because if this branch never gets called the data.yaml stuff is confusing.

viper.SetConfigFile("./data.yaml")
case "-":
if isStdInFromTerminal() {
log.Info().Msg("Reading input directly from command line...")
// TODO: this can take up to half a second to output which interrupts the user's experience
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 If this is working correctly users shouldn't see this unless they are manually typing in yaml formatted input. If that's not the case lmk and I can take a closer look

Copy link
Author

Choose a reason for hiding this comment

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

To clarify, this happens to me only when manually typing in the command. (The check isStdInFromTerminal() is fine)

What happens is: I start typing, then a second later the message pops up, I lose track of what I've typed, then CTRL+C and re-run the command and start typing again. It's a UX annoyance

@davidbloss
Copy link
Contributor

Overall looks good! Just left a few comments 👍

Copy link
Collaborator

@rocktavious rocktavious left a comment

Choose a reason for hiding this comment

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

LGTM

@ghost ghost merged commit cbddbba into main Sep 25, 2023
5 checks passed
@ghost ghost deleted the secrets-date branch September 25, 2023 21:24
@taimoorgit taimoorgit self-assigned this Mar 7, 2024
This pull request was closed.
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.

3 participants