Method: PackageCloud::CLI::MasterToken#destroy

Defined in:
lib/package_cloud/cli/master_token.rb

#destroy(repo_name, token_name) ⇒ 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
# File 'lib/package_cloud/cli/master_token.rb', line 40

def destroy(repo_name, token_name)
  ARGV.clear # otherwise gets explodes

  if token_name == "default"
    abort("You can't delete the default master_token.".color(:red))
  end

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

  token = repo.master_tokens.detect do |token|
    token.name == token_name
  end

  if token
    msg = "\nAre you sure you want to delete #{token_name}?"
    msg << " #{token.read_tokens.length} read tokens will no longer work afterwards (y/n)" if token.read_tokens.length > 0
    answer = get_valid(msg) do |s|
      s == "y" || s == "n"
    end
    if answer == "y"
      print "Attempting to destroy token named #{token_name}... "
      token.destroy
      print "success!\n".color(:green)
    else
      puts "Aborting...".color(:red)
    end
  else
    puts "Wasn't able to find a token named #{token_name}.".color(:red)
    exit(1)
  end
end