axemclion / grunt-saucelabs

Grunt task for running all your browser tests using Sauce Labs
MIT License
182 stars 98 forks source link

Ensure key option isn't printed to console #204

Closed Nycto closed 8 years ago

Nycto commented 8 years ago

He folks! This patch addresses issue #203.

The options hash will now be printed like this when Grunt is running in verbose mode:

Options: ...snip..., key="[hidden]", ...snip...

Try it on your own! Just run: grunt --verbose

I freely admit that this code might be a bit confusing because of the mismatched API. By "mismatched", I mean that you assign a value like you normally would:

options.key = "My secret key";

But to read the value, you need to call a function:

{ key: options.key() }

There are a few reasons I went this route:

  1. grunt.log.writeflags, which is used to print the hash of options when in verbose mode, uses JSON.stringify, so I needed to override the toJSON function. This meant I had to return an object.
  2. This integrates nicely with the this.options Grunt function, which uses assignment
  3. It meant I didn't have to rewire how this gets passed through the entire API
  4. The 'key' property can still be set as an option, and this will still work
  5. The key will still show up when enumerated, so it's easy to see that a value was set, even if you can't see what it was
Jonahss commented 8 years ago

Good one, thoroughly impressed :)