Class: PackageCloud::CLI::GpgKey

Inherits:
Base
  • Object
show all
Defined in:
lib/package_cloud/cli/gpg_key.rb

Instance Method Summary collapse

Instance Method Details

#create(repo_name, file_path) ⇒ Object


31
32
33
34
35
36
# File 'lib/package_cloud/cli/gpg_key.rb', line 31

def create(repo_name, file_path)
  print "Looking for repository at #{repo_name}... "
  repo = client.repository(repo_name)
  print "success!\n"
  repo.create_gpg_key(file_path)
end

#destroy(repo_name, keyname) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/package_cloud/cli/gpg_key.rb', line 40

def destroy(repo_name, keyname)
  ARGV.clear
  print "Looking for repository at #{repo_name}... "
  repo = client.repository(repo_name)
  print "success!\n"

  key = repo.gpg_keys.detect do |key|
    key.name == keyname
  end

  if key
    msg = "\nAre you sure you want to delete the GPG key #{keyname}? (y/n)"
    answer = get_valid(msg) do |s|
      s == "y" || s == "n"
    end

    if answer == "y"
      print "Attempting to destroy GPG key named #{keyname}... "
      begin
        key.destroy
      rescue RestClient::ResourceNotFound =>e
        print "\nError, could not find key: #{keyname}. No GPG keys deleted.\n".color(:red)
        print "Please note that you cannot delete repository signing keys.\n"
        exit(1)
      else
        print "success!\n".color(:green)
      end
    else
      puts "Aborting...".color(:red)
    end
  else
    puts "Wasn't able to find a GPG key name: #{keyname}".color(:red)
  end
end

#list(repo_name) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/package_cloud/cli/gpg_key.rb', line 6

def list(repo_name)
  print "Looking for repository at #{repo_name}... "
  repo = client.repository(repo_name)
  print "success!\n"

  keys = repo.gpg_keys
  puts "GPG Keys for #{repo_name}:\n"

  keys.each_with_index do |key, i|
    if key.keytype == "package"
      keytype = "Package signing key"
    else
      keytype = "Repository signing key"
    end

    puts "Key name: #{key.name}"
    puts "Key type: #{keytype}"
    puts "Key fingerprint: #{key.fingerprint}"
    puts "GPG key url: #{key.download_url}"
    puts
  end
end