foreman_teamdynamix 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: ce914cf3650810a7b8b11a7da6d8fce4300c07e4
4
- data.tar.gz: 6644dfc9e975f38d77999d98048eb36e9d47b7ad
3
+ metadata.gz: 1cd084945a1d6d14d7cfd2a24ae43dd2cedfd342
4
+ data.tar.gz: a9000907c7c653d1d52ecd7d06057b79a4d246b0
5
5
  SHA512:
6
- metadata.gz: dca0adc273e5c3704a8758db94c02907277e5e572f177d0dc660f22229612f664567da98f1919156e40f3c99d01f1bb312066bacf74fa0a8706e4b42496a096e
7
- data.tar.gz: 474ccd4916aafa8714afeed5fffcc6aa26005a6446d8c5856a1ad102b9dbddb78db4f86bac994e087f6447aeaf7d9f1609e2d7cae3b14a5d210c09cc8996138f
6
+ metadata.gz: f9f3ace967bd42994303b182e4ef60896610e9bc7e6416ebae1140c9d7bad0e30611a7e6bbfb2a037aa2fde65d7daf4f2fd9d522f1bced591608c17013812f30
7
+ data.tar.gz: 95cbe16944f53abc9090b882d73d10e9d2842046328d6802f628db595541d2085e4c5d7b86e3aaee09c24d2145c924293145a9b66299f3adbc14bcd77720e280
data/README.md CHANGED
@@ -29,17 +29,20 @@ Example Configuration
29
29
  :password: 'xxxxxx'
30
30
  :create:
31
31
  :StatusID: 641
32
- :OwningCustomerName: foreman_teamdynamix_plugin_test
32
+ :AcquisitionDate: host.created_at
33
+ :OwningCustomerName: "'foreman_teamdynamix_plugin_test'"
33
34
  :Attributes:
34
35
  - name: mu.ci.Lifecycle Status
35
36
  id: 11634
36
37
  value: 26190
37
38
  - name: mu.ci.Description
38
39
  id: 11632
39
- value: "created by ForemanTeamdynamix plugin, owner is #{host.owner_id}"
40
+ value: >-
41
+ "created by ForemanTeamdynamix plugin, owner is #{host.owner_id}"
40
42
  - name: Ticket Routing Details
41
43
  id: 11636
42
- value: "Asset for host running on OS #{host.operatingsystem_id}"
44
+ value: >-
45
+ "Asset for host running on OS #{host.operatingsystem_id}"
43
46
  :delete:
44
47
  :StatusId: 642
45
48
  :fields:
@@ -59,7 +62,7 @@ Example Configuration
59
62
  * To configure any [Custom Attributes](https://api.teamdynamix.com/TDWebApi/Home/type/TeamDynamix.Api.CustomAttributes.CustomAttribute) for the asset.
60
63
  * It must contain expected value for 'id' and 'value' fields.
61
64
  * rest of the fields are optional, check the Custom Attribute's definition for what other fields are updatable.
62
- * String interpolation is supported for custom attribute's value.
65
+ * Code evaluation is supported for custom attribute's value.
63
66
 
64
67
  [:fields]
65
68
  * The keys are the display title and the values are the methods that are actually called to produce the value.
@@ -122,13 +122,26 @@ class TeamdynamixApi
122
122
  end
123
123
 
124
124
  def evaluate_attributes(create_attrs, host)
125
- return if create_attrs[:Attributes].blank?
126
- create_attrs[:Attributes].each do |attribute|
127
- attribute.transform_keys!(&:downcase)
128
- attribute['value'] = eval("\"#{attribute['value']}\"", binding, __FILE__, __LINE__) # rubocop:disable Security/Eval
125
+ create_attrs.each do |k, v|
126
+ if k.eql?(:Attributes)
127
+ v.each do |attribute|
128
+ attribute.transform_keys!(&:downcase)
129
+ attribute['value'] = eval_attribute(attribute['value'], host)
130
+ v.delete(attribute) if attribute['value'].nil?
131
+ end
132
+ else
133
+ create_attrs[k] = eval_attribute(v, host)
134
+ create_attrs.delete(k) if create_attrs[k].nil?
135
+ end
129
136
  end
130
137
  end
131
138
 
139
+ def eval_attribute(value, host)
140
+ eval(value.to_s, binding, __FILE__, __LINE__) # rubocop:disable Security/Eval
141
+ rescue StandardError
142
+ nil
143
+ end
144
+
132
145
  def must_configure_create_params
133
146
  [:StatusID]
134
147
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanTeamdynamix
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_teamdynamix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nipendar Tyagi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-17 00:00:00.000000000 Z
11
+ date: 2018-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface