Drone CLI's `--token` option does not work

If I create a machine user with CLI and try to specify a token for that user:

drone user add testuser --machine --token ONE_TOKEN
Successfully added user testuser
Generated account token ANOTHER_TOKEN

What happens is that the user is created with another (randomly generated) token.

This is problematic, because if I want to create a user automatically (e.g. creating a user for Autoscaler with Ansible), it’s tricky to get the token out of the printed text (which is not a stable API), instead of specifying it.

Looking into the code it seems that the words token and hash are a bit mixed up and that is causing the problem.

First a user object is created with a Token:

This is marshalled as token:

Then it’s sent to the server:

But when the server unmarshals it:

It doesn’t find it:

And more importantly, it doesn’t even look at token, but at hash instead:

So it generates a random one:

And sends it back as token:

Finally, the client prints it: