diff --git a/.rubocop.yml b/.rubocop.yml index 9220fbe..d3163ee 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,7 @@ inherit_from: #- cocoapods-keys ------------------------------------------------------------- -Style/FileName: +Naming/FileName: Exclude: - bin/* - Rakefile diff --git a/.rubocop_cocoapods.yml b/.rubocop_cocoapods.yml index 3deb027..c5eb65f 100644 --- a/.rubocop_cocoapods.yml +++ b/.rubocop_cocoapods.yml @@ -1,4 +1,6 @@ AllCops: + NewCops: enable + SuggestExtensions: false Include: - ./Rakefile - ./Gemfile @@ -8,44 +10,47 @@ AllCops: # At the moment not ready to be used # https://github.com/bbatsov/rubocop/issues/947 -Documentation: +Style/Documentation: Enabled: false #- CocoaPods -----------------------------------------------------------------# # We adopted raise instead of fail. -SignalException: +Style/SignalException: EnforcedStyle: only_raise # They are idiomatic -AssignmentInCondition: +Lint/AssignmentInCondition: Enabled: false # Allow backticks -AsciiComments: +Style/AsciiComments: Enabled: false # Indentation clarifies logic branches in implementations -IfUnlessModifier: +Style/IfUnlessModifier: Enabled: false # No enforced convention here. -SingleLineBlockParams: +Style/SingleLineBlockParams: Enabled: false # We only add the comment when needed. -Encoding: +Style/Encoding: + Enabled: false + +Style/FrozenStringLiteralComment: Enabled: false Layout/MultilineOperationIndentation: EnforcedStyle: indented # Clashes with CLAide Command#validate! -GuardClause: +Style/GuardClause: Enabled: false # Not always desirable: lib/claide/command/plugins_helper.rb:12:15 -Next: +Style/Next: Enabled: false # Arbitrary max lengths for classes simply do not work and enabling this will @@ -74,16 +79,16 @@ Metrics/CyclomaticComplexity: #- CocoaPods support for Ruby 1.8.7 ------------------------------------------# -HashSyntax: +Style/HashSyntax: EnforcedStyle: hash_rockets -Lambda: +Style/Lambda: Enabled: false -DotPosition: +Layout/DotPosition: EnforcedStyle: trailing -EachWithObject: +Style/EachWithObject: Enabled: false Style/SpecialGlobalVars: @@ -92,20 +97,20 @@ Style/SpecialGlobalVars: #- CocoaPods specs -----------------------------------------------------------# # Allow for `should.match /regexp/`. -AmbiguousRegexpLiteral: +Lint/AmbiguousRegexpLiteral: Exclude: - spec/**/* # Allow `object.should == object` syntax. -Void: +Lint/Void: Exclude: - spec/**/* -ClassAndModuleChildren: +Style/ClassAndModuleChildren: Exclude: - spec/**/* -UselessComparison: +Lint/BinaryOperatorWithIdenticalOperands: Exclude: - spec/**/* diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3e45176..8308a4b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -23,7 +23,7 @@ Lint/Void: # Offense count: 38 # Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: +Layout/LineLength: Max: 173 # Offense count: 1 @@ -31,7 +31,7 @@ Metrics/PerceivedComplexity: Max: 9 # Offense count: 4 -Style/AccessorMethodName: +Naming/AccessorMethodName: Enabled: false # Offense count: 1 diff --git a/.travis.yml b/.travis.yml index 618eeb1..ee9a775 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: objective-c -install: bundle install --deployment +install: bundle install script: bundle exec rake spec diff --git a/Gemfile b/Gemfile index 680e915..bc348ea 100644 --- a/Gemfile +++ b/Gemfile @@ -3,5 +3,6 @@ source 'https://rubygems.org' # Specify your gem's dependencies in cocoapods-keys.gemspec gemspec -gem 'cocoapods', '1.0.0.beta.6' -gem 'activesupport', '< 5' \ No newline at end of file +gem 'cocoapods', '>= 1.11' +gem 'activesupport', '>= 5' +gem 'ruby-keychain', :require => 'keychain' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 7557b49..665e239 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,117 +3,155 @@ PATH specs: cocoapods-keys (2.2.1) dotenv - osx_keychain + keychain GEM remote: https://rubygems.org/ specs: - CFPropertyList (2.3.5) - RubyInline (3.12.5) - ZenTest (~> 4.3) - ZenTest (4.12.0) - activesupport (4.2.9) - i18n (~> 0.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - ast (2.3.0) - claide (1.0.2) - cocoapods (1.0.0.beta.6) - activesupport (>= 4.0.2) - claide (>= 1.0.0.beta.3, < 2.0) - cocoapods-core (= 1.0.0.beta.6) - cocoapods-deintegrate (>= 1.0.0.beta.1, < 2.0) - cocoapods-downloader (>= 1.0.0.beta.2, < 2.0) - cocoapods-plugins (>= 1.0.0.beta.1, < 2.0) - cocoapods-search (>= 1.0.0.beta.1, < 2.0) - cocoapods-stats (>= 1.0.0.beta.3, < 2.0) - cocoapods-trunk (>= 1.0.0.beta.2, < 2.0) - cocoapods-try (>= 1.0.0.beta.3, < 2.0) - colored (~> 1.2) + CFPropertyList (3.0.5) + rexml + activesupport (6.1.7) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) + algoliasearch (1.27.5) + httpclient (~> 2.8, >= 2.8.3) + json (>= 1.5.1) + ast (2.4.2) + atomos (0.1.3) + claide (1.1.0) + cocoapods (1.11.3) + addressable (~> 2.8) + claide (>= 1.0.2, < 2.0) + cocoapods-core (= 1.11.3) + cocoapods-deintegrate (>= 1.0.3, < 2.0) + cocoapods-downloader (>= 1.4.0, < 2.0) + cocoapods-plugins (>= 1.0.0, < 2.0) + cocoapods-search (>= 1.0.0, < 2.0) + cocoapods-trunk (>= 1.4.0, < 2.0) + cocoapods-try (>= 1.1.0, < 2.0) + colored2 (~> 3.1) escape (~> 0.0.4) - fourflusher (~> 0.3.0) - molinillo (~> 0.4.4) + fourflusher (>= 2.3.0, < 3.0) + gh_inspector (~> 1.0) + molinillo (~> 0.8.0) nap (~> 1.0) - xcodeproj (>= 1.0.0.beta.3, < 2.0) - cocoapods-core (1.0.0.beta.6) - activesupport (>= 4.0.2) + ruby-macho (>= 1.0, < 3.0) + xcodeproj (>= 1.21.0, < 2.0) + cocoapods-core (1.11.3) + activesupport (>= 5.0, < 7) + addressable (~> 2.8) + algoliasearch (~> 1.0) + concurrent-ruby (~> 1.1) fuzzy_match (~> 2.0.4) nap (~> 1.0) - cocoapods-deintegrate (1.0.1) + netrc (~> 0.11) + public_suffix (~> 4.0) + typhoeus (~> 1.0) + cocoapods-deintegrate (1.0.5) cocoapods-downloader (1.6.3) cocoapods-plugins (1.0.0) nap - cocoapods-search (1.0.0) - cocoapods-stats (1.0.0) - cocoapods-trunk (1.2.0) + cocoapods-search (1.0.1) + cocoapods-trunk (1.6.0) nap (>= 0.8, < 2.0) - netrc (= 0.7.8) - cocoapods-try (1.1.0) - colored (1.2) + netrc (~> 0.11) + cocoapods-try (1.2.0) colored2 (3.1.2) - diff-lcs (1.3) - dotenv (2.7.5) + concurrent-ruby (1.1.10) + crypt (2.2.1) + diff-lcs (1.5.0) + dotenv (2.8.1) escape (0.0.4) - fourflusher (0.3.2) + ethon (0.16.0) + ffi (>= 1.15.0) + ffi (1.15.5) + fourflusher (2.3.1) fuzzy_match (2.0.4) - i18n (0.8.4) - minitest (5.10.2) - molinillo (0.4.5) - nanaimo (0.2.3) + gh_inspector (1.1.3) + highline (2.0.3) + httpclient (2.8.3) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + json (2.6.2) + keychain (0.2.3) + crypt (>= 1.1.4) + highline (>= 1.4.0) + minitest (5.16.3) + molinillo (0.8.0) + nanaimo (0.3.0) nap (1.1.0) - netrc (0.7.8) - osx_keychain (1.0.2) - RubyInline (~> 3) - parallel (1.11.2) - parser (2.4.0.0) - ast (~> 2.2) - powerpack (0.1.1) - rainbow (2.2.2) - rake - rake (12.0.0) - rspec (3.6.0) - rspec-core (~> 3.6.0) - rspec-expectations (~> 3.6.0) - rspec-mocks (~> 3.6.0) - rspec-core (3.6.0) - rspec-support (~> 3.6.0) - rspec-expectations (3.6.0) + netrc (0.11.0) + og-corefoundation (0.2.3) + ffi + parallel (1.22.1) + parser (3.1.3.0) + ast (~> 2.4.1) + public_suffix (4.0.7) + rainbow (3.1.1) + rake (13.0.6) + regexp_parser (2.6.1) + rexml (3.2.5) + rspec (3.12.0) + rspec-core (~> 3.12.0) + rspec-expectations (~> 3.12.0) + rspec-mocks (~> 3.12.0) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.6.0) - rspec-mocks (3.6.0) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.6.0) - rspec-support (3.6.0) - rubocop (0.49.1) + rspec-support (~> 3.12.0) + rspec-support (3.12.0) + rubocop (1.39.0) + json (~> 2.3) parallel (~> 1.10) - parser (>= 2.3.3.1, < 3.0) - powerpack (~> 0.1) - rainbow (>= 1.99.1, < 3.0) + parser (>= 3.1.2.1) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.23.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (~> 1.0, >= 1.0.1) - ruby-progressbar (1.8.1) - thread_safe (0.3.6) - tzinfo (1.2.3) - thread_safe (~> 0.1) - unicode-display_width (1.3.0) - xcodeproj (1.5.0) - CFPropertyList (~> 2.3.3) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.24.0) + parser (>= 3.1.1.0) + ruby-keychain (0.4.0) + ffi + og-corefoundation (~> 0.2.0) + ruby-macho (2.5.1) + ruby-progressbar (1.11.0) + typhoeus (1.4.0) + ethon (>= 0.9.0) + tzinfo (2.0.5) + concurrent-ruby (~> 1.0) + unicode-display_width (2.3.0) + xcodeproj (1.22.0) + CFPropertyList (>= 2.3.3, < 4.0) + atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) colored2 (~> 3.1) - nanaimo (~> 0.2.3) + nanaimo (~> 0.3.0) + rexml (~> 3.2.4) + zeitwerk (2.6.6) PLATFORMS - ruby + arm64-darwin-22 DEPENDENCIES - activesupport (< 5) - bundler (~> 1.3) - cocoapods (= 1.0.0.beta.6) + activesupport (>= 5) + bundler (~> 2.3) + cocoapods (>= 1.11) cocoapods-keys! rake rspec - rubocop + rubocop (> 1.38) + ruby-keychain BUNDLED WITH - 1.17.3 + 2.3.26 diff --git a/cocoapods_keys.gemspec b/cocoapods_keys.gemspec index f3bf6c0..5d47de8 100644 --- a/cocoapods_keys.gemspec +++ b/cocoapods_keys.gemspec @@ -18,12 +18,12 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.add_runtime_dependency "osx_keychain" + spec.add_runtime_dependency "ruby-keychain" spec.add_runtime_dependency "dotenv" # spec.add_runtime_dependency "cocoapods", "> 1" - spec.add_development_dependency "bundler", "~> 1.3" + spec.add_development_dependency "bundler", "~> 2.3" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" - spec.add_development_dependency "rubocop" + spec.add_development_dependency "rubocop", "> 1.38" end diff --git a/lib/keyring.rb b/lib/keyring.rb index 24baea5..ee9f065 100644 --- a/lib/keyring.rb +++ b/lib/keyring.rb @@ -1,4 +1,6 @@ -require 'osx_keychain' +require 'keychain' +require 'base64' +require 'json' module CocoaPodsKeys class Keyring @@ -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) + end end def keychain_data @@ -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 diff --git a/spec/fixtures/Podfile b/spec/fixtures/Podfile index d969a3c..2e81977 100644 --- a/spec/fixtures/Podfile +++ b/spec/fixtures/Podfile @@ -4,5 +4,5 @@ plugin 'cocoapods-keys', { :keys => [ 'KeyWithData', 'KeyWithoutData', - ] + ], } diff --git a/spec/keyring_spec.rb b/spec/keyring_spec.rb index dfc067e..57ebc0e 100644 --- a/spec/keyring_spec.rb +++ b/spec/keyring_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 108ee3d..c6d1152 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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