Skip to content

Commit

Permalink
Replaced osx_keychain with ruby-keychain gem
Browse files Browse the repository at this point in the history
  • Loading branch information
tritter committed Dec 3, 2022
1 parent 0700310 commit 38ff89c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
16 changes: 12 additions & 4 deletions lib/keyring.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'osx_keychain'
require 'keychain'
require 'base64'
require 'json'

module CocoaPodsKeys
class Keyring
Expand Down Expand Up @@ -27,11 +29,17 @@ def self.keychain_prefix
end

def keychain
@keychain ||= OSXKeychain.new
@keychain ||= Keychain.generic_passwords
end

def save(key, value)
keychain[self.class.keychain_prefix + name, key] = value
item = keychain.where(service: self.class.keychain_prefix + name, account: key).first
if item
item.password = value
item.save!
else
keychain_has_keykeychain.create(service: self.class.keychain_prefix + name, password: value, account: key)

This comment has been minimized.

Copy link
@OmarSamirMohamed

OmarSamirMohamed Dec 6, 2022

Hello @tritter This line produces this error, could you please double check var's name
NameError - undefined local variable or methodkeychain_has_keykeychain' for #CocoaPodsKeys::Keyring:0x00007f83022bc438`

This comment has been minimized.

Copy link
@tritter

tritter Dec 6, 2022

Author Contributor

Hi @OmarSamirMohamed yes sorry, I fixed it already in my PR: #236

This comment has been minimized.

Copy link
@tritter

tritter Dec 6, 2022

Author Contributor

You can rename it to keychain or install the gem like this:
gem 'cocoapods-keys', git: 'https://github.com/tritter/cocoapods-keys.git'

This comment has been minimized.

Copy link
@OmarSamirMohamed

OmarSamirMohamed via email Dec 6, 2022

This comment has been minimized.

Copy link
@OmarSamirMohamed

OmarSamirMohamed Dec 6, 2022

Hi @tritter
it produces these errors when installing this gem from your fork

ERROR: Could not find a valid gem 'cocoapods-keys,' (>= 0) in any repository
ERROR: Possible alternatives: cocoapods-keys, cocoapods-try, cocoapods-repo-sq, cocoapods-dep, cocoapods-nexus
ERROR: Could not find a valid gem 'git:' (>= 0) in any repository
ERROR: Possible alternatives: gitx, git, git2, gita, gito
ERROR: Could not find a valid gem 'https://github.com/tritter/cocoapods-keys.git' (>= 0) in any repository

This comment has been minimized.

Copy link
@tritter

tritter Dec 6, 2022

Author Contributor

Hmm that has something to do with your local gems I think?

This comment has been minimized.

Copy link
@tritter

tritter Dec 6, 2022

Author Contributor

If that doesn't work you can apply my changes as a patch

end
end

def keychain_data
Expand All @@ -53,7 +61,7 @@ def keychain_has_key?(key)
end

def keychain_value(key)
ENV[key] || keychain[self.class.keychain_prefix + name, key]
ENV[key] || keychain.where(service: self.class.keychain_prefix + name, account: key).first.password
end

def camel_cased_keys
Expand Down
2 changes: 1 addition & 1 deletion spec/keyring_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
expect(keyring.keychain_data).to eq('ARMyKey' => 'Hello')
end

it 'looks up keys from the OSXKeychain' do
it 'looks up keys from Keychain Access' do
keyring = Keyring.new('test', '/', ['ARMyKey'])
keyring.instance_variable_set(:@keychain, FakeKeychain.new('KeychainKey' => 'abcde'))
expect(keyring.keychain_has_key?('KeychainKey')).to be_truthy
Expand Down
14 changes: 12 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,22 @@ def fixture(name)
c.color = true
end

class FakeKeychainItem
attr_accessor :password

def initialize(password)
@password = password
end
end

class FakeKeychain
def initialize(data)
@data = data
end

def [](_, key)
@data[key]
def where(conditions)
password = @data[conditions[:account]]
item = FakeKeychainItem.new(password)
[item]
end
end

0 comments on commit 38ff89c

Please sign in to comment.