pprof 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d476948086afa6ea5bb7de05378c7e384bf85b14a42f083c2850b5b497ce0f45
4
- data.tar.gz: 158efbc09babce572ced4074c231793af16ed2c7db3567bd5b60fb1c8c7a66b0
3
+ metadata.gz: f7691660bb69c7c6f6f4fedb4722dc0e647183378e5aa79cfa0ce2a80f7e4cef
4
+ data.tar.gz: ae54346cc1d76c10a89468b605a698727ff38909f683bed7ff8a6d779c6605b0
5
5
  SHA512:
6
- metadata.gz: 224f0d480b357a04a6e3dc2e13f1962b337b100ee599fd36a9a937060056cba90f7fcdf49080b87334ad79d62a61a4e80d817737c7680725e6ded84f506580b2
7
- data.tar.gz: 04b13e78ae4a7b133d21c5786bb9f4bd4ccb4238bff33b3007bcf11dfe520b26af4157168883a7456766f93ad9efa9ed37087a0b5cb8ad5cf9d64ec4e4b91efb
6
+ metadata.gz: 9b2490137336562c025610bbfc7de8b0fe1a177005b9a7c7cfea21310fedb3f77164745303dc08b1816d3e8dd5a0f7a5aaa71373a71c784921982d36da4e876f
7
+ data.tar.gz: 22665cd4ba32a996577a8ed8099348f29193fb88589a32b1faaf8ca03298a971902373d23cdad568c59a1b6e23f59f81e3c0a3e543e8173c18ddd71f098379a5
data/bin/pprof CHANGED
@@ -64,6 +64,9 @@ parser = OptionParser.new do |opts|
64
64
  opts.on('-p', '--path', 'Print only the paths, one per line (instead of an ASCII table)') do
65
65
  list_options[:mode] = :path
66
66
  end
67
+ opts.on('-j', '--json', 'Print the output information as a JSON') do
68
+ list_options[:mode] = :json
69
+ end
67
70
  opts.on('-0', '--print0', 'Separate each found entry by \\0, to be used by `xargs -0`') do
68
71
  list_options[:zero] = true
69
72
  end
@@ -156,9 +159,12 @@ else
156
159
  begin
157
160
  # Print info about given profile path/UUID
158
161
  p = PProf::ProvisioningProfile.new(ARGV[0])
159
-
160
162
  options = { info: true } if options.empty?
161
- o.print_info(p, options)
163
+ if list_options[:mode] == :json
164
+ o.print_json(p, options)
165
+ else
166
+ o.print_info(p, options)
167
+ end
162
168
  rescue StandardError => e
163
169
  o.print_error(e, ARGV[0])
164
170
  end
@@ -1,9 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+
3
5
  # Module for the pprof tool to manipulate Provisioning Profiles
4
6
  module PProf
5
7
  # A helper tool to pretty-print Provisioning Profile informations
6
8
  class OutputFormatter
9
+ # List of properties of a `PProf::ProvisioningProfile` to print when using the `-i` flag
10
+ MAIN_PROFILE_KEYS = %i[name uuid app_id_name app_id_prefix creation_date expiration_date ttl team_ids team_name]
11
+
7
12
  # Initialize a new OutputFormatter
8
13
  #
9
14
  # @param [IO] output
@@ -63,8 +68,7 @@ module PProf
63
68
  def print_info(profile, options = nil)
64
69
  options ||= { info: true }
65
70
  if options[:info]
66
- keys = %i[name uuid app_id_name app_id_prefix creation_date expiration_date ttl team_ids
67
- team_name]
71
+ keys = MAIN_PROFILE_KEYS
68
72
  keys.each do |key|
69
73
  @output.puts "- #{key}: #{profile.send(key.to_sym)}"
70
74
  end
@@ -93,6 +97,49 @@ module PProf
93
97
  # rubocop:enable Style/GuardClause
94
98
  end
95
99
 
100
+ # Returns a Provisioning Profile hash ready to be printed as a JSON output
101
+ #
102
+ # @param [Array<PProf::ProvisioningProfile>] profile
103
+ # List of provisioning profiles to include in the JSON output
104
+ # @param [Hash] options
105
+ # Options to indicate what to include in the generated JSON.
106
+ # `:certs`: if set to `true`, output will also include the info about `DeveloperCertificates` in each profile
107
+ # `:devices`: if set to `true`, output will also include the list of `ProvisionedDevices` for each profile
108
+ #
109
+ # @return [Hash] The hash ready to be `JSON.pretty_generate`'d
110
+ #
111
+ def as_json(profile, options = {})
112
+ hash = profile.to_hash.dup
113
+ hash.delete 'DER-Encoded-Profile'
114
+ hash.delete 'ProvisionedDevices' unless options[:devices]
115
+ if options[:certs]
116
+ hash['DeveloperCertificates'] = developer_certificates.map do |cert|
117
+ {
118
+ subject: cert.subject,
119
+ issuer: cert.issuer,
120
+ serial: cert.serial,
121
+ expires: cert.not_after
122
+ }
123
+ end
124
+ else
125
+ hash.delete 'DeveloperCertificates'
126
+ end
127
+ hash
128
+ end
129
+
130
+ # Prints a Provisioning Profile as JSON
131
+ #
132
+ # @param [Array<PProf::ProvisioningProfile>] profile
133
+ # List of provisioning profiles to include in the JSON output
134
+ # @param [Hash] options
135
+ # Options to indicate what to include in the generated JSON.
136
+ # `:certs`: if set to `true`, output will also include the info about `DeveloperCertificates` in each profile
137
+ # `:devices`: if set to `true`, output will also include the list of `ProvisionedDevices` for each profile
138
+ #
139
+ def print_json(profile, options = {})
140
+ @output.puts JSON.pretty_generate(as_json(profile, options))
141
+ end
142
+
96
143
  # Prints the filtered list of Provisioning Profiles
97
144
  #
98
145
  # Convenience method. Calls self.print_list with a filter block build from a filter hash
@@ -129,6 +176,8 @@ module PProf
129
176
  case list_options[:mode]
130
177
  when :table
131
178
  print_table(dir, &filter_func)
179
+ when :json
180
+ print_json_list(dir, list_options, &filter_func)
132
181
  else
133
182
  print_list(dir, list_options, &filter_func)
134
183
  end
@@ -181,7 +230,7 @@ module PProf
181
230
  # Defaults to '~/Library/MobileDevice/Provisioning Profiles'
182
231
  # @param [Hash] options
183
232
  # The options hash typically filled while parsing the command line arguments.
184
- # - :mode: will print the UUIDs if set to `:uuid`, the file path otherwise
233
+ # - :mode: will print the UUIDs if set to `:list`, the file path otherwise
185
234
  # - :zero: will concatenate the entries with `\0` instead of `\n` if set
186
235
  #
187
236
  # @yield each provisioning profile for filtering/validation
@@ -195,7 +244,7 @@ module PProf
195
244
  p = PProf::ProvisioningProfile.new(file)
196
245
  next if block_given? && !yield(p)
197
246
 
198
- @output.print options[:mode] == :uuid ? p.uuid.chomp : file.chomp
247
+ @output.print options[:mode] == :list ? p.uuid.chomp : file.chomp
199
248
  @output.print options[:zero] ? "\0" : "\n"
200
249
  rescue StandardError => e
201
250
  errors << { message: e, file: file }
@@ -203,6 +252,33 @@ module PProf
203
252
  errors.each { |e| print_error(e[:message], e[:file]) } unless errors.empty?
204
253
  end
205
254
 
255
+ # Prints the filtered list of profiles as a JSON array
256
+ #
257
+ # @param [String] dir
258
+ # The directory containing the mobileprovision files to list.
259
+ # Defaults to '~/Library/MobileDevice/Provisioning Profiles'
260
+ # @param [Hash] options
261
+ # The options hash typically filled while parsing the command line arguments.
262
+ # - :mode: will print the UUIDs if set to `:list`, the file path otherwise
263
+ # - :zero: will concatenate the entries with `\0` instead of `\n` if set
264
+ #
265
+ # @yield each provisioning profile for filtering/validation
266
+ # The block is given ProvisioningProfile object and should
267
+ # return true to display the row, false to filter it out
268
+ #
269
+ def print_json_list(dir = PProf::ProvisioningProfile::DEFAULT_DIR, options) # rubocop:disable Style/OptionalArguments
270
+ errors = []
271
+ profiles = Dir['*.mobileprovision', base: dir].map do |file_name|
272
+ file = File.join(dir, file_name)
273
+ p = PProf::ProvisioningProfile.new(file)
274
+ as_json(p, options) unless block_given? && !yield(p)
275
+ rescue StandardError => e
276
+ errors << { message: e, file: file }
277
+ end.compact
278
+ errors.each { |e| print_error(e[:message], e[:file]) } unless errors.empty?
279
+ @output.puts JSON.pretty_generate(profiles)
280
+ end
281
+
206
282
  def self.match_aps_env(actual, expected)
207
283
  return false if actual.nil? # false if no Push entitlements
208
284
  return true if expected == true # true if Push present but we don't filter on specific env
@@ -146,7 +146,7 @@ module PProf
146
146
  #
147
147
  # @return [Hash]
148
148
  def to_hash
149
- @dict
149
+ @plist
150
150
  end
151
151
 
152
152
  # The human-readable string representation of this Provisioning Profile
data/lib/pprof/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module PProf
4
4
  # Module version
5
- VERSION = '0.4.1'
5
+ VERSION = '0.5.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pprof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olivier Halligon
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-28 00:00:00.000000000 Z
11
+ date: 2022-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: plist
@@ -44,7 +44,7 @@ licenses:
44
44
  - MIT
45
45
  metadata:
46
46
  rubygems_mfa_required: 'true'
47
- post_install_message:
47
+ post_install_message:
48
48
  rdoc_options: []
49
49
  require_paths:
50
50
  - lib
@@ -59,8 +59,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  requirements: []
62
- rubygems_version: 3.2.19
63
- signing_key:
62
+ rubygems_version: 3.0.3
63
+ signing_key:
64
64
  specification_version: 4
65
65
  summary: A Provisioning Profiles library
66
66
  test_files: []