Class: Fastlane::Flint::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/flint/helper/generator.rb

Overview

Generate missing resources

Class Method Summary collapse

Class Method Details

.generate_keystore(params, keystore_name, alias_name, password) ⇒ Object



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
# File 'lib/fastlane/plugin/flint/helper/generator.rb', line 8

def self.generate_keystore(params, keystore_name, alias_name, password)
  # Ensure output dir exists
  output_dir = File.join(params[:workspace], "certs")
  FileUtils.mkdir_p output_dir
  output_path = File.join(output_dir, keystore_name)

  full_name = params[:full_name]
  org = params[:orgization]
  org_unit = params[:orgization_unit]
  city_locality = params[:city]
  state_province = params[:state]
  country = params[:country]
  valid_days = 10000 # > 27 years

  cmd = "keytool -genkey -v -keystore %s -alias %s " % [output_path, alias_name]
  cmd << "-keyalg RSA -keysize 2048 -validity %s -keypass %s -storepass %s " % [valid_days, password, password]
  cmd << "-dname \"CN=#{full_name}, OU=#{org_unit}, O=#{org}, L=#{city_locality}, S=#{state_province}, C=#{country}\""

  begin
    output = IO.popen(cmd)
    error = output.read
    output.close
    raise error unless $?.exitstatus == 0
  rescue => ex
    raise ex
  end

  return output_path
end

.update_keystore_password(workspace, keystore_name, alias_name, password, new_password) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fastlane/plugin/flint/helper/generator.rb', line 38

def self.update_keystore_password(workspace, keystore_name, alias_name, password, new_password)
  output_dir = File.join(workspace, "certs")
  output_path = File.join(output_dir, keystore_name)

  if File.file?(output_path)
    cmd = "keytool -storepasswd -v -keystore %s -storepass %s -new %s" % [output_path, password, new_password]
    begin
      output = IO.popen(cmd)
      error = output.read
      output.close
      raise error unless $?.exitstatus == 0
    rescue => ex
      raise ex
    end

    cmd = "keytool -keypasswd -v -keystore %s -alias %s -keypass %s -storepass %s -new %s" % [
      output_path, alias_name, password, new_password, new_password]

    begin
      output = IO.popen(cmd)
      error = output.read
      output.close
      raise error unless $?.exitstatus == 0
    rescue => ex
      raise ex
    end
  else
    UI.message("output_path does not exist %s" % output_path)
  end
end