ipa-ruby 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +1 -1
- data/lib/ipa/client.rb +56 -5
- data/lib/ipa/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1d7160cfb18104746bf1b13bcf5474084d063cf
|
4
|
+
data.tar.gz: 09b6cd2c4f776fe497260085aeb5efeb593e8d24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3b5a4b085e9a91aa7c6b799a12ebae9ecef61a02cfc71e6316c92673483b2d83c3ff28ae060ceb9ca704168563a49b13a404cf26a6da76b3e2d8c9647193588
|
7
|
+
data.tar.gz: 6caf47d62a95df3d22634d6a2e46de516df4422ae1b397b73e1f66a0d5961530c899eefd191322dce6c1dc227b5fc92ec525395e7a4c32b146d82fd33203c355
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ gem install ipa-ruby
|
|
15
15
|
|
16
16
|
You can optionally pass a `ca_cert` keyword argument specifying the path to the FreeIPA CA certificate. Default is /etc/ipa/ca.crt.
|
17
17
|
```
|
18
|
-
require 'ipa'
|
18
|
+
require 'ipa/client'
|
19
19
|
ipa = IPA::Client.new(host: 'ipa.example.org')
|
20
20
|
```
|
21
21
|
|
data/lib/ipa/client.rb
CHANGED
@@ -17,19 +17,37 @@ module IPA
|
|
17
17
|
def initialize(host: nil, ca_cert: '/etc/ipa/ca.crt')
|
18
18
|
raise ArgumentError, 'Missing FreeIPA host' unless host
|
19
19
|
|
20
|
-
@uri = URI.parse("https://#{host}/ipa/json")
|
20
|
+
@uri = URI.parse("https://#{host}/ipa/session/json")
|
21
21
|
|
22
|
-
|
22
|
+
@http = HTTPClient.new
|
23
|
+
@http.ssl_config.set_trust_ca(ca_cert)
|
24
|
+
@headers = {'referer' => "https://#{uri.host}/ipa/json", 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
|
25
|
+
|
26
|
+
self.login(host)
|
27
|
+
end
|
28
|
+
|
29
|
+
def login(host)
|
30
|
+
# Set the timeout to 15 minutes
|
31
|
+
@session_timeout = (Time.new.to_i + 900)
|
32
|
+
|
33
|
+
gssapi = GSSAPI::Simple.new(@uri.host, 'HTTP')
|
23
34
|
# Initiate the security context
|
24
35
|
token = gssapi.init_context
|
25
36
|
|
26
|
-
|
27
|
-
|
28
|
-
|
37
|
+
login_uri = URI.parse("https://#{host}/ipa/session/login_kerberos")
|
38
|
+
login_request = {:method => "ping", :params => [[], {}]}
|
39
|
+
login_headers = {'referer' => "https://#{uri.host}/ipa/ui/index.html", 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Authorization' => "Negotiate #{Base64.strict_encode64(token)}"}
|
40
|
+
|
41
|
+
self.http.post(login_uri, login_request.to_json, login_headers)
|
29
42
|
end
|
30
43
|
|
31
44
|
def api_post(method: nil, item: [], params: {})
|
32
45
|
raise ArgumentError, 'Missing method in API request' unless method
|
46
|
+
|
47
|
+
if Time.new.to_i > @session_timeout then
|
48
|
+
self.login
|
49
|
+
end
|
50
|
+
|
33
51
|
request = {}
|
34
52
|
request[:method] = method
|
35
53
|
request[:params] = [[item || []], params]
|
@@ -37,6 +55,39 @@ module IPA
|
|
37
55
|
JSON.parse(resp.body)
|
38
56
|
end
|
39
57
|
|
58
|
+
def hostgroup_show(hostgroup: nil,all: false, params: {})
|
59
|
+
raise ArgumentError, 'Hostgroup is required' unless hostgroup
|
60
|
+
|
61
|
+
params[:all] = all
|
62
|
+
|
63
|
+
self.api_post(method: 'hostgroup_show', item: hostgroup, params: params)
|
64
|
+
end
|
65
|
+
|
66
|
+
def hostgroup_add(hostgroup: nil, description: nil, all: false, params: {})
|
67
|
+
raise ArgumentError, 'Hostgroup is required' unless hostgroup
|
68
|
+
raise ArgumentError, 'description is required' unless description
|
69
|
+
|
70
|
+
params[:all] = all
|
71
|
+
params[:description] = description
|
72
|
+
|
73
|
+
self.api_post(method: 'hostgroup_add', item: hostgroup, params: params)
|
74
|
+
end
|
75
|
+
|
76
|
+
def hostgroup_add_member(hostgroup: nil, hostnames: nil, params: {})
|
77
|
+
raise ArgumentError, 'Hostgroup is required' unless hostgroup
|
78
|
+
raise ArgumentError, 'Hostnames is required' unless hostnames
|
79
|
+
params[:all] = true
|
80
|
+
|
81
|
+
if hostnames.kind_of?(Array)
|
82
|
+
params[:host] = hostnames
|
83
|
+
end
|
84
|
+
if hostnames.kind_of?(String)
|
85
|
+
params[:host] = [hostnames]
|
86
|
+
end
|
87
|
+
|
88
|
+
self.api_post(method: 'hostgroup_add_member', item: hostgroup, params: params)
|
89
|
+
end
|
90
|
+
|
40
91
|
def host_add(hostname: nil, all: false, force: false, random: nil, userpassword: nil, params: {})
|
41
92
|
raise ArgumentError, 'Hostname is required' unless hostname
|
42
93
|
|
data/lib/ipa/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ipa-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matteo Cerutti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -82,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
82
|
version: '0'
|
83
83
|
requirements: []
|
84
84
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
85
|
+
rubygems_version: 2.6.8
|
86
86
|
signing_key:
|
87
87
|
specification_version: 4
|
88
88
|
summary: Ruby client library that allows to interact with the FreeIPA JSON API
|