Class: Fastlane::Actions::DownloadAppPrivacyDetailsFromAppStoreAction

Inherits:
Fastlane::Action
  • Object
show all
Defined in:
fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb

Constant Summary collapse

DEFAULT_PATH =
Fastlane::Helper.fastlane_enabled_folder_path
DEFAULT_FILE_NAME =
"app_privacy_details.json"

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, deprecated_notes, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



109
110
111
# File 'fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb', line 109

def self.author
  "igor-makarov"
end

.available_optionsObject



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
# File 'fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb', line 68

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

  [
    FastlaneCore::ConfigItem.new(key: :username,
                                 env_name: "FASTLANE_USER",
                                 description: "Your Apple ID Username for App Store Connect",
                                 default_value: user,
                                 default_value_dynamic: true),
    FastlaneCore::ConfigItem.new(key: :app_identifier,
                                 env_name: "UPLOAD_APP_PRIVACY_DETAILS_TO_APP_STORE_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: :team_id,
                                 env_name: "FASTLANE_ITC_TEAM_ID",
                                 description: "The ID of your App Store Connect team if you're in multiple teams",
                                 optional: true,
                                 skip_type_validation: true, # as we also allow integers, which we convert to strings anyway
                                 code_gen_sensitive: true,
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:itc_team_id),
                                 default_value_dynamic: true),
    FastlaneCore::ConfigItem.new(key: :team_name,
                                 env_name: "FASTLANE_ITC_TEAM_NAME",
                                 description: "The name of your App Store Connect team if you're in multiple teams",
                                 optional: true,
                                 code_gen_sensitive: true,
                                 default_value: CredentialsManager::AppfileConfig.try_fetch_value(:itc_team_name),
                                 default_value_dynamic: true),

    # JSON paths
    FastlaneCore::ConfigItem.new(key: :output_json_path,
                                 env_name: "UPLOAD_APP_PRIVACY_DETAILS_TO_APP_STORE_OUTPUT_JSON_PATH",
                                 description: "Path to the app usage data JSON file generated by interactive questions",
                                 conflicting_options: [:skip_json_file_saving],
                                 default_value: File.join(DEFAULT_PATH, DEFAULT_FILE_NAME))
  ]
end

.categoryObject



137
138
139
# File 'fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb', line 137

def self.category
  :production
end

.descriptionObject



64
65
66
# File 'fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb', line 64

def self.description
  "Download App Privacy Details from an app in App Store Connect"
end

.detailsObject



117
118
119
# File 'fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb', line 117

def self.details
  "Download App Privacy Details from an app in App Store Connect. For more detail information, view https://docs.fastlane.tools/uploading-app-privacy-details"
end

.download_app_data_usages(params, app) ⇒ Object



57
58
59
60
61
62
# File 'fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb', line 57

def self.download_app_data_usages(params, app)
  UI.message("Downloading App Data Usage")

  # Delete all existing usages for new ones
  Spaceship::ConnectAPI::AppDataUsage.all(app_id: app.id, includes: "category,grouping,purpose,dataProtection", limit: 500)
end

.example_codeObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb', line 121

def self.example_code
  [
    'download_app_privacy_details_from_app_store(
      username: "[email protected]",
      team_name: "Your Team",
      app_identifier: "com.your.bundle"
    )',
    'download_app_privacy_details_from_app_store(
      username: "[email protected]",
      team_name: "Your Team",
      app_identifier: "com.your.bundle",
      output_json_path: "fastlane/app_data_usages.json"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



113
114
115
# File 'fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb', line 113

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

.output_path(params) ⇒ Object



52
53
54
55
# File 'fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb', line 52

def self.output_path(params)
  path = params[:output_json_path]
  return File.absolute_path(path)
end

.run(params) ⇒ Object



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
39
40
41
42
43
44
45
46
47
48
49
50
# File 'fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb', line 7

def self.run(params)
  require 'spaceship'

  # Prompts select team if multiple teams and none specified
  UI.message("Login to App Store Connect (#{params[:username]})")
  Spaceship::ConnectAPI.(params[:username], use_portal: false, use_tunes: true, tunes_team_id: params[:team_id], team_name: params[:team_name])
  UI.message("Login successful")

  # Get App
  app = Spaceship::ConnectAPI::App.find(params[:app_identifier])
  unless app
    UI.user_error!("Could not find app with bundle identifier '#{params[:app_identifier]}' on account #{params[:username]}")
  end

  # Download usages and return a config
  raw_usages = download_app_data_usages(params, app)

  usages_config = []
  if raw_usages.count == 1 && raw_usages.first.data_protection.id == Spaceship::ConnectAPI::AppDataUsageDataProtection::ID::DATA_NOT_COLLECTED
    usages_config << {
      "data_protections" => [Spaceship::ConnectAPI::AppDataUsageDataProtection::ID::DATA_NOT_COLLECTED]
    }
  else
    grouped_usages = raw_usages.group_by do |usage|
      usage.category.id
    end
    grouped_usages.sort_by(&:first).each do |key, usage_group|
      purposes = usage_group.map(&:purpose).compact || []
      data_protections = usage_group.map(&:data_protection).compact || []
      usages_config << {
        "category" => key,
        "purposes" => purposes.map(&:id).sort.uniq,
        "data_protections" => data_protections.map(&:id).sort.uniq
      }
    end
  end

  # Save to JSON file
  json = JSON.pretty_generate(usages_config)
  path = output_path(params)

  UI.message("Writing file to #{path}")
  File.write(path, json)
end