pem 0.4.0 → 0.5.0

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: 53a49d82dfa51942bda7945a2abe14519aa1628d
4
- data.tar.gz: 18add6dbe91bfb711a6277001f2317e7b40b023b
3
+ metadata.gz: 441f838576b5abd063e89f7619a9f3c14574c35d
4
+ data.tar.gz: a4f7a7821bc379329248e5b7d4bf7c9f0394a2f7
5
5
  SHA512:
6
- metadata.gz: d79b9265d80ad370c50339a890e3aeafbac1ee3a7a7cdf94ab053a48739bb5d7863f423ed8b15d5d77759fd5e8bd4a9f8d89a4d2e258e5762060db51e0151f9f
7
- data.tar.gz: 4699b6fa184d3e69bd472e41aa3ee29fc8fbdd82e24c60fcdc3655473004e037ae034a8dd68d926899a97e6f404f4e397f33073da7d1c0c9e83d39fe48cab5fa
6
+ metadata.gz: d669e76632dab4da9dd21add714e8e75a665113fa661c00a26f9cf58ddedbd4246badcb3347c8575fdeaddc96e4416ef8a35347346074c64833afa06ac24246c
7
+ data.tar.gz: 4769e953014210318a78c0a90c5c7205f14f68dcd8c49e7137a37cdb4d45fc8449bab52acbb535e5943a9c03fb0ebd2d73cc6fff00cf44477b79476f65bc55e9
data/README.md CHANGED
@@ -72,6 +72,7 @@ Make sure, you have the latest version of the Xcode command line tools installed
72
72
  # Usage
73
73
 
74
74
  pem
75
+
75
76
  Yes, that's the whole command!
76
77
 
77
78
  This does the following:
@@ -83,6 +84,10 @@ This does the following:
83
84
 
84
85
  ```PEM``` will never revoke your existing certificates.
85
86
 
87
+ If you already have a push certificate enabled, which is active for at least 2 more weeks, `PEM` will not create a new certificate. If you still want to create one, use the `force`:
88
+
89
+ pem --force
90
+
86
91
  You can pass parameters like this:
87
92
 
88
93
  pem -a com.krausefx.app -u username
@@ -13,21 +13,23 @@ module PEM
13
13
  dev = PEM::DeveloperCenter.new
14
14
 
15
15
  self.cert_file = dev.fetch_cer_file
16
- self.rsa_file = File.join(TMP_FOLDER, 'private_key.key')
17
- self.certificate_type = (PEM.config[:development] ? 'development' : 'production')
18
- self.pem_file = File.join(TMP_FOLDER, "#{certificate_type}_#{PEM.config[:app_identifier]}.pem")
19
- self.passphrase = ''
20
-
21
- File.write(pem_file, pem_certificate)
22
-
23
- # Generate p12 file as well
24
- if PEM.config[:generate_p12]
25
- output = "#{certificate_type}_#{PEM.config[:app_identifier]}.p12"
26
- File.write(output, p12_certificate.to_der)
27
- puts output.green
16
+ if self.cert_file
17
+ self.rsa_file = File.join(TMP_FOLDER, 'private_key.key')
18
+ self.certificate_type = (PEM.config[:development] ? 'development' : 'production')
19
+ self.pem_file = File.join(TMP_FOLDER, "#{certificate_type}_#{PEM.config[:app_identifier]}.pem")
20
+ self.passphrase = ''
21
+
22
+ File.write(pem_file, pem_certificate)
23
+
24
+ # Generate p12 file as well
25
+ if PEM.config[:generate_p12]
26
+ output = "#{certificate_type}_#{PEM.config[:app_identifier]}.p12"
27
+ File.write(output, p12_certificate.to_der)
28
+ puts output.green
29
+ end
30
+
31
+ return pem_file, rsa_file
28
32
  end
29
-
30
- return pem_file, rsa_file
31
33
  end
32
34
 
33
35
  def private_key
@@ -4,7 +4,7 @@ module PEM
4
4
  class DeveloperCenter < FastlaneCore::DeveloperCenter
5
5
  APP_IDS_URL = "https://developer.apple.com/account/ios/identifiers/bundle/bundleList.action"
6
6
 
7
-
7
+
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
@@ -25,13 +25,30 @@ module PEM
25
25
  sleep 3 # this takes some time
26
26
  end
27
27
 
28
- Helper.log.warn "Creating push certificate for app '#{@app_identifier}'."
29
- create_push_for_app
28
+ if has_actual_cert and not PEM.config[:force]
29
+ Helper.log.info "You already have a push certificate, which is active for more than 2 more weeks. No need to create a new one".green
30
+ Helper.log.info "If you still want to create a new one, use the --force option when running PEM.".green
31
+ false
32
+ else
33
+ Helper.log.warn "Creating push certificate for app '#{@app_identifier}'."
34
+ create_push_for_app
35
+ end
30
36
  rescue => ex
31
37
  error_occured(ex)
32
38
  end
33
39
  end
34
40
 
41
+ def has_actual_cert
42
+ apps = all(:xpath, "//div[@class = 'certificate']")
43
+ cert_type = PEM.config[:development] ? 'Development' : 'Production'
44
+ cert_section = apps.select { |c| c.text.include? cert_type }
45
+
46
+ unless cert_section.empty?
47
+ data_s = cert_section.last.all('dd').last.text
48
+ data = Date.parse(data_s)
49
+ data - Time.now.to_date > 14 # valid for more than 2 weeks
50
+ end
51
+ end
35
52
 
36
53
  private
37
54
  def open_app_page
@@ -98,20 +115,20 @@ module PEM
98
115
  url = download_button['href']
99
116
  url = [host, url].join('')
100
117
  Helper.log.info "Downloading URL: '#{url}'"
101
-
118
+
102
119
  cookie_string = page.driver.cookies.collect { |key, cookie| "#{cookie.name}=#{cookie.value}" }.join(";")
103
-
120
+
104
121
  data = open(url, {'Cookie' => cookie_string}).read
105
122
 
106
123
  raise "Something went wrong when downloading the certificate" unless data
107
124
 
108
125
  path = "#{TMP_FOLDER}aps_#{certificate_type}_#{@app_identifier}.cer"
109
126
  dataWritten = File.write(path, data)
110
-
127
+
111
128
  if dataWritten == 0
112
129
  raise "Can't write to #{TMP_FOLDER}"
113
130
  end
114
-
131
+
115
132
  Helper.log.info "Successfully downloaded latest .cer file to '#{path}'".green
116
133
  return path
117
134
  end
data/lib/pem/manager.rb CHANGED
@@ -17,7 +17,7 @@ module PEM
17
17
  FileUtils.mv(rsa_file, output)
18
18
  puts output.green
19
19
  else
20
- File.delete(rsa_file)
20
+ File.delete(rsa_file) if rsa_file
21
21
  end
22
22
  end
23
23
  end
data/lib/pem/options.rb CHANGED
@@ -17,6 +17,10 @@ module PEM
17
17
  env_name: "PEM_SAVE_PRIVATEKEY",
18
18
  description: "Set to save the private RSA key in the current directory",
19
19
  is_string: false),
20
+ FastlaneCore::ConfigItem.new(key: :force,
21
+ env_name: "PEM_FORCE",
22
+ description: "Create a new push certificate, even if the current one is active for 2 more weeks",
23
+ is_string: false),
20
24
  FastlaneCore::ConfigItem.new(key: :app_identifier,
21
25
  short_option: "-a",
22
26
  env_name: "PEM_APP_IDENTIFIER",
data/lib/pem/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module PEM
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
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.4.0
4
+ version: 0.5.0
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-04-12 00:00:00.000000000 Z
11
+ date: 2015-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastlane_core