orta / cocoapods-keys

A key value store for storing per-developer environment and application keys
MIT License
1.55k stars 92 forks source link

Keys not recorded in YML on first run. #175

Closed ileitch closed 5 years ago

ileitch commented 6 years ago

Given a simple Podfile config:

plugin 'cocoapods-keys', {
  :project => "TTKit",
  :keys => [
    "TophatHmacKey",
  ]
}

and an empty macOS keychain and no files generated in ~/.cocoapods/keys, I can demonstrate that the TophatHmacKey is not recorded in the generated YML, and thus is not included in the generated ObjC class.

In a nutshell, this commit from @colinta makes no sense: https://github.com/orta/cocoapods-keys/commit/7743a9be8ebadedc4d8efa4b655d86cc3697cc96

It appears the reasoning for the commit is that we need to re-save the keychain if the user was prompted and provided a value for a missing key. However, saving of a new key is performed here & here which loads and saves its own instance of CocoaPodsKeys::Keyring. Once all missing key values have been provided and saved the line from the commit is executed which saves a Keyring instanced created before the missing keys were saved. The end result is that the YML is overwritten with an empty keys array.

This output should make things more clear:

$ pod install

====================
PreInstaller.setup
has existing keyring? false
====================

 CocoaPods-Keys has detected a keys mismatch for your setup.
 What is the key for TophatHmacKey
 > abc123

====================
KeyringLiberator.save_keyring: {"keys"=>["TophatHmacKey"], "path"=>"/Users/ian/code/tt/ios", "name"=>"TTKit"}

/Users/ian/.rvm/gems/ruby-2.3.4/gems/cocoapods-keys-2.0.0/lib/pod/command/keys/set.rb:43:in `run'
/Users/ian/.rvm/gems/ruby-2.3.4/gems/cocoapods-keys-2.0.0/lib/preinstaller.rb:72:in `block in setup'
/Users/ian/.rvm/gems/ruby-2.3.4/gems/cocoapods-keys-2.0.0/lib/preinstaller.rb:50:in `each'
/Users/ian/.rvm/gems/ruby-2.3.4/gems/cocoapods-keys-2.0.0/lib/preinstaller.rb:50:in `setup'
/Users/ian/.rvm/gems/ruby-2.3.4/gems/cocoapods-keys-2.0.0/lib/plugin.rb:17:in `setup'
/Users/ian/.rvm/gems/ruby-2.3.4/gems/cocoapods-keys-2.0.0/lib/plugin.rb:11:in `block in singleton class'
/Users/ian/.rvm/gems/ruby-2.3.4/gems/cocoapods-1.3.1/lib/cocoapods/hooks_manager.rb:109:in `block (3 levels) in run'
... truncated for brevity ...
====================

Saved TophatHmacKey to TTKit.

====================
KeyringLiberator.save_keyring: {"keys"=>[], "path"=>"/Users/ian/code/tt/ios", "name"=>"TTKit"}

/Users/ian/.rvm/gems/ruby-2.3.4/gems/cocoapods-keys-2.0.0/lib/preinstaller.rb:75:in `setup'
/Users/ian/.rvm/gems/ruby-2.3.4/gems/cocoapods-keys-2.0.0/lib/plugin.rb:17:in `setup'
/Users/ian/.rvm/gems/ruby-2.3.4/gems/cocoapods-keys-2.0.0/lib/plugin.rb:11:in `block in singleton class'
/Users/ian/.rvm/gems/ruby-2.3.4/gems/cocoapods-1.3.1/lib/cocoapods/hooks_manager.rb:109:in `block (3 levels) in run'
... truncated for brevity ...
====================

Analyzing dependencies
Fetching podspec for `Keys` from `Pods/CocoaPodsKeys`
... truncated for brevity ...
Pod installation complete! There are 42 dependencies from the Podfile and 46 total pods installed.

$ cat ~/.cocoapods/keys/f0a91780cf6fd09582d758ff310a3a31.yml
---
keys: []
path: "/Users/ian/code/tt/ios"
name: TTKit

Note: the final call in setup has line 75 in the backtrace, this is due my debugging modifications. The line number without any modifications is 68.

Perhaps there used to be some caching of Keyring instances that made this work previously, but it seems to be now that https://github.com/orta/cocoapods-keys/commit/7743a9be8ebadedc4d8efa4b655d86cc3697cc96 should be reverted.

There appears to be at least one other bug report of this incorrect behavior: https://github.com/orta/cocoapods-keys/issues/153

ileitch commented 6 years ago

@orta ping?

BasThomas commented 5 years ago

We're hitting this too; would you be interested in merging a pull request to fix this?

ashfurrow commented 5 years ago

Yeah, for sure. We've just always re-ran pod install, but getting this fixed would be 👍

BasThomas commented 5 years ago

@ileitch do you want to open a pull request from your fork? :)

ileitch commented 5 years ago

https://github.com/orta/cocoapods-keys/pull/192

orta commented 5 years ago

Fixed by #192 and shipped in 2.0.7

BasThomas commented 5 years ago

Awesome, thanks @orta :)