Class: PackageCloud::CLI::ReadToken

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

Instance Method Summary collapse

Instance Method Details

#destroy(repo_name, master_and_read_token) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/package_cloud/cli/read_token.rb', line 6

def destroy(repo_name, master_and_read_token)
  print "Looking for repository at #{repo_name}... "
  repo = client.repository(repo_name)

  given_master_token, given_read_token = master_and_read_token.split("/")

  if given_master_token.nil? || given_read_token.nil?
    print "invalid master token and/or read token!\n".color(:red)
    exit(127)
  end

  master_token = repo.master_tokens.detect { |t| t.name == given_master_token }

  if master_token.nil?
    print "couldn't find master token named #{given_master_token}\n".color(:red)
    exit(127)
  end

  read_token = master_token.read_tokens.detect { |t| t.name == given_read_token }

  if read_token.nil?
    print "couldn't find read token named #{given_read_token} for #{given_master_token}\n".color(:red)
    exit(127)
  end

  master_token_path = master_token.paths["self"]

  read_token.destroy(master_token_path, read_token.id)

  print "success!\n"
end