Class: Tug::Keychain

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keychain_yaml) ⇒ Keychain

Returns a new instance of Keychain.



19
20
21
22
23
24
25
26
27
28
# File 'lib/tug/keychain/keychain.rb', line 19

def initialize(keychain_yaml)
  @apple_certificate          = keychain_yaml["apple_certificate"]
  @distribution_certificate   = keychain_yaml["distribution_certificate"]
  @distribution_profile       = keychain_yaml["distribution_profile"]
  @private_key                = keychain_yaml["private_key"]

  # these defaults are also set in Interface
  @private_key_password       = ENV['TUG_P12_PASSWORD']
  @name                       = "tug"
end

Instance Attribute Details

#apple_certificateObject (readonly)

Returns the value of attribute apple_certificate.



4
5
6
# File 'lib/tug/keychain/keychain.rb', line 4

def apple_certificate
  @apple_certificate
end

#distribution_certificateObject (readonly)

Returns the value of attribute distribution_certificate.



5
6
7
# File 'lib/tug/keychain/keychain.rb', line 5

def distribution_certificate
  @distribution_certificate
end

#distribution_profileObject (readonly)

Returns the value of attribute distribution_profile.



6
7
8
# File 'lib/tug/keychain/keychain.rb', line 6

def distribution_profile
  @distribution_profile
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/tug/keychain/keychain.rb', line 9

def name
  @name
end

#private_keyObject (readonly)

Returns the value of attribute private_key.



7
8
9
# File 'lib/tug/keychain/keychain.rb', line 7

def private_key
  @private_key
end

#private_key_passwordObject

Returns the value of attribute private_key_password.



8
9
10
# File 'lib/tug/keychain/keychain.rb', line 8

def private_key_password
  @private_key_password
end

Class Method Details

.keychain(config) ⇒ Object



12
13
14
15
16
# File 'lib/tug/keychain/keychain.rb', line 12

def keychain(config)
  if config.has_key?("keychain")
    Tug::Keychain.new(config["keychain"])
  end
end

Instance Method Details

#configure(options) ⇒ Object



30
31
32
33
# File 'lib/tug/keychain/keychain.rb', line 30

def configure(options)
  @name = options["keychain"]
  @private_key_password = options["password"]
end

#create_keychainObject



35
36
37
# File 'lib/tug/keychain/keychain.rb', line 35

def create_keychain
  system("security create-keychain -p tug #{name}.keychain")
end

#delete_keychainObject



43
44
45
# File 'lib/tug/keychain/keychain.rb', line 43

def delete_keychain
  system("security delete-keychain #{name}.keychain")
end

#import_apple_certificateObject



55
56
57
# File 'lib/tug/keychain/keychain.rb', line 55

def import_apple_certificate
  system(import_command(apple_certificate))
end

#import_distribution_certificateObject



59
60
61
# File 'lib/tug/keychain/keychain.rb', line 59

def import_distribution_certificate
  system(import_command(distribution_certificate))
end

#import_private_keyObject



63
64
65
# File 'lib/tug/keychain/keychain.rb', line 63

def import_private_key
  system(import_command(private_key) + " -P '#{private_key_password}'")
end

#import_profileObject



67
68
69
70
# File 'lib/tug/keychain/keychain.rb', line 67

def import_profile
  FileUtils.mkdir_p "#{File.expand_path('~')}/Library/MobileDevice/Provisioning\ Profiles/"
  system("cp #{distribution_profile} #{profile_export_path}")
end

#select_keychain(keychain_name = name) ⇒ Object



39
40
41
# File 'lib/tug/keychain/keychain.rb', line 39

def select_keychain(keychain_name=name)
  system("security default-keychain -s #{keychain_name}.keychain")
end

#set_timeoutObject



51
52
53
# File 'lib/tug/keychain/keychain.rb', line 51

def set_timeout
  system("security set-keychain-settings -t 3600 -u #{name}.keychain")
end

#unlock_keychainObject



47
48
49
# File 'lib/tug/keychain/keychain.rb', line 47

def unlock_keychain
  system("security unlock-keychain -p tug #{name}.keychain")
end