usd 1.2 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -9
- data/bin/rusdc +161 -8
- data/change_log.md +10 -0
- data/usd.gemspec +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4448a1b65d863520eea90c9fd76f4bc27f437871697c5d5efc150a7cdf6fe30b
|
4
|
+
data.tar.gz: a8e0416e4e629b95add9bdf050fab5a3e8f77d9369147dd006b26a2910bb9a07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2982682a3d2df44517df1129aa2754bc9824b56c170c0af053272ac4f89ac1404832d94062058620c6b3668902b78cc99e1d2d55604eb511664204839d799a39
|
7
|
+
data.tar.gz: 155b49fb190294484d453b90716c1a8b6da0d9715a617d634be775e4a221991451b03c8f9948c7dce2a6008f13f6c373bd91d64c79deece02a48fdfe28df2921
|
data/README.md
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
|
4
4
|
There is a ruby class and a commandline tool rusdc.
|
5
5
|
|
6
|
+
[![asciicast](https://asciinema.org/a/7zw3RLpikFluqX9XJMxCpMEmS.svg)](https://asciinema.org/a/7zw3RLpikFluqX9XJMxCpMEmS)
|
7
|
+
|
6
8
|
# installation
|
7
9
|
|
8
10
|
just install the gem:
|
@@ -30,31 +32,38 @@ yum install ruby-devel
|
|
30
32
|
|
31
33
|
see [https://github.com/ogaida/usd/wiki/bash-completion](https://github.com/ogaida/usd/wiki/bash-completion)
|
32
34
|
|
33
|
-
# external tools
|
35
|
+
# external tools / requirements
|
34
36
|
|
35
37
|
If you use the `rusdc find` command with `--format mlr` option then you need `mlr`.
|
36
38
|
|
37
39
|
- [mlr - Miller](http://johnkerl.org/miller/doc/index.html) - a great tool for data-transforming to and from json, csv and many more
|
38
40
|
|
39
|
-
Place the `mlr`-binary in a path, which is in your PATH-Environment. Download-Url for mlr-releases: [https://github.com/johnkerl/miller/releases](https://github.com/johnkerl/miller/releases)
|
41
|
+
Place the `mlr`-binary in a path, which is in your PATH-Environment. Download-Url for mlr-releases: [https://github.com/johnkerl/miller/releases](https://github.com/johnkerl/miller/releases).
|
42
|
+
|
43
|
+
For uloading attachments `unix2dos` and `base64` is used.
|
40
44
|
|
41
45
|
# functions from the commandline-tool `rusdc`
|
42
46
|
|
43
47
|
```
|
48
|
+
rusdc chg_add_attachment <co> <file> # attach the file to co
|
44
49
|
rusdc chg_add_nr <co> <ci> # add a CI to a changeorder
|
45
50
|
rusdc chg_list_nr <co> # list all CIs of one changeorder
|
46
51
|
rusdc create # pipe json-data to create object
|
47
52
|
rusdc field_names <object-type> [wc] # list all fields of an object including its format
|
48
53
|
rusdc find <object-type> [where-clause] [fields, comma separated] [options] # finds each object which meets the wc-condition
|
49
54
|
rusdc get <object-type> <common_name|id> # shows one object by name or id
|
50
|
-
rusdc get_all_attachments_of_co <co_name> # get all attachments of a changeorder and save all
|
51
|
-
rusdc get_attachment_of_ci <ci_name> <filename> # download an attachment of a CI and print it out on
|
52
|
-
rusdc get_attachment_of_co <co_name> <filename> # download an attachment of a changeorder and print it
|
55
|
+
rusdc get_all_attachments_of_co <co_name> # get all attachments of a changeorder and save all these to current folder
|
56
|
+
rusdc get_attachment_of_ci <ci_name> <filename> # download an attachment of a CI and print it out on stdout
|
57
|
+
rusdc get_attachment_of_co <co_name> <filename> # download an attachment of a changeorder and print it out on stdout
|
58
|
+
rusdc get_attachment_of_in <incident> <filename> # download an attachment of an Incident and print it out on stdout
|
53
59
|
rusdc help [COMMAND] # Describe available commands or one specific command
|
54
60
|
rusdc in_add_2_chg <changeorder> <incident> # add incident to changeorder
|
61
|
+
rusdc in_add_attachment <in> <file> # attach the file to incident
|
55
62
|
rusdc in_list_child_ins <in> # list all child-incidents of one incident
|
56
63
|
rusdc list_attachments_of_ci <ci_name> # list all attachments of a CI
|
57
64
|
rusdc list_attachments_of_co <co_name> # list all attachments of a changeorder
|
65
|
+
rusdc list_attachments_of_in <in> # list all attachments of an Incident
|
66
|
+
rusdc nr_add_attachment <nr> <file> # attach the file to nr
|
58
67
|
rusdc nr_add_child <nr-name> <child-name> # add one child CI to another CI
|
59
68
|
rusdc nr_add_org <nr> <org> # add an Organisation to a ConfigurationItem
|
60
69
|
rusdc nr_changes <nr> [inactive-too] # list all open changeorders of one CI
|
@@ -62,10 +71,11 @@ rusdc nr_childs <ci-name> # l
|
|
62
71
|
rusdc nr_incidents <nr> [inactive-too] # lists all incident of a specific CI
|
63
72
|
rusdc nr_parents <ci-name> # lists all parent CIs of a specific CI
|
64
73
|
rusdc update # pipe json-data to update object
|
65
|
-
rusdc update_attr <obj> <common_name|wc> <key> <value> # updates a direct (not referenced) attribute of one
|
66
|
-
rusdc update_attr_by_id <obj> <id> <key> <value> # updates a plain attribute of one object by id, does
|
67
|
-
rusdc update_ref_attr <obj> <common_name> <key> <value>
|
68
|
-
rusdc update_ref_attr_by_id <obj> <id> <key> <value_id> # updates a referenced attribute of one object_id by
|
74
|
+
rusdc update_attr <obj> <common_name|wc> <key> <value> # updates a direct (not referenced) attribute of one or more objects.
|
75
|
+
rusdc update_attr_by_id <obj> <id> <key> <value> # updates a plain attribute of one object by id, does not work
|
76
|
+
rusdc update_ref_attr <obj> <common_name> <key> <value> [ref_obj=nr] # updates a referenced attribute of one object.
|
77
|
+
rusdc update_ref_attr_by_id <obj> <id> <key> <value_id> # updates a referenced attribute of one object_id by value-id
|
78
|
+
rusdc vcard_via_email <email> # creates a vcard from the given email-address and saves it in the /tmp directory.
|
69
79
|
```
|
70
80
|
|
71
81
|
# environment-variables
|
data/bin/rusdc
CHANGED
@@ -7,6 +7,31 @@ require "usd"
|
|
7
7
|
|
8
8
|
class Rusdc < Thor
|
9
9
|
|
10
|
+
desc "chg_add_attachment <co> <file>", "attach the file to co"
|
11
|
+
def chg_add_attachment(co, file)
|
12
|
+
response = upload_attachment(file, loadcon.base_url, loadcon.access_key)
|
13
|
+
puts response
|
14
|
+
data = JSON.parse(response)
|
15
|
+
template = ERB.new <<-EOF
|
16
|
+
{
|
17
|
+
"lrel_attachments_changes": {
|
18
|
+
"attmnt": {
|
19
|
+
"@id": "<%= id %>"
|
20
|
+
},
|
21
|
+
"chg": {
|
22
|
+
"@COMMON_NAME": "<%= co %>"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
EOF
|
27
|
+
json = template.result_with_hash({
|
28
|
+
:id => data["attmnt"]["@id"],
|
29
|
+
:co => co
|
30
|
+
})
|
31
|
+
#puts "create relation to chg with json: #{json}"
|
32
|
+
puts loadcon.create({:type => "json", :data => json})
|
33
|
+
end
|
34
|
+
|
10
35
|
desc "chg_add_nr <co> <ci>", "add a CI to a changeorder"
|
11
36
|
def chg_add_nr(co, ci)
|
12
37
|
template = ERB.new <<-EOF
|
@@ -194,11 +219,10 @@ class Rusdc < Thor
|
|
194
219
|
end
|
195
220
|
end
|
196
221
|
|
197
|
-
desc "
|
198
|
-
def
|
199
|
-
|
200
|
-
|
201
|
-
att_nr.each do |att|
|
222
|
+
desc "get_attachment_of_in <incident> <filename>", "download an attachment of an Incident and print it out on stdout"
|
223
|
+
def get_attachment_of_in(incident, filename)
|
224
|
+
att_in = loadcon.search("lrel_attachments_requests",{'fields' => "attmnt","wc" => "cr.ref_num = '#{incident}'"})
|
225
|
+
att_in.each do |att|
|
202
226
|
attmnt = loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]
|
203
227
|
if attmnt["orig_file_name"] == filename
|
204
228
|
puts loadcon.request("/caisd-rest/attmnt/#{attmnt["@id"]}/file-resource",{:unchanged => true})
|
@@ -206,6 +230,41 @@ class Rusdc < Thor
|
|
206
230
|
end
|
207
231
|
end
|
208
232
|
|
233
|
+
# in: lrel_attachments_requests ?
|
234
|
+
|
235
|
+
desc "get_attachment_of_co <co_name> <filename>", "download an attachment of a changeorder and print it out on stdout"
|
236
|
+
def get_attachment_of_co(coname, filename)
|
237
|
+
ids = loadcon.search("lrel_attachments_changes",{'fields' => "*","wc" => "chg.chg_ref_num = 'CO341144' and attmnt.orig_file_name = 'IMAP61A845F524A9D06536_3212.eml'"})
|
238
|
+
puts loadcon.request("/caisd-rest/attmnt/#{ids[0]["@id"]}/file-resource",{:unchanged => true}) if ids.class == Array
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
#lrel_attachments_requests",{'fields' => "attmnt","wc" => "cr.ref_num
|
243
|
+
desc "in_add_attachment <in> <file>", "attach the file to incident"
|
244
|
+
def in_add_attachment(incident, file)
|
245
|
+
response = upload_attachment(file, loadcon.base_url, loadcon.access_key)
|
246
|
+
puts response
|
247
|
+
data = JSON.parse(response)
|
248
|
+
template = ERB.new <<-EOF
|
249
|
+
{
|
250
|
+
"lrel_attachments_requests": {
|
251
|
+
"attmnt": {
|
252
|
+
"@id": "<%= id %>"
|
253
|
+
},
|
254
|
+
"cr": {
|
255
|
+
"@COMMON_NAME": "<%= incident %>"
|
256
|
+
}
|
257
|
+
}
|
258
|
+
}
|
259
|
+
EOF
|
260
|
+
json = template.result_with_hash({
|
261
|
+
:id => data["attmnt"]["@id"],
|
262
|
+
:incident => incident
|
263
|
+
})
|
264
|
+
#puts "create relation to chg with json: #{json}"
|
265
|
+
puts loadcon.create({:type => "json", :data => json})
|
266
|
+
end
|
267
|
+
|
209
268
|
desc "in_add_2_chg <changeorder> <incident>", "add incident to changeorder"
|
210
269
|
def in_add_2_chg(chg, incident)
|
211
270
|
invoke('update_ref_attr',['in', incident, 'change', chg])
|
@@ -227,12 +286,46 @@ class Rusdc < Thor
|
|
227
286
|
desc "list_attachments_of_co <co_name>", "list all attachments of a changeorder"
|
228
287
|
def list_attachments_of_co(coname)
|
229
288
|
chg_id=loadcon.request("/caisd-rest/chg/COMMON_NAME-#{coname}")["chg"]["@id"]
|
230
|
-
|
231
|
-
|
289
|
+
att_chg = loadcon.search("lrel_attachments_changes",{'fields' => "attmnt","wc" => "chg = #{chg_id}"})
|
290
|
+
att_chg.each do |att|
|
232
291
|
puts loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]["orig_file_name"]
|
233
292
|
end
|
234
293
|
end
|
235
294
|
|
295
|
+
desc "list_attachments_of_in <in>", "list all attachments of an Incident"
|
296
|
+
def list_attachments_of_in(incident)
|
297
|
+
att_in = loadcon.search("lrel_attachments_requests",{'fields' => "attmnt","wc" => "cr.ref_num = '#{incident}'"})
|
298
|
+
att_in.each do |att|
|
299
|
+
puts loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]["orig_file_name"]
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
desc "nr_add_attachment <nr> <file>", "attach the file to nr"
|
304
|
+
def nr_add_attachment(nr, file)
|
305
|
+
response = upload_attachment(file, loadcon.base_url, loadcon.access_key)
|
306
|
+
puts response
|
307
|
+
data = JSON.parse(response)
|
308
|
+
nr_id = loadcon.search("nr",{'fields' => "@id","wc" => "name = '#{nr}'"})[0]["@id"]
|
309
|
+
template = ERB.new <<-EOF
|
310
|
+
{
|
311
|
+
"lrel_attachments_nr": {
|
312
|
+
"attmnt": {
|
313
|
+
"@id": "<%= id %>"
|
314
|
+
},
|
315
|
+
"nr": {
|
316
|
+
"@id": "<%= nr_id %>"
|
317
|
+
}
|
318
|
+
}
|
319
|
+
}
|
320
|
+
EOF
|
321
|
+
json = template.result_with_hash({
|
322
|
+
:id => data["attmnt"]["@id"],
|
323
|
+
:nr_id => nr_id
|
324
|
+
})
|
325
|
+
#puts "create relation to chg with json: #{json}"
|
326
|
+
puts loadcon.create({:type => "json", :data => json})
|
327
|
+
end
|
328
|
+
|
236
329
|
desc "nr_add_child <nr-name> <child-name>", "add one child CI to another CI"
|
237
330
|
def nr_add_child(nr, child)
|
238
331
|
template = ERB.new <<-EOF
|
@@ -406,7 +499,7 @@ class Rusdc < Thor
|
|
406
499
|
if data.class == RestClient::BadRequest
|
407
500
|
puts "BadRequest-Response from USD-API, try to update via IDs. be aware to specify a ref_obj if it's not nr."
|
408
501
|
cn_id = loadcon.search(obj,{'fields' => "@id","wc" => "#{Usd::CN[obj]} = '#{cn}' and delete_flag = 0"})[0]["@id"]
|
409
|
-
value_id = loadcon.search(ref_obj,{'fields' => "@id","wc" => "#{Usd::CN[
|
502
|
+
value_id = loadcon.search(ref_obj,{'fields' => "@id","wc" => "#{Usd::CN[ref_obj]} = '#{v}' and delete_flag = 0"})[0]["@id"]
|
410
503
|
invoke "update_ref_attr_by_id", [obj, cn_id, k, value_id]
|
411
504
|
else
|
412
505
|
puts data
|
@@ -434,6 +527,36 @@ class Rusdc < Thor
|
|
434
527
|
puts loadcon.update({:type => "json", :data => json})
|
435
528
|
end
|
436
529
|
|
530
|
+
desc "vcard_via_email <email>", "creates a vcard from the given email-address and saves it in the /tmp directory."
|
531
|
+
def vcard_via_email(email)
|
532
|
+
cnt = loadcon.search("cnt",{'fields' => "*","wc" => "email_address = '#{email}' and delete_flag = 0"})[0]
|
533
|
+
template = ERB.new <<-EOF
|
534
|
+
BEGIN:VCARD
|
535
|
+
VERSION:2.1
|
536
|
+
N;LANGUAGE=de:;<%= last_name %>;<%= first_name %>
|
537
|
+
FN:<%= last_name %>, <%= first_name %>
|
538
|
+
TEL;WORK;VOICE:<%= phone_number %>
|
539
|
+
TEL;CELL;VOICE:<%= mobile_phone %>
|
540
|
+
EMAIL;PREF;INTERNET:<%= email_address %>
|
541
|
+
X-MS-OL-DEFAULT-POSTAL-ADDRESS:0
|
542
|
+
X-MS-OL-DESIGN;CHARSET=utf-8:<card xmlns="http://schemas.microsoft.com/office/outlook/12/electronicbusinesscards" ver="1.0" layout="left" bgcolor="ffffff"><img xmlns="" align="fit" area="16" use="cardpicture"/><fld xmlns="" prop="name" align="left" dir="ltr" style="b" color="000000" size="10"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="telwork" align="left" dir="ltr" color="d48d2a" size="8"><label align="right" color="626262">Geschäftlich</label></fld><fld xmlns="" prop="telcell" align="left" dir="ltr" color="d48d2a" size="8"><label align="right" color="626262">Mobiltelefon</label></fld><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/><fld xmlns="" prop="blank" size="8"/></card>
|
543
|
+
REV:<%= time %>
|
544
|
+
END:VCARD
|
545
|
+
EOF
|
546
|
+
vcard=template.result_with_hash({
|
547
|
+
:last_name => cnt["last_name"],
|
548
|
+
:first_name => cnt["first_name"],
|
549
|
+
:email_address => cnt["email_address"],
|
550
|
+
:phone_number => cnt["phone_number"],
|
551
|
+
:mobile_phone => cnt["mobile_phone"],
|
552
|
+
:time => Time.now.strftime("%Y%m%dT%H%M%SZ")
|
553
|
+
})
|
554
|
+
file = `mktemp /tmp/#{cnt["last_name"]}-XXXXX.vcf`.chop
|
555
|
+
f = File.open(file,"w+")
|
556
|
+
f.puts vcard
|
557
|
+
f.close
|
558
|
+
puts "the vcard for #{cnt["first_name"]} #{cnt["last_name"]} was created under: #{file}"
|
559
|
+
end
|
437
560
|
|
438
561
|
private
|
439
562
|
|
@@ -446,6 +569,36 @@ class Rusdc < Thor
|
|
446
569
|
end
|
447
570
|
end
|
448
571
|
|
572
|
+
def upload_attachment(file, baseurl, ak)
|
573
|
+
baseurl =~ /^([^:]+):/
|
574
|
+
server = $1
|
575
|
+
filename = File.basename(file)
|
576
|
+
uri = "/caisd-rest/attmnt?repositoryId=1002&serverName=#{server}&mimeType=Text&description=#{filename}"
|
577
|
+
url = URI("#{baseurl}#{uri}")
|
578
|
+
tempfile = Tempfile.new('base64_encoding')
|
579
|
+
temp_path=tempfile.path
|
580
|
+
tempfile.write("")
|
581
|
+
tempfile.close
|
582
|
+
cmd = %(base64 "#{file}" > #{temp_path})
|
583
|
+
`#{cmd}`
|
584
|
+
cmd = %(unix2dos #{tempfile.path})
|
585
|
+
`#{cmd}`
|
586
|
+
fileObj = File.open(temp_path, "rb")
|
587
|
+
fileContent = fileObj.read
|
588
|
+
fileObj.close
|
589
|
+
tempfile.unlink
|
590
|
+
http = Net::HTTP.new(url.host, url.port);
|
591
|
+
request = Net::HTTP::Post.new(url)
|
592
|
+
request["X-AccessKey"] = ak
|
593
|
+
request["Content-Type"] = "multipart/form-data; BOUNDARY=*****MessageBoundary*****"
|
594
|
+
request["accept"] = "application/json"
|
595
|
+
request["Cache-Control"] = "no-cache"
|
596
|
+
request.body = "--*****MessageBoundary*****\r\n \r\nContent-Disposition: form-data; name=\"payload\" \r\nContent-Type: application/xml; CHARACTERSET=UTF-8 \r\n\r\n \r\n<attmnt> \r\n<repository id=\"1002\"></repository> \r\n<orig_file_name>#{filename}</orig_file_name> \r\n<attmnt_name>#{filename}</attmnt_name> \r\n<description>Uploaded with rusdc from rubygem usd</description> \r\n</attmnt> \r\n\r\n \r\n--*****MessageBoundary*****\r\n \r\nContent-Disposition: form-data; name=\"#{filename}\"; filename=\"#{filename}\" \r\nContent-Type: application/octet-stream \r\nContent-Transfer-Encoding: base64\r\n\r\n#{fileContent}\r\n\r\n \r\n--*****MessageBoundary*****--\r\n"
|
597
|
+
|
598
|
+
response = http.request(request)
|
599
|
+
response.read_body
|
600
|
+
end
|
601
|
+
|
449
602
|
end
|
450
603
|
|
451
604
|
Rusdc.start(ARGV)
|
data/change_log.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# rusdc changelog
|
2
2
|
|
3
|
+
## 1.3.1
|
4
|
+
|
5
|
+
- new functions:
|
6
|
+
- `chg_add_attachment`
|
7
|
+
- `nr_add_attachment`
|
8
|
+
- `in_chg_add_attachment`
|
9
|
+
- `vcard_via_email`
|
10
|
+
|
11
|
+
with the first three funtions you are able to upload files to changeorders, configurationitems and incidents and it does not matter if it is text or binary. the last new function creates vcards in version 2.1 from a contact via its email as identifier.
|
12
|
+
|
3
13
|
## 1.2
|
4
14
|
|
5
15
|
- now in Usd.search function:
|
data/usd.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'usd'
|
3
|
-
spec.version = '1.
|
4
|
-
spec.date = '2020-09-
|
3
|
+
spec.version = '1.3.1'
|
4
|
+
spec.date = '2020-09-10'
|
5
5
|
spec.summary = "SDM REST-API-Calls"
|
6
6
|
spec.description = "a Ruby class and a commandlinetool for SDM REST-API-Calls"
|
7
7
|
spec.authors = ["Oliver Gaida"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oliver Gaida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|