groupr 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -4
- data/Gemfile +1 -1
- data/README.rdoc +12 -7
- data/VERSION +1 -1
- data/groupr.gemspec +2 -4
- data/lib/groupr.rb +35 -3
- data/spec/groupr_spec.rb +28 -5
- data/spec/sample_responses/get_membership.html +40 -0
- metadata +3 -18
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Groupr provides an interface to the University of Washington Groups Service, which allows administrators to leverage a simple yet robust groups system for access control for applications campus-wide.
|
6
6
|
|
7
|
-
Groupr strives to followly closely to the naming conventions and functions as outlined in the Groups Service documentation, but does expand certain functionality, notably adding the
|
7
|
+
Groupr strives to followly closely to the naming conventions and functions as outlined in the Groups Service documentation, but does expand certain functionality, notably adding the <tt>group_exist?</tt> method to verify that a group exists.
|
8
8
|
|
9
9
|
== Features
|
10
10
|
|
@@ -33,18 +33,23 @@ Groupr is designed to work with a very specific application API, and is likely n
|
|
33
33
|
|
34
34
|
Once the conditions as outlined in "system requirements" are met, this gem can be utilized.
|
35
35
|
|
36
|
-
|
37
|
-
testr.key = "path to key file"
|
38
|
-
testr.cert = "path to certificate file"
|
39
|
-
testr.group_exists?("u_nikky_awesome")
|
40
|
-
testr.create_group("u_nikky_yeast-lords")
|
36
|
+
testr = Groupr.new
|
37
|
+
testr.key = "path to key file"
|
38
|
+
testr.cert = "path to certificate file"
|
39
|
+
testr.group_exists?("u_nikky_awesome")
|
40
|
+
testr.create_group("u_nikky_yeast-lords")</tt>
|
41
41
|
|
42
42
|
By default, it will look for a UWCA root file in ~/uwca.crt. You can manually change this by running:
|
43
43
|
|
44
|
-
|
44
|
+
testr.ua_ca_file = "path to uwca root certificate"
|
45
45
|
|
46
46
|
== Version History
|
47
47
|
|
48
|
+
=== 0.2.2
|
49
|
+
|
50
|
+
* Add Groupr#get_membership
|
51
|
+
* Add Groupr#delete_group
|
52
|
+
|
48
53
|
=== 0.2.1
|
49
54
|
|
50
55
|
Initial documentation release
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
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.2.
|
8
|
+
s.version = "0.2.2"
|
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"]
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"groupr.gemspec",
|
29
29
|
"lib/groupr.rb",
|
30
30
|
"spec/groupr_spec.rb",
|
31
|
+
"spec/sample_responses/get_membership.html",
|
31
32
|
"spec/sample_responses/view_group.html",
|
32
33
|
"spec/spec_helper.rb"
|
33
34
|
]
|
@@ -46,14 +47,12 @@ Gem::Specification.new do |s|
|
|
46
47
|
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
47
48
|
s.add_development_dependency(%q<bundler>, [">= 0"])
|
48
49
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
49
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
50
50
|
else
|
51
51
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
52
52
|
s.add_dependency(%q<rspec>, [">= 0"])
|
53
53
|
s.add_dependency(%q<rdoc>, [">= 0"])
|
54
54
|
s.add_dependency(%q<bundler>, [">= 0"])
|
55
55
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
56
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
57
56
|
end
|
58
57
|
else
|
59
58
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
@@ -61,7 +60,6 @@ Gem::Specification.new do |s|
|
|
61
60
|
s.add_dependency(%q<rdoc>, [">= 0"])
|
62
61
|
s.add_dependency(%q<bundler>, [">= 0"])
|
63
62
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
64
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
65
63
|
end
|
66
64
|
end
|
67
65
|
|
data/lib/groupr.rb
CHANGED
@@ -2,7 +2,7 @@ require 'net/http'
|
|
2
2
|
require 'nokogiri'
|
3
3
|
class Groupr
|
4
4
|
attr_accessor :api_url, :certificate, :key, :uw_ca_file
|
5
|
-
attr_reader :request
|
5
|
+
attr_reader :request, :status
|
6
6
|
def initialize
|
7
7
|
@api_url = "https://iam-ws.u.washington.edu:7443/group_sws/v2"
|
8
8
|
@uw_ca_file = "#{ENV['HOME']}/uwca.crt"
|
@@ -26,7 +26,15 @@ class Groupr
|
|
26
26
|
|
27
27
|
|
28
28
|
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Members
|
29
|
-
def get_membership
|
29
|
+
def get_membership(group)
|
30
|
+
@uri = URI.parse("#{@api_url}/group/#{group}/member")
|
31
|
+
body = make_get_request
|
32
|
+
doc = Nokogiri::HTML(body)
|
33
|
+
members = []
|
34
|
+
doc.css('li').each do |m|
|
35
|
+
members << m.text
|
36
|
+
end
|
37
|
+
members
|
30
38
|
end
|
31
39
|
|
32
40
|
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Get+Effective+Members
|
@@ -108,7 +116,16 @@ class Groupr
|
|
108
116
|
end
|
109
117
|
|
110
118
|
# https://wiki.cac.washington.edu/display/infra/Groups+WebService+Delete+Group
|
111
|
-
def delete_group
|
119
|
+
def delete_group(group)
|
120
|
+
@uri = URI.parse("#{@api_url}/group/#{group}")
|
121
|
+
make_delete_request
|
122
|
+
if get_response_code == 200
|
123
|
+
@status = "Group deleted or not found"
|
124
|
+
true
|
125
|
+
else
|
126
|
+
@status = "No authorization"
|
127
|
+
false
|
128
|
+
end
|
112
129
|
end
|
113
130
|
|
114
131
|
## Search
|
@@ -138,6 +155,21 @@ class Groupr
|
|
138
155
|
end
|
139
156
|
@response.body
|
140
157
|
end
|
158
|
+
# This makes a delete request against the groups service, used for uh, deleting things
|
159
|
+
def make_delete_request
|
160
|
+
options = {
|
161
|
+
use_ssl: true,
|
162
|
+
cert: OpenSSL::X509::Certificate.new(@certificate),
|
163
|
+
key: OpenSSL::PKey::RSA.new(@key),
|
164
|
+
ca_file: @uw_ca_file,
|
165
|
+
verify_mode: OpenSSL::SSL::VERIFY_PEER
|
166
|
+
}
|
167
|
+
Net::HTTP.start(@uri.host, @uri.port, options) do |http|
|
168
|
+
request = Net::HTTP::Delete.new(@uri.request_uri)
|
169
|
+
@response = http.request(request)
|
170
|
+
end
|
171
|
+
@response.body
|
172
|
+
end
|
141
173
|
# This makes a put request against the groups service, useful for pushing information
|
142
174
|
def make_put_request
|
143
175
|
options = {
|
data/spec/groupr_spec.rb
CHANGED
@@ -53,18 +53,41 @@ describe "Groupr" do
|
|
53
53
|
@group.should_receive(:make_put_request).and_return(nil)
|
54
54
|
end
|
55
55
|
it "Should create a new group" do
|
56
|
-
|
56
|
+
@group.should_receive(:get_response_code).and_return(200)
|
57
57
|
@group.create_group("u_test_hi").should eq true
|
58
58
|
end
|
59
59
|
it "Should fail to create a new group if the response code is non-200" do
|
60
|
-
|
61
|
-
|
60
|
+
@group.should_receive(:get_response_code).and_return(419)
|
61
|
+
@group.create_group("u_test_hi").should eq false
|
62
62
|
end
|
63
|
+
end
|
63
64
|
|
65
|
+
context "#delete_group" do
|
66
|
+
before do
|
67
|
+
@group.should_receive(:make_delete_request).and_return(nil)
|
68
|
+
end
|
69
|
+
it "Should delete a currently existing group" do
|
70
|
+
@group.should_receive(:get_response_code).and_return(200)
|
71
|
+
@group.delete_group("u_test-group").should eq true
|
72
|
+
@group.status.should eq "Group deleted or not found"
|
73
|
+
end
|
74
|
+
it "Should return false upon fail" do
|
75
|
+
@group.should_receive(:get_response_code).and_return(412)
|
76
|
+
@group.delete_group("u_test_group").should eq false
|
77
|
+
@group.status.should eq "No authorization"
|
78
|
+
end
|
64
79
|
end
|
80
|
+
end
|
81
|
+
context "member operations" do
|
82
|
+
|
83
|
+
context "#get_membership" do
|
84
|
+
before do
|
85
|
+
@group.should_receive(:make_get_request).and_return(File.open("spec/sample_responses/get_membership.html"))
|
86
|
+
end
|
87
|
+
it "Gets the members of a group" do
|
88
|
+
@group.get_membership("u_nikky_awesome").should eq ["blogs", "blogsdev", "hiigara.cac.washington.edu", "nikky", "nikky.cac.washington.edu", "solanum.cac.washington.edu", "sqltest", "u_nikky_git", "webtest"]
|
89
|
+
end
|
65
90
|
|
66
|
-
context "#get_members" do
|
67
|
-
it "Gets the members of a group"
|
68
91
|
end
|
69
92
|
|
70
93
|
context "#add_member" do
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
3
|
+
|
4
|
+
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
6
|
+
<head>
|
7
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
<div class="group">
|
15
|
+
Members of u_nikky_awesome
|
16
|
+
<br/>
|
17
|
+
Regid: <span class="regid">cd58f8f44e9b494bb6fc57be021e4ba2</span>
|
18
|
+
<br/>
|
19
|
+
|
20
|
+
<ul class="members">
|
21
|
+
<li><a rel="memberlink" class="member" type="uwnetid" href="/group_sws/v2/group/cd58f8f44e9b494bb6fc57be021e4ba2/member/blogs">blogs</a></li>
|
22
|
+
<li><a rel="memberlink" class="member" type="uwnetid" href="/group_sws/v2/group/cd58f8f44e9b494bb6fc57be021e4ba2/member/blogsdev">blogsdev</a></li>
|
23
|
+
<li><a rel="memberlink" class="member" type="dns" href="/group_sws/v2/group/cd58f8f44e9b494bb6fc57be021e4ba2/member/hiigara.cac.washington.edu">hiigara.cac.washington.edu</a></li>
|
24
|
+
<li><a rel="memberlink" class="member" type="uwnetid" href="/group_sws/v2/group/cd58f8f44e9b494bb6fc57be021e4ba2/member/nikky">nikky</a></li>
|
25
|
+
<li><a rel="memberlink" class="member" type="dns" href="/group_sws/v2/group/cd58f8f44e9b494bb6fc57be021e4ba2/member/nikky.cac.washington.edu">nikky.cac.washington.edu</a></li>
|
26
|
+
<li><a rel="memberlink" class="member" type="dns" href="/group_sws/v2/group/cd58f8f44e9b494bb6fc57be021e4ba2/member/solanum.cac.washington.edu">solanum.cac.washington.edu</a></li>
|
27
|
+
<li><a rel="memberlink" class="member" type="uwnetid" href="/group_sws/v2/group/cd58f8f44e9b494bb6fc57be021e4ba2/member/sqltest">sqltest</a></li>
|
28
|
+
<li><a rel="memberlink" class="member" type="group" href="/group_sws/v2/group/cd58f8f44e9b494bb6fc57be021e4ba2/member/u_nikky_git">u_nikky_git</a></li>
|
29
|
+
<li><a rel="memberlink" class="member" type="uwnetid" href="/group_sws/v2/group/cd58f8f44e9b494bb6fc57be021e4ba2/member/webtest">webtest</a></li>
|
30
|
+
|
31
|
+
</ul>
|
32
|
+
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div class="status">{status}</div>
|
36
|
+
|
37
|
+
|
38
|
+
</body>
|
39
|
+
</html>
|
40
|
+
|
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.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -91,22 +91,6 @@ dependencies:
|
|
91
91
|
- - ~>
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: 1.8.4
|
94
|
-
- !ruby/object:Gem::Dependency
|
95
|
-
name: simplecov
|
96
|
-
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
|
-
requirements:
|
99
|
-
- - ! '>='
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: '0'
|
102
|
-
type: :development
|
103
|
-
prerelease: false
|
104
|
-
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
|
-
requirements:
|
107
|
-
- - ! '>='
|
108
|
-
- !ruby/object:Gem::Version
|
109
|
-
version: '0'
|
110
94
|
description: Gem used to interact with University of Washington Groups Service
|
111
95
|
email: nikky@uw.edu
|
112
96
|
executables: []
|
@@ -126,6 +110,7 @@ files:
|
|
126
110
|
- groupr.gemspec
|
127
111
|
- lib/groupr.rb
|
128
112
|
- spec/groupr_spec.rb
|
113
|
+
- spec/sample_responses/get_membership.html
|
129
114
|
- spec/sample_responses/view_group.html
|
130
115
|
- spec/spec_helper.rb
|
131
116
|
homepage: http://github.com/allynfolksjr/groupr
|
@@ -143,7 +128,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
128
|
version: '0'
|
144
129
|
segments:
|
145
130
|
- 0
|
146
|
-
hash:
|
131
|
+
hash: 379539324252946890
|
147
132
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
133
|
none: false
|
149
134
|
requirements:
|