Class: Fastlane::Actions::CheckPushCertificateAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



51
52
53
# File 'lib/fastlane/plugin/push_cert_alert/actions/check_push_certificate_action.rb', line 51

def self.authors
  ["Nico Richard"]
end

.available_optionsObject



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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/fastlane/plugin/push_cert_alert/actions/check_push_certificate_action.rb', line 55

def self.available_options
  user = CredentialsManager::AppfileConfig.try_fetch_value(:apple_dev_portal_id)
  user ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)

  [
    FastlaneCore::ConfigItem.new(key: :expires_soon,
                                 description: "Block that is called if the profile expires in less than the `active_days_limit`. Called with `certificate, days_remaining`",
                                 optional: true,
                                 type: Proc),
    FastlaneCore::ConfigItem.new(key: :expired,
                                 description: "Block that is called if the profile is expired. Called with empty params",
                                 optional: true,
                                 type: Proc),
    FastlaneCore::ConfigItem.new(key: :active_days_limit,
                                 env_name: "PEM_ACTIVE_DAYS_LIMIT",
                                 description: "If the current certificate is active for less than this number of days, generate a new one",
                                 default_value: 30,
                                 is_string: false,
                                 type: Integer,
                                 verify_block: proc do |value|
                                   UI.user_error!("Value of active_days_limit must be a positive integer or left blank") unless value.kind_of?(Integer) && value > 0
                                 end),          
    # Spaceship Certificate Fetching
    FastlaneCore::ConfigItem.new(key: :development,
                                 env_name: "PEM_DEVELOPMENT",
                                 description: "Renew the development push certificate instead of the production one",
                                 is_string: false,
                                 default_value: false),
    FastlaneCore::ConfigItem.new(key: :website_push,
                                 env_name: "PEM_WEBSITE_PUSH",
                                 description: "Create a Website Push certificate",
                                 is_string: false,
                                 conflicting_options: [:development],
                                 default_value: false),          
    FastlaneCore::ConfigItem.new(key: :app_identifier,
                                 short_option: "-a",
                                 env_name: "PEM_APP_IDENTIFIER",
                                 description: "The bundle identifier of your app",
                                 code_gen_sensitive: true,
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier),
                                 default_value_dynamic: true),
    FastlaneCore::ConfigItem.new(key: :username,
                                 short_option: "-u",
                                 env_name: "PEM_USERNAME",
                                 description: "Your Apple ID Username",
                                 default_value: user,
                                 default_value_dynamic: true),
    FastlaneCore::ConfigItem.new(key: :team_id,
                                 short_option: "-b",
                                 env_name: "PEM_TEAM_ID",
                                 code_gen_sensitive: true,
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:team_id),
                                 default_value_dynamic: true,
                                 description: "The ID of your Developer Portal team if you're in multiple teams",
                                 optional: true,
                                 verify_block: proc do |value|
                                   ENV["FASTLANE_TEAM_ID"] = value.to_s
                                 end),
    # Slack
    FastlaneCore::ConfigItem.new(key: :skip_slack,
                                 description: "Skip sending an alert to Slack",
                                 optional: true,
                                 type: Boolean,
                                 default_value: false),          
    FastlaneCore::ConfigItem.new(key: :slack_url,
                                 short_option: "-i",
                                 env_name: "SLACK_URL",
                                 sensitive: true,
                                 description: "Create an Incoming WebHook for your Slack group to post results there",
                                 optional: true,
                                 verify_block: proc do |value|
                                   if !value.to_s.empty? && !value.start_with?("https://")
                                     UI.user_error!("Invalid URL, must start with https://")
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :slack_channel,
                                 short_option: "-e",
                                 env_name: "SCAN_SLACK_CHANNEL",
                                 description: "#channel or @username",
                                 optional: true)
  ]
end

.descriptionObject



47
48
49
# File 'lib/fastlane/plugin/push_cert_alert/actions/check_push_certificate_action.rb', line 47

def self.description
  "Easily create alerts for your APNS push certificate expiration"
end

.example_codeObject



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/fastlane/plugin/push_cert_alert/actions/check_push_certificate_action.rb', line 142

def self.example_code
  [
    <<-CODE
      check_push_certificate(
        active_days_limit: 60,
        expires_soon: proc do |cert, days|
          puts "#{days} days to live!"
        end,
        expired: proc do
          puts "UH OH!!! Our push cert may be expired!"
        end
      )
    CODE
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/fastlane/plugin/push_cert_alert/actions/check_push_certificate_action.rb', line 138

def self.is_supported?(platform)
  platform == :ios
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/push_cert_alert/actions/check_push_certificate_action.rb', line 9

def self.run(params)
  Helper::Login.(params)

  UI.message("Attempting to fetch existing an existing push certificate.")

  existing_certificate = Helper::Certificate.existing_certificate(params)
  remaining_days = existing_certificate ? Helper::Certificate.remaining_days(existing_certificate) : 0

  if existing_certificate and remaining_days > 0
    UI.message("The push notification profile for '#{existing_certificate.owner_name}' is valid for #{remaining_days.round} days")

    if remaining_days < params[:active_days_limit]
      UI.message("The push notification profile is valid for less than the limit of #{params[:active_days_limit]} days")

      params[:expires_soon].call(existing_certificate, remaining_days) if params[:expires_soon]

      Helper::Slack.slack(
        message: "An APNS push certificate expires in #{remaining_days} days",
        certificate: existing_certificate,
        params: params
      ) if not params[:skip_slack]
    end
  else
    if existing_certificate
      UI.message("The push notification profile has expired")
    else
      UI.message("A push notification profile cannot be found")
    end

    params[:expired].call() if params[:expired]

    Helper::PushCertAlertSlackHelper.slack(
      message: "An APNS push certificate has expired or cannot be found",
      params: params
    ) if not params[:skip_slack]
  end
end