samanage 2.1.04 → 2.1.05
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -1
- data/Gemfile.lock +8 -1
- data/changelog.md +3 -0
- data/lib/samanage/api.rb +8 -9
- data/lib/samanage/api/custom_forms.rb +0 -1
- data/lib/samanage/api/users.rb +4 -2
- data/lib/samanage/error.rb +1 -1
- data/lib/samanage/version.rb +1 -1
- data/spec/api/samanage_attachment_spec.rb +35 -6
- data/spec/api/samanage_contract_spec.rb +5 -5
- data/spec/api/samanage_custom_form_spec.rb +1 -1
- data/spec/api/samanage_department_spec.rb +3 -2
- data/spec/api/samanage_group_spec.rb +2 -2
- data/spec/api/samanage_hardware_spec.rb +7 -4
- data/spec/api/samanage_incident_spec.rb +6 -4
- data/spec/api/samanage_site_spec.rb +1 -1
- data/spec/api/samanage_solution_spec.rb +3 -3
- data/spec/api/samanage_user_spec.rb +11 -7
- data/spec/api/samanage_util_spec.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c12e9f23a7417d96f83d1c76e7e5780cba44460
|
4
|
+
data.tar.gz: 1df4bc708e4688b5b84a6d33b358eb0f3d6eba0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96ab8a94116c16ae22b3a35e466f0826a03b43793937e9c34a6664811b41442b311c4bfd957e8abcc3fac37c703837e084a7ac6d08d5851e73963f0cefcbf7d4
|
7
|
+
data.tar.gz: f64fc20a63cfa50828f909d9156f0fbb5bfca20834bcbf7f524cd2737539f66d649a0747fbca5a9211b4ccf8d08a5d33b5b19f9ad61dffeb711629570fed4117
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,7 +2,10 @@ GEM
|
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
4
|
coderay (1.1.2)
|
5
|
+
concurrent-ruby (1.0.5)
|
5
6
|
diff-lcs (1.3)
|
7
|
+
faker (1.9.1)
|
8
|
+
i18n (>= 0.7)
|
6
9
|
ffi (1.9.23)
|
7
10
|
formatador (0.2.5)
|
8
11
|
guard (2.14.2)
|
@@ -21,6 +24,8 @@ GEM
|
|
21
24
|
rspec (>= 2.99.0, < 4.0)
|
22
25
|
httparty (0.15.7)
|
23
26
|
multi_xml (>= 0.5.2)
|
27
|
+
i18n (1.1.0)
|
28
|
+
concurrent-ruby (~> 1.0)
|
24
29
|
listen (3.1.5)
|
25
30
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
26
31
|
rb-inotify (~> 0.9, >= 0.9.7)
|
@@ -59,9 +64,11 @@ PLATFORMS
|
|
59
64
|
ruby
|
60
65
|
|
61
66
|
DEPENDENCIES
|
67
|
+
faker
|
68
|
+
ffi (= 1.9.24)
|
62
69
|
guard-rspec
|
63
70
|
httparty (= 0.15.7)
|
64
71
|
rspec
|
65
72
|
|
66
73
|
BUNDLED WITH
|
67
|
-
1.16.
|
74
|
+
1.16.1
|
data/changelog.md
CHANGED
data/lib/samanage/api.rb
CHANGED
@@ -3,6 +3,7 @@ require 'open-uri'
|
|
3
3
|
module Samanage
|
4
4
|
class Api
|
5
5
|
include HTTParty
|
6
|
+
attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins, :max_retries
|
6
7
|
MAX_RETRIES = 3
|
7
8
|
PATHS = {
|
8
9
|
category: 'categories.json',
|
@@ -20,11 +21,9 @@ module Samanage
|
|
20
21
|
solution: 'solutions.json',
|
21
22
|
user: 'users.json',
|
22
23
|
}
|
23
|
-
attr_accessor :datacenter, :content_type, :base_url, :token, :custom_forms, :authorized, :admins, :max_retries
|
24
|
-
|
25
24
|
# Development mode forces authorization & pre-populates admins and custom forms / fields
|
26
25
|
# datacenter should equal 'eu' or blank
|
27
|
-
def initialize(token: , datacenter: nil, development_mode: false, max_retries: MAX_RETRIES)
|
26
|
+
def initialize(token: , datacenter: nil, development_mode: false, max_retries: MAX_RETRIES, content_type: 'json')
|
28
27
|
self.token = token
|
29
28
|
if !datacenter.nil? && datacenter.to_s.downcase != 'eu'
|
30
29
|
datacenter = nil
|
@@ -47,15 +46,15 @@ module Samanage
|
|
47
46
|
self.authorized
|
48
47
|
end
|
49
48
|
|
50
|
-
# Check
|
49
|
+
# Check "oken against api.json"
|
51
50
|
def authorize
|
52
|
-
self.execute(path:
|
51
|
+
self.execute(path: "api.#{self.content_type}")
|
53
52
|
self.authorized = true
|
54
53
|
end
|
55
54
|
|
56
55
|
# Calling execute without a method defaults to GET
|
57
56
|
def execute(http_method: 'get', path: nil, payload: nil, verbose: nil, headers: {})
|
58
|
-
if payload.class == String
|
57
|
+
if payload.class == String && self.content_type == 'json'
|
59
58
|
begin
|
60
59
|
payload = JSON.parse(payload)
|
61
60
|
rescue => e
|
@@ -92,8 +91,8 @@ module Samanage
|
|
92
91
|
else
|
93
92
|
raise Samanage::Error.new(response: {response: 'Unknown HTTP method'})
|
94
93
|
end
|
95
|
-
rescue Errno::ECONNREFUSED, Net::OpenTimeout, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError => e
|
96
|
-
puts "[Warning]#{e.class}: #{e} - Retry: #{retries}/#{self.max_retries}"
|
94
|
+
rescue Errno::ECONNREFUSED, Net::OpenTimeout, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError, Errno::ENETDOWN, Errno::ECONNRESET, Errno::ENOENT, EOFError => e
|
95
|
+
puts "[Warning] #{e.class}: #{e} - Retry: #{retries}/#{self.max_retries}"
|
97
96
|
sleep 3
|
98
97
|
retries += 1
|
99
98
|
retry if retries < self.max_retries
|
@@ -150,7 +149,7 @@ module Samanage
|
|
150
149
|
|
151
150
|
# Return all admins in the account
|
152
151
|
def list_admins
|
153
|
-
admin_role_id = self.execute(path:
|
152
|
+
admin_role_id = self.execute(path: "roles.json")[:data].select{|role| role['name'] == 'Administrator'}.first['id']
|
154
153
|
self.admins.push(
|
155
154
|
self.execute(path: "users.json?role=#{admin_role_id}")[:data].map{|u| u['email']}
|
156
155
|
).flatten
|
data/lib/samanage/api/users.rb
CHANGED
@@ -41,8 +41,10 @@ module Samanage
|
|
41
41
|
|
42
42
|
# Email is unique so compare first for exact match only. Returns nil or the id
|
43
43
|
def find_user_id_by_email(email: )
|
44
|
-
api_call = self.
|
45
|
-
api_call[:data]
|
44
|
+
api_call = self.get_users(options: {email: email})
|
45
|
+
api_call[:data]
|
46
|
+
.select{|u| u['email'].to_s.downcase == email.to_s.downcase}
|
47
|
+
.first.to_h['id']
|
46
48
|
end
|
47
49
|
|
48
50
|
# Returns nil if no matching group_id
|
data/lib/samanage/error.rb
CHANGED
data/lib/samanage/version.rb
CHANGED
@@ -3,12 +3,41 @@ require 'samanage'
|
|
3
3
|
describe Samanage::Api do
|
4
4
|
context 'Attachments' do
|
5
5
|
describe 'API Functions' do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
6
|
+
before(:all) do
|
7
|
+
TOKEN ||= ENV['SAMANAGE_TEST_API_TOKEN']
|
8
|
+
@samanage = Samanage::Api.new(token: TOKEN)
|
9
|
+
@users = @samanage.get_users[:data]
|
10
|
+
@incidents = @samanage.incidents
|
12
11
|
end
|
12
|
+
# it 'uploads an attachment' do
|
13
|
+
# filename = 'sample_file.txt'
|
14
|
+
# attachment = File.open(filename)
|
15
|
+
# incident_id = @incidents.sample.dig('id')
|
16
|
+
# attach = @samanage.upload_attachment(
|
17
|
+
# attachment: attachment,
|
18
|
+
# attachable_id: incident_id,
|
19
|
+
# attachable_type: 'Incident'
|
20
|
+
# )
|
21
|
+
# expect(attach[:code]).to eq(200).or(201)
|
22
|
+
# expect(filename).to eq(attach[:data]['filename'])
|
23
|
+
# expect(attachment.size).to eq(attach[:data]['size'])
|
24
|
+
# end
|
25
|
+
# it 'downloads an attachment' do
|
26
|
+
# incident_id = @incidents.sample.dig('id')
|
27
|
+
# filename = 'sample_file.txt'
|
28
|
+
# attachment = File.open(filename)
|
29
|
+
# attach = @samanage.upload_attachment(
|
30
|
+
# attachment: attachment,
|
31
|
+
# attachable_id: incident_id,
|
32
|
+
# attachable_type: 'Incident'
|
33
|
+
# )
|
34
|
+
# attachable_incident_id = incident_id # Need filter for has attachment?
|
35
|
+
# incident = @samanage.find_incident(id: attachable_incident_id, options: {layout: 'long'})
|
36
|
+
# attachment = @samanage.download_attachment(attachment: incident[:data]['attachments'].first)
|
37
|
+
# expect(attachment.class).to be(File)
|
38
|
+
# expect(attach[:code]).to eq(200)
|
39
|
+
# expect(attachment.path.split('/').last).to eq(filename)
|
40
|
+
# end
|
41
|
+
end
|
13
42
|
end
|
14
43
|
end
|
@@ -21,7 +21,7 @@ describe Samanage::Api do
|
|
21
21
|
expect(@contracts.size).to eq(contract_count)
|
22
22
|
end
|
23
23
|
it 'create_contract(payload: json): creates a contract' do
|
24
|
-
random_name =
|
24
|
+
random_name = Faker::Artist.name
|
25
25
|
json = {
|
26
26
|
contract: {
|
27
27
|
type: 'SoftwareLicense',
|
@@ -36,7 +36,7 @@ describe Samanage::Api do
|
|
36
36
|
expect(contract_create[:data]['name']).to eq(random_name)
|
37
37
|
end
|
38
38
|
it 'create_contract: fails if no status' do
|
39
|
-
contract_name =
|
39
|
+
contract_name = Faker::Ancient.god
|
40
40
|
json = {
|
41
41
|
:contract => {
|
42
42
|
model: 'test',
|
@@ -60,7 +60,7 @@ describe Samanage::Api do
|
|
60
60
|
end
|
61
61
|
it 'update_contract: update_contract by id' do
|
62
62
|
sample_id = @contracts.sample['id']
|
63
|
-
new_name =
|
63
|
+
new_name = Faker::Company.name
|
64
64
|
json = {
|
65
65
|
contract: {
|
66
66
|
manufacturer_name: new_name
|
@@ -74,10 +74,10 @@ describe Samanage::Api do
|
|
74
74
|
sample_id = @contracts.sample['id']
|
75
75
|
item = {
|
76
76
|
item: {
|
77
|
-
name:
|
77
|
+
name: Faker::Company.catch_phrase ,
|
78
78
|
version:" 123",
|
79
79
|
qty: "2",
|
80
|
-
tag:
|
80
|
+
tag: Faker::Company.profession,
|
81
81
|
}
|
82
82
|
}
|
83
83
|
add_item = @samanage.add_item_to_contract(id: sample_id, payload: item)
|
@@ -9,7 +9,7 @@ describe Samanage::Api do
|
|
9
9
|
@custom_forms = @controller.collect_custom_forms
|
10
10
|
end
|
11
11
|
it 'collects all custom forms' do
|
12
|
-
expect(@custom_forms).to
|
12
|
+
expect(@custom_forms).to be_an(Array)
|
13
13
|
end
|
14
14
|
it 'Organizes custom forms by module' do
|
15
15
|
api_call = @controller.organize_forms
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'samanage'
|
2
|
+
require 'faker'
|
2
3
|
describe Samanage::Api do
|
3
4
|
context 'department' do
|
4
5
|
before(:all) do
|
@@ -19,8 +20,8 @@ describe Samanage::Api do
|
|
19
20
|
expect(@departments.size).to eq(department_count)
|
20
21
|
end
|
21
22
|
it 'creates a department' do
|
22
|
-
department_name =
|
23
|
-
department_description =
|
23
|
+
department_name = Faker::Book.title
|
24
|
+
department_description = Faker::Book.author
|
24
25
|
payload = {
|
25
26
|
department: {
|
26
27
|
name: department_name,
|
@@ -26,8 +26,8 @@ describe Samanage::Api do
|
|
26
26
|
expect(group[:data]).to have_key('name')
|
27
27
|
end
|
28
28
|
it 'creates a group' do
|
29
|
-
group_name =
|
30
|
-
group_description =
|
29
|
+
group_name = Faker::BossaNova.artist
|
30
|
+
group_description = Faker::BossaNova.song
|
31
31
|
payload = {
|
32
32
|
group: {
|
33
33
|
name: group_name,
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'samanage'
|
2
|
+
require 'faker'
|
2
3
|
describe Samanage::Api do
|
3
4
|
context 'Hardware' do
|
4
5
|
describe 'API Functions' do
|
@@ -21,8 +22,8 @@ describe Samanage::Api do
|
|
21
22
|
expect(@hardwares.size).to eq(hardware_count)
|
22
23
|
end
|
23
24
|
it 'create_hardware(payload: payload): creates a hardware' do
|
24
|
-
hardware_name =
|
25
|
-
serial_number =
|
25
|
+
hardware_name = Faker::Science.scientist
|
26
|
+
serial_number = Faker::Device.serial
|
26
27
|
payload = {
|
27
28
|
:hardware => {
|
28
29
|
:name => hardware_name,
|
@@ -70,10 +71,12 @@ describe Samanage::Api do
|
|
70
71
|
end
|
71
72
|
it 'update_hardware: update_hardware by id' do
|
72
73
|
sample_id = @hardwares.sample['id']
|
73
|
-
new_name =
|
74
|
+
new_name = [Faker::Dune.planet,Faker::ProgrammingLanguage.name].join('-')
|
74
75
|
payload = {
|
75
76
|
:hardware => {
|
76
|
-
:
|
77
|
+
name: new_name,
|
78
|
+
tag: Faker::Dune.saying,
|
79
|
+
asset_id: Faker::Space.moon
|
77
80
|
}
|
78
81
|
}
|
79
82
|
hardware_update = @samanage.update_hardware(payload: payload, id: sample_id)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'samanage'
|
2
|
+
require 'faker'
|
2
3
|
describe Samanage::Api do
|
3
4
|
context 'Incidents' do
|
4
5
|
describe 'API Functions' do
|
@@ -24,12 +25,12 @@ describe Samanage::Api do
|
|
24
25
|
end
|
25
26
|
it 'create_incident(payload: json): creates a incident' do
|
26
27
|
users_email = @samanage.collect_users.sample['email']
|
27
|
-
incident_name =
|
28
|
+
incident_name = [Faker::StarWars.specie,Faker::StarWars.planet,Faker::StarWars.droid].shuffle.join(' ')
|
28
29
|
json = {
|
29
30
|
:incident => {
|
30
31
|
:requester => {:email => users_email},
|
31
32
|
:name => incident_name,
|
32
|
-
:description =>
|
33
|
+
:description => Faker::StarWars.quote
|
33
34
|
}
|
34
35
|
}
|
35
36
|
incident_create = @samanage.create_incident(payload: json)
|
@@ -43,7 +44,7 @@ describe Samanage::Api do
|
|
43
44
|
json = {
|
44
45
|
:incident => {
|
45
46
|
:requester => {:email => users_email},
|
46
|
-
:description =>
|
47
|
+
:description => Faker::StarWars.quote
|
47
48
|
}
|
48
49
|
}
|
49
50
|
expect{@samanage.create_incident(payload: json)}.to raise_error(Samanage::InvalidRequest)
|
@@ -73,7 +74,8 @@ describe Samanage::Api do
|
|
73
74
|
it 'update_incident: update_incident by id' do
|
74
75
|
sample_incident = @incidents.reject{|i| ['Closed','Resolved'].include? i['state']}.sample
|
75
76
|
sample_id = sample_incident['id']
|
76
|
-
|
77
|
+
name = Faker::Movie.quote
|
78
|
+
description = [Faker::String.random,Faker::Seinfeld.quote,Faker::Lorem.paragraph].sample
|
77
79
|
incident_json = {
|
78
80
|
:incident => {
|
79
81
|
:description => description
|
@@ -22,7 +22,7 @@ describe Samanage::Api do
|
|
22
22
|
it 'creates a site' do
|
23
23
|
site_name = "Site ##{(rand*10**4).ceil}"
|
24
24
|
site_location = "Location #{(rand*10**4).ceil}"
|
25
|
-
site_description =
|
25
|
+
site_description = Faker::Movie.quote
|
26
26
|
payload = {
|
27
27
|
site: {
|
28
28
|
name: site_name,
|
@@ -20,8 +20,8 @@ describe Samanage::Api do
|
|
20
20
|
expect(solutions.size).to eq(solution_count)
|
21
21
|
end
|
22
22
|
it 'creates a solution' do
|
23
|
-
solution_name =
|
24
|
-
solution_description =
|
23
|
+
solution_name = Faker::Music.album
|
24
|
+
solution_description = Faker::Music.band
|
25
25
|
payload = {
|
26
26
|
solution: {
|
27
27
|
name: solution_name,
|
@@ -36,7 +36,7 @@ describe Samanage::Api do
|
|
36
36
|
end
|
37
37
|
it 'updates a valid solution' do
|
38
38
|
sample_solution_id = @solutions.sample['id']
|
39
|
-
new_description =
|
39
|
+
new_description = Faker::Movie.quote
|
40
40
|
payload = {solution: {description: new_description}}
|
41
41
|
solution_update = @samanage.update_solution(id: sample_solution_id, payload: payload)
|
42
42
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'samanage'
|
2
|
+
require 'faker'
|
2
3
|
|
3
4
|
describe Samanage::Api do
|
4
5
|
context 'Users' do
|
@@ -9,8 +10,10 @@ describe Samanage::Api do
|
|
9
10
|
end
|
10
11
|
describe 'API Functions' do
|
11
12
|
it 'ensures custom field is updated' do
|
12
|
-
val =
|
13
|
-
field_name = @samanage.custom_forms['user'][0]['custom_form_fields']
|
13
|
+
val = Faker::Seinfeld.quote
|
14
|
+
field_name = @samanage.custom_forms['user'][0]['custom_form_fields']
|
15
|
+
.select{|f| f.dig('custom_field','field_type') == 1} # field_type == 1 is text
|
16
|
+
.sample.dig('custom_field','name')
|
14
17
|
payload = {
|
15
18
|
user: {
|
16
19
|
custom_fields_values:{
|
@@ -38,8 +41,8 @@ describe Samanage::Api do
|
|
38
41
|
expect(@users.size).to eq(user_count)
|
39
42
|
end
|
40
43
|
it 'create_user(payload: json): creates a user' do
|
41
|
-
user_name =
|
42
|
-
email = user_name
|
44
|
+
user_name = [Faker::Simpsons.character,Faker::StarWars.character,Faker::Name.name].sample
|
45
|
+
email = Faker::Internet.safe_email(user_name)
|
43
46
|
json = {
|
44
47
|
:user => {
|
45
48
|
:name => user_name,
|
@@ -53,7 +56,7 @@ describe Samanage::Api do
|
|
53
56
|
expect(user_create[:code]).to eq(200).or(201)
|
54
57
|
end
|
55
58
|
it 'create_user: fails if no email' do
|
56
|
-
user_name =
|
59
|
+
user_name = Faker::Superhero.name
|
57
60
|
json = {
|
58
61
|
:user => {
|
59
62
|
:name => user_name,
|
@@ -120,10 +123,11 @@ describe Samanage::Api do
|
|
120
123
|
|
121
124
|
it 'update_user: update_user by id' do
|
122
125
|
sample_id = @users.sample['id']
|
123
|
-
new_name =
|
126
|
+
new_name = [Faker::Simpsons.character,Faker::StarWars.character,Faker::Name.name].sample
|
124
127
|
json = {
|
125
128
|
:user => {
|
126
|
-
:
|
129
|
+
name: new_name,
|
130
|
+
title: Faker::Job.title
|
127
131
|
}
|
128
132
|
}
|
129
133
|
user_update = @samanage.update_user(payload: json, id: sample_id)
|
@@ -9,7 +9,7 @@ describe Samanage::Api do
|
|
9
9
|
@incidents = @samanage.incidents
|
10
10
|
end
|
11
11
|
it 'sends an activation email' do
|
12
|
-
valid_email = @users.sample['email']
|
12
|
+
valid_email = @users.select{|u| !u['disabled'] && !u['last_login']}.sample['email']
|
13
13
|
send_email = @samanage.send_activation_email(email: valid_email)
|
14
14
|
expect(send_email[:code]).to eq(200)
|
15
15
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samanage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.05
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Walls
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|