Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Modernize keytar #63

Merged
merged 47 commits into from
Apr 13, 2017
Merged

Modernize keytar #63

merged 47 commits into from
Apr 13, 2017

Conversation

BinaryMuse
Copy link
Contributor

@BinaryMuse BinaryMuse commented Apr 5, 2017

This pull requests makes some significant changes to keytar to bring it more in line with other modules maintained by the Atom and Electron teams, and would result in a major version bump:

  • Move from CoffeeScript to JavaScript
  • Move from Jasmine to Mocha
  • 🔥 Grunt
  • Convert to a Promise-based async API with actual real error handling 🎉
  • Update nan
  • Include the changes from Use libsecret instead of gnome-keyring. #53 to move from gnome-keyring to libsecret

🚧 WIP 🚧

Welcome 💭 s if anyone has any.

Closes #60
Closes #57
Closes #53
Closes #47
Closes #46
Closes #58
Closes #17
Closes #7

/cc - FYI in particular @paulcbetts, @as-cii, @kevinsawicki

BinaryMuse and others added 2 commits April 7, 2017 15:50
🔥 add/replacePassword and use setPassword
@odensc
Copy link
Contributor

odensc commented Apr 8, 2017

This is great! Didn't look too far into the code - but is there any reason why you're using a worker over libsecret's async API?

@BinaryMuse
Copy link
Contributor Author

@TheSBros Thanks! Primarily because the async bridge wraps the API calls on all three platforms, so it was easiest to use the sync versions for all and throw them on the libuv thread pool.

@janekolszak
Copy link

Nice

@BinaryMuse
Copy link
Contributor Author

Perhaps while you're at it, change licenses to license with a SPDX expression?

Good catch, I've made this change.

Copy link
Contributor

@as-cii as-cii left a comment

Choose a reason for hiding this comment

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

I left some minor comments, but overall this looks good to me. Amazing job, @kuychaco and @BinaryMuse! ✨


* Debian/Ubuntu: `sudo apt-get install libsecret-1-dev`
* Red Hat-based: `sudo yum install libsecret-devel`
* Arch Linux: `sudo pacman -S libsecret`
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we will need to update the Debian and RPM package manifests on Atom too?

Copy link
Contributor

Choose a reason for hiding this comment

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

(I made the libsecret patch) The deb/rpm packages will need the non-dev dependencies, which I believe are libsecret-1-0 and libsecret respectively.

lib/keytar.js Outdated
checkRequired(service, 'Service')
checkRequired(account, 'Account')

var ret = callbackOrPromise(callback)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why we need to support both async styles? If not, could we expose only the Promise-based API?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Callbacks are Node's "lowest common denominator" for async APIs, so it seemed reasonable to include it. But some browser APIs are going Promise-based. I am easily swayed either direction on this one.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think I am ok with either too honestly. Maybe, given that we are going to use these new methods via the Promise based API, we could just expose that and save an object allocation?

})
})

it("yeilds null when the password was not found", function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor suggestion: s/yeilds/yields.

@@ -0,0 +1,130 @@
var assert = require('chai').assert
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about using async/await to increase this test's readability? We could include babel only in specs but still take advantage of the nicer syntax.

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 thought about it but it seemed a pretty hefty price for a small test suite. If you think it'd be worth it I'm happy to pull it in.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it's quite minor honestly. Given we'd pay for it only in tests, I would still suggest doing it so that we can get rid of async.waterfall and use a modern syntax across the entire Atom org.

README.md Outdated
A native Node module to get, add, replace, and delete passwords in system's
keychain. On OS X the passwords are managed by the Keychain, on Linux they are
managed by Gnome Keyring and on Windows they are managed by Credential Vault.
A native Node module to get, add, replace, and delete passwords in system's keychain. On OS X the passwords are managed by the Keychain, on Linux they are managed by the Secret Service API/libsecret, and on Windows they are managed by Credential Vault.

Choose a reason for hiding this comment

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

Nit: s/OS X/macOS

@joshaber
Copy link

Removed addPassword and renamed replacePassword to setPassword

🤘

This looks great. Thanks so much!

@BinaryMuse BinaryMuse merged commit 1181e4d into master Apr 13, 2017
@BinaryMuse BinaryMuse deleted the mkt-asyncify branch April 13, 2017 00:36
@odensc
Copy link
Contributor

odensc commented Apr 13, 2017

Congratulations! I'll be sure to tell some package maintainers I know that they can remove the dependency on gnome-keyring :)

@rgbkrk
Copy link

rgbkrk commented Apr 13, 2017

Oh my gosh, yay, thank you!

@mritchie712
Copy link

mritchie712 commented Nov 29, 2017

Any examples of how to use the callback API?

EDIT:
nevermind, dumb question

pass = keytar.getPassword('Service', account).then(pass => { return pass })

@BinaryMuse
Copy link
Contributor Author

@mritchie712 The callback API was removed in a later commit in this PR (c4fe6de), so the API only returns promises now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants