Class: JumpCloud
- Inherits:
-
Object
- Object
- JumpCloud
- Defined in:
- lib/jumpcloud.rb
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_system_name(system_name) ⇒ Object
- .set_system_tags(*tags) ⇒ Object
Class Method Details
.create_signature(verb, date, system_key) ⇒ Object
19 20 21 22 23 |
# File 'lib/jumpcloud.rb', line 19 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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jumpcloud.rb', line 37 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 http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.ssl_version = :SSLv3 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
7 8 9 |
# File 'lib/jumpcloud.rb', line 7 def self.get_date Time.now.utc.strftime("+%a, %d %h %Y %H:%M:%S GMT") end |
.get_key_from_config ⇒ Object
15 16 17 |
# File 'lib/jumpcloud.rb', line 15 def self.get_key_from_config parse_config["systemKey"] end |
.get_system_data ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/jumpcloud.rb', line 54 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
11 12 13 |
# File 'lib/jumpcloud.rb', line 11 def self.parse_config JSON.parse( IO.read("/opt/jc/jcagent.conf") ) end |
.send_to_server(data) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/jumpcloud.rb', line 72 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 http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.ssl_version = :SSLv3 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_system_name(system_name) ⇒ Object
31 32 33 34 35 |
# File 'lib/jumpcloud.rb', line 31 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
25 26 27 28 29 |
# File 'lib/jumpcloud.rb', line 25 def self.(*) system_data = get_system_data() system_data["tags"] = send_to_server(system_data) end |