jumpcloud 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/jumpcloud.rb +90 -0
- metadata +45 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: bfdd5bc16e62d165b902d9ebc6e963e8c03d1abd
|
|
4
|
+
data.tar.gz: bdfdcfa6b2f82f12184340d86682badda219a256
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5cf48406b7462fe68a2924ed1e833ef34c553f32717f64d5bf85212e04caaf9540274100a6157650641896116d3d6f5f4241ddbbd39edd95602e5bd4b24b0336
|
|
7
|
+
data.tar.gz: 99a335c35a29013e77c76821326d73cc42f2748a8236a564835d94014c94c7754a975ed8dfd9da1cfd01651d35c1b518010134b13933f9bdbcaf85e9a3093bf6
|
data/lib/jumpcloud.rb
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'base64'
|
|
3
|
+
require 'openssl'
|
|
4
|
+
require 'net/http'
|
|
5
|
+
|
|
6
|
+
class JumpCloud
|
|
7
|
+
def self.get_date
|
|
8
|
+
Time.now.utc.strftime("+%a, %d %h %Y %H:%M:%S GMT")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.parse_config
|
|
12
|
+
JSON.parse( IO.read("/opt/jc/jcagent.conf") )
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.get_key_from_config
|
|
16
|
+
parse_config["systemKey"]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.create_signature(verb, date, system_key)
|
|
20
|
+
signed_string = "#{verb} /api/systems/#{system_key} HTTP/1.1\ndate: #{date}"
|
|
21
|
+
key = OpenSSL::PKey::RSA.new(File.open("/opt/jc/client.key"))
|
|
22
|
+
Base64.strict_encode64(key.sign(OpenSSL::Digest::SHA256.new, signed_string))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.set_system_tags(*tags)
|
|
26
|
+
system_data = get_system_data()
|
|
27
|
+
system_data["tags"] = tags
|
|
28
|
+
send_to_server(system_data)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.set_system_name(system_name)
|
|
32
|
+
system_data = get_system_data()
|
|
33
|
+
system_data["displayName"] = system_name
|
|
34
|
+
send_to_server(system_data)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.delete_system()
|
|
38
|
+
date = get_date
|
|
39
|
+
system_key = get_key_from_config
|
|
40
|
+
signature = create_signature("DELETE", date, system_key)
|
|
41
|
+
uri = URI.parse("https://console.jumpcloud.com/api/systems/#{system_key}")
|
|
42
|
+
request = Net::HTTP::Delete.new(uri.request_uri)
|
|
43
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
44
|
+
http.use_ssl = true
|
|
45
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
46
|
+
http.ssl_version = :SSLv3
|
|
47
|
+
request["Authorization"] = "Signature keyId=\"system/#{system_key}\",headers=\"request-line date\",algorithm=\"rsa-sha256\",signature=\"#{signature}\""
|
|
48
|
+
request["Date"] = "#{date}"
|
|
49
|
+
request["accept"] = "application/json"
|
|
50
|
+
request["Content-Type"] = "application/json"
|
|
51
|
+
response = http.request(request)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.get_system_data()
|
|
55
|
+
date = get_date
|
|
56
|
+
system_key = get_key_from_config
|
|
57
|
+
signature = create_signature("GET", date, system_key)
|
|
58
|
+
uri = URI.parse("https://console.jumpcloud.com/api/systems/#{system_key}")
|
|
59
|
+
request = Net::HTTP.new(uri.host, uri.port)
|
|
60
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
61
|
+
http.use_ssl = true
|
|
62
|
+
|
|
63
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
|
64
|
+
request["Authorization"] = "Signature keyId=\"system/#{system_key}\",headers=\"request-line date\",algorithm=\"rsa-sha256\",signature=\"#{signature}\""
|
|
65
|
+
request["Date"] = "#{date}"
|
|
66
|
+
request["accept"] = "application/json"
|
|
67
|
+
|
|
68
|
+
response = http.request(request)
|
|
69
|
+
return JSON.parse(response.body)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def self.send_to_server(data)
|
|
73
|
+
date = get_date
|
|
74
|
+
system_key = get_key_from_config
|
|
75
|
+
signature = create_signature("PUT", date, system_key)
|
|
76
|
+
uri = URI.parse("https://console.jumpcloud.com/api/systems/#{system_key}")
|
|
77
|
+
request = Net::HTTP::Put.new(uri.request_uri)
|
|
78
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
79
|
+
http.use_ssl = true
|
|
80
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
81
|
+
http.ssl_version = :SSLv3
|
|
82
|
+
request["Authorization"] = "Signature keyId=\"system/#{system_key}\",headers=\"request-line date\",algorithm=\"rsa-sha256\",signature=\"#{signature}\""
|
|
83
|
+
request["Date"] = "#{date}"
|
|
84
|
+
request["accept"] = "application/json"
|
|
85
|
+
request["Content-Type"] = "application/json"
|
|
86
|
+
request.body = JSON.generate(data)
|
|
87
|
+
response = http.request(request)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jumpcloud
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.2.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Topher Marie
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Allows simple configuration of a system name and its JumpCloud tags,
|
|
14
|
+
and allows you to delete a system
|
|
15
|
+
email: topher@jumpcloud.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/jumpcloud.rb
|
|
21
|
+
homepage: https://github.com/TheJumpCloud/jumpcloud-ruby-gem
|
|
22
|
+
licenses:
|
|
23
|
+
- Mozilla Public License v2.0 (https://www.mozilla.org/MPL/2.0/)
|
|
24
|
+
metadata: {}
|
|
25
|
+
post_install_message:
|
|
26
|
+
rdoc_options: []
|
|
27
|
+
require_paths:
|
|
28
|
+
- lib
|
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 2.2.2
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 4
|
|
44
|
+
summary: Basic JumpCloud system configuration via api
|
|
45
|
+
test_files: []
|