pem 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d12ab8bf44ad8467e32200e2b77d60e0406d6254
4
- data.tar.gz: 5379f10009de542b8ad113da8d0906d1c9ab86ee
3
+ metadata.gz: d017f22c946bf5b7edc3f19207fc18f4a7f44d74
4
+ data.tar.gz: a768d2968115885940b6eae235e986918b4415e1
5
5
  SHA512:
6
- metadata.gz: 49ae6ed9e1b5439c20360591550734ee320b4ddc3842f4d9f0e36da12dd172ea899b5262c9c33f288179a9aee296c7c6420db5698575b1af67a99589d5b1389a
7
- data.tar.gz: 94d1036a54d9e728a8ec498fd48cb6f934bb2754c85e9a76e4820b563789e9ba7145148e1ebf98d3757d95ba246c3c04a135212c7a71340d735f6db81f7a36ef
6
+ metadata.gz: de12a00972b77b529f0636029c919f491607d38b7d65e3781297ae17880390da23e951c3a4b7e12ebfadca519a515474773037d4e56ea917f0696d4582a39ac8
7
+ data.tar.gz: 8e08fb66e95a7641021a929934c8898a4b45133d485c9f6588b2b5030ad592869dbd68fa0a4fc27f3faa6c92c29f2d4e0682e57ef7f6b71e4a1492152391b871
data/README.md CHANGED
@@ -91,6 +91,11 @@ If you want to generate a development certificate instead:
91
91
 
92
92
  pem --development
93
93
 
94
+ To get a list of available options run:
95
+
96
+ pem --help
97
+
98
+
94
99
  ##### [Like this tool? Be the first to know about updates and new fastlane tools](https://tinyletter.com/krausefx)
95
100
 
96
101
  ## Environment Variables
data/bin/pem CHANGED
@@ -6,6 +6,8 @@ require 'pem'
6
6
  require 'commander'
7
7
  require 'credentials_manager/password_manager'
8
8
  require 'credentials_manager/appfile_config'
9
+ require 'pem/options'
10
+ require 'pem/manager'
9
11
 
10
12
  HighLine.track_eof = false
11
13
 
@@ -22,36 +24,15 @@ class PemApplication
22
24
 
23
25
  always_trace!
24
26
 
25
- global_option '--development', 'Renew the development push certificate instead of the production one'
26
- global_option '-u', '--username STRING', 'Your Apple ID username'
27
- global_option '-a', '--identifier STRING', String, 'The bundle identifier of your app'
27
+ FastlaneCore::CommanderGenerator.new.generate(PEM::Options.available_options)
28
28
 
29
29
  command :renew do |c|
30
30
  c.syntax = 'pem renew'
31
31
  c.description = 'Renews the certificate (in case it expired) and shows the path to the generated pem file'
32
32
 
33
33
  c.action do |args, options|
34
- app = app_identifier(options)
35
- username(options)
36
-
37
- path, rsa_file = PEM::CertManager.new.run(app, !options.development)
38
-
39
- if path
40
- file_name = File.basename(path)
41
- output = "./#{file_name}"
42
- FileUtils.mv(path, output)
43
- puts output.green
44
- end
45
-
46
- if ENV["PEM_SAVE_PRIVATEKEY"]
47
- file_name = File.basename(rsa_file)
48
- output = "./#{file_name}"
49
- FileUtils.mv(rsa_file, output)
50
- puts output.green
51
- else
52
- File.delete(rsa_file)
53
- end
54
-
34
+ PEM.config = FastlaneCore::Configuration.create(PEM::Options.available_options, options.__hash__)
35
+ PEM::Manager.start
55
36
  end
56
37
  end
57
38
 
@@ -59,23 +40,6 @@ class PemApplication
59
40
 
60
41
  run!
61
42
  end
62
-
63
- def username(options)
64
- user = options.username
65
- user ||= ENV["PEM_USERNAME"]
66
- user ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)
67
-
68
- CredentialsManager::PasswordManager.shared_manager(user) if user
69
- end
70
-
71
- def app_identifier(options)
72
- value = options.identifier
73
- value ||= ENV["PEM_APP_IDENTIFIER"]
74
- value ||= CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)
75
- value ||= ask("App Identifier (Bundle ID, e.g. com.krausefx.app): ")
76
- return value
77
- end
78
-
79
43
  end
80
44
 
81
45
  PemApplication.new.run
data/lib/pem.rb CHANGED
@@ -7,10 +7,16 @@ require 'pem/signing_request'
7
7
  require 'fastlane_core'
8
8
 
9
9
  module PEM
10
+ # Use this to just setup the configuration attribute and set it later somewhere else
11
+ class << self
12
+ attr_accessor :config
13
+ end
14
+
10
15
  TMP_FOLDER = "/tmp/PEM/"
11
16
  FileUtils.mkdir_p TMP_FOLDER
12
17
 
13
18
  ENV['FASTLANE_TEAM_ID'] ||= ENV["PEM_TEAM_ID"]
19
+ ENV['DELIVER_USER'] ||= ENV["PEM_USERNAME"]
14
20
 
15
21
  Helper = FastlaneCore::Helper # you gotta love Ruby: Helper.* should use the Helper class contained in FastlaneCore
16
22
 
@@ -1,26 +1,33 @@
1
1
  module PEM
2
2
  class CertManager
3
3
  # Download the cert, do all kinds of Keychain related things
4
- def run(app_identifier, production)
4
+ def run
5
5
  # Keychain (security) documentation: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/security.1.html
6
6
  # Old project, which might be helpful: https://github.com/jprichardson/keychain_manager
7
7
 
8
- Helper.log.info "Refreshing push notification profiles for app '#{app_identifier}'"
8
+ Helper.log.info "Refreshing push notification profiles for app '#{PEM.config[:app_identifier]}'"
9
9
 
10
10
  dev = PEM::DeveloperCenter.new
11
11
 
12
- cert_file = dev.fetch_cer_file(app_identifier, production)
12
+ cert_file = dev.fetch_cer_file
13
13
  rsa_file = File.join(TMP_FOLDER, 'private_key.key')
14
14
 
15
15
  pem_temp = File.join(TMP_FOLDER, 'pem_temp.pem')
16
16
 
17
- certificate_type = (production ? 'production' : 'development')
17
+ certificate_type = (PEM.config[:development] ? 'development' : 'production')
18
18
 
19
19
 
20
- pem_file = File.join(TMP_FOLDER, "#{certificate_type}_#{app_identifier}.pem")
20
+ pem_file = File.join(TMP_FOLDER, "#{certificate_type}_#{PEM.config[:app_identifier]}.pem")
21
21
  command("openssl x509 -inform der -in '#{cert_file}' -out #{pem_temp}")
22
22
  content = File.read(pem_temp) + File.read(rsa_file)
23
23
  File.write(pem_file, content)
24
+
25
+ # Generate p12 file as well
26
+ if PEM.config[:generate_p12]
27
+ output = "#{certificate_type}.p12"
28
+ command("openssl pkcs12 -export -password pass:"" -in '#{pem_file}' -inkey '#{pem_file}' -out '#{output}'")
29
+ puts output.green
30
+ end
24
31
 
25
32
  return pem_file, rsa_file
26
33
  end
@@ -8,24 +8,25 @@ module PEM
8
8
  # This method will enable push for the given app
9
9
  # and download the cer file in any case, no matter if it existed before or not
10
10
  # @return the path to the push file
11
- def fetch_cer_file(app_identifier, production)
11
+ def fetch_cer_file
12
+ @app_identifier = PEM.config[:app_identifier]
12
13
  begin
13
- open_app_page(app_identifier)
14
+ open_app_page
14
15
 
15
16
  click_on "Edit"
16
17
  wait_for_elements(".item-details") # just to finish loading
17
18
 
18
19
  push_value = first(:css, '#pushEnabled').value
19
20
  if push_value == "on"
20
- Helper.log.info "Push for app '#{app_identifier}' is enabled"
21
+ Helper.log.info "Push for app '#{@app_identifier}' is enabled"
21
22
  else
22
- Helper.log.warn "Push for app '#{app_identifier}' is disabled. This has to change."
23
+ Helper.log.warn "Push for app '#{@app_identifier}' is disabled. This has to change."
23
24
  first(:css, '#pushEnabled').click
24
25
  sleep 3 # this takes some time
25
26
  end
26
27
 
27
- Helper.log.warn "Creating push certificate for app '#{app_identifier}'."
28
- create_push_for_app(app_identifier, production)
28
+ Helper.log.warn "Creating push certificate for app '#{@app_identifier}'."
29
+ create_push_for_app
29
30
  rescue => ex
30
31
  error_occured(ex)
31
32
  end
@@ -33,36 +34,36 @@ module PEM
33
34
 
34
35
 
35
36
  private
36
- def open_app_page(app_identifier)
37
+ def open_app_page
37
38
  begin
38
39
  visit APP_IDS_URL
39
40
  sleep 5
40
41
 
41
42
  wait_for_elements(".toolbar-button.search").first.click
42
- fill_in "bundle-list-search", with: app_identifier
43
+ fill_in "bundle-list-search", with: @app_identifier
43
44
  sleep 5
44
45
 
45
- apps = all(:xpath, "//td[@title='#{app_identifier}']")
46
+ apps = all(:xpath, "//td[@title='#{@app_identifier}']")
46
47
  if apps.count == 1
47
48
  apps.first.click
48
49
  sleep 2
49
50
 
50
51
  return true
51
52
  else
52
- raise DeveloperCenterGeneralError.new("Could not find app with identifier '#{app_identifier}' on apps page. The identifier is case sensitive.")
53
+ raise DeveloperCenterGeneralError.new("Could not find app with identifier '#{@app_identifier}' on apps page. The identifier is case sensitive.")
53
54
  end
54
55
  rescue => ex
55
56
  error_occured(ex)
56
57
  end
57
58
  end
58
59
 
59
- def create_push_for_app(app_identifier, production)
60
+ def create_push_for_app
60
61
 
61
- element_name = (production ? '.button.small.navLink.distribution.enabled' : '.button.small.navLink.development.enabled')
62
+ element_name = (PEM.config[:development] ? '.button.small.navLink.development.enabled' : '.button.small.navLink.distribution.enabled')
62
63
  begin
63
64
  wait_for_elements(element_name).first.click # Create Certificate button
64
65
  rescue
65
- raise "Could not create a new push profile for app '#{app_identifier}'. There are already 2 certificates active. Please revoke one to let PEM create a new one\n\n#{current_url}".red
66
+ raise "Could not create a new push profile for app '#{@app_identifier}'. There are already 2 certificates active. Please revoke one to let PEM create a new one\n\n#{current_url}".red
66
67
  end
67
68
 
68
69
  sleep 2
@@ -84,7 +85,7 @@ module PEM
84
85
  sleep 2
85
86
  end
86
87
 
87
- certificate_type = (production ? 'production' : 'development')
88
+ certificate_type = (PEM.config[:development] ? 'development' : 'production')
88
89
 
89
90
  # Download the newly created certificate
90
91
  Helper.log.info "Going to download the latest profile"
@@ -108,7 +109,7 @@ module PEM
108
109
 
109
110
  raise "Something went wrong when downloading the certificate" unless data
110
111
 
111
- path = "#{TMP_FOLDER}aps_#{certificate_type}_#{app_identifier}.cer"
112
+ path = "#{TMP_FOLDER}aps_#{certificate_type}_#{@app_identifier}.cer"
112
113
  dataWritten = File.write(path, data)
113
114
 
114
115
  if dataWritten == 0
@@ -0,0 +1,24 @@
1
+ module PEM
2
+ # Creates the push profile and stores it in the correct location
3
+ class Manager
4
+ def self.start
5
+ path, rsa_file = PEM::CertManager.new.run
6
+
7
+ if path
8
+ file_name = File.basename(path)
9
+ output = "./#{file_name}"
10
+ FileUtils.mv(path, output)
11
+ puts output.green
12
+ end
13
+
14
+ if PEM.config[:save_private_key]
15
+ file_name = File.basename(rsa_file)
16
+ output = "./#{file_name}"
17
+ FileUtils.mv(rsa_file, output)
18
+ puts output.green
19
+ else
20
+ File.delete(rsa_file)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ require 'fastlane_core'
2
+
3
+ module PEM
4
+ class Options
5
+ def self.available_options
6
+ @@options ||= [
7
+ FastlaneCore::ConfigItem.new(key: :development,
8
+ env_name: "PEM_DEVELOPMENT",
9
+ description: "Renew the development push certificate instead of the production one",
10
+ is_string: false),
11
+ FastlaneCore::ConfigItem.new(key: :generate_p12,
12
+ env_name: "PEM_GENERATE_P12_FILE",
13
+ description: "Generate a p12 file additionally to a PEM file",
14
+ is_string: false),
15
+ FastlaneCore::ConfigItem.new(key: :save_private_key,
16
+ short_option: "-s",
17
+ env_name: "PEM_SAVE_PRIVATEKEY",
18
+ description: "Set to save the private RSA key in the current directory",
19
+ is_string: false),
20
+ FastlaneCore::ConfigItem.new(key: :app_identifier,
21
+ short_option: "-a",
22
+ env_name: "PEM_APP_IDENTIFIER",
23
+ description: "The bundle identifier of your app",
24
+ default_value: CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)),
25
+ FastlaneCore::ConfigItem.new(key: :username,
26
+ short_option: "-u",
27
+ env_name: "PEM_USERNAME",
28
+ description: "Your Apple ID Username",
29
+ default_value: CredentialsManager::AppfileConfig.try_fetch_value(:apple_id),
30
+ verify_block: Proc.new do |value|
31
+ CredentialsManager::PasswordManager.shared_manager(value)
32
+ end),
33
+ FastlaneCore::ConfigItem.new(key: :team_id,
34
+ short_option: "-t",
35
+ env_name: "PEM_TEAM_ID",
36
+ description: "The ID of your team if you're in multiple teams",
37
+ optional: true,
38
+ verify_block: Proc.new do |value|
39
+ ENV["FASTLANE_TEAM_ID"] = value
40
+ end),
41
+ ]
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module PEM
2
- VERSION = "0.3.7"
2
+ VERSION = "0.3.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Krause
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastlane_core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0
19
+ version: 0.3.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0
26
+ version: 0.3.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -137,6 +137,8 @@ files:
137
137
  - lib/pem/cert_manager.rb
138
138
  - lib/pem/dependency_checker.rb
139
139
  - lib/pem/developer_center.rb
140
+ - lib/pem/manager.rb
141
+ - lib/pem/options.rb
140
142
  - lib/pem/signing_request.rb
141
143
  - lib/pem/version.rb
142
144
  homepage: https://fastlane.tools