Class: CocoaPodsKeys::PreInstaller

Inherits:
Object
  • Object
show all
Defined in:
lib/preinstaller.rb

Instance Method Summary collapse

Constructor Details

#initialize(user_options) ⇒ PreInstaller

Returns a new instance of PreInstaller.



3
4
5
# File 'lib/preinstaller.rb', line 3

def initialize(user_options)
  @user_options = user_options
end

Instance Method Details

#check_for_multiple_keyrings(project, current_dir) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/preinstaller.rb', line 73

def check_for_multiple_keyrings(project, current_dir)
  if !ENV['TRAVIS'] && !ENV['TEAMCITY_VERSION'] && !ENV['CIRCLECI']
    ui = Pod::UserInterface
    keyrings = KeyringLiberator.get_all_keyrings_named(project)
    if keyrings.count > 1
      ui.puts "Found multiple keyrings for project #{project.inspect}, but"
      ui.puts "no match found for current path (#{current_dir}):"
      keyrings.each do |found_keyring|
        ui.puts "- #{found_keyring.path}"
      end
      ui.puts "\nPress enter to create a new keyring, or `ctrl + c` to cancel"
      ui.gets
    end
  end
end

#setupObject

Returns ‘true` if all keys specified by the user are satisfied by either an existing keyring or environment variables.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/preinstaller.rb', line 9

def setup
  require 'key_master'
  require 'keyring_liberator'
  require 'pod/command/keys/set'
  require 'cocoapods/user_interface'
  require 'dotenv'

  ui = Pod::UserInterface

  options = @user_options || {}
  current_dir = Pathname.pwd
  Dotenv.load
  project = options.fetch('project') { CocoaPodsKeys::NameWhisperer.get_project_name }

  keyring = KeyringLiberator.get_current_keyring(project, current_dir)

  unless keyring
    check_for_multiple_keyrings(project, current_dir)
  end

  existing_keyring = !keyring.nil?
  keyring = CocoaPodsKeys::Keyring.new(project, current_dir, []) unless keyring

  has_shown_intro = false
  keys = options.fetch('keys', [])

  # Remove keys from the keyring that no longer exist
  original_keyring_keys = keyring.keys.clone
  original_keyring_keys.each do |key|
    keyring.keychain_has_key?(key)
  end

  # Add keys to the keyring that have been added,
  # and prompt for their value if needed.
  keys.each do |key|
    unless keyring.keychain_has_key?(key)
      if ENV['CI']
        raise Informative, "CocoaPods-Keys could not find a key named: #{key}"
      end

      unless has_shown_intro
        ui.puts "\n CocoaPods-Keys has detected a keys mismatch for your setup."
        has_shown_intro = true
      end

      ui.puts ' What is the key for ' + key.green
      answer = ''
      loop do
        ui.print ' > '
        answer = ui.gets.strip
        break unless answer.empty?
      end

      ui.puts
      args = CLAide::ARGV.new([key, answer, keyring.name])
      setter = Pod::Command::Keys::Set.new(args)
      setter.run
    end
  end
  CocoaPodsKeys::KeyringLiberator.save_keyring(keyring)

  existing_keyring || !keys.empty?
end