Skip to content

[Uid] add command to generate UIDs #36405

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

Closed
wants to merge 14 commits into from

Conversation

guillbdx
Copy link

@guillbdx guillbdx commented Apr 9, 2020

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets #36102
License MIT
Doc PR symfony/symfony-docs#...

Command to generate UUID and ULID.

@javiereguiluz
Copy link
Member

@guillbdx thanks for this and all your other contributions related to Uids.

I'd like to ask something: is this really a common need? Do people generate Uids often in the console?

@sstok
Copy link
Contributor

sstok commented Apr 9, 2020

FYI. Ramsey/uuid has a console library for the UUID component. I runs on Symfony, but I stopped using it because it kept being outdated.

It's mostly usable during development when you need it a value for your tests or fixtures.

@wouterj
Copy link
Member

wouterj commented Apr 9, 2020

My go-to solution has always been https://www.uuidgenerator.net/ There is also the uuidgen command, available on Linux and MacOS, that does a great and easy job.

However, for password, we also have a command to generate them, while there are also online bcrypt and libsodium generators. So I think it can make sense to include a UID generate command?

@MichaelDemeyer
Copy link

I usually use website to generate uuid when needed. I think it will be slower to use command line 🤔

@tarlepp
Copy link
Contributor

tarlepp commented Apr 9, 2020

I have always used that https://www.uuidgenerator.net/ to generate some UUIDs when needed, I don't think that I would never use cli command for that.

@stof
Copy link
Member

stof commented Apr 9, 2020

@wouterj for hashing password, there is a good reason not to use a third-party site: that would require that you give them the plaintext password.
Another reason is that the command is hashing password with the config used in the project.

For the UUID generation, I'm not sure having a command for it in the core is worth it (there is no configuration needing to match).

@nicolas-grekas
Copy link
Member

https://www.uuidgenerator.net/ doesn't support eg. ULID

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Apr 9, 2020

Oh, another reason to have the command: the ability to represent uids in base58/base32 (aka shorter identifiers) - this needs to be added to the command btw.

break;
}

$io->title('Generated UID:');
Copy link
Member

Choose a reason for hiding this comment

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

Just a thought: I understand that you want to provide a friendly user interface. However, this command could be consumed by shell scripts if we provided a way to produce a UUID without any additional interaction or output.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should (if that possible) output everything except from the UID to stderr instead of stdout?

Copy link
Author

Choose a reason for hiding this comment

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

I've updated the code, so it just outputs the result now.

Copy link
Contributor

@Taluu Taluu left a comment

Choose a reason for hiding this comment

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

I think having an interactive way of covering the null defaults isn't such a good idea TBH

@guillbdx
Copy link
Author

Oh, another reason to have the command: the ability to represent uids in base58/base32 (aka shorter identifiers) - this needs to be added to the command btw.

@nicolas-grekas ok, i've added base32 and base58 as options.

@guillbdx
Copy link
Author

guillbdx commented Apr 10, 2020

Hi, i've updated my PR accordingly to your feedbacks. Main changes are:

  • the definition is removed if the Uid component is not installed
  • options base32 and base58 to represent the result in base32 or base58.
  • use uuid-1, uuid-3, etc instead of 1, 3 etc
  • removed the interactive stuff and made the type argument required.

@nicolas-grekas nicolas-grekas changed the title [FWB] Command to generate UIDs. [Uid] add command to generate UIDs Apr 10, 2020
@nicolas-grekas nicolas-grekas added this to the next milestone Apr 10, 2020
@guillbdx guillbdx force-pushed the fwb-command-generate-uid branch from 9cdd200 to 78c8e2b Compare April 10, 2020 23:49
$name = $input->getArgument('name');

if (\in_array($type, [self::UUID_3, self::UUID_5], true) && !Uuid::isValid($namespace)) {
throw new InvalidArgumentException('You must specify a valid namespace as a second argument.');
Copy link
Contributor

Choose a reason for hiding this comment

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

worth generating/outputting one? perhaps toggle name/namespace args

Copy link
Author

Choose a reason for hiding this comment

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

Do you mean that, in case the user hasn't provided a namespace, we should generate/output a random one?

Guillaume Pédelagrabe added 2 commits April 11, 2020 20:15
@derrabus
Copy link
Member

To get the tests green, use PHPUnit's TestCase class instead of the one from FrameworkBundle and add symfony/console to the require-dev section of the Uid component.

@fabpot
Copy link
Member

fabpot commented Apr 12, 2020

I'd like to add one more reason to NOT have this command: cluttering the CLI output. We've work hard in the past to get rid of commands (by way of removing optional deps) so that the "default" list of commands is at short as possible. I'm leaning towards a 👎 for adding this one.

@nicolas-grekas
Copy link
Member

Let's close then, time we tell if we really miss this.

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.