Class: CredentialsManager::AppfileConfig

Inherits:
Object
  • Object
show all
Defined in:
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.



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

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

  path ||= self.class.default_path

  if path and 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)

      # From https://github.com/orta/danger/blob/master/lib/danger/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 Lint/Eval
      eval(content)
      # rubocop:enable Lint/Eval
    end
  end

  fallback_to_default_values
end

Class Method Details

.default_pathObject



15
16
17
18
19
20
# File 'lib/credentials_manager/appfile_config.rb', line 15

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



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

def self.try_fetch_value(key)
  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



62
63
64
# File 'lib/credentials_manager/appfile_config.rb', line 62

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

#apple_dev_portal_id(*args, &block) ⇒ Object



70
71
72
# File 'lib/credentials_manager/appfile_config.rb', line 70

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

#apple_id(*args, &block) ⇒ Object



66
67
68
# File 'lib/credentials_manager/appfile_config.rb', line 66

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

#dataObject



55
56
57
# File 'lib/credentials_manager/appfile_config.rb', line 55

def data
  @data ||= {}
end

#fallback_to_default_valuesObject



51
52
53
# File 'lib/credentials_manager/appfile_config.rb', line 51

def fallback_to_default_values
  data[:apple_id] ||= ENV["FASTLANE_USER"] || ENV["DELIVER_USER"]
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.


122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/credentials_manager/appfile_config.rb', line 122

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://github.com/fastlane/fastlane/blob/master/docs/Appfile.md".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 paltform name does not match the platform name available as environment variable, no changes will

be applied.


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

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

#issuer(*args, &block) ⇒ Object



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

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

#itc_team_id(*args, &block) ⇒ Object

iTunes Connect



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

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

#itc_team_name(*args, &block) ⇒ Object



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

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

#itunes_connect_id(*args, &block) ⇒ Object



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

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

#json_key_file(*args, &block) ⇒ Object

Android



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

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

#keyfile(*args, &block) ⇒ Object



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

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

#package_name(*args, &block) ⇒ Object



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

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

#team_id(*args, &block) ⇒ Object

Developer Portal



79
80
81
# File 'lib/credentials_manager/appfile_config.rb', line 79

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

#team_name(*args, &block) ⇒ Object



83
84
85
# File 'lib/credentials_manager/appfile_config.rb', line 83

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