fastlane-plugin-google_data_safety 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +52 -0
- data/lib/fastlane/plugin/google_data_safety/actions/upload_google_data_safety_action.rb +184 -0
- data/lib/fastlane/plugin/google_data_safety/helper/upload_google_data_safety_helper.rb +16 -0
- data/lib/fastlane/plugin/google_data_safety/version.rb +5 -0
- data/lib/fastlane/plugin/google_data_safety.rb +16 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 40b801d950ef2c54b5dff6015bf2ff90f77b502c509408c8bd51538c0eca0948
|
4
|
+
data.tar.gz: f469686cb3772ab11d328d4891b8e8e4aa30a7a744de9e94b99919d68822495a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d65d43564f78fcc032356047b3ae7a6053d3fadae44d78ab8d92c26b786e8799d27c71d021b7acb5528544477cb8a878a5e3c6e9e32413be0c287e3e57ed7576
|
7
|
+
data.tar.gz: 600b3413608be49ff72fcd0abd115a452c0a8e862f11d9c9ed0fd95e6e37ebf4dba98eb952c91a8a33712d01a08e7891f30ead1f22527cd0d540dd78ff859886
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Owen Bean <owenbean400@gmail.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# google_data_safety plugin
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/fastlane-plugin-data_safety)
|
4
|
+
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-google_data_safety`, add it to your project by running:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
fastlane add_plugin google_data_safety
|
11
|
+
```
|
12
|
+
|
13
|
+
## About google_data_safety
|
14
|
+
|
15
|
+
Google safety data sheet for automation of safety form
|
16
|
+
|
17
|
+
**Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here.
|
18
|
+
|
19
|
+
## Example
|
20
|
+
|
21
|
+
Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
|
22
|
+
|
23
|
+
**Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
|
24
|
+
|
25
|
+
## Run tests for this plugin
|
26
|
+
|
27
|
+
To run both the tests, and code style validation, run
|
28
|
+
|
29
|
+
```
|
30
|
+
rake
|
31
|
+
```
|
32
|
+
|
33
|
+
To automatically fix many of the styling issues, use
|
34
|
+
```
|
35
|
+
rubocop -a
|
36
|
+
```
|
37
|
+
|
38
|
+
## Issues and Feedback
|
39
|
+
|
40
|
+
For any other issues and feedback about this plugin, please submit it to this repository.
|
41
|
+
|
42
|
+
## Troubleshooting
|
43
|
+
|
44
|
+
If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
|
45
|
+
|
46
|
+
## Using _fastlane_ Plugins
|
47
|
+
|
48
|
+
For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
|
49
|
+
|
50
|
+
## About _fastlane_
|
51
|
+
|
52
|
+
_fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
|
@@ -0,0 +1,184 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require 'googleauth'
|
3
|
+
require_relative '../helper/upload_google_data_safety_helper'
|
4
|
+
require 'net/http'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module Fastlane
|
8
|
+
module Actions
|
9
|
+
class UploadGoogleDataSafetyAction < Action
|
10
|
+
def self.run(params)
|
11
|
+
|
12
|
+
csv_content = self.csv_file_content(params: params)
|
13
|
+
|
14
|
+
service_account_data = self.service_account_authentication(params: params)
|
15
|
+
|
16
|
+
body = self.get_google_auth(service_account_json: service_account_data)
|
17
|
+
|
18
|
+
access_token = body["access_token"]
|
19
|
+
|
20
|
+
self.send_data_safety_sheet(package_name: params[:package_name], auth_token: access_token, csv_content: csv_content)
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.csv_file_content(params: nil)
|
25
|
+
unless params[:csv_file] || params[:csv_content]
|
26
|
+
if UI.interactive?
|
27
|
+
UI.important("To not be asked about this value, you can specify it using 'csv_file'")
|
28
|
+
csv_file_path = UI.input("The csv file used for Google data safety sheet: ")
|
29
|
+
csv_file_path = File.expand_path(csv_file_path)
|
30
|
+
|
31
|
+
UI.user_error!("Could not find csv file at path '#{csv_file_path}'") unless File.exist?(csv_file_path)
|
32
|
+
params[:csv_file]
|
33
|
+
else
|
34
|
+
UI.user_error!("Could not obtain data safety information as comma separated values. Please have 'csv_file' or 'csv_content' variable set.")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
csv_file_content = ""
|
39
|
+
|
40
|
+
if params[:csv_file]
|
41
|
+
csv_file_content = File.read(File.expand_path(params[:csv_file]))
|
42
|
+
elsif params[:csv_content]
|
43
|
+
csv_file_content = params[:csv_content]
|
44
|
+
end
|
45
|
+
|
46
|
+
csv_file_content
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.service_account_authentication(params: nil)
|
50
|
+
unless params[:json_key] || params[:json_key_data]
|
51
|
+
if UI.interactive?
|
52
|
+
UI.important("To not be asked about this value, you can specify it using 'json_key'")
|
53
|
+
json_key_path = UI.input("The service account json file used to authenticate with Google: ")
|
54
|
+
json_key_path = File.expand_path(json_key_path)
|
55
|
+
|
56
|
+
UI.user_error!("Could not find service account json file at path '#{json_key_path}'") unless File.exist?(json_key_path)
|
57
|
+
params[:json_key] = json_key_path
|
58
|
+
else
|
59
|
+
UI.user_error!("Could not load Google authentication. Make sure it has been added as an environment variable in 'json_key' or 'json_key_data'")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if params[:json_key]
|
64
|
+
service_account_json = File.open(File.expand_path(params[:json_key]))
|
65
|
+
elsif params[:json_key_data]
|
66
|
+
service_account_json = StringIO.new(params[:json_key_data])
|
67
|
+
end
|
68
|
+
|
69
|
+
service_account_json
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.get_google_auth(service_account_json: nil)
|
73
|
+
scope = 'https://www.googleapis.com/auth/androidpublisher'
|
74
|
+
|
75
|
+
auth = Google::Auth::ServiceAccountCredentials.make_creds(json_key_io: service_account_json, scope: scope)
|
76
|
+
|
77
|
+
token = auth.fetch_access_token!
|
78
|
+
|
79
|
+
token
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.send_data_safety_sheet(package_name: nil, auth_token: nil, csv_content: nil)
|
83
|
+
if package_name.nil?
|
84
|
+
if UI.interactive?
|
85
|
+
UI.important("To not be asked package name, you can specify it using 'package_name'.")
|
86
|
+
package_name_input = UI.input("The package name to upload Google safety data sheet: ")
|
87
|
+
package_name = package_name_input
|
88
|
+
else
|
89
|
+
UI.Error("Package name is required to upload Google safety data sheet. Please specify package name with 'package_name' variable.")
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
uri = URI("https://androidpublisher.googleapis.com/androidpublisher/v3/applications/#{package_name}/dataSafety")
|
94
|
+
|
95
|
+
request = Net::HTTP::Post.new(uri)
|
96
|
+
request["Authorization"] = "Bearer #{auth_token}"
|
97
|
+
request["Content-Type"] = "application/json"
|
98
|
+
request.body = { safetyLabels: csv_content }.to_json
|
99
|
+
|
100
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme = 'https') do | http |
|
101
|
+
http.request(request)
|
102
|
+
end
|
103
|
+
|
104
|
+
if response.is_a?(Net::HTTPSuccess)
|
105
|
+
UI.success("Google Safety Data sheet has been uploaded!")
|
106
|
+
else
|
107
|
+
if response.is_a?(Net::HTTPUnauthorized)
|
108
|
+
UI.error("Unauthorized request to upload Google Data Safety sheet.")
|
109
|
+
elsif response.is_a?(Net::HTTPBadRequest)
|
110
|
+
UI.error("Bad request to upload Google Data Safety sheet.")
|
111
|
+
else
|
112
|
+
UI.error("Google Data Safety sheet upload error with API")
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.description
|
119
|
+
"Google safety data sheet for automation of safety form"
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.authors
|
123
|
+
["Owen Bean"]
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.return_value
|
127
|
+
# If your method provides a return value, you can describe here what it does
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.details
|
131
|
+
# Optional:
|
132
|
+
"Uploads and update any data safety sheet on Google Play Console API."
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.available_options
|
136
|
+
[
|
137
|
+
FastlaneCore::ConfigItem.new(
|
138
|
+
key: :csv_file,
|
139
|
+
env_name: "CSV_FILE",
|
140
|
+
description: "Csv file path to upload to Google Play Console Data Safety",
|
141
|
+
optional: true,
|
142
|
+
type: String
|
143
|
+
),
|
144
|
+
FastlaneCore::ConfigItem.new(
|
145
|
+
key: :csv_content,
|
146
|
+
env_name: "CSV_CONTENT",
|
147
|
+
description: "Comma delimited list of Google Data Safety form",
|
148
|
+
optional: true,
|
149
|
+
type: String
|
150
|
+
),
|
151
|
+
FastlaneCore::ConfigItem.new(
|
152
|
+
key: :package_name,
|
153
|
+
env_name: "PACKAGE_NAME",
|
154
|
+
description: "Package name of project",
|
155
|
+
optional: false,
|
156
|
+
type: String
|
157
|
+
),
|
158
|
+
FastlaneCore::ConfigItem.new(
|
159
|
+
key: :json_key,
|
160
|
+
env_name: "JSON_KEY_FILE",
|
161
|
+
description: "Json key file for service account authentication",
|
162
|
+
optional: true,
|
163
|
+
type: String
|
164
|
+
),
|
165
|
+
FastlaneCore::ConfigItem.new(
|
166
|
+
key: :json_key_data,
|
167
|
+
env_name: "JSON_KEY_DATA",
|
168
|
+
description: "Json key data for service account authentication",
|
169
|
+
optional: true,
|
170
|
+
type: Hash
|
171
|
+
),
|
172
|
+
]
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.is_supported?(platform)
|
176
|
+
# Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
|
177
|
+
# See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
|
178
|
+
#
|
179
|
+
# [:ios, :mac, :android].include?(platform)
|
180
|
+
true
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fastlane_core/ui/ui'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
|
5
|
+
|
6
|
+
module Helper
|
7
|
+
class GoogleDataSafetyHelper
|
8
|
+
# class methods that you define here become available in your action
|
9
|
+
# as `Helper::DataSafetyHelper.your_method`
|
10
|
+
#
|
11
|
+
def self.show_message
|
12
|
+
UI.message("Hello from the data_safety plugin helper!")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fastlane/plugin/google_data_safety/version'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module GoogleDataSafety
|
5
|
+
# Return all .rb files inside the "actions" and "helper" directory
|
6
|
+
def self.all_classes
|
7
|
+
Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# By default we want to import all available actions and helpers
|
13
|
+
# A plugin can contain any number of actions and plugins
|
14
|
+
Fastlane::GoogleDataSafety.all_classes.each do |current|
|
15
|
+
require current
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fastlane-plugin-google_data_safety
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Owen Bean
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: googleauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.1
|
27
|
+
description:
|
28
|
+
email: owenbean400@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- LICENSE
|
34
|
+
- README.md
|
35
|
+
- lib/fastlane/plugin/google_data_safety.rb
|
36
|
+
- lib/fastlane/plugin/google_data_safety/actions/upload_google_data_safety_action.rb
|
37
|
+
- lib/fastlane/plugin/google_data_safety/helper/upload_google_data_safety_helper.rb
|
38
|
+
- lib/fastlane/plugin/google_data_safety/version.rb
|
39
|
+
homepage:
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
rubygems_mfa_required: 'true'
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.6'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.0.3.1
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: Google safety data sheet for automation of safety form
|
63
|
+
test_files: []
|