Class: Mysigner::Cleanup::PrivateKeysPurger

Inherits:
Object
  • Object
show all
Defined in:
lib/mysigner/cleanup/private_keys_purger.rb

Constant Summary collapse

LEGACY_DIRS =
[
  '~/.private_keys',
  '~/.appstoreconnect/private_keys'
].freeze

Instance Method Summary collapse

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mysigner/cleanup/private_keys_purger.rb', line 17

def call
  return if ENV['MYSIGNER_USE_LEGACY_ASC'] == '1'
  return if File.exist?(marker_path)

  LEGACY_DIRS.each do |dir|
    expanded = File.expand_path(dir)
    Dir.glob(File.join(expanded, 'AuthKey_*.p8')).each do |path|
      File.delete(path)
      warn "mysigner: deleted legacy private key #{path}" if ENV['MYSIGNER_VERBOSE'] == '1'
    rescue Errno::ENOENT
      # Raced with another process — already gone.
    rescue Errno::EACCES, Errno::EPERM => e
      # Owned by another user. Skip this file but keep going so the
      # marker still gets written — otherwise the purger retries on
      # every CLI invocation and keeps failing on the same file.
      warn "mysigner: could not delete #{path} (#{e.class}); skipping" if ENV['MYSIGNER_VERBOSE'] == '1'
    end
  end

  FileUtils.mkdir_p(File.dirname(marker_path))
  FileUtils.touch(marker_path)
end

#marker_pathObject



13
14
15
# File 'lib/mysigner/cleanup/private_keys_purger.rb', line 13

def marker_path
  File.expand_path('~/.mysigner/.private_keys_purged')
end