sis_ruby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +41 -0
- data/Gemfile +3 -0
- data/LICENSE +28 -0
- data/README.md +188 -0
- data/RELEASE_NOTES.md +3 -0
- data/Rakefile +35 -0
- data/lib/sis_ruby/client.rb +85 -0
- data/lib/sis_ruby/common.rb +5 -0
- data/lib/sis_ruby/endpoint.rb +108 -0
- data/lib/sis_ruby/exceptions/bad_response_error.rb +35 -0
- data/lib/sis_ruby/exceptions/missing_id_error.rb +12 -0
- data/lib/sis_ruby/get_helper.rb +41 -0
- data/lib/sis_ruby/hash_builder.rb +31 -0
- data/lib/sis_ruby/params.rb +117 -0
- data/lib/sis_ruby/result_enumerable.rb +86 -0
- data/lib/sis_ruby/version.rb +3 -0
- data/lib/sis_ruby.rb +8 -0
- data/samples/sample-1.rb +26 -0
- data/samples/sample-2.rb +33 -0
- data/sis_ruby.gemspec +22 -0
- data/spec/client_spec.rb +57 -0
- data/spec/endpoint_spec.rb +54 -0
- data/spec/hash_builder_spec.rb +83 -0
- data/spec/params_spec.rb +75 -0
- data/spec/setup/drop-db.js +4 -0
- data/spec/setup/recreate-db.sh +14 -0
- data/spec/setup/test-user.json +6 -0
- data/spec/spec_helper.rb +1 -0
- data/spec-writing/entity.json +50 -0
- data/spec-writing/hiera.json +58 -0
- data/spec-writing/hook.json +64 -0
- data/spec-writing/schema.json +131 -0
- data/spec-writing/write_spec.rb +105 -0
- metadata +149 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
{
|
2
|
+
"type": "hiera",
|
3
|
+
"id_field": "name",
|
4
|
+
"valid_items": [
|
5
|
+
{
|
6
|
+
"name": "hiera1",
|
7
|
+
"owner": "hiera_owner",
|
8
|
+
"hieradata": {
|
9
|
+
"key1": "data1",
|
10
|
+
"key2": "data2"
|
11
|
+
},
|
12
|
+
"_sis": {
|
13
|
+
"owner": "test"
|
14
|
+
}
|
15
|
+
},
|
16
|
+
{
|
17
|
+
"name": "hiera2",
|
18
|
+
"owner": "hiera_owner",
|
19
|
+
"hieradata": {
|
20
|
+
"key3": "data1",
|
21
|
+
"key4": "data2"
|
22
|
+
},
|
23
|
+
"_sis": {
|
24
|
+
"owner": "test"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
],
|
28
|
+
"invalid_items": [
|
29
|
+
{
|
30
|
+
"name": "hiera1",
|
31
|
+
"owner": "hiera_owner",
|
32
|
+
"hieradata": {
|
33
|
+
"key3": "data1",
|
34
|
+
"key4": "data2"
|
35
|
+
}
|
36
|
+
},
|
37
|
+
{
|
38
|
+
"name": "hiera3",
|
39
|
+
"hieradata": {
|
40
|
+
"key3": "data1",
|
41
|
+
"key4": "data2"
|
42
|
+
}
|
43
|
+
},
|
44
|
+
{
|
45
|
+
"name": "hiera_no_data"
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"name": "hiera_empty_data",
|
49
|
+
"hieradata": {
|
50
|
+
}
|
51
|
+
},
|
52
|
+
{
|
53
|
+
"hieradata": {
|
54
|
+
"no": "name"
|
55
|
+
}
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
{
|
2
|
+
"type": "hooks",
|
3
|
+
"id_field": "name",
|
4
|
+
"valid_items": [
|
5
|
+
{
|
6
|
+
"name": "hook1",
|
7
|
+
"entity_type": "some_entity",
|
8
|
+
"owner": "hook_owner",
|
9
|
+
"target": {
|
10
|
+
"action": "POST",
|
11
|
+
"url": "http=>//my.hook.endpoint/endpoint"
|
12
|
+
},
|
13
|
+
"events": [
|
14
|
+
"update",
|
15
|
+
"insert"
|
16
|
+
],
|
17
|
+
"_sis": {
|
18
|
+
"owner": "test"
|
19
|
+
}
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"name": "hook2",
|
23
|
+
"entity_type": "some_other_entity",
|
24
|
+
"owner": "hook_owner",
|
25
|
+
"target": {
|
26
|
+
"action": "PUT",
|
27
|
+
"url": "http=>//my.hook.endpoint/endpoint"
|
28
|
+
},
|
29
|
+
"events": [
|
30
|
+
"insert"
|
31
|
+
],
|
32
|
+
"_sis": {
|
33
|
+
"owner": "test"
|
34
|
+
}
|
35
|
+
}
|
36
|
+
],
|
37
|
+
"invalid_items": [
|
38
|
+
{
|
39
|
+
"name": "hook3",
|
40
|
+
"entity_type": "random",
|
41
|
+
"events": [
|
42
|
+
"update"
|
43
|
+
],
|
44
|
+
"_sis": {
|
45
|
+
"owner": "test"
|
46
|
+
}
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"name": "hook2",
|
50
|
+
"entity_type": "some_other_entity",
|
51
|
+
"owner": "hook_owner",
|
52
|
+
"target": {
|
53
|
+
"action": "PUT",
|
54
|
+
"url": "http=>//my.hook.endpoint/endpoint"
|
55
|
+
},
|
56
|
+
"events": [
|
57
|
+
"insert"
|
58
|
+
],
|
59
|
+
"_sis": {
|
60
|
+
"owner": "test"
|
61
|
+
}
|
62
|
+
}
|
63
|
+
]
|
64
|
+
}
|
@@ -0,0 +1,131 @@
|
|
1
|
+
{
|
2
|
+
"type": "schemas",
|
3
|
+
"id_field": "name",
|
4
|
+
"valid_items": [
|
5
|
+
{
|
6
|
+
"name": "schema1",
|
7
|
+
"owner": "schema_owner",
|
8
|
+
"definition": {
|
9
|
+
"requiredField": {
|
10
|
+
"type": "String",
|
11
|
+
"required": true
|
12
|
+
},
|
13
|
+
"uniqueNumberField": {
|
14
|
+
"type": "Number",
|
15
|
+
"unique": true
|
16
|
+
},
|
17
|
+
"stringField": "String",
|
18
|
+
"numberField": "Number",
|
19
|
+
"nestedDocument": {
|
20
|
+
"nestedString": "String",
|
21
|
+
"nestedBoolean": "Boolean"
|
22
|
+
},
|
23
|
+
"anythingField": {
|
24
|
+
"type": "Mixed"
|
25
|
+
}
|
26
|
+
},
|
27
|
+
"_sis": {
|
28
|
+
"owner": "test"
|
29
|
+
}
|
30
|
+
},
|
31
|
+
{
|
32
|
+
"name": "schema2",
|
33
|
+
"owner": "schema_owner",
|
34
|
+
"definition": {
|
35
|
+
"stringField": {
|
36
|
+
"type": "String",
|
37
|
+
"required": true
|
38
|
+
},
|
39
|
+
"numberField": "Number"
|
40
|
+
},
|
41
|
+
"_sis": {
|
42
|
+
"owner": "test"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
],
|
46
|
+
"invalid_items": [
|
47
|
+
{
|
48
|
+
"name": "schema1",
|
49
|
+
"owner": "schema_owner",
|
50
|
+
"definition": {
|
51
|
+
"requiredField": {
|
52
|
+
"type": "String",
|
53
|
+
"required": true
|
54
|
+
},
|
55
|
+
"uniqueNumberField": {
|
56
|
+
"type": "Number",
|
57
|
+
"unique": true
|
58
|
+
},
|
59
|
+
"stringField": "String",
|
60
|
+
"numberField": "Number",
|
61
|
+
"nestedDocument": {
|
62
|
+
"nestedString": "String",
|
63
|
+
"nestedBoolean": "Boolean"
|
64
|
+
},
|
65
|
+
"anythingField": {
|
66
|
+
"type": "Mixed"
|
67
|
+
}
|
68
|
+
},
|
69
|
+
"_sis": {
|
70
|
+
"owner": "test"
|
71
|
+
}
|
72
|
+
},
|
73
|
+
{
|
74
|
+
"name": "no_owner_schema",
|
75
|
+
"definition": {
|
76
|
+
"requiredField": {
|
77
|
+
"type": "String",
|
78
|
+
"required": true
|
79
|
+
},
|
80
|
+
"uniqueNumberField": {
|
81
|
+
"type": "Number",
|
82
|
+
"unique": true
|
83
|
+
},
|
84
|
+
"stringField": "String",
|
85
|
+
"numberField": "Number",
|
86
|
+
"nestedDocument": {
|
87
|
+
"nestedString": "String",
|
88
|
+
"nestedBoolean": "Boolean"
|
89
|
+
},
|
90
|
+
"anythingField": {
|
91
|
+
"type": "Mixed"
|
92
|
+
}
|
93
|
+
}
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"owner": "no_name_schema",
|
97
|
+
"definition": {
|
98
|
+
"requiredField": {
|
99
|
+
"type": "String",
|
100
|
+
"required": true
|
101
|
+
},
|
102
|
+
"uniqueNumberField": {
|
103
|
+
"type": "Number",
|
104
|
+
"unique": true
|
105
|
+
},
|
106
|
+
"stringField": "String",
|
107
|
+
"numberField": "Number",
|
108
|
+
"nestedDocument": {
|
109
|
+
"nestedString": "String",
|
110
|
+
"nestedBoolean": "Boolean"
|
111
|
+
},
|
112
|
+
"anythingField": {
|
113
|
+
"type": "Mixed"
|
114
|
+
}
|
115
|
+
},
|
116
|
+
"_sis": {
|
117
|
+
"owner": "test"
|
118
|
+
}
|
119
|
+
},
|
120
|
+
{
|
121
|
+
"name": "bad_definition_schema",
|
122
|
+
"owner": "owner",
|
123
|
+
"definition": {
|
124
|
+
"whats_up": "bad_type"
|
125
|
+
},
|
126
|
+
"_sis": {
|
127
|
+
"owner": "test"
|
128
|
+
}
|
129
|
+
}
|
130
|
+
]
|
131
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'rspec'
|
3
|
+
require_relative '../lib/sis_ruby/client'
|
4
|
+
|
5
|
+
# TODO Add tests for invalid items
|
6
|
+
|
7
|
+
TEST_SERVER_URL = 'http://localhost:3000'
|
8
|
+
|
9
|
+
def describe_test(test_name, source_data)
|
10
|
+
|
11
|
+
# Note that although real world servers should use https,
|
12
|
+
# this server only works with http when installed and configured
|
13
|
+
# with the instructions at https://github.com/sis-cmdb/sis-api
|
14
|
+
|
15
|
+
client = SisRuby::Client.new(TEST_SERVER_URL)
|
16
|
+
data = OpenStruct.new(source_data)
|
17
|
+
id_field = data.id_field
|
18
|
+
endpoint = data.entity_type ? client.entities(data.entity_type) : client.send(data.type)
|
19
|
+
|
20
|
+
describe test_name do
|
21
|
+
|
22
|
+
before(:all) do
|
23
|
+
client.authenticate('test', 'abc123')
|
24
|
+
if data.required_schema
|
25
|
+
client.schemas.create(data.required_schema)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if data.required_schema
|
30
|
+
after(:all) do
|
31
|
+
client.schemas.delete(data.required_schema)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
valid_items = data.valid_items || []
|
36
|
+
valid_items.each_with_index do |item, index|
|
37
|
+
|
38
|
+
it "should create, get, list, and delete valid item #{index}" do
|
39
|
+
|
40
|
+
# Test creation ................................................
|
41
|
+
result = endpoint.create(item)
|
42
|
+
expect(result).to be, 'Result returned by create was nil.'
|
43
|
+
id = result[id_field]
|
44
|
+
name = result['name']
|
45
|
+
|
46
|
+
expect(id).to be, 'Id on create was nil, or record not created.'
|
47
|
+
|
48
|
+
# Test retrieval with get.......................................
|
49
|
+
result = endpoint.get(id)
|
50
|
+
|
51
|
+
if data.type == 'hiera' # special type of data, extract inner data structure for test
|
52
|
+
expected = { id => item['hieradata'] }
|
53
|
+
expect(result).to eq(expected)
|
54
|
+
else
|
55
|
+
actual_id = result[id_field]
|
56
|
+
expect(actual_id).to eq(id), "Get error; expected id '#{id}' but got '#{actual_id}'"
|
57
|
+
end
|
58
|
+
|
59
|
+
# Test retrieval with list.......................................
|
60
|
+
expect(endpoint.list.any?).to eq(true), 'List returned no records.'
|
61
|
+
|
62
|
+
# Test deletion - result will be the deleted record..............
|
63
|
+
result = endpoint.delete(id)
|
64
|
+
actual_name = result['name']
|
65
|
+
actual_id = result[id_field]
|
66
|
+
expect(actual_id).to eq(id), "After delete, expected id '#{id}' but got '#{actual_id}'"
|
67
|
+
expect(actual_name).to eq(name), "After delete, expected name '#{name}' but got '#{actual_name}'"
|
68
|
+
|
69
|
+
# Ensure that the get fails since we just deleted the record
|
70
|
+
expect { endpoint.get(id) }.to raise_error(SisRuby::BadResponseError)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# Generates test expectations for the specified data type.
|
78
|
+
# Assumes that:
|
79
|
+
#
|
80
|
+
# 1) the file containing the specified type of data contains JSON text
|
81
|
+
# 2) the file is in the same directory as this test file
|
82
|
+
# 3) the file is named: type + '.json'
|
83
|
+
def process_test_data(type)
|
84
|
+
filespec = File.join(File.dirname(__FILE__), type + '.json')
|
85
|
+
data = JSON.parse(File.read(filespec))
|
86
|
+
describe_test(type, data)
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
describe 'Authentication Error Handling' do
|
91
|
+
it 'should raise a Client::AuthenticationError with bad credentials' do
|
92
|
+
client = SisRuby::Client.new(TEST_SERVER_URL)
|
93
|
+
expect { client.authenticate('test', 'bad-password') }.to \
|
94
|
+
raise_error(SisRuby::Client::AuthenticationError, /HTTP\/1.1 401/)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
def main
|
100
|
+
%w(entity hiera hook schema).each { |type| process_test_data(type) }
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
main
|
105
|
+
|
metadata
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sis_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Keith Bennett
|
8
|
+
- Neel Goyal
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-12-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: awesome_print
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.6.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 1.6.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: trick_bag
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.63.1
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.63.1
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: typhoeus
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 0.8.0
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.8.0
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.0'
|
84
|
+
description: Ruby client for SIS web service (https://github.com/sis-cmdb/sis-api)
|
85
|
+
email:
|
86
|
+
- keithrbennett@gmail.com
|
87
|
+
- sis-dev@verisign.com
|
88
|
+
executables: []
|
89
|
+
extensions: []
|
90
|
+
extra_rdoc_files: []
|
91
|
+
files:
|
92
|
+
- ".gitignore"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE
|
95
|
+
- README.md
|
96
|
+
- RELEASE_NOTES.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/sis_ruby.rb
|
99
|
+
- lib/sis_ruby/client.rb
|
100
|
+
- lib/sis_ruby/common.rb
|
101
|
+
- lib/sis_ruby/endpoint.rb
|
102
|
+
- lib/sis_ruby/exceptions/bad_response_error.rb
|
103
|
+
- lib/sis_ruby/exceptions/missing_id_error.rb
|
104
|
+
- lib/sis_ruby/get_helper.rb
|
105
|
+
- lib/sis_ruby/hash_builder.rb
|
106
|
+
- lib/sis_ruby/params.rb
|
107
|
+
- lib/sis_ruby/result_enumerable.rb
|
108
|
+
- lib/sis_ruby/version.rb
|
109
|
+
- samples/sample-1.rb
|
110
|
+
- samples/sample-2.rb
|
111
|
+
- sis_ruby.gemspec
|
112
|
+
- spec-writing/entity.json
|
113
|
+
- spec-writing/hiera.json
|
114
|
+
- spec-writing/hook.json
|
115
|
+
- spec-writing/schema.json
|
116
|
+
- spec-writing/write_spec.rb
|
117
|
+
- spec/client_spec.rb
|
118
|
+
- spec/endpoint_spec.rb
|
119
|
+
- spec/hash_builder_spec.rb
|
120
|
+
- spec/params_spec.rb
|
121
|
+
- spec/setup/drop-db.js
|
122
|
+
- spec/setup/recreate-db.sh
|
123
|
+
- spec/setup/test-user.json
|
124
|
+
- spec/spec_helper.rb
|
125
|
+
homepage: https://github.com/keithrbennett/sis_ruby
|
126
|
+
licenses:
|
127
|
+
- BSD 3-Clause
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.4.6
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: SIS Ruby Client
|
149
|
+
test_files: []
|