Class: Match::Utils

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

Class Method Summary collapse

Class Method Details

.environment_variable_name(params) ⇒ Object



37
38
39
# File 'lib/match/utils.rb', line 37

def self.environment_variable_name(params)
  ["sigh", params[:app_identifier], params[:type]].join("_")
end

.fill_environment(params, uuid) ⇒ Object

Fill in the UUID of the profiles in environment variables, much recycling



30
31
32
33
34
35
# File 'lib/match/utils.rb', line 30

def self.fill_environment(params, uuid)
  # instead we specify the UUID of the profiles
  key = environment_variable_name(params)
  UI.important "Setting environment variable '#{key}' to '#{uuid}'" if $verbose
  ENV[key] = uuid
end

.import(item_path, keychain) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/match/utils.rb', line 3

def self.import(item_path, keychain)
  # Existing code expects that a keychain name will be expanded into a default path to Libary/Keychains
  # in the user's home directory. However, this will not allow the user to pass an absolute path
  # for the keychain value
  #
  # So, if the passed value can't be resolved as a file in Library/Keychains, just use it as-is
  # as the keychain path.
  #
  # We need to expand each path because File.exist? won't handle directories including ~ properly
  keychain_paths = [
    File.join(Dir.home, 'Library', 'Keychains', keychain),
    keychain
  ].map { |path| File.expand_path(path) }

  keychain_path = keychain_paths.find { |path| File.exist?(path) }

  UI.user_error!("Could not locate the provided keychain. Tried:\n\t#{keychain_paths.join("\n\t")}") unless keychain_path

  command = "security import #{item_path.shellescape} -k #{keychain_path.shellescape}"
  command << " -T /usr/bin/codesign" # to not be asked for permission when running a tool like `gym`
  command << " -T /usr/bin/security"
  command << " &> /dev/null" unless $verbose

  Helper.backticks(command, print: $verbose)
end