Class: Gleis::AuthKey
- Inherits:
-
Object
- Object
- Gleis::AuthKey
- Defined in:
- lib/gleis/auth_key.rb
Overview
The class implements the methods required to manage git authentication keys
Class Method Summary collapse
- .add(key_file, key_name = nil, run_server = false) ⇒ Object
- .list ⇒ Object
- .remove(key_name) ⇒ Object
Class Method Details
.add(key_file, key_name = nil, run_server = false) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gleis/auth_key.rb', line 4 def self.add(key_file, key_name = nil, run_server = false) token = Token.check abort("SSH public key file #{key_file} does not exist.") unless File.exist?(key_file) ssh_public_key = SSH.load_public_key(key_file) body = API.request('post', 'keys', token, 'key' => ssh_public_key, 'name' => key_name, 'run_server' => run_server) if body['success'] == 1 puts "Successfully uploaded your SSH public key #{key_file}" SSH.add_host_to_config(body['git_server'], key_file.gsub(/\.pub$/, '')) # Get run server name and add Host to SSH config if run_server params = Params.get_cli_parameters(token) SSH.add_host_to_config(params['run_server'], key_file.gsub(/\.pub$/, '')) end else puts "Failed to upload SSH public key: #{body['message']}" end end |
.list ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gleis/auth_key.rb', line 22 def self.list token = Token.check body = API.request('get', 'keys', token) keys = body ['data'] if keys.any? puts "SSH public keys configured for your account:\n\n" printf("\t%-39s %s\n", 'KEY NAME', 'CREATED ON') printf("\t%-39s %s\n", 'PUBLIC KEY', '----------') printf("\t%-39s\n\n", '----------') keys.each do |_id, key| printf("\t%-39s %s\n", key['title'], Time.parse(key['created_at']).localtime.strftime('%c')) printf("\t%s\n\n", key['key']) end else puts 'No keys found.' end end |
.remove(key_name) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/gleis/auth_key.rb', line 40 def self.remove(key_name) token = Token.check body = API.request('delete', "keys/#{CGI.escape(key_name)}", token) if body['success'] == 1 puts 'Successfully removed SSH public key' else puts "Failed to remove SSH public key: #{body['message']}" end end |