groupr 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +6 -0
- data/README.rdoc +2 -0
- data/VERSION +1 -1
- data/groupr.gemspec +3 -1
- data/lib/groupr.rb +183 -73
- data/spec/groupr_spec.rb +67 -55
- data/spec/sample_responses/view_group.html +87 -0
- metadata +4 -2
data/.travis.yml
ADDED
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/groupr.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "groupr"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nikky Southerland"]
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
".rspec",
|
22
|
+
".travis.yml",
|
22
23
|
"Gemfile",
|
23
24
|
"LICENSE.txt",
|
24
25
|
"README.rdoc",
|
@@ -27,6 +28,7 @@ Gem::Specification.new do |s|
|
|
27
28
|
"groupr.gemspec",
|
28
29
|
"lib/groupr.rb",
|
29
30
|
"spec/groupr_spec.rb",
|
31
|
+
"spec/sample_responses/view_group.html",
|
30
32
|
"spec/spec_helper.rb"
|
31
33
|
]
|
32
34
|
s.homepage = "http://github.com/allynfolksjr/groupr"
|
data/lib/groupr.rb
CHANGED
@@ -1,76 +1,186 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'nokogiri'
|
3
3
|
class Groupr
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
4
|
+
attr_accessor :api_url, :certificate, :key, :uw_ca_file
|
5
|
+
attr_reader :request
|
6
|
+
def initialize
|
7
|
+
@api_url = "https://iam-ws.u.washington.edu:7443/group_sws/v2"
|
8
|
+
@uw_ca_file = "#{ENV['HOME']}/uwca.crt"
|
9
|
+
end
|
10
|
+
|
11
|
+
# This method returns nil if the http request doesn't return a 200. Maybe also support for not-authorized?
|
12
|
+
# def validate_response(response)
|
13
|
+
# nil if get_response_code != 200
|
14
|
+
# response.body if get_response_code == 200
|
15
|
+
# end
|
16
|
+
def get_response_code
|
17
|
+
@response.code.to_i
|
18
|
+
end
|
19
|
+
def group_exists?(group)
|
20
|
+
@uri = URI.parse("#{@api_url}/group/#{group}")
|
21
|
+
make_get_request
|
22
|
+
if get_response_code == 200
|
23
|
+
true
|
24
|
+
else
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
## Membership-related methods: get, get effective, update, delete
|
30
|
+
|
31
|
+
|
32
|
+
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Members
|
33
|
+
def get_membership
|
34
|
+
end
|
35
|
+
|
36
|
+
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Effective+Members
|
37
|
+
def get_effective_membership
|
38
|
+
end
|
39
|
+
|
40
|
+
# http://wiki.cac.washington.edu/display/infra/Groups+WebService+Update+Members
|
41
|
+
def update_membership
|
42
|
+
end
|
43
|
+
|
44
|
+
# http://wiki.cac.washington.edu/display/infra/Groups+WebService+Delete+Members
|
45
|
+
def delete_membership
|
46
|
+
end
|
47
|
+
|
48
|
+
## Member-related methods
|
49
|
+
|
50
|
+
# http://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Member
|
51
|
+
def get_member
|
52
|
+
end
|
53
|
+
|
54
|
+
# http://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Effective+Member
|
55
|
+
def get_effective_member
|
56
|
+
end
|
57
|
+
|
58
|
+
# http://wiki.cac.washington.edu/display/infra/Groups+WebService+Add+Member
|
59
|
+
def add_member
|
60
|
+
end
|
61
|
+
|
62
|
+
# http://wiki.cac.washington.edu/display/infra/Groups+WebService+Delete+Member
|
63
|
+
def delete_member
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
## Group-related methods. View, create, update, delete.
|
68
|
+
|
69
|
+
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Group
|
70
|
+
def view_group(group)
|
71
|
+
@uri = URI.parse("#{@api_url}/group/#{group}")
|
72
|
+
body = make_get_request
|
73
|
+
@doc = Nokogiri::HTML(body)
|
74
|
+
{
|
75
|
+
title: get_title,
|
76
|
+
description: get_description,
|
77
|
+
name: get_name,
|
78
|
+
regid: get_regid,
|
79
|
+
contact: get_contact
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Create+Group
|
86
|
+
def create_group(group,description=nil)
|
87
|
+
@group = group
|
88
|
+
description.nil? ? @description = group : @description = description
|
89
|
+
@uri = URI.parse("#{@api_url}/group/#{group}")
|
90
|
+
make_put_request
|
91
|
+
get_response_code == 200 ? true : false
|
92
|
+
end
|
93
|
+
|
94
|
+
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Update+Group
|
95
|
+
def update_group
|
96
|
+
end
|
97
|
+
|
98
|
+
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Delete+Group
|
99
|
+
def delete_group
|
100
|
+
end
|
101
|
+
|
102
|
+
## Search
|
103
|
+
|
104
|
+
# http://wiki.cac.washington.edu/display/infra/Groups+WebService+Search
|
105
|
+
def search
|
106
|
+
end
|
107
|
+
|
108
|
+
# http://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+History
|
109
|
+
def get_history
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
private
|
114
|
+
def make_get_request
|
115
|
+
options = {
|
116
|
+
use_ssl: true,
|
117
|
+
cert: OpenSSL::X509::Certificate.new(@certificate),
|
118
|
+
key: OpenSSL::PKey::RSA.new(@key),
|
119
|
+
ca_file: @uw_ca_file,
|
120
|
+
verify_mode: OpenSSL::SSL::VERIFY_PEER
|
121
|
+
}
|
122
|
+
Net::HTTP.start(@uri.host, @uri.port, options) do |http|
|
123
|
+
request = Net::HTTP::Get.new(@uri.request_uri)
|
124
|
+
@response = http.request(request)
|
125
|
+
end
|
126
|
+
@response.body
|
127
|
+
end
|
128
|
+
|
129
|
+
def make_put_request
|
130
|
+
options = {
|
131
|
+
use_ssl: true,
|
132
|
+
cert: OpenSSL::X509::Certificate.new(@certificate),
|
133
|
+
key: OpenSSL::PKey::RSA.new(@key),
|
134
|
+
ca_file: @uw_ca_file,
|
135
|
+
verify_mode: OpenSSL::SSL::VERIFY_PEER
|
136
|
+
}
|
137
|
+
Net::HTTP.start(@uri.host, @uri.port, options) do |http|
|
138
|
+
request = Net::HTTP::Put.new(@uri.request_uri)
|
139
|
+
request.body = %Q{<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
140
|
+
"http://www.w3.org/TR/xhtml11/DTD/xhtml11/dtd">
|
141
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
142
|
+
<head>
|
143
|
+
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8"/>
|
144
|
+
</head>
|
145
|
+
<body>
|
146
|
+
<div class="group">
|
147
|
+
<span class="description">#{@description}</span>
|
148
|
+
<ul class="names"><li class="name">#{@group}</li></ul>
|
149
|
+
<ul class="admins">
|
150
|
+
<li class="admin">nikky</li>
|
151
|
+
</ul>
|
152
|
+
</div>
|
153
|
+
</body>
|
154
|
+
</html>}
|
155
|
+
@response = http.request(request)
|
156
|
+
end
|
157
|
+
puts "Response is: #{get_response_code}"
|
158
|
+
puts "Body is: #{@response.body}"
|
159
|
+
@response.body
|
160
|
+
end
|
161
|
+
|
162
|
+
def get_response_code
|
163
|
+
@response.code.to_i
|
164
|
+
end
|
165
|
+
|
166
|
+
def get_contact
|
167
|
+
@doc.xpath('//span[@class="contact"]').text
|
168
|
+
end
|
169
|
+
|
170
|
+
def get_title
|
171
|
+
@doc.xpath('//span[@class="title"]').text
|
172
|
+
end
|
173
|
+
|
174
|
+
def get_description
|
175
|
+
@doc.xpath('//span[@class="description"]').text
|
176
|
+
end
|
177
|
+
|
178
|
+
def get_name
|
179
|
+
@doc.xpath('//span[@class="name"]').text
|
180
|
+
end
|
181
|
+
|
182
|
+
def get_regid
|
183
|
+
@doc.xpath('//span[@class="regid"]').text
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
data/spec/groupr_spec.rb
CHANGED
@@ -2,65 +2,77 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
2
|
|
3
3
|
describe "Groupr" do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@group.key = File.read("#{ENV['HOME']}/nikky_cac_washington_edu.key")
|
9
|
-
end
|
5
|
+
before do
|
6
|
+
@group = Groupr.new
|
7
|
+
end
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
9
|
+
it "Checks for network connectivity"
|
10
|
+
it "Should allow you to specify a custom Service API" do
|
11
|
+
@group.respond_to?(:api_url).should eq true
|
12
|
+
end
|
13
|
+
it "Should allow you to specify your X509 certificate" do
|
14
|
+
@group.respond_to?(:certificate).should eq true
|
15
|
+
end
|
16
|
+
it "Should Allow you to specify your RSA key" do
|
17
|
+
@group.respond_to?(:key).should eq true
|
18
|
+
end
|
19
|
+
context "group operations" do
|
20
|
+
context "#group_exists?" do
|
21
|
+
it "Should tell you that the uw_employees group exists" do
|
22
|
+
@group.should_receive(:make_get_request).and_return(nil)
|
23
|
+
@group.should_receive(:get_response_code).and_return(200)
|
24
|
+
@group.group_exists?("u_nikky_git").should be_true
|
25
|
+
end
|
26
|
+
it "Should tell you that the a_team group does not exist" do
|
27
|
+
@group.should_receive(:make_get_request).and_return(nil)
|
28
|
+
@group.should_receive(:get_response_code).and_return(404)
|
29
|
+
@group.group_exists?("a_team").should be_false
|
30
|
+
end
|
31
|
+
end
|
21
32
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
context "#view_group" do
|
34
|
+
before do
|
35
|
+
@group.should_receive(:make_get_request).and_return(File.open('spec/sample_responses/view_group.html'))
|
36
|
+
@results = @group.view_group("u_nikky_git")
|
37
|
+
end
|
38
|
+
it "Should tell you the group name" do
|
39
|
+
@results[:name].should eq "u_nikky_git"
|
40
|
+
end
|
41
|
+
it "Should tell you the group description" do
|
42
|
+
@results[:description].should_not == ""
|
43
|
+
end
|
44
|
+
it "Should tell you the group contact" do
|
45
|
+
@results[:contact].should eq "nikky"
|
46
|
+
end
|
47
|
+
it "Should tell you the group title" do
|
48
|
+
@results[:title].should eq "nikky git"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
context "#create_group" do
|
52
|
+
before do
|
53
|
+
@group.should_receive(:make_put_request).and_return(nil)
|
54
|
+
end
|
55
|
+
it "Should create a new group" do
|
56
|
+
@group.should_receive(:get_response_code).and_return(200)
|
57
|
+
@group.create_group("u_test_hi").should eq true
|
58
|
+
end
|
59
|
+
it "Should fail to create a new group if the response code is non-200" do
|
60
|
+
@group.should_receive(:get_response_code).and_return(419)
|
61
|
+
@group.create_group("u_test_hi").should eq false
|
62
|
+
end
|
34
63
|
|
35
|
-
|
36
|
-
before do
|
37
|
-
@group.should_receive(:make_get_request).and_return(File.open('view_group.html'))
|
38
|
-
@results = @group.view_group("u_nikky_git")
|
39
|
-
end
|
40
|
-
it "Should tell you the group name" do
|
41
|
-
@results[:name].should eq "u_nikky_git"
|
42
|
-
end
|
43
|
-
it "Should tell you the group description" do
|
44
|
-
@results[:description].should_not == ""
|
45
|
-
end
|
46
|
-
it "Should tell you the group contact" do
|
47
|
-
@results[:contact].should eq "nikky"
|
48
|
-
end
|
49
|
-
it "Should tell you the group title" do
|
50
|
-
@results[:title].should eq "nikky git"
|
51
|
-
end
|
52
|
-
end
|
64
|
+
end
|
53
65
|
|
66
|
+
context "#get_members" do
|
67
|
+
it "Gets the members of a group"
|
68
|
+
end
|
54
69
|
|
55
|
-
|
56
|
-
|
57
|
-
|
70
|
+
context "#add_member" do
|
71
|
+
it "Adds a member to a group"
|
72
|
+
end
|
58
73
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
context "#remove_member" do
|
64
|
-
it "Removes a member from a group"
|
65
|
-
end
|
74
|
+
context "#remove_member" do
|
75
|
+
it "Removes a member from a group"
|
76
|
+
end
|
77
|
+
end
|
66
78
|
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
3
|
+
<head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"></head>
|
4
|
+
<body>
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
<div class="group" version="2">
|
10
|
+
|
11
|
+
Regid: <span class="regid">ddd677bfea054b2191fd7bcdf4d715e4</span>
|
12
|
+
<br><span class="names">
|
13
|
+
Name: <span class="name">u_nikky_git</span>
|
14
|
+
</span>
|
15
|
+
<br>
|
16
|
+
Title: <span class="title">nikky git</span>
|
17
|
+
<br>
|
18
|
+
Description: <span class="description">List to restrict access to my "public" git repository to CAC and other campus support staff as needed.</span>
|
19
|
+
<br>
|
20
|
+
|
21
|
+
Group contact: <span class="contact">nikky</span>
|
22
|
+
<br>
|
23
|
+
|
24
|
+
Created: <span class="createtime">1292452356669</span>
|
25
|
+
<br>
|
26
|
+
Modified: <span class="modifytime">1292452357055</span>
|
27
|
+
<br>
|
28
|
+
Membership modified: <span class="membermodifytime">1301805036473</span>
|
29
|
+
<br>
|
30
|
+
Authn factor: <span class="authnfactor">1</span>
|
31
|
+
<br>
|
32
|
+
Classification: <span class="classification">u</span>
|
33
|
+
<br>
|
34
|
+
Membership dependency group: <span class="dependson"></span>
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
Email Enabled: <span class="emailenabled">disabled</span>
|
39
|
+
<br>
|
40
|
+
|
41
|
+
Published email address: <span class="publishemail"></span>
|
42
|
+
<br>
|
43
|
+
|
44
|
+
Report to owner:
|
45
|
+
<span class="reporttoowner">no</span>
|
46
|
+
<br>
|
47
|
+
|
48
|
+
Allowed senders: <ul class="authorigs">
|
49
|
+
<li class="authorig" type="none">dc=none</li>
|
50
|
+
</ul>
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
Administrators:
|
59
|
+
<ul class="admins">
|
60
|
+
<li class="admin" type="uwnetid">nikky</li>
|
61
|
+
</ul>
|
62
|
+
Updaters:
|
63
|
+
<ul class="updaters"></ul>
|
64
|
+
Creators:
|
65
|
+
<ul class="creators"></ul>
|
66
|
+
Readers:
|
67
|
+
<ul class="readers">
|
68
|
+
<li class="reader" type="none">dc=all</li>
|
69
|
+
</ul>
|
70
|
+
|
71
|
+
Optins:
|
72
|
+
<ul class="optins"></ul>
|
73
|
+
Optouts:
|
74
|
+
<ul class="optouts"></ul>
|
75
|
+
<br>
|
76
|
+
|
77
|
+
Membership: <a rel="members" href="/group_sws/v2/group/ddd677bfea054b2191fd7bcdf4d715e4/member">Membership</a>
|
78
|
+
|
79
|
+
</div>
|
80
|
+
|
81
|
+
<div class="status"></div>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
</body>
|
87
|
+
</html>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groupr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -117,6 +117,7 @@ extra_rdoc_files:
|
|
117
117
|
files:
|
118
118
|
- .document
|
119
119
|
- .rspec
|
120
|
+
- .travis.yml
|
120
121
|
- Gemfile
|
121
122
|
- LICENSE.txt
|
122
123
|
- README.rdoc
|
@@ -125,6 +126,7 @@ files:
|
|
125
126
|
- groupr.gemspec
|
126
127
|
- lib/groupr.rb
|
127
128
|
- spec/groupr_spec.rb
|
129
|
+
- spec/sample_responses/view_group.html
|
128
130
|
- spec/spec_helper.rb
|
129
131
|
homepage: http://github.com/allynfolksjr/groupr
|
130
132
|
licenses:
|
@@ -141,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
143
|
version: '0'
|
142
144
|
segments:
|
143
145
|
- 0
|
144
|
-
hash:
|
146
|
+
hash: 4214034756816010912
|
145
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
148
|
none: false
|
147
149
|
requirements:
|