Class: CredentialsManager::AppfileConfig

Inherits:
Object
  • Object
show all
Defined in:
credentials_manager/lib/credentials_manager/appfile_config.rb

Overview

Access the content of the app file (e.g. app identifier and Apple ID)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ AppfileConfig

Returns a new instance of AppfileConfig.


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
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 25

def initialize(path = nil)
  if path
    raise "Could not find Appfile at path '#{path}'".red unless File.exist?(File.expand_path(path))
  end

  path ||= self.class.default_path

  if path && File.exist?(path) # it might not exist, we still want to use the default values
    full_path = File.expand_path(path)
    Dir.chdir(File.expand_path('..', path)) do
      content = File.read(full_path, encoding: "utf-8")

      # From https://github.com/orta/danger/blob/master/lib/danger/danger_core/dangerfile.rb
      if content.tr!('“”‘’‛', %(""'''))
        puts("Your #{File.basename(path)} has had smart quotes sanitised. " \
             'To avoid issues in the future, you should not use ' \
             'TextEdit for editing it. If you are not using TextEdit, ' \
             'you should turn off smart quotes in your editor of choice.'.red)
      end

      # rubocop:disable Security/Eval
      eval(content)
      # rubocop:enable Security/Eval

      print_debug_information(path: full_path) if FastlaneCore::Globals.verbose?
    end
  end

  fallback_to_default_values
end

Class Method Details

.already_printed_debug_informationObject


73
74
75
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 73

def self.already_printed_debug_information
  @already_printed_debug_information ||= {}
end

.default_pathObject


18
19
20
21
22
23
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 18

def self.default_path
  ["./fastlane/Appfile", "./.fastlane/Appfile", "./Appfile"].each do |current|
    return current if File.exist?(current)
  end
  nil
end

.try_fetch_value(key) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 6

def self.try_fetch_value(key)
  # We need to load the file every time we call this method
  # to support the `for_lane` keyword
  begin
    return self.new.data[key]
  rescue => ex
    puts(ex.to_s)
    return nil
  end
  nil
end

Instance Method Details

#app_identifier(*args, &block) ⇒ Object

iOS


88
89
90
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 88

def app_identifier(*args, &block)
  setter(:app_identifier, *args, &block)
end

#apple_dev_portal_id(*args, &block) ⇒ Object


96
97
98
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 96

def apple_dev_portal_id(*args, &block)
  setter(:apple_dev_portal_id, *args, &block)
end

#apple_id(*args, &block) ⇒ Object


92
93
94
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 92

def apple_id(*args, &block)
  setter(:apple_id, *args, &block)
end

#dataObject


81
82
83
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 81

def data
  @data ||= {}
end

#fallback_to_default_valuesObject


77
78
79
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 77

def fallback_to_default_values
  data[:apple_id] ||= ENV["FASTLANE_USER"] || ENV["DELIVER_USER"] || ENV["DELIVER_USERNAME"]
end

#for_lane(lane_name) ⇒ Object

Override Appfile configuration for a specific lane.

lane_name - Symbol representing a lane name. (Can be either :name, 'name' or 'platform name') block - Block to execute to override configuration values.

Discussion If received lane name does not match the lane name available as environment variable, no changes will

be applied.

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 156

def for_lane(lane_name)
  if lane_name.to_s.split(" ").count > 1
    # That's the legacy syntax 'platform name'
    puts("You use deprecated syntax '#{lane_name}' in your Appfile.".yellow)
    puts("Please follow the Appfile guide: https://docs.fastlane.tools/advanced/#appfile".yellow)
    platform, lane_name = lane_name.split(" ")

    return unless platform == ENV["FASTLANE_PLATFORM_NAME"]
    # the lane name will be verified below
  end

  if ENV["FASTLANE_LANE_NAME"] == lane_name.to_s
    yield
  end
end

#for_platform(platform_name) ⇒ Object

Override Appfile configuration for a specific platform.

platform_name - Symbol representing a platform name. block - Block to execute to override configuration values.

Discussion If received platform name does not match the platform name available as environment variable, no changes will

be applied.

179
180
181
182
183
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 179

def for_platform(platform_name)
  if ENV["FASTLANE_PLATFORM_NAME"] == platform_name.to_s
    yield
  end
end

#issuer(*args, &block) ⇒ Object


135
136
137
138
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 135

def issuer(*args, &block)
  puts("Appfile: DEPRECATED issuer: use json_key_file instead".red)
  setter(:issuer, *args, &block)
end

#itc_provider(*args, &block) ⇒ Object


122
123
124
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 122

def itc_provider(*args, &block)
  setter(:itc_provider, *args, &block)
end

#itc_team_id(*args, &block) ⇒ Object

App Store Connect


114
115
116
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 114

def itc_team_id(*args, &block)
  setter(:itc_team_id, *args, &block)
end

#itc_team_name(*args, &block) ⇒ Object


118
119
120
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 118

def itc_team_name(*args, &block)
  setter(:itc_team_name, *args, &block)
end

#itunes_connect_id(*args, &block) ⇒ Object


100
101
102
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 100

def itunes_connect_id(*args, &block)
  setter(:itunes_connect_id, *args, &block)
end

#json_key_data_raw(*args, &block) ⇒ Object


131
132
133
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 131

def json_key_data_raw(*args, &block)
  setter(:json_key_data_raw, *args, &block)
end

#json_key_file(*args, &block) ⇒ Object

Android


127
128
129
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 127

def json_key_file(*args, &block)
  setter(:json_key_file, *args, &block)
end

#keyfile(*args, &block) ⇒ Object


144
145
146
147
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 144

def keyfile(*args, &block)
  puts("Appfile: DEPRECATED keyfile: use json_key_file instead".red)
  setter(:keyfile, *args, &block)
end

#package_name(*args, &block) ⇒ Object


140
141
142
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 140

def package_name(*args, &block)
  setter(:package_name, *args, &block)
end

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 56

def print_debug_information(path: nil)
  self.class.already_printed_debug_information ||= {}
  return if self.class.already_printed_debug_information[self.data]
  # self.class.already_printed_debug_information is a hash, we use to detect if we already printed this data
  # this is necessary, as on the course of a fastlane run, the values might change, e.g. when using
  # the `for_lane` keyword.

  puts("Successfully loaded Appfile at path '#{path}'".yellow)

  self.data.each do |key, value|
    puts("- #{key.to_s.cyan}: '#{value.to_s.green}'")
  end
  puts("-------")

  self.class.already_printed_debug_information[self.data] = true
end

#team_id(*args, &block) ⇒ Object

Developer Portal


105
106
107
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 105

def team_id(*args, &block)
  setter(:team_id, *args, &block)
end

#team_name(*args, &block) ⇒ Object


109
110
111
# File 'credentials_manager/lib/credentials_manager/appfile_config.rb', line 109

def team_name(*args, &block)
  setter(:team_name, *args, &block)
end