Class: Fastlane::Actions::VerifyTwoStepSessionAction

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

Documentation collapse

Class Method Summary collapse

Class Method Details

.authorsObject



88
89
90
# File 'lib/fastlane/plugin/verify_two_step_session/actions/verify_two_step_session_action.rb', line 88

def self.authors
  ["thasegaw"]
end

.available_optionsObject



79
80
81
82
83
84
85
86
# File 'lib/fastlane/plugin/verify_two_step_session/actions/verify_two_step_session_action.rb', line 79

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :user,
                                 env_name: "FL_VERIFY_TWO_STEP_SESSION_USER",
                                 description: "User for Two-Step verification for Apple ID (email address)",
                                 optional: true)
  ]
end

.categoryObject



102
103
104
# File 'lib/fastlane/plugin/verify_two_step_session/actions/verify_two_step_session_action.rb', line 102

def self.category
  :misc
end

.check_expiration_time(cookie) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/verify_two_step_session/actions/verify_two_step_session_action.rb', line 40

def self.check_expiration_time(cookie)
  cookie.each do |content|
    next unless content.domain == 'idmsa.apple.com' && content.max_age.to_s.length > 0
    next unless content.created_at.to_s =~ /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/
    require 'time'
    time = Time.parse(content.created_at.to_s)
    created_date = time.getutc
    expiration_date = created_date + content.max_age
    remaining_sec = expiration_date - Time.now.utc
    remaining_hours = (remaining_sec / (60 * 60)).floor
    local_expiration_date = expiration_date.getlocal

    if remaining_hours >= 48
      remaining_days = remaining_hours / 24
      UI.important("Your session cookie will expire at #{local_expiration_date} (#{remaining_days} days left).")
    else
      UI.important("Your session cookie will expire at #{local_expiration_date} (#{remaining_hours} hours left).")
    end

    UI.error("Your session cookie is due to expire today!") if remaining_hours <= 24
    break
  end
end

.descriptionObject



68
69
70
# File 'lib/fastlane/plugin/verify_two_step_session/actions/verify_two_step_session_action.rb', line 68

def self.description
  "Verifies the session cookie for 'Two-Step verification for Apple ID'"
end

.detailsObject



72
73
74
75
76
77
# File 'lib/fastlane/plugin/verify_two_step_session/actions/verify_two_step_session_action.rb', line 72

def self.details
  [
    "This action will validate the session cookie for 'Two-Step verification for Apple ID'",
    "and display the remaining days until an expiration date."
  ].join(' ')
end

.example_codeObject



96
97
98
99
100
# File 'lib/fastlane/plugin/verify_two_step_session/actions/verify_two_step_session_action.rb', line 96

def self.example_code
  [
    'verify_two_step_session(user: [email protected])'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/fastlane/plugin/verify_two_step_session/actions/verify_two_step_session_action.rb', line 92

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

.run(params) ⇒ Object



4
5
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
# File 'lib/fastlane/plugin/verify_two_step_session/actions/verify_two_step_session_action.rb', line 4

def self.run(params)
  user = params[:user] || ENV["FASTLANE_USER"] || ENV["DELIVER_USER"] || ENV["DELIVER_USERNAME"]

  begin
    Spaceship::Tunes.(user)
  rescue Spaceship::Client::InvalidUserCredentialsError => e
    # Invalid username and password combination
    UI.user_error!(e.message)
  rescue StandardError
    UI.user_error!('Your session cookie has been expired.')
  end

  UI.success('Login successful')

  cookie = nil
  if Spaceship::Tunes.client.load_session_from_file
    require 'yaml'
    cookie = YAML.safe_load(
      File.read(Spaceship::Tunes.client.persistent_cookie_path),
      [HTTP::Cookie, Time], # classes whitelist
      [],                   # symbols whitelist
      true                  # allow YAML aliases
    )
  end

  # If this is a CI, the user can pass the session via environment variable
  if Spaceship::Tunes.client.load_session_from_env
    cookie = Spaceship::Tunes.client.load_session_from_env
  end

  # user does not use 2 step verification
  return if cookie.nil?

  check_expiration_time(cookie)
end