Class: Google::Cloud::Gemserver::Backend::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/gemserver/backend/key.rb

Overview

Key

Manages the creation and deletion of a key used to push gems to the gemserver and download them.

Constant Summary collapse

MAPPING =

A mapping from gemserver permissions to gemstash permissions.

{
  "write" => %w[push yank],
  "read"  => %w[fetch]
}.freeze
ALL =

Aliases for read and write permissions.

["both", "all", "", nil].freeze
GEM_CREDS =

Path to the credentials file checked when pushing gems to the gem server (or any endpoint).

File.expand_path("~/.gem")
KEY_LENGTH =

The length of a key generated by gemstash.

32

Class Method Summary collapse

Class Method Details

.create_key(permissions = nil) ⇒ String

Creates a key with given permissions.

Parameters:

  • permissions (String) (defaults to: nil)

    The permissions for a key. Optional.

Returns:

  • (String)


57
58
59
60
61
62
63
64
# File 'lib/google/cloud/gemserver/backend/key.rb', line 57

def self.create_key permissions = nil
  mapped = map_perms permissions
  args = base_args.concat mapped
  output = capture_stdout { GemstashServer.start args }
  key = parse_key(output)
  puts "Created key: #{key}"
  key
end

.delete_key(key) ⇒ Object

Deletes a given key.

Parameters:

  • key (String)

    The key to delete.



70
71
72
73
74
75
76
77
78
# File 'lib/google/cloud/gemserver/backend/key.rb', line 70

def self.delete_key key
  args = [
    "--remove",
    "--key=#{key}"
  ]
  GemstashServer.start base_args.concat(args)
  puts "Deleted key: #{key}"
  true
end