Module: Pindo::PemHelper

Included in:
Command::Deploy::Pem
Defined in:
lib/pindo/module/cert/pemhelper.rb

Instance Method Summary collapse

Instance Method Details

#create_certificate(bundle_id: nil, type: "prod", output_path: "") ⇒ Object



6
7
8
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
# File 'lib/pindo/module/cert/pemhelper.rb', line 6

def create_certificate(bundle_id:nil, type:"prod", output_path:"")

  if bundle_id.empty? || output_path.empty?
    UI.user_error!("bundle id is nil or output_path is nil.")
  end

  puts "Creating a new push certificate for app '#{bundle_id}'. "

  csr, pkey = Spaceship::Portal.certificate.create_certificate_signing_request

  cert = nil
  begin
    if type == "dev"
      cert = Spaceship::Portal.certificate.development_push.create!(csr: csr, bundle_id: bundle_id)
    else
      cert = Spaceship::Portal.certificate.production_push.create!(csr: csr, bundle_id: bundle_id)
    end
  rescue => ex
    if ex.to_s.include?("You already have a current")
      # That's the most common failure probably
      raise Informative, "You already have 2 active push profiles for this application/environment. You'll need to revoke an old certificate to make room for a new one"
    else
      raise ex
    end
  end


  x509_certificate = cert.download
  certificate_type = (type == "dev" ? 'development' : 'production')

  base_base = bundle_id.gsub('.', '_')
  puts base_base
  filename_base = base_base + '_' + type
  
  
  private_key_path = File.join(output_path, "#{filename_base}.pkey")
  File.write(private_key_path, pkey.to_pem)
  puts "key: #{private_key_path}"


  p12_cert_path = File.join(output_path, "#{filename_base}.p12")
  p12 = OpenSSL::PKCS12.create('goodcert1', certificate_type, pkey, x509_certificate)
  File.write(p12_cert_path, p12.to_der)
  puts "p12 : #{p12_cert_path}"


  x509_cert_path = File.join(output_path, "#{filename_base}.pem")
  File.write(x509_cert_path, x509_certificate.to_pem + pkey.to_pem)
  puts "pem : #{x509_cert_path}"

  return x509_cert_path
end

#login(apple_id: nil) ⇒ Object



59
60
61
62
63
# File 'lib/pindo/module/cert/pemhelper.rb', line 59

def (apple_id:nil)
  puts apple_id
  Spaceship::Portal.(apple_id.to_s)
  Spaceship::Portal.select_team
end