usd 0.2.4.2 → 1.2

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 +16 -6
  3. data/bin/rusdc +31 -4
  4. data/change_log.md +95 -0
  5. data/lib/usd.rb +78 -0
  6. data/usd.gemspec +16 -16
  7. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 515503469768aad64a6610b7fc0b9e8233f0cc77aa765226503e14f9a6d22a51
4
- data.tar.gz: ef1b76360680e68fcf1c2fc701757c40632c780be4adc9243890168f19d44a76
3
+ metadata.gz: 278dc411942f77e45434ee0463e50b748af2f65f373923107b979d4c41cf8064
4
+ data.tar.gz: '0265695f32cf5e377cf94d0e49c1370923d278cd625b557bc188bd0bd1bb6f0e'
5
5
  SHA512:
6
- metadata.gz: 271c5acb4202200f6d3cf82974307262ac99e9d8f42044c4006108001192bed71ffed0d7155ff3b60ebc4f6204f9306282a08bbafab07007cddca1227b08f2ac
7
- data.tar.gz: 655db19bfe69c81bd94b4421e54e722012d50b566192d2fac0ef7794c5a2aeef504a40ef3b58d8ea2cddd72f823f503437e8a2ee04ea31aaa09278a3e01b71be
6
+ metadata.gz: 8ade7a831bc17847218142b30ad9a0d30b57d2b214b021c42befc4775271a376ec4d2a600ea0272595da3b1f018fc5a02b1a5f51792995142e7a3936b0ed624e
7
+ data.tar.gz: 650d000528d4af5d2132e7737dca6aa2fbcfd9e0bb74d85b981753727ef2f9feb80c5d82fcae33c3456d7a0818053b947ddfe066bb7c59b022496850d65f38c4
data/README.md CHANGED
@@ -21,6 +21,15 @@ yum group install "Development Tools"
21
21
  yum install ruby-devel
22
22
  ```
23
23
 
24
+ # documentation
25
+
26
+ - see [https://github.com/ogaida/usd/wiki](https://github.com/ogaida/usd/wiki)
27
+ - if you are looking for dependencies in between the objects, objectnames or relational objects, then have a look at [techdocs.broadcom.com](https://techdocs.broadcom.com/content/broadcom/techdocs/us/en/ca-enterprise-software/business-management/ca-service-management/14-1/reference/ca-service-desk-manager-reference-commands/objects-and-attributes.html)
28
+
29
+ ## bash-completion
30
+
31
+ see [https://github.com/ogaida/usd/wiki/bash-completion](https://github.com/ogaida/usd/wiki/bash-completion)
32
+
24
33
  # external tools
25
34
 
26
35
  If you use the `rusdc find` command with `--format mlr` option then you need `mlr`.
@@ -38,24 +47,25 @@ rusdc create # p
38
47
  rusdc field_names <object-type> [wc] # list all fields of an object including its format
39
48
  rusdc find <object-type> [where-clause] [fields, comma separated] [options] # finds each object which meets the wc-condition
40
49
  rusdc get <object-type> <common_name|id> # shows one object by name or id
41
- rusdc get_all_attachments_of_co <co_name> # get all attachments of a changeorder and save all these to current folder
42
- rusdc get_attachment_of_ci <ci_name> <filename> # download an attachment of a CI and print it out on stdout
43
- rusdc get_attachment_of_co <co_name> <filename> # download an attachment of a changeorder and print it out on stdout
50
+ rusdc get_all_attachments_of_co <co_name> # get all attachments of a changeorder and save all th...
51
+ rusdc get_attachment_of_ci <ci_name> <filename> # download an attachment of a CI and print it out on s...
52
+ rusdc get_attachment_of_co <co_name> <filename> # download an attachment of a changeorder and print it...
44
53
  rusdc help [COMMAND] # Describe available commands or one specific command
45
54
  rusdc in_add_2_chg <changeorder> <incident> # add incident to changeorder
46
55
  rusdc in_list_child_ins <in> # list all child-incidents of one incident
47
56
  rusdc list_attachments_of_ci <ci_name> # list all attachments of a CI
48
57
  rusdc list_attachments_of_co <co_name> # list all attachments of a changeorder
49
58
  rusdc nr_add_child <nr-name> <child-name> # add one child CI to another CI
59
+ rusdc nr_add_org <nr> <org> # add an Organisation to a ConfigurationItem
50
60
  rusdc nr_changes <nr> [inactive-too] # list all open changeorders of one CI
51
61
  rusdc nr_childs <ci-name> # lists all childs CIs of a specific CI
52
62
  rusdc nr_incidents <nr> [inactive-too] # lists all incident of a specific CI
53
63
  rusdc nr_parents <ci-name> # lists all parent CIs of a specific CI
54
64
  rusdc update # pipe json-data to update object
55
- rusdc update_attr <obj> <common_name|wc> <key> <value> # updates a direct (not referenced) attribute of one or more objects.
56
- rusdc update_attr_by_id <obj> <id> <key> <value> # updates a plain attribute of one object by id, does not work
65
+ rusdc update_attr <obj> <common_name|wc> <key> <value> # updates a direct (not referenced) attribute of one o...
66
+ rusdc update_attr_by_id <obj> <id> <key> <value> # updates a plain attribute of one object by id, does ...
57
67
  rusdc update_ref_attr <obj> <common_name> <key> <value> # updates a referenced attribute of one object.
58
- rusdc update_ref_attr_by_id <obj> <id> <key> <value_id> # updates a referenced attribute of one object_id by value-id
68
+ rusdc update_ref_attr_by_id <obj> <id> <key> <value_id> # updates a referenced attribute of one object_id by v...
59
69
  ```
60
70
 
61
71
  # environment-variables
data/bin/rusdc CHANGED
@@ -107,7 +107,7 @@ class Rusdc < Thor
107
107
  elem.keys.each do |elem_key|
108
108
  if options[:nice_time]
109
109
  if elem_key =~ /(date|last_mod|warranty_start|warranty_end|time_stamp)$/
110
- elem[elem_key]=Time.at(elem[elem_key]).to_s
110
+ elem[elem_key]=Time.at(elem[elem_key]).to_s if elem[elem_key] != "" # not empty
111
111
  end
112
112
  end
113
113
  if fields_array.include?(elem_key)
@@ -127,6 +127,7 @@ class Rusdc < Thor
127
127
  case options[:format]
128
128
  when "json"
129
129
  puts mlr
130
+ e
130
131
  exit exitcode
131
132
  when "yaml"
132
133
  # keys not sorted, maybe a todo
@@ -250,6 +251,24 @@ class Rusdc < Thor
250
251
  puts loadcon.create({:type => "json", :data => json})
251
252
  end
252
253
 
254
+ desc "nr_add_org <nr> <org>", "add an Organisation to a ConfigurationItem"
255
+ def nr_add_org(nr, org)
256
+ template = ERB.new <<-EOF
257
+ {
258
+ "lrel_oenv_orgref": {
259
+ "nr": {
260
+ "@id": "<%= uid_nr %>"
261
+ },
262
+ "org": {
263
+ "@id": "<%= uid_org %>"
264
+ }
265
+ }
266
+ }
267
+ EOF
268
+ json = template.result_with_hash(:uid_org => loadcon.request("/caisd-rest/org/COMMON_NAME-#{org}")["org"]["@id"], :uid_nr => loadcon.request("/caisd-rest/nr/COMMON_NAME-#{nr}")["nr"]["@id"])
269
+ puts loadcon.create({:type => "json", :data => json})
270
+ end
271
+
253
272
  desc "nr_changes <nr> [inactive-too]", "list all open changeorders of one CI"
254
273
  option :inactive_too, :type => :boolean, :default => false
255
274
  def nr_changes(nr)
@@ -365,8 +384,8 @@ class Rusdc < Thor
365
384
  puts loadcon.update({:type => "json", :data => json})
366
385
  end
367
386
 
368
- desc "update_ref_attr <obj> <common_name> <key> <value>", "updates a referenced attribute of one object."
369
- def update_ref_attr(obj, cn, k, v)
387
+ desc "update_ref_attr <obj> <common_name> <key> <value> [ref_obj=nr]", "updates a referenced attribute of one object."
388
+ def update_ref_attr(obj, cn, k, v, ref_obj = "nr")
370
389
  template = ERB.new <<-EOF
371
390
  {
372
391
  "<%= obj %>": {
@@ -383,7 +402,15 @@ class Rusdc < Thor
383
402
  :k => k,
384
403
  :v => v
385
404
  })
386
- puts loadcon.update({:type => "json", :data => json})
405
+ data = loadcon.update({:type => "json", :data => json})
406
+ if data.class == RestClient::BadRequest
407
+ puts "BadRequest-Response from USD-API, try to update via IDs. be aware to specify a ref_obj if it's not nr."
408
+ 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[obj]} = '#{v}' and delete_flag = 0"})[0]["@id"]
410
+ invoke "update_ref_attr_by_id", [obj, cn_id, k, value_id]
411
+ else
412
+ puts data
413
+ end
387
414
  end
388
415
 
389
416
  desc "update_ref_attr_by_id <obj> <id> <key> <value_id>", "updates a referenced attribute of one object_id by value-id"
@@ -1,5 +1,100 @@
1
1
  # rusdc changelog
2
2
 
3
+ ## 1.2
4
+
5
+ - now in Usd.search function:
6
+ - whereclause is enriched with "common_name like '% wc%'" if it is not a valid whereclause.
7
+
8
+ ## 1.0 and 1.1
9
+
10
+ - `update_ref_attr` rusdc-function fetches the IDs to update the object by itself.
11
+
12
+ ## 0.3
13
+
14
+ - some common_name resolution
15
+
16
+ ```ruby
17
+ class Usd
18
+ CN={
19
+ "chg" => "chg_ref_num",
20
+ "cnt" => "combo_name",
21
+ "arcpur_rule" => "name",
22
+ "ca_tou" => "name",
23
+ "cost_cntr" => "name",
24
+ "country" => "name",
25
+ "dept" => "name",
26
+ "gl_code" => "name",
27
+ "job_func" => "name",
28
+ "loc" => "name",
29
+ "nr" => "name",
30
+ "opsys" => "name",
31
+ "org" => "name",
32
+ "tab" => "name",
33
+ "auto_close" => "sym",
34
+ "aty" => "sym",
35
+ "act_type_assoc" => "sym",
36
+ "ca_cmpny" => "sym",
37
+ "closure_code" => "sym",
38
+ "cmth" => "sym",
39
+ "symptom_code" => "sym",
40
+ "state" => "sym",
41
+ "crt" => "sym",
42
+ "ctab" => "sym",
43
+ "ctp" => "sym",
44
+ "dcon_typ" => "sym",
45
+ "dlgsrvr" => "sym",
46
+ "dmn" => "sym",
47
+ "doc_rep" => "sym",
48
+ "fmgrp" => "sym",
49
+ "ical_alarm" => "sym",
50
+ "ical_event_template" => "sym",
51
+ "imp" => "sym",
52
+ "intfc" => "sym",
53
+ "kwrd" => "sym",
54
+ "mfrmod" => "sym",
55
+ "mgsstat" => "sym",
56
+ "nrf" => "sym",
57
+ "options" => "sym",
58
+ "outage_type" => "sym",
59
+ "perscnt" => "sym",
60
+ "position" => "sym",
61
+ "pr_trans" => "sym",
62
+ "prod" => "sym",
63
+ "quick_tpl_types" => "sym",
64
+ "rc" => "sym",
65
+ "resocode" => "sym",
66
+ "resomethod" => "sym",
67
+ "response" => "sym",
68
+ "rrf" => "sym",
69
+ "rss" => "sym",
70
+ "seq" => "sym",
71
+ "sev" => "sym",
72
+ "site" => "sym",
73
+ "slatpl" => "sym",
74
+ "special_handling" => "sym",
75
+ "svc_contract" => "sym",
76
+ "typecnt" => "sym",
77
+ "tz" => "sym",
78
+ "tspan" => "sym",
79
+ "transition_type" => "sym",
80
+ "urg" => "sym",
81
+ "vpt" => "sym",
82
+ "wrkshft" => "sym",
83
+ "cr" => "ref_num",
84
+ "in" => "ref_num",
85
+ "pr" => "ref_num"
86
+ }
87
+ end
88
+ ```
89
+
90
+ ## 0.2.5.3
91
+
92
+ - neu function : `rusdc nr_add_org <nr> <org> # add an Organisation to a ConfigurationItem`
93
+
94
+ #### fixes:
95
+
96
+ - rusdc - line 110: more robust when querying date fields
97
+
3
98
  ## 0.2.4.2
4
99
 
5
100
  the same fixes as in 0.2.4.1 for:
data/lib/usd.rb CHANGED
@@ -10,6 +10,76 @@ require 'tempfile'
10
10
 
11
11
  class Usd
12
12
 
13
+ CN={
14
+ "chg" => "chg_ref_num",
15
+ "cnt" => "combo_name",
16
+ "arcpur_rule" => "name",
17
+ "ca_tou" => "name",
18
+ "cost_cntr" => "name",
19
+ "country" => "name",
20
+ "dept" => "name",
21
+ "gl_code" => "name",
22
+ "job_func" => "name",
23
+ "loc" => "name",
24
+ "nr" => "name",
25
+ "opsys" => "name",
26
+ "org" => "name",
27
+ "tab" => "name",
28
+ "auto_close" => "sym",
29
+ "aty" => "sym",
30
+ "act_type_assoc" => "sym",
31
+ "ca_cmpny" => "sym",
32
+ "closure_code" => "sym",
33
+ "cmth" => "sym",
34
+ "symptom_code" => "sym",
35
+ "state" => "sym",
36
+ "crt" => "sym",
37
+ "ctab" => "sym",
38
+ "ctp" => "sym",
39
+ "dcon_typ" => "sym",
40
+ "dlgsrvr" => "sym",
41
+ "dmn" => "sym",
42
+ "doc_rep" => "sym",
43
+ "fmgrp" => "sym",
44
+ "ical_alarm" => "sym",
45
+ "ical_event_template" => "sym",
46
+ "imp" => "sym",
47
+ "intfc" => "sym",
48
+ "kwrd" => "sym",
49
+ "mfrmod" => "sym",
50
+ "mgsstat" => "sym",
51
+ "nrf" => "sym",
52
+ "options" => "sym",
53
+ "outage_type" => "sym",
54
+ "perscnt" => "sym",
55
+ "position" => "sym",
56
+ "pr_trans" => "sym",
57
+ "prod" => "sym",
58
+ "quick_tpl_types" => "sym",
59
+ "rc" => "sym",
60
+ "resocode" => "sym",
61
+ "resomethod" => "sym",
62
+ "response" => "sym",
63
+ "rrf" => "sym",
64
+ "rss" => "sym",
65
+ "seq" => "sym",
66
+ "sev" => "sym",
67
+ "site" => "sym",
68
+ "slatpl" => "sym",
69
+ "special_handling" => "sym",
70
+ "svc_contract" => "sym",
71
+ "typecnt" => "sym",
72
+ "tz" => "sym",
73
+ "tspan" => "sym",
74
+ "transition_type" => "sym",
75
+ "urg" => "sym",
76
+ "vpt" => "sym",
77
+ "wrkshft" => "sym",
78
+ "cr" => "ref_num",
79
+ "in" => "ref_num",
80
+ "pr" => "ref_num"
81
+ }
82
+
13
83
  RestClient.proxy = ""
14
84
 
15
85
  attr_reader :base_url, :user, :access_key, :expiration_date, :debug
@@ -178,6 +248,14 @@ class Usd
178
248
  attr.push set_url_parm(params,"start","1")
179
249
  attr.push set_url_parm(params,"size","50")
180
250
  attr.push set_url_parm(params,"WC","")
251
+ # if wc contains no sql-compare operater, it will be changed to "COMMON_NAME like '%<wc-before>%'"
252
+ wc = attr.pop
253
+ wc.gsub!(/^WC=/,'')
254
+ if ([" like ","<",">","="," is "].find {|e| wc =~ /#{e}/}).nil?
255
+ wc = "#{CN[object]} like '%#{wc}%'"
256
+ end
257
+ attr.push "WC=#{wc}"
258
+ # puts attr.jp # debug
181
259
  fields = set_param(params,"fields","COMMON_NAME,id")
182
260
  query_string=attr.join("&")
183
261
  res_rdata = request("/caisd-rest/#{object}?#{query_string}",{:method => "get", :header => header({'X-Obj-Attrs' => fields})})
@@ -1,16 +1,16 @@
1
- Gem::Specification.new do |spec|
2
- spec.name = 'usd'
3
- spec.version = '0.2.4.2'
4
- spec.date = '2020-01-28'
5
- spec.summary = "SDM REST-API-Calls"
6
- spec.description = "a Ruby class and a commandlinetool for SDM REST-API-Calls"
7
- spec.authors = ["Oliver Gaida"]
8
- spec.email = 'oliver.gaida@sycor.de'
9
- #spec.files = ["bin/rusdc", "bin/set_env", "lib/usd.rb"] # Dir["*/*"]
10
- spec.files = `git ls-files`.split($/)
11
- spec.homepage = 'https://github.com/ogaida/usd'
12
- spec.executables = %w(rusdc)
13
- spec.add_runtime_dependency 'thor', '~> 0.20', '>= 0.20.3'
14
- spec.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.0'
15
- spec.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
16
- end
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'usd'
3
+ spec.version = '1.2'
4
+ spec.date = '2020-09-02'
5
+ spec.summary = "SDM REST-API-Calls"
6
+ spec.description = "a Ruby class and a commandlinetool for SDM REST-API-Calls"
7
+ spec.authors = ["Oliver Gaida"]
8
+ spec.email = 'oliver.gaida@sycor.de'
9
+ #spec.files = ["bin/rusdc", "bin/set_env", "lib/usd.rb"] # Dir["*/*"]
10
+ spec.files = `git ls-files`.split($/)
11
+ spec.homepage = 'https://github.com/ogaida/usd'
12
+ spec.executables = %w(rusdc)
13
+ spec.add_runtime_dependency 'thor', '~> 0.20', '>= 0.20.3'
14
+ spec.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.0'
15
+ spec.add_runtime_dependency 'json', '~> 2.1', '>= 2.1.0'
16
+ 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: 0.2.4.2
4
+ version: '1.2'
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-01-28 00:00:00.000000000 Z
11
+ date: 2020-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor