usd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +4 -0
- data/bin/rusdc +265 -0
- data/bin/set_env +11 -0
- data/lib/usd.rb +218 -0
- data/usd.gemspec +22 -0
- metadata +187 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b7ee6cd159beb63fa0f91e51c300f90000e134adad2c348540a76b1aed6b2960
|
4
|
+
data.tar.gz: c3ea66730d275a9ae7a6c9ca1ada2b86ec083b1a2c0d44657840cf5728db2477
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f00d963b94685905e03c5f1b7d999454fc26fa6a81ec2997d5d07194ad9070b9e43b7495feaf5ff4da5d932a2fef1c00566f3fafc1f28fa44f07ddf532b43d7d
|
7
|
+
data.tar.gz: beecba4f9b33bb7058c1fd371aa3ce7ed380bfd3d88770d6b1d3a1a9429b3014895779891fa3d9a683439a99e102061bca4d16687cadbb14dc4267345a664012
|
data/README.md
ADDED
data/bin/rusdc
ADDED
@@ -0,0 +1,265 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "thor"
|
4
|
+
require 'tempfile'
|
5
|
+
require "erb"
|
6
|
+
|
7
|
+
load "#{__dir__}/usd.rb"
|
8
|
+
|
9
|
+
class Rusdc < Thor
|
10
|
+
|
11
|
+
desc "chg_add_nr", "<CO> <CI> - fügt einer CO ein CI hinzu"
|
12
|
+
def chg_add_nr(co, ci)
|
13
|
+
template = ERB.new <<-EOF
|
14
|
+
{
|
15
|
+
"lrel_asset_chgnr": {
|
16
|
+
"chg": {
|
17
|
+
"@id": "<%= uid_co %>"
|
18
|
+
},
|
19
|
+
"nr": {
|
20
|
+
"@id": "<%= uid_nr %>"
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
24
|
+
EOF
|
25
|
+
json = template.result_with_hash(:uid_co => loadcon.request("/caisd-rest/chg/COMMON_NAME-#{co}")["chg"]["@id"], :uid_nr => loadcon.request("/caisd-rest/nr/COMMON_NAME-#{ci}")["nr"]["@id"])
|
26
|
+
puts loadcon.create({:type => "json", :data => json})
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "chg_list_nr", "<CO> - listet alle CIs einer CO"
|
30
|
+
def chg_list_nr(co)
|
31
|
+
invoke 'find', ['lrel_asset_chgnr', %(chg.chg_ref_num = '#{co}'), "nr"], {:format => "mlr", :mlr_format => "xtab"}
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "create", "pipe json-data to create object"
|
35
|
+
def create()
|
36
|
+
puts loadcon.create({:type => "json", :data => STDIN.read})
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "field_names","field_names <object> , listet die Attribute und Beziehungen eines Objektes auf."
|
40
|
+
def field_names(object)
|
41
|
+
e = loadcon.search(object,{'fields' => "*","start" => "1", "size" => "1"})[0]
|
42
|
+
e.keys.sort.each do |k|
|
43
|
+
puts "#{k} (#{e[k].class})"
|
44
|
+
if e[k].class == Hash
|
45
|
+
puts e[k].jp
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "find", "find <object> <where-clause> [fields - Komma getrennt (id,name)] - findet alle Objecte die die wc erfüllen."
|
51
|
+
long_desc <<-LONGDESC
|
52
|
+
|
53
|
+
|
54
|
+
Mit --mlr_format kann man das output-Format von Miller (mlr) ändern auf csv, md (markdown), xtab (sehr übersichtlich), dkvp (Delimited key-value pairs) ..., siehe `mlr --help`
|
55
|
+
|
56
|
+
Beispiele:
|
57
|
+
|
58
|
+
- alle aktiven CIs die mit sygosrv beginnen und die Zahl 58 enthalten:
|
59
|
+
./rusdc find nr "name like 'servername' and delete_flag.sym = 'Active' " "id,name" --format mlr
|
60
|
+
|
61
|
+
- meine aktiven Incidents:
|
62
|
+
./rusdc find --format mlr in "assignee.last_name = 'gaida' and status.sym in ('Service pending','Work in progress.','Customer Pending','Open','Hold','Resolved')" ref_num,z_project,summary,status,call_back_date,affected_resource,orig_user_organization
|
63
|
+
|
64
|
+
- Activity-Log eines Incidents:
|
65
|
+
./rusdc find alg "call_req_id.ref_num = 'I00001'" "call_req_id,action_desc,analyst,description,time_stamp,type" --format mlr --mlr_format xtab
|
66
|
+
|
67
|
+
- nur die Beschreibungen Activity-Log eines Incidents:
|
68
|
+
./rusdc find alg "call_req_id.ref_num = 'I00001'" "description" --format mlr --mlr_format csv
|
69
|
+
|
70
|
+
- Incidents einer Maschine
|
71
|
+
./rusdc find in "affected_resource.name = 'servername'" "ref_num,summary" --format mlr
|
72
|
+
|
73
|
+
- Kombiniert, alle Activity-Log-Beschreibungen aller Incidents einer Maschine:
|
74
|
+
./rusdc find alg "call_req_id.affected_resource.name = 'servername'" "description" --format mlr
|
75
|
+
|
76
|
+
- Changes einer Maschine:
|
77
|
+
rusdc find chg "asset.nr.name = 'servername'" "@COMMON_NAME,summary,status" --format mlr
|
78
|
+
|
79
|
+
- Alle Maschinen finden die mit goes beginnen und deren childs auf Linux und Windows prüfen:
|
80
|
+
for ci in $(rusdc find nr "name like 'dc%' and delete_flag.sym = 'active'" "name" --format mlr | sed '1 d'); do rusdc nr_childs $ci > help ; echo "$ci: $(grep -iP '^(Linux|.*MS windows).*server' help)" ; done
|
81
|
+
|
82
|
+
LONGDESC
|
83
|
+
option :format, :type => :string, :default => "json"
|
84
|
+
option :mlr_format, :type => :string, :default => "pprint"
|
85
|
+
option :nice_time, :type => :boolean, :default => true
|
86
|
+
option :debug, :type => :boolean, :default => false
|
87
|
+
def find(object, wc, fields="*")
|
88
|
+
con = loadcon
|
89
|
+
con.debug = options[:debug]
|
90
|
+
e = con.search(object,{'fields' => fields,"wc" => wc})
|
91
|
+
if e.length > 0
|
92
|
+
if options[:nice_time]
|
93
|
+
e.each_index do |i|
|
94
|
+
e[i].keys.each do |key|
|
95
|
+
if key =~ /(date|last_mod|warranty_start|warranty_end|time_stamp)$/
|
96
|
+
e[i][key]=Time.at(e[i][key]).to_s
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
case options[:format]
|
102
|
+
when "json"
|
103
|
+
puts e.jp
|
104
|
+
when "yaml"
|
105
|
+
puts e.to_yaml
|
106
|
+
when "mlr"
|
107
|
+
# hierfuer muessen jq und mlr verfuegbar sein
|
108
|
+
if (fields =~ /^[\w\_,@]+$/)
|
109
|
+
fields_array=fields.split(/,/)
|
110
|
+
jq_mapping = []
|
111
|
+
fields_array.each do |key|
|
112
|
+
if e[0].keys.include?(key)
|
113
|
+
if e[0][key].class == Hash
|
114
|
+
jq_mapping << %("#{key}": ."#{key}"."@COMMON_NAME")
|
115
|
+
else
|
116
|
+
jq_mapping << %("#{key}": ."#{key}")
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
jq_mapping_string = jq_mapping.join(",")
|
121
|
+
file = Tempfile.new('inner_cmd')
|
122
|
+
cmd = %(jq '[.[]|{#{jq_mapping_string}}]' #{file.path} | mlr --ijson --o#{options[:mlr_format]} cat)
|
123
|
+
file.write(e.jp)
|
124
|
+
file.close
|
125
|
+
`cp #{file.path} /tmp/test.json`
|
126
|
+
puts `#{cmd}`
|
127
|
+
file.unlink
|
128
|
+
else
|
129
|
+
puts "fields Problem: es sind nur Buchstaben, Ziffern, Komma und Unterstrich zulaessig."
|
130
|
+
end
|
131
|
+
else
|
132
|
+
puts "das Format #{options[:format]} ist nicht hinterlegt. Es gibt nur json, yaml oder mlr."
|
133
|
+
end
|
134
|
+
else
|
135
|
+
puts "keine Einträge gefunden!"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
desc "get", "get <object> <cn>"
|
140
|
+
option :yaml, :type => :boolean, :default => false
|
141
|
+
def get(object, cn)
|
142
|
+
e = loadcon.request("/caisd-rest/#{object}/COMMON_NAME-#{cn}")
|
143
|
+
if e.class == Hash
|
144
|
+
puts options[:yaml] ? e[object].to_yaml : e[object].jp
|
145
|
+
elsif e.message == "409 Conflict"
|
146
|
+
puts %(#{e.message} - try with 'rusdc find #{object} "" "@COMMON_NAME" --format mlr | sort | uniq -c | sort -n -r | head -20', may be more then one object with this COMMON_NAME)
|
147
|
+
else
|
148
|
+
puts e.response
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
desc "get_attachment_of_ci", "<ci_name> <filename>"
|
153
|
+
def get_attachment_of_ci(ciname, filename)
|
154
|
+
att_nr = loadcon.search("lrel_attachments_nr",{'fields' => "attmnt","wc" => "nr.name = '#{ciname}'"})
|
155
|
+
att_nr.each do |att|
|
156
|
+
attmnt = loadcon.request("/caisd-rest/attmnt/COMMON_NAME-#{att["attmnt"]["@COMMON_NAME"]}")["attmnt"]
|
157
|
+
if attmnt["orig_file_name"] == filename
|
158
|
+
puts loadcon.request("/caisd-rest/attmnt/#{attmnt["@id"]}/file-resource",{:unchanged => true})
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
desc "get_attachment_of_co", "<co_name> <filename>"
|
164
|
+
def get_attachment_of_co(coname, filename)
|
165
|
+
chg_id=loadcon.request("/caisd-rest/chg/COMMON_NAME-#{coname}")["chg"]["@id"]
|
166
|
+
att_nr = loadcon.search("lrel_attachments_changes",{'fields' => "attmnt","wc" => "chg = #{chg_id}"})
|
167
|
+
att_nr.each do |att|
|
168
|
+
attmnt = loadcon.request("/caisd-rest/attmnt/COMMON_NAME-#{att["attmnt"]["@COMMON_NAME"]}")["attmnt"]
|
169
|
+
if attmnt["orig_file_name"] == filename
|
170
|
+
puts loadcon.request("/caisd-rest/attmnt/#{attmnt["@id"]}/file-resource",{:unchanged => true})
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
desc "list_attachments_of_ci", "<ci_name>"
|
176
|
+
def list_attachments_of_ci(ciname)
|
177
|
+
att_nr = loadcon.search("lrel_attachments_nr",{'fields' => "attmnt","wc" => "nr.name = '#{ciname}'"})
|
178
|
+
att_nr.each do |att|
|
179
|
+
puts loadcon.request("/caisd-rest/attmnt/COMMON_NAME-#{att["attmnt"]["@COMMON_NAME"]}")["attmnt"]["orig_file_name"]
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
desc "list_attachments_of_co", "<co_name>"
|
184
|
+
def list_attachments_of_co(coname)
|
185
|
+
chg_id=loadcon.request("/caisd-rest/chg/COMMON_NAME-#{coname}")["chg"]["@id"]
|
186
|
+
att_nr = loadcon.search("lrel_attachments_changes",{'fields' => "attmnt","wc" => "chg = #{chg_id}"})
|
187
|
+
att_nr.each do |att|
|
188
|
+
puts loadcon.request("/caisd-rest/attmnt/COMMON_NAME-#{att["attmnt"]["@COMMON_NAME"]}")["attmnt"]["orig_file_name"]
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
desc "nr_add_child", "<nr-name> <child-name>"
|
193
|
+
def nr_add_child(nr, child)
|
194
|
+
template = ERB.new <<-EOF
|
195
|
+
{
|
196
|
+
"hier": {
|
197
|
+
"child": {
|
198
|
+
"@id": "<%= uid_child %>"
|
199
|
+
},
|
200
|
+
"parent": {
|
201
|
+
"@id": "<%= uid_parent %>"
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
EOF
|
206
|
+
json = template.result_with_hash(:uid_child => loadcon.request("/caisd-rest/nr/COMMON_NAME-#{child}")["nr"]["@id"], :uid_parent => loadcon.request("/caisd-rest/nr/COMMON_NAME-#{nr}")["nr"]["@id"])
|
207
|
+
puts loadcon.create({:type => "json", :data => json})
|
208
|
+
end
|
209
|
+
|
210
|
+
desc "nr_changes", "<nr> [inactive-too] - listet alle offenen Change eines nr, bei Bedarf auch inaktive"
|
211
|
+
option :inactive_too, :type => :boolean, :default => false
|
212
|
+
def nr_changes(nr)
|
213
|
+
wc_add = (options[:inactive_too] ? "" : " and status.sym in ('Service pending','Work in progress','Customer Pending','Open','Hold')")
|
214
|
+
wc = %(asset.nr.name = '#{nr}'#{wc_add})
|
215
|
+
invoke 'find', ['chg', wc, 'chg_ref_num,summary,status'], {:format => "mlr"}
|
216
|
+
end
|
217
|
+
|
218
|
+
desc "nr_childs", "nr_childs <ci-name> , listet alle Childs eines CI"
|
219
|
+
def nr_childs(name)
|
220
|
+
loadcon.search("hier",{'fields' => "*","wc" => "parent.name = '#{name}'"}).each do |c|
|
221
|
+
puts c["child"]["@COMMON_NAME"]
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
desc "nr_incidents", "<nr> [inactive-too] - listet alle offenen Incidents eines nr, bei Bedarf auch inaktive"
|
226
|
+
option :inactive_too, :type => :boolean, :default => false
|
227
|
+
def nr_incidents(nr)
|
228
|
+
invoke 'find', ['in', %(affected_resource.name = '#{nr}'#{options[:inactive_too] ? "" : " and not status.sym in ('Cancelled','Closed')"}), "ref_num,summary,status"], {:format => "mlr"}
|
229
|
+
end
|
230
|
+
|
231
|
+
desc "nr_parents", "nr_parents <ci-name> , listet alle Parents eines CI"
|
232
|
+
def nr_parents(name)
|
233
|
+
loadcon.search("hier",{'fields' => "*","wc" => "child.name = '#{name}'"}).each do |c|
|
234
|
+
puts c["parent"]["@COMMON_NAME"]
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
desc "update", "pipe json-data to update object"
|
239
|
+
long_desc <<-LONGDESC
|
240
|
+
|
241
|
+
Hier ein Beispiel
|
242
|
+
|
243
|
+
ciname=servername
|
244
|
+
rusdc find nr "name like '$ciname'" "z_backup" |jq '{nr:(.[0]|.z_backup= (.z_backup +"\n----\neine neue Zeile")|del(.link,."@id",."@REL_ATTR"))}' | rusdc update
|
245
|
+
|
246
|
+
LONGDESC
|
247
|
+
def update()
|
248
|
+
puts loadcon.update({:type => "json", :data => STDIN.read})
|
249
|
+
end
|
250
|
+
|
251
|
+
|
252
|
+
private
|
253
|
+
|
254
|
+
def loadcon
|
255
|
+
if ENV["usduser"] and ENV["usdpass"] and ENV["usdurl"]
|
256
|
+
Usd.new(ENV["usduser"],ENV["usdpass"],ENV["usdurl"])
|
257
|
+
else
|
258
|
+
puts "ACHTUNG:\n\nMindestens einer der Umgebunsvariablen usduser, usdpass und usdurl ist nicht gesetzt. Am besten das Skript #{__dir__}/set_env_prod mit `source` aufrufen!"
|
259
|
+
puts " also : source #{__dir__}/set_env_prod \n"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
Rusdc.start(ARGV)
|
data/bin/set_env
ADDED
data/lib/usd.rb
ADDED
@@ -0,0 +1,218 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require "base64"
|
3
|
+
require "json"
|
4
|
+
require "yaml"
|
5
|
+
require 'uri'
|
6
|
+
require "time"
|
7
|
+
require "ostruct"
|
8
|
+
require 'tempfile'
|
9
|
+
|
10
|
+
class Usd
|
11
|
+
|
12
|
+
RestClient.proxy = ""
|
13
|
+
|
14
|
+
attr_reader :base_url, :user, :access_key, :expiration_date, :debug
|
15
|
+
attr_writer :debug
|
16
|
+
|
17
|
+
def initialize(user, password="", base_url = "http://localhost:8050", hash={})
|
18
|
+
hash = {:expiration_date => 0, :access_key => "",:save_access_key => true }.update hash
|
19
|
+
make_new = true
|
20
|
+
@base_url = base_url
|
21
|
+
@user = user
|
22
|
+
@debug = false
|
23
|
+
if File.exist?(".usd") and hash[:save_access_key]
|
24
|
+
tt = YAML.load(File.open(".usd","r"))
|
25
|
+
if (tt.expiration_date - Time.now.to_i ) > 900 and tt.base_url == base_url
|
26
|
+
@access_key = tt.access_key
|
27
|
+
@expiration_date = tt.expiration_date
|
28
|
+
make_new = false
|
29
|
+
puts "cache key loaded..." if @debug
|
30
|
+
end
|
31
|
+
end
|
32
|
+
if hash[:save_access_key] and hash[:access_key].length > 0
|
33
|
+
if (hash[:expiration_date] - Time.now.to_i ) > 900
|
34
|
+
@access_key = hash[:access_key]
|
35
|
+
@expiration_date = hash[:expiration_date]
|
36
|
+
make_new = false
|
37
|
+
puts "use existing access_key ..." if @debug
|
38
|
+
end
|
39
|
+
end
|
40
|
+
if make_new
|
41
|
+
encoded=Base64.encode64( "#{@user}:#{password}")
|
42
|
+
begin
|
43
|
+
response = RestClient::Request.execute(method: :post, url: "#{@base_url}/caisd-rest/rest_access?_type=json",
|
44
|
+
payload: '<rest_access/>',
|
45
|
+
headers: {
|
46
|
+
'content-type' => "application/xml",
|
47
|
+
"accept" => "application/json",
|
48
|
+
"authorization" => "Basic #{encoded}",
|
49
|
+
"cache-control" => "no-cache"
|
50
|
+
},
|
51
|
+
log: Logger.new(STDOUT)
|
52
|
+
)
|
53
|
+
authData=JSON.parse(response.body)
|
54
|
+
if authData['rest_access']['access_key'] > 0
|
55
|
+
@access_key = authData['rest_access']['access_key']
|
56
|
+
@expiration_date = authData['rest_access']['expiration_date']
|
57
|
+
if hash[:save_access_key]
|
58
|
+
f=File.open(".usd","w")
|
59
|
+
f.puts self.to_yaml
|
60
|
+
f.close
|
61
|
+
end
|
62
|
+
else
|
63
|
+
"keinen Accesskey erhalten. \nresponse.body:\n#{response.body}"
|
64
|
+
end
|
65
|
+
rescue RestClient::ExceptionWithResponse => e
|
66
|
+
e.response
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.loadcon
|
72
|
+
# load from env
|
73
|
+
Usd.new(ENV["usduser"],ENV["usdpass"],ENV["usdurl"])
|
74
|
+
end
|
75
|
+
|
76
|
+
def header(hash={})
|
77
|
+
hash = {
|
78
|
+
'x-accesskey' => @access_key,
|
79
|
+
'accept' => "application/json",
|
80
|
+
"Content-Type" =>"application/json; charset=UTF-8",
|
81
|
+
'X-Obj-Attrs' => "*",
|
82
|
+
'cache-control'=> "no-cache"
|
83
|
+
}.update hash
|
84
|
+
hash
|
85
|
+
end
|
86
|
+
|
87
|
+
def request(uri, hash={})
|
88
|
+
RestClient.log = STDOUT if @debug
|
89
|
+
hash = {:method => "get", :header => header(), :unchanged => false, :ostruct => false, :json => "", :base_url => @base_url}.update hash
|
90
|
+
puts "request - hash: #{JSON.pretty_generate(hash)}" if @debug
|
91
|
+
if (uri !~ /^http/)
|
92
|
+
url = URI.escape("#{hash[:base_url]}#{uri}")
|
93
|
+
else
|
94
|
+
url = URI.escape(uri)
|
95
|
+
end
|
96
|
+
begin
|
97
|
+
if hash[:method] == "get"
|
98
|
+
response = RestClient::Request.execute(method: hash[:method], url: url, headers: hash[:header])
|
99
|
+
elsif hash[:method] == "post"
|
100
|
+
response = RestClient.post(url, hash[:json], hash[:header])
|
101
|
+
elsif hash[:method] == "put"
|
102
|
+
response = RestClient.put(url, hash[:json], hash[:header])
|
103
|
+
elsif hash[:method] =~ /delete/i
|
104
|
+
response = RestClient.delete(url, hash[:header])
|
105
|
+
end
|
106
|
+
if hash[:ostruct]
|
107
|
+
JSON.parse(response.body, object_class: OpenStruct)
|
108
|
+
elsif hash[:unchanged]
|
109
|
+
response.body
|
110
|
+
else
|
111
|
+
JSON.parse(response.body)
|
112
|
+
end
|
113
|
+
rescue RestClient::ExceptionWithResponse => e
|
114
|
+
e
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def create(hash = {})
|
119
|
+
hash = {:type => "ruby", :data => {}}.update hash
|
120
|
+
case hash[:type]
|
121
|
+
when "ruby"
|
122
|
+
data = hash[:data]
|
123
|
+
when "json"
|
124
|
+
data = JSON.parse(hash[:data])
|
125
|
+
when "yaml"
|
126
|
+
data = YAML.load(hash[:data])
|
127
|
+
else
|
128
|
+
"Error: 'data[:type]': '#{hash[:data]}' not found!"
|
129
|
+
end
|
130
|
+
puts "create - data: #{JSON.pretty_generate(data)}" if @debug
|
131
|
+
object = data.keys[0]
|
132
|
+
uri = "/caisd-rest/#{object}"
|
133
|
+
request("/caisd-rest/#{object}",{:method => "post", :json => data.to_json})
|
134
|
+
end
|
135
|
+
|
136
|
+
def update(hash = {})
|
137
|
+
hash = {:type => "ruby", :data => {}}.update hash
|
138
|
+
case hash[:type]
|
139
|
+
when "ruby"
|
140
|
+
data = hash[:data]
|
141
|
+
when "json"
|
142
|
+
data = JSON.parse(hash[:data])
|
143
|
+
when "yaml"
|
144
|
+
data = YAML.load(hash[:data])
|
145
|
+
else
|
146
|
+
"Error: 'data[:type]': '#{hash[:data]}' not found!"
|
147
|
+
end
|
148
|
+
puts "update - data: #{JSON.pretty_generate(data)}" if @debug
|
149
|
+
object = data.keys[0]
|
150
|
+
cn = data[object]["@COMMON_NAME"]
|
151
|
+
request("/caisd-rest/#{object}/COMMON_NAME-#{cn}",{:method => "put", :json => data.to_json, :header => header({'X-Obj-Attrs' => 'COMMON_NAME'})})
|
152
|
+
end
|
153
|
+
|
154
|
+
def set_url_parm(params_hash,attribute_name,default)
|
155
|
+
# disable case
|
156
|
+
params_hash.keys.each do |k|
|
157
|
+
if k =~ /^#{attribute_name}$/i
|
158
|
+
v = params_hash[k]
|
159
|
+
params_hash.delete(k)
|
160
|
+
params_hash[attribute_name] = v
|
161
|
+
end
|
162
|
+
end
|
163
|
+
"#{attribute_name}=#{params_hash[attribute_name]?params_hash[attribute_name]:default}"
|
164
|
+
end
|
165
|
+
|
166
|
+
def set_param(params_hash,attribute_name,default)
|
167
|
+
params_hash[attribute_name]?params_hash[attribute_name]:default
|
168
|
+
end
|
169
|
+
|
170
|
+
def search(object,params={})
|
171
|
+
attr=[]
|
172
|
+
attr.push set_url_parm(params,"SORT","id DESC")
|
173
|
+
attr.push set_url_parm(params,"start","1")
|
174
|
+
attr.push set_url_parm(params,"size","50")
|
175
|
+
attr.push set_url_parm(params,"WC","")
|
176
|
+
fields = set_param(params,"fields","COMMON_NAME,id")
|
177
|
+
query_string=attr.join("&")
|
178
|
+
res_rdata = request("/caisd-rest/#{object}?#{query_string}",{:method => "get", :header => header({'X-Obj-Attrs' => fields})})
|
179
|
+
puts res_rdata if @debug
|
180
|
+
count = res_rdata["collection_#{object}"]["@COUNT"].to_i
|
181
|
+
start = res_rdata["collection_#{object}"]["@START"].to_i
|
182
|
+
total_count = res_rdata["collection_#{object}"]["@TOTAL_COUNT"].to_i
|
183
|
+
# turn throught the pages
|
184
|
+
if count == 1
|
185
|
+
[res_rdata["collection_#{object}"][object]]
|
186
|
+
elsif count == 0
|
187
|
+
[]
|
188
|
+
else
|
189
|
+
retArray = res_rdata["collection_#{object}"][object]
|
190
|
+
if total_count > (count + start - 1)
|
191
|
+
new_params = {"start" => (start + 50)}
|
192
|
+
params = params.update new_params
|
193
|
+
retArray += search(object,params)
|
194
|
+
end
|
195
|
+
retArray
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
module Jsonpretty
|
202
|
+
def jp
|
203
|
+
# return in json_pretty
|
204
|
+
JSON.pretty_generate(self)
|
205
|
+
end
|
206
|
+
def jpp
|
207
|
+
# print in json_pretty
|
208
|
+
puts JSON.pretty_generate(self)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
class Hash
|
213
|
+
include Jsonpretty
|
214
|
+
end
|
215
|
+
|
216
|
+
class Array
|
217
|
+
include Jsonpretty
|
218
|
+
end
|
data/usd.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'usd'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2019-10-31'
|
5
|
+
s.summary = "SDM REST-API-Calls"
|
6
|
+
s.description = "a Ruby class and a commandlinetool for SDM REST-API-Calls"
|
7
|
+
s.authors = ["Oliver Gaida"]
|
8
|
+
s.email = 'oliver.gaida@sycor.de'
|
9
|
+
#s.files = ["bin/rusdc", "bin/set_env", "lib/usd.rb"] # Dir["*/*"]
|
10
|
+
s.files = `git ls-files`.split($/)
|
11
|
+
s.homepage = 'https://github.com/ogaida/usd'
|
12
|
+
s.add_dependency('tempfile', '~> 0')
|
13
|
+
s.add_dependency('thor', '~> 0')
|
14
|
+
s.add_dependency('erb', '~> 0')
|
15
|
+
s.add_dependency('rest-client', '~> 0')
|
16
|
+
s.add_dependency('base64', '~> 0')
|
17
|
+
s.add_dependency('json', '~> 0')
|
18
|
+
s.add_dependency('yaml', '~> 0')
|
19
|
+
s.add_dependency('uri', '~> 0')
|
20
|
+
s.add_dependency('time', '~> 0')
|
21
|
+
s.add_dependency('ostruct', '~> 0')
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: usd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oliver Gaida
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tempfile
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: erb
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: base64
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yaml
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: uri
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: time
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: ostruct
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description: a Ruby class and a commandlinetool for SDM REST-API-Calls
|
154
|
+
email: oliver.gaida@sycor.de
|
155
|
+
executables: []
|
156
|
+
extensions: []
|
157
|
+
extra_rdoc_files: []
|
158
|
+
files:
|
159
|
+
- README.md
|
160
|
+
- bin/rusdc
|
161
|
+
- bin/set_env
|
162
|
+
- lib/usd.rb
|
163
|
+
- usd.gemspec
|
164
|
+
homepage: https://github.com/ogaida/usd
|
165
|
+
licenses: []
|
166
|
+
metadata: {}
|
167
|
+
post_install_message:
|
168
|
+
rdoc_options: []
|
169
|
+
require_paths:
|
170
|
+
- lib
|
171
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - ">="
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
requirements: []
|
182
|
+
rubyforge_project:
|
183
|
+
rubygems_version: 2.7.6
|
184
|
+
signing_key:
|
185
|
+
specification_version: 4
|
186
|
+
summary: SDM REST-API-Calls
|
187
|
+
test_files: []
|