Class: Fastlane::Actions::ExtractCertificateAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/xamarin_build/actions/extract_certificate.rb

Constant Summary collapse

PROVISIONS =
"#{Dir.home}/Library/MobileDevice/Provisioning\ Profiles/".freeze

Class Method Summary collapse

Class Method Details

.authorsObject



90
91
92
# File 'lib/fastlane/plugin/xamarin_build/actions/extract_certificate.rb', line 90

def self.authors
  ['punksta']
end

.available_optionsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fastlane/plugin/xamarin_build/actions/extract_certificate.rb', line 49

def self.available_options
  [
    FastlaneCore::ConfigItem.new(
      key: :provision_path,
      env_name: 'FL_EXTRACT_CERTIFICATE_PR_PATH',
      description: 'Path to provision profile',
      is_string: true,
      optional: true,
      verify_block: proc do |path|
                      check_profile(path)
                    end
    ),

    FastlaneCore::ConfigItem.new(
      key: :uuid,
      env_name: 'FL_EXTRACT_CERTIFICATE_UUID',
      description: 'UUID of provision profile in default dir',
      is_string: true,
      optional: true,
      verify_block: proc do |uuid|
        provision_path = default_path(uuid)
        check_profile(provision_path)
      end
    ),

    FastlaneCore::ConfigItem.new(
      key: :log_certificate,
      env_name: 'FL_EXTRACT_CERTIFICATE_LOG',
      description: 'Logging extracting certificate',
      optional: true,
      default_value: true,
      is_string: false
    )
  ]
end

.check_profile(file) ⇒ Object



39
40
41
42
43
# File 'lib/fastlane/plugin/xamarin_build/actions/extract_certificate.rb', line 39

def self.check_profile(file)
  UI.user_error!('Empty input') if file.nil?
  UI.user_error!("#{file} does not exist") unless File.exist? file
  UI.user_error!("#{file} is not a file") unless File.file? file
end

.default_path(uuid) ⇒ Object



45
46
47
# File 'lib/fastlane/plugin/xamarin_build/actions/extract_certificate.rb', line 45

def self.default_path(uuid)
  File.join PROVISIONS, "#{uuid}.mobileprovision"
end

.descriptionObject



30
31
32
# File 'lib/fastlane/plugin/xamarin_build/actions/extract_certificate.rb', line 30

def self.description
  'Extract certificate public key from provision profile'
end

.detailsObject



34
35
36
37
# File 'lib/fastlane/plugin/xamarin_build/actions/extract_certificate.rb', line 34

def self.details
  'You can use it to get info about signing certificate' \
    'like certificate name and id'
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/fastlane/plugin/xamarin_build/actions/extract_certificate.rb', line 94

def self.is_supported?(platform)
  [:ios, :mac].include?(platform)
end

.return_valueObject



85
86
87
88
# File 'lib/fastlane/plugin/xamarin_build/actions/extract_certificate.rb', line 85

def self.return_value
  'Returns OpenSSL::X509::Certificate object representing' \
    'signing certificate from provision profile'
end

.run(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fastlane/plugin/xamarin_build/actions/extract_certificate.rb', line 10

def self.run(params)
  path = params[:provision_path]
  path = default_path(params[:uuid]) if path.nil?
  check_profile(path)

  o, e, s = Open3.capture3("security cms -D -i '#{path}'")
  if s.exitstatus != 0
    UI.user_error!("Can't extract plist from provision profile\n" + e)
  end

  provision_plist_raw = o
  provision_plist = Plist.parse_xml(provision_plist_raw)

  cert_data = provision_plist['DeveloperCertificates'][0].string
  cert = OpenSSL::X509::Certificate.new(cert_data)

  print cert.to_text if params[:log_certificate]
  cert
end