class Google::Cloud::Gemserver::Backend::Key
# Key
Manages the creation and deletion of a key used to push gems to the gemserver and download them.
Constants
- ALL
Aliases for read and write permissions.
- GEM_CREDS
Path to the credentials file checked when pushing gems to the gem server (or any endpoint).
- KEY_LENGTH
The length of a key generated by gemstash.
- MAPPING
A mapping from gemserver permissions to gemstash permissions.
Public Class Methods
@private The arguments passed to every gemstash key generation command.
@return [Array]
# File lib/google/cloud/gemserver/backend/key.rb, line 114 def self.base_args [ "authorize", "--config-file=#{Google::Cloud::Gemserver::Configuration.new.config_path}" ] end
Creates a key with given permissions.
@param permissions [String] The permissions for a key. Optional.
@return [String]
# 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
Deletes a given key.
@param [String] key The key to delete.
# 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
@private Outputs important information to the user on how they should set up their keys so pushing/installing gems works as intended.
# File lib/google/cloud/gemserver/backend/key.rb, line 125 def self.output_key_info puts "Note: remember to add this key to ~/.gem/credentials" \ " so that you are able to push gems to the gemserver." puts "Note: remember to add this key to your bundle config so " \ "that `bundle install` works for private gems (bundle config" \ " http://my-gemserver.appspot.com/private/ my-key" end
Private Class Methods
@private Temporarily routes stdout to a temporary variable such that stdout from gemstash is captured.
@return [String]
# File lib/google/cloud/gemserver/backend/key.rb, line 100 def self.capture_stdout old_stdout = $stdout $stdout = StringIO.new yield $stdout.string ensure $stdout = old_stdout end
@private Maps read/write permissions to the permissions the gemstash gem uses.
@param [String] perms The permissions to be mapped.
# File lib/google/cloud/gemserver/backend/key.rb, line 85 def self.map_perms perms if perms == "write" MAPPING["write"] elsif ALL.include? perms MAPPING["write"] + MAPPING["read"] else MAPPING["read"] end end
Parses the key from output generated from the corresponding key creation command in gemstash.
@param [String] output The output to parse.
@return [String]
# File lib/google/cloud/gemserver/backend/key.rb, line 140 def self.parse_key output i = output.index(":") output[i+2..i+2+KEY_LENGTH].chomp end