usd 1.3.2 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f3f388a3efedae368a6a99c7169029d78f92e11179ca97ad8edb196a125be5d
4
- data.tar.gz: ed31ec8a487df5132d06fd71cb77e301017b5292fcd6dde662359d169a0a27cb
3
+ metadata.gz: 2f200b7489e39e8790b98cd217f685141c977eea38b009ff4e7c086aa475868a
4
+ data.tar.gz: e520b09923e8ebc24e2ddf3f03d2c4d455896e99dc708b0439a23c0f37154a61
5
5
  SHA512:
6
- metadata.gz: 3d0d07c311dcc0b1b20c41ea818a08d3e910ae47e6909c0df1a00e4143ab4c190fdaaa9cf3da522bdbf104e54cf2a6404504261edb4d68e80084ca85cd90eb4d
7
- data.tar.gz: ad097417d07cec1dc9c097dea1785f91fb4b3ff737abb03840e05d4e779b31a2176ed47f5e53e841ce72c261da6dc8fb15cf831fd7887c95f21b9c1a103bff34
6
+ metadata.gz: 1a66a5e24cf6651dab72a6c5a564c466d8320f7c2d9c3c74a5d832b90eb384a257043d245dcb2636e270631a775cdb25e3dd3ec584bcf3ce01f484485354375b
7
+ data.tar.gz: c4bb48aa371fcd9770e8fb3e64e4c79dcebed55cf6100aa1ca330f0fe403c66427fc5c94ac7a5ed7fd334376ffd2e62ddb927e1346698d91d1bfef9066091f7b
data/README.md CHANGED
@@ -40,8 +40,6 @@ If you use the `rusdc find` command with `--format mlr` option then you need `ml
40
40
 
41
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
42
 
43
- For uloading attachments `unix2dos` and `base64` is used.
44
-
45
43
  # functions from the commandline-tool `rusdc`
46
44
 
47
45
  ```
@@ -58,13 +56,14 @@ rusdc get_attachment_of_co <co_name> <filename> # d
58
56
  rusdc get_attachment_of_in <incident> <filename> # download an attachment of an Incident and print it out on stdout
59
57
  rusdc help [COMMAND] # Describe available commands or one specific command
60
58
  rusdc in_add_2_chg <changeorder> <incident> # add incident to changeorder
61
- rusdc in_add_attachment <in> <file> # attach the file to incident
59
+ rusdc in_add_attachment <in> <file> # attach a file to an incident or problem
62
60
  rusdc in_list_child_ins <in> # list all child-incidents of one incident
63
61
  rusdc list_attachments_of_ci <ci_name> # list all attachments of a CI
64
62
  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
63
+ rusdc list_attachments_of_in <in> # list all attachments of an incident or problem
66
64
  rusdc nr_add_attachment <nr> <file> # attach the file to nr
67
65
  rusdc nr_add_child <nr-name> <child-name> # add one child CI to another CI
66
+ rusdc nr_add_contact <nr> <cnt_email> # add contact to configuration-item
68
67
  rusdc nr_add_org <nr> <org> # add an Organisation to a ConfigurationItem
69
68
  rusdc nr_changes <nr> [inactive-too] # list all open changeorders of one CI
70
69
  rusdc nr_childs <ci-name> # lists all childs CIs of a specific CI
data/bin/rusdc CHANGED
@@ -9,7 +9,7 @@ class Rusdc < Thor
9
9
 
10
10
  desc "chg_add_attachment <co> <file>", "attach the file to co"
11
11
  def chg_add_attachment(co, file)
12
- response = upload_attachment(file, loadcon.base_url, loadcon.access_key)
12
+ response = loadcon.upload_attachment(file)
13
13
  puts response
14
14
  data = JSON.parse(response)
15
15
  template = ERB.new <<-EOF
@@ -230,19 +230,15 @@ class Rusdc < Thor
230
230
  end
231
231
  end
232
232
 
233
- # in: lrel_attachments_requests ?
234
-
235
233
  desc "get_attachment_of_co <co_name> <filename>", "download an attachment of a changeorder and print it out on stdout"
236
234
  def get_attachment_of_co(coname, filename)
237
235
  ids = loadcon.search("lrel_attachments_changes",{'fields' => "*","wc" => "chg.chg_ref_num = 'CO341144' and attmnt.orig_file_name = 'IMAP61A845F524A9D06536_3212.eml'"})
238
236
  puts loadcon.request("/caisd-rest/attmnt/#{ids[0]["@id"]}/file-resource",{:unchanged => true}) if ids.class == Array
239
237
  end
240
238
 
241
-
242
- #lrel_attachments_requests",{'fields' => "attmnt","wc" => "cr.ref_num
243
- desc "in_add_attachment <in> <file>", "attach the file to incident"
239
+ desc "in_add_attachment <in> <file>", "attach a file to an incident or problem"
244
240
  def in_add_attachment(incident, file)
245
- response = upload_attachment(file, loadcon.base_url, loadcon.access_key)
241
+ response = loadcon.upload_attachment(file)
246
242
  puts response
247
243
  data = JSON.parse(response)
248
244
  template = ERB.new <<-EOF
@@ -261,7 +257,6 @@ class Rusdc < Thor
261
257
  :id => data["attmnt"]["@id"],
262
258
  :incident => incident
263
259
  })
264
- #puts "create relation to chg with json: #{json}"
265
260
  puts loadcon.create({:type => "json", :data => json})
266
261
  end
267
262
 
@@ -292,7 +287,7 @@ class Rusdc < Thor
292
287
  end
293
288
  end
294
289
 
295
- desc "list_attachments_of_in <in>", "list all attachments of an Incident"
290
+ desc "list_attachments_of_in <in>", "list all attachments of an incident or problem"
296
291
  def list_attachments_of_in(incident)
297
292
  att_in = loadcon.search("lrel_attachments_requests",{'fields' => "attmnt","wc" => "cr.ref_num = '#{incident}'"})
298
293
  att_in.each do |att|
@@ -302,7 +297,7 @@ class Rusdc < Thor
302
297
 
303
298
  desc "nr_add_attachment <nr> <file>", "attach the file to nr"
304
299
  def nr_add_attachment(nr, file)
305
- response = upload_attachment(file, loadcon.base_url, loadcon.access_key)
300
+ response = loadcon.upload_attachment(file)
306
301
  puts response
307
302
  data = JSON.parse(response)
308
303
  nr_id = loadcon.search("nr",{'fields' => "@id","wc" => "name = '#{nr}'"})[0]["@id"]
@@ -344,6 +339,28 @@ class Rusdc < Thor
344
339
  puts loadcon.create({:type => "json", :data => json})
345
340
  end
346
341
 
342
+ desc "nr_add_contact <nr> <cnt_email>", "add contact to configuration-item"
343
+ def nr_add_contact(nr, cnt_email)
344
+ template = ERB.new <<-EOF
345
+ {
346
+ "lrel_cenv_cntref": {
347
+ "nr": {
348
+ "@id": "<%= uid_nr %>"
349
+ },
350
+ "cnt": {
351
+ "@id": "<%= uid_cnt %>"
352
+ }
353
+ }
354
+ }
355
+ EOF
356
+ json = template.result_with_hash({
357
+ :uid_nr => loadcon.request("/caisd-rest/nr/COMMON_NAME-#{nr}")["nr"]["@id"],
358
+ :uid_cnt => loadcon.search("cnt",{'fields' => "@id","wc" => "email_address = '#{cnt_email}'"})[0]["@id"]
359
+ })
360
+ #puts "create relation to chg with json: #{json}"
361
+ puts loadcon.create({:type => "json", :data => json})
362
+ end
363
+
347
364
  desc "nr_add_org <nr> <org>", "add an Organisation to a ConfigurationItem"
348
365
  def nr_add_org(nr, org)
349
366
  template = ERB.new <<-EOF
@@ -569,36 +586,6 @@ END:VCARD
569
586
  end
570
587
  end
571
588
 
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
-
602
589
  end
603
590
 
604
591
  Rusdc.start(ARGV)
@@ -1,5 +1,29 @@
1
1
  # rusdc changelog
2
2
 
3
+ ## 1.3.6
4
+
5
+ - Bugfix : uploaded filename with special character will be renamed with `URI.escape`
6
+
7
+ ## 1.3.5
8
+
9
+ - new function `nr_add_contact <nr> <email>` to assign a contact to a configuration-item
10
+
11
+ ## 1.3.4.1
12
+
13
+ - fixed another error in Usd.search. which comes with 1.3.1 .
14
+
15
+ ## 1.3.4
16
+
17
+ - move function `upload_attachment` from `bin/rusdc` to `lib/usd`.
18
+
19
+ ## 1.3.3
20
+
21
+ - private `rusdc`-funktion `upload_attachment` changed. Instead using `base64` and `unix2dos` binaries, we use Base64-Ruby-Class now. It is already required by usd.
22
+
23
+ ## 1.3.2
24
+
25
+ - fixed error in Usd.search. which comes with 1.3.1 .
26
+
3
27
  ## 1.3.1
4
28
 
5
29
  - new functions:
Binary file
data/lib/usd.rb CHANGED
@@ -251,7 +251,7 @@ class Usd
251
251
  # if wc contains no sql-compare operater, it will be changed to "COMMON_NAME like '%<wc-before>%'"
252
252
  wc = attr.pop
253
253
  wc.gsub!(/^WC=/,'')
254
- if ([" like ","<",">","="," is "," in "].find {|e| wc =~ /#{e}/}).nil?
254
+ if ([" like ","<",">","="," is "," in "," LIKE ", " IS ", " IN "].find {|e| wc =~ /#{e}/}).nil?
255
255
  wc = "#{CN[object]} like '%#{wc}%'"
256
256
  end
257
257
  attr.push "WC=#{wc}"
@@ -279,6 +279,27 @@ class Usd
279
279
  end
280
280
  end
281
281
 
282
+ def upload_attachment(file, baseurl = @base_url, ak = @access_key)
283
+ baseurl =~ /^([^:]+):/
284
+ server = $1
285
+ filename = File.basename(file)
286
+ filename_escaped = URI.escape(filename)
287
+ uri = "/caisd-rest/attmnt?repositoryId=1002&serverName=#{server}&mimeType=Text&description=#{filename_escaped}"
288
+ url = URI("#{baseurl}#{uri}")
289
+ http = Net::HTTP.new(url.host, url.port);
290
+ request = Net::HTTP::Post.new(url)
291
+ request["X-AccessKey"] = ak
292
+ request["Content-Type"] = "multipart/form-data; BOUNDARY=*****MessageBoundary*****"
293
+ request["accept"] = "application/json"
294
+ request["Cache-Control"] = "no-cache"
295
+ fileObj = File.open(file, "rb")
296
+ fileContent = fileObj.read
297
+ fileObj.close
298
+ 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_escaped}</orig_file_name> \r\n<attmnt_name>#{filename_escaped}</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_escaped}\"; filename=\"#{filename_escaped}\" \r\nContent-Type: application/octet-stream \r\nContent-Transfer-Encoding: base64\r\n\r\n#{Base64.encode64(fileContent)}\r\n\r\n \r\n--*****MessageBoundary*****--\r\n"
299
+ response = http.request(request)
300
+ response.read_body
301
+ end
302
+
282
303
  end
283
304
 
284
305
  module Jsonpretty
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'usd'
3
- spec.version = '1.3.2'
4
- spec.date = '2020-09-10'
3
+ spec.version = '1.3.6'
4
+ spec.date = '2020-09-29'
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: 1.3.2
4
+ version: 1.3.6
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-10 00:00:00.000000000 Z
11
+ date: 2020-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -82,6 +82,7 @@ files:
82
82
  - bin/rusdc
83
83
  - bin/set_env
84
84
  - change_log.md
85
+ - images/vcard.png
85
86
  - lib/usd.rb
86
87
  - usd.gemspec
87
88
  homepage: https://github.com/ogaida/usd