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

Add SecretsRevealCommand #53466

Merged
merged 1 commit into from
Feb 3, 2024
Merged

Conversation

danielburger1337
Copy link
Contributor

@danielburger1337 danielburger1337 commented Jan 9, 2024

Q A
Branch? 7.1
Bug fix? no
New feature? yes
Deprecations? no
Issues n/a
License MIT

Add a new command to reveal a specific secrets value. The output is able to be piped into other commands.

Docs PR will be submitted if this is a desired feature.

@danielburger1337 danielburger1337 changed the title [FramworkBundle] Add name argument to SecretsListCommand [FrameworkBundle] Add name argument to SecretsListCommand Jan 9, 2024
@carsonbot carsonbot changed the title [FrameworkBundle] Add name argument to SecretsListCommand Add name argument to SecretsListCommand Jan 9, 2024
Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

This is a great PR. Thank you.

@stof
Copy link
Member

stof commented Jan 9, 2024

should the command fail when passing a name and there is no secret with that name ?

@danielburger1337
Copy link
Contributor Author

danielburger1337 commented Jan 9, 2024

should the command fail when passing a name and there is no secret with that name ?

Thats one way to do it. I just reused the current behavior when the secret store is empty.

If we go your way, we should refactor a bit so that the comments about how to reference/reveal a secret are not displayed when an invalid name is passed.

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);

        $reveal = $input->getOption('reveal');

        $secrets = $this->vault->list($reveal);

        if (null !== $name = $input->getArgument('name')) {
            if (!\array_key_exists($name, $secrets)) {
                $io->error(\sprintf('The secret "%s" does not exist.', $name));

                return self::INVALID;
            }

            $secrets = [$name => $secrets[$name]];
        }

        $localSecrets = $this->localVault?->list($reveal);

        $io->comment('Use <info>"%env(<name>)%"</info> to reference a secret in a config file.');

        if (!$reveal) {
            $io->comment(\sprintf('To reveal the secrets run <info>php %s %s --reveal</info>', $_SERVER['PHP_SELF'], $this->getName()));
        }

@chalasr
Copy link
Member

chalasr commented Jan 10, 2024

If we go your way, we should refactor a bit so that the comments about how to reference/reveal a secret are not displayed when an invalid name is passed.

Sounds good to me

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

Would allowing more than one name to get a subset of the list make sense? It would be more consistent with the command name.

@danielburger1337
Copy link
Contributor Author

Would allowing more than one name to get a subset of the list make sense? It would be more consistent with the command name.

I agree that this would fit better with the command name, but how would you handle passing a valid AND an invalid secret name? Only return an error? Return the valid secret and an error message? Would this result in exit code 0, 1 or 2?

@chalasr
Copy link
Member

chalasr commented Jan 20, 2024

It would be more consistent with the command name.

Good point. Given the number of questions that supporting multiple names raise, what about adding a secrets:show command instead?
Otherwise, I would just make the command fail entirely when an invalid name is passed.

@fabpot
Copy link
Member

fabpot commented Jan 21, 2024

It would be more consistent with the command name.

Good point. Given the number of questions that supporting multiple names raise, what about adding a secrets:show command instead? Otherwise, I would just make the command fail entirely when an invalid name is passed.

That's maybe a better option indeed.

@nicolas-grekas
Copy link
Member

secrets:show

Or secrets:reveal to use the existing wording?
but I agree with the proposal. That could be even more useful since this wouldn't require decorating the output with fancy layout. Instead, the result could be directly piped to another command when needed.

@chalasr
Copy link
Member

chalasr commented Jan 29, 2024

👍 for reveal

@fabpot
Copy link
Member

fabpot commented Feb 2, 2024

@danielburger1337 Are you still interested in moving this PR forward?

@danielburger1337
Copy link
Contributor Author

@danielburger1337 Are you still interested in moving this PR forward?

Yes I am. Just to make sure, you guys want to add the new SecretsRevealCommand. This would entail removing the added "name" argument from the SecretsListCommand again and then the "-r" option will be deprecated?

@nicolas-grekas
Copy link
Member

I wouldn't deprecated -r, but yes for the rest

@danielburger1337 danielburger1337 changed the title Add name argument to SecretsListCommand Add SecretsRevealCommand Feb 2, 2024
@danielburger1337
Copy link
Contributor Author

Updated title and description to match new proposed idea.

Copy link
Contributor

@94noni 94noni left a comment

Choose a reason for hiding this comment

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

nice one, small comments regarding desc

Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

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

Can you rebase to get rid of the merge commit?

@fabpot
Copy link
Member

fabpot commented Feb 3, 2024

Thank you @danielburger1337.

@fabpot fabpot merged commit c8d24c5 into symfony:7.1 Feb 3, 2024
1 of 3 checks passed
@danielburger1337
Copy link
Contributor Author

@fabpot All done. Sorry for the extra work on your part.

Is there any particular reason why you guys don't add the "void" return type to test cases?

use Symfony\Component\Console\Style\SymfonyStyle;

/**
* @internal
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed when the class is final?

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 have no idea. I just copied it from SecretsListCommand (as this command is based on it).

I don't think it makes much sense on either.

Copy link
Member

Choose a reason for hiding this comment

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

@OskarStark That gives us more flexibility 👍 as there is no need to use that class from userland, only the command itself (via CLI) matters

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I don't get what you mean.

I can do absolutely the same without the internal tag, the class is final and I can only execute the command in userland

Copy link
Member

Choose a reason for hiding this comment

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

I guess what @chalasr means is that we could also rename this class or move it to another namespace without having to worry about consumers of it. Not sure if we really need that flexibility though tbh.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok got it

Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we really need that flexibility though tbh.

👍 Thinking about it, I agree we should not fall in being too much defensive in general.

OskarStark added a commit to symfony/symfony-docs that referenced this pull request Feb 4, 2024
This PR was squashed before being merged into the 7.1 branch.

Discussion
----------

Document `secrets:reveal` command

Document the new `secrets:reveal` command.

Docs Issue: #19481
Feature PR: symfony/symfony#53466

Commits
-------

22ad2d9 Document `secrets:reveal` command
@fabpot fabpot mentioned this pull request May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet