Class: JumpCloud
- Inherits:
-
Object
- Object
- JumpCloud
- Defined in:
- lib/jumpcloud.rb
Instance Attribute Summary collapse
-
#settings ⇒ Object
Returns the value of attribute settings.
Class Method Summary collapse
- .create_signature(verb, date, system_key) ⇒ Object
- .delete_system ⇒ Object
- .get_date ⇒ Object
- .get_key_from_config ⇒ Object
- .get_system_data ⇒ Object
- .parse_config ⇒ Object
- .send_to_server(data) ⇒ Object
- .set_sshPassEnabled ⇒ Object
- .set_system_name(system_name) ⇒ Object
- .set_system_tags(*tags) ⇒ Object
Instance Method Summary collapse
-
#initialize(args = self.class.get_system_data()) ⇒ JumpCloud
constructor
A new instance of JumpCloud.
- #update_settings(options) ⇒ Object
Constructor Details
#initialize(args = self.class.get_system_data()) ⇒ JumpCloud
10 11 12 |
# File 'lib/jumpcloud.rb', line 10 def initialize(args=self.class.get_system_data()) @settings = args end |
Instance Attribute Details
#settings ⇒ Object
Returns the value of attribute settings.
8 9 10 |
# File 'lib/jumpcloud.rb', line 8 def settings @settings end |
Class Method Details
.create_signature(verb, date, system_key) ⇒ Object
35 36 37 38 39 |
# File 'lib/jumpcloud.rb', line 35 def self.create_signature(verb, date, system_key) signed_string = "#{verb} /api/systems/#{system_key} HTTP/1.1\ndate: #{date}" key = OpenSSL::PKey::RSA.new(File.open("/opt/jc/client.key")) Base64.strict_encode64(key.sign(OpenSSL::Digest::SHA256.new, signed_string)) end |
.delete_system ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jumpcloud.rb', line 59 def self.delete_system() date = get_date system_key = get_key_from_config signature = create_signature("DELETE", date, system_key) uri = URI.parse("https://console.jumpcloud.com/api/systems/#{system_key}") request = Net::HTTP::Delete.new(uri.request_uri) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request["Authorization"] = "Signature keyId=\"system/#{system_key}\",headers=\"request-line date\",algorithm=\"rsa-sha256\",signature=\"#{signature}\"" request["Date"] = "#{date}" request["accept"] = "application/json" request["Content-Type"] = "application/json" response = http.request(request) end |
.get_date ⇒ Object
23 24 25 |
# File 'lib/jumpcloud.rb', line 23 def self.get_date Time.now.utc.strftime("+%a, %d %h %Y %H:%M:%S GMT") end |
.get_key_from_config ⇒ Object
31 32 33 |
# File 'lib/jumpcloud.rb', line 31 def self.get_key_from_config parse_config["systemKey"] end |
.get_system_data ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jumpcloud.rb', line 74 def self.get_system_data() date = get_date system_key = get_key_from_config signature = create_signature("GET", date, system_key) uri = URI.parse("https://console.jumpcloud.com/api/systems/#{system_key}") request = Net::HTTP.new(uri.host, uri.port) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.request_uri) request["Authorization"] = "Signature keyId=\"system/#{system_key}\",headers=\"request-line date\",algorithm=\"rsa-sha256\",signature=\"#{signature}\"" request["Date"] = "#{date}" request["accept"] = "application/json" response = http.request(request) return JSON.parse(response.body) end |
.parse_config ⇒ Object
27 28 29 |
# File 'lib/jumpcloud.rb', line 27 def self.parse_config JSON.parse( IO.read("/opt/jc/jcagent.conf") ) end |
.send_to_server(data) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/jumpcloud.rb', line 91 def self.send_to_server(data) date = get_date system_key = get_key_from_config signature = create_signature("PUT", date, system_key) uri = URI.parse("https://console.jumpcloud.com/api/systems/#{system_key}") request = Net::HTTP::Put.new(uri.request_uri) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request["Authorization"] = "Signature keyId=\"system/#{system_key}\",headers=\"request-line date\",algorithm=\"rsa-sha256\",signature=\"#{signature}\"" request["Date"] = "#{date}" request["accept"] = "application/json" request["Content-Type"] = "application/json" request.body = JSON.generate(data) response = http.request(request) end |
.set_sshPassEnabled ⇒ Object
53 54 55 56 57 |
# File 'lib/jumpcloud.rb', line 53 def self.set_sshPassEnabled() system_data = get_system_data() system_data["allowSshPasswordAuthentication"] = true send_to_server(system_data) end |
.set_system_name(system_name) ⇒ Object
47 48 49 50 51 |
# File 'lib/jumpcloud.rb', line 47 def self.set_system_name(system_name) system_data = get_system_data() system_data["displayName"] = system_name send_to_server(system_data) end |
.set_system_tags(*tags) ⇒ Object
41 42 43 44 45 |
# File 'lib/jumpcloud.rb', line 41 def self.(*) system_data = get_system_data() system_data["tags"] = send_to_server(system_data) end |
Instance Method Details
#update_settings(options) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/jumpcloud.rb', line 14 def update_settings() data = {} data.merge!(@settings) .each do |k,v| data[k] = v if @settings.has_key?(k) end JumpCloud.send_to_server(data) end |