usd 1.3.4 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -2
  3. data/bin/rusdc +32 -9
  4. data/change_log.md +20 -0
  5. data/lib/usd.rb +9 -5
  6. data/usd.gemspec +3 -2
  7. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f324bd2fb86597239321dad232f442527502773a66fda4cf5096e9ebec7d30b1
4
- data.tar.gz: 8376aa51f4e5ec5be644c452d93bb7b975c02368121cb7be2c80baa2ae14dac9
3
+ metadata.gz: d0f4c4811a43c68772d1caddb04541173cd3ca9818cd4b24519d3935a3434ff2
4
+ data.tar.gz: e13a6fe87854b0d8f5bcbcf9de6cb159dc35eb1b833f54b7047cffb07414d15e
5
5
  SHA512:
6
- metadata.gz: 03c0822a8e18840e2beda5b720fd9bb81fb64c8bf3bd17f6ee10db9af77c9bb97157fa5faad5ff31c7cd3976c64bf0f3d98994b6878e9527b6b986cebc3ff67a
7
- data.tar.gz: bb0df905af199fa12e3abaa0e83debde076e9bc40a204dd75dd5c07d930f592ce2b4c34cf510dc4402592dc770ed898560ce628f34280a996e1b82a4b24ad4ca
6
+ metadata.gz: a39169e0643ec4b4c860b2a01ce6de2ab8f599e23f7b15d1daab7299d0d9ea60c6a8bf94426eae9d08165903bc95e6d64f0f81477b8d188a7d49c2f720a83543
7
+ data.tar.gz: f83e92536d7541fc3b22cd7cc960acff97e59eb8197662eb4f935b1bcfefdb1a61d0acebb5edec6e4120e8d2bc45aa20f116fd22d155ee7e08bc71c22dfc6873
data/README.md CHANGED
@@ -56,13 +56,14 @@ rusdc get_attachment_of_co <co_name> <filename> # d
56
56
  rusdc get_attachment_of_in <incident> <filename> # download an attachment of an Incident and print it out on stdout
57
57
  rusdc help [COMMAND] # Describe available commands or one specific command
58
58
  rusdc in_add_2_chg <changeorder> <incident> # add incident to changeorder
59
- 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
60
60
  rusdc in_list_child_ins <in> # list all child-incidents of one incident
61
61
  rusdc list_attachments_of_ci <ci_name> # list all attachments of a CI
62
62
  rusdc list_attachments_of_co <co_name> # list all attachments of a changeorder
63
- 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
64
64
  rusdc nr_add_attachment <nr> <file> # attach the file to nr
65
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
66
67
  rusdc nr_add_org <nr> <org> # add an Organisation to a ConfigurationItem
67
68
  rusdc nr_changes <nr> [inactive-too] # list all open changeorders of one CI
68
69
  rusdc nr_childs <ci-name> # lists all childs CIs of a specific CI
@@ -112,3 +113,7 @@ foo2 foo TEST
112
113
  ```
113
114
 
114
115
  more examples under [find examples-Wikipage](https://github.com/ogaida/usd/wiki/find-examples) or in the [change_log](https://github.com/ogaida/usd/blob/master/change_log.md)
116
+
117
+ # senarios
118
+
119
+ <img src="https://yuml.me/diagram/scruffy/class/[SDM%20REST-API{bg:red}]<->[usd-gem{bg:green}]<->[rusdc{bg:orange}],[ruby-script{bg:orange}]<->[usd-gem],[sinatra%20web-app{bg:orange}]<->[usd-gem],[bash commands]<->[rusdc],[shell-scripts]<->[rusdc],[import]->[ruby-script],[ruby-script]->[export],[reports]<-[sinatra%20web-app]<-[drop datafiles/emails/create objects]">
data/bin/rusdc CHANGED
@@ -230,17 +230,19 @@ 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
- 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
235
+ chg_id=loadcon.request("/caisd-rest/chg/COMMON_NAME-#{coname}")["chg"]["@id"]
236
+ att_nr = loadcon.search("lrel_attachments_changes",{'fields' => "attmnt","wc" => "chg = #{chg_id}"})
237
+ att_nr.each do |att|
238
+ attmnt = loadcon.request("/caisd-rest/attmnt/#{att["attmnt"]["@id"]}")["attmnt"]
239
+ if attmnt["orig_file_name"] == filename
240
+ puts loadcon.request("/caisd-rest/attmnt/#{attmnt["@id"]}/file-resource",{:unchanged => true})
241
+ end
242
+ end
239
243
  end
240
244
 
241
-
242
- #lrel_attachments_requests",{'fields' => "attmnt","wc" => "cr.ref_num
243
- desc "in_add_attachment <in> <file>", "attach the file to incident"
245
+ desc "in_add_attachment <in> <file>", "attach a file to an incident or problem"
244
246
  def in_add_attachment(incident, file)
245
247
  response = loadcon.upload_attachment(file)
246
248
  puts response
@@ -261,7 +263,6 @@ class Rusdc < Thor
261
263
  :id => data["attmnt"]["@id"],
262
264
  :incident => incident
263
265
  })
264
- #puts "create relation to chg with json: #{json}"
265
266
  puts loadcon.create({:type => "json", :data => json})
266
267
  end
267
268
 
@@ -292,7 +293,7 @@ class Rusdc < Thor
292
293
  end
293
294
  end
294
295
 
295
- desc "list_attachments_of_in <in>", "list all attachments of an Incident"
296
+ desc "list_attachments_of_in <in>", "list all attachments of an incident or problem"
296
297
  def list_attachments_of_in(incident)
297
298
  att_in = loadcon.search("lrel_attachments_requests",{'fields' => "attmnt","wc" => "cr.ref_num = '#{incident}'"})
298
299
  att_in.each do |att|
@@ -344,6 +345,28 @@ class Rusdc < Thor
344
345
  puts loadcon.create({:type => "json", :data => json})
345
346
  end
346
347
 
348
+ desc "nr_add_contact <nr> <cnt_email>", "add contact to configuration-item"
349
+ def nr_add_contact(nr, cnt_email)
350
+ template = ERB.new <<-EOF
351
+ {
352
+ "lrel_cenv_cntref": {
353
+ "nr": {
354
+ "@id": "<%= uid_nr %>"
355
+ },
356
+ "cnt": {
357
+ "@id": "<%= uid_cnt %>"
358
+ }
359
+ }
360
+ }
361
+ EOF
362
+ json = template.result_with_hash({
363
+ :uid_nr => loadcon.request("/caisd-rest/nr/COMMON_NAME-#{nr}")["nr"]["@id"],
364
+ :uid_cnt => loadcon.search("cnt",{'fields' => "@id","wc" => "email_address = '#{cnt_email}'"})[0]["@id"]
365
+ })
366
+ #puts "create relation to chg with json: #{json}"
367
+ puts loadcon.create({:type => "json", :data => json})
368
+ end
369
+
347
370
  desc "nr_add_org <nr> <org>", "add an Organisation to a ConfigurationItem"
348
371
  def nr_add_org(nr, org)
349
372
  template = ERB.new <<-EOF
@@ -1,5 +1,25 @@
1
1
  # rusdc changelog
2
2
 
3
+ ## 1.4.0
4
+
5
+ - remove "warning: URI.escape is obsolete"
6
+
7
+ ## 1.3.7
8
+
9
+ - Bugfix in rusdc-function `get_attachment_of_co`
10
+
11
+ ## 1.3.6
12
+
13
+ - Bugfix : uploaded filename with special character will be renamed with `URI.escape`
14
+
15
+ ## 1.3.5
16
+
17
+ - new function `nr_add_contact <nr> <email>` to assign a contact to a configuration-item
18
+
19
+ ## 1.3.4.1
20
+
21
+ - fixed another error in Usd.search. which comes with 1.3.1 .
22
+
3
23
  ## 1.3.4
4
24
 
5
25
  - move function `upload_attachment` from `bin/rusdc` to `lib/usd`.
data/lib/usd.rb CHANGED
@@ -11,6 +11,7 @@ require 'tempfile'
11
11
  class Usd
12
12
 
13
13
  CN={
14
+ "grc" => "type",
14
15
  "chg" => "chg_ref_num",
15
16
  "cnt" => "combo_name",
16
17
  "arcpur_rule" => "name",
@@ -160,10 +161,11 @@ class Usd
160
161
  RestClient.log = STDOUT if @debug
161
162
  hash = {:method => "get", :header => header(), :unchanged => false, :json => "", :base_url => @base_url}.update hash
162
163
  puts "request - hash: #{JSON.pretty_generate(hash)}" if @debug
164
+ parser = URI::RFC2396_Parser.new
163
165
  if (uri !~ /^http/)
164
- url = URI.escape("#{hash[:base_url]}#{uri}")
166
+ url = parser.escape("#{hash[:base_url]}#{uri}")
165
167
  else
166
- url = URI.escape(uri)
168
+ url = parser.escape(uri)
167
169
  end
168
170
  begin
169
171
  if hash[:method] == "get"
@@ -251,7 +253,7 @@ class Usd
251
253
  # if wc contains no sql-compare operater, it will be changed to "COMMON_NAME like '%<wc-before>%'"
252
254
  wc = attr.pop
253
255
  wc.gsub!(/^WC=/,'')
254
- if ([" like ","<",">","="," is "," in "].find {|e| wc =~ /#{e}/}).nil?
256
+ if ([" like ","<",">","="," is "," in "," LIKE ", " IS ", " IN "].find {|e| wc =~ /#{e}/}).nil?
255
257
  wc = "#{CN[object]} like '%#{wc}%'"
256
258
  end
257
259
  attr.push "WC=#{wc}"
@@ -283,7 +285,9 @@ class Usd
283
285
  baseurl =~ /^([^:]+):/
284
286
  server = $1
285
287
  filename = File.basename(file)
286
- uri = "/caisd-rest/attmnt?repositoryId=1002&serverName=#{server}&mimeType=Text&description=#{filename}"
288
+ #filename_escaped = URI.escape(filename)
289
+ filename_escaped = filename.gsub(/[^0-9A-Za-z.\-]/, '_')
290
+ uri = "/caisd-rest/attmnt?repositoryId=1002&serverName=#{server}&mimeType=Text&description=#{filename_escaped}"
287
291
  url = URI("#{baseurl}#{uri}")
288
292
  http = Net::HTTP.new(url.host, url.port);
289
293
  request = Net::HTTP::Post.new(url)
@@ -294,7 +298,7 @@ class Usd
294
298
  fileObj = File.open(file, "rb")
295
299
  fileContent = fileObj.read
296
300
  fileObj.close
297
- 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#{Base64.encode64(fileContent)}\r\n\r\n \r\n--*****MessageBoundary*****--\r\n"
301
+ 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"
298
302
  response = http.request(request)
299
303
  response.read_body
300
304
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'usd'
3
- spec.version = '1.3.4'
4
- spec.date = '2020-09-11'
3
+ spec.version = '1.4.0'
4
+ spec.date = '2020-11-12'
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"]
@@ -13,4 +13,5 @@ Gem::Specification.new do |spec|
13
13
  spec.add_runtime_dependency 'thor', '~> 0.20', '>= 0.20.3'
14
14
  spec.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.0'
15
15
  spec.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
16
+ spec.license = 'MIT'
16
17
  end
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.4
4
+ version: 1.4.0
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 00:00:00.000000000 Z
11
+ date: 2020-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -86,7 +86,8 @@ files:
86
86
  - lib/usd.rb
87
87
  - usd.gemspec
88
88
  homepage: https://github.com/ogaida/usd
89
- licenses: []
89
+ licenses:
90
+ - MIT
90
91
  metadata: {}
91
92
  post_install_message:
92
93
  rdoc_options: []
@@ -103,8 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
104
  - !ruby/object:Gem::Version
104
105
  version: '0'
105
106
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.7.6
107
+ rubygems_version: 3.1.2
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: SDM REST-API-Calls