dtk_crd_parser 0.0.129 → 0.0.130

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 189d2d26d42fdd9b366408854bb50982f9ea16e917402e18d27b6a5bdaa5021f
4
- data.tar.gz: bd444ef0fa7fd1f13e948f42e8392d572d718cd0ee4a1b4c484ae7f4dc04f06c
2
+ SHA1:
3
+ metadata.gz: 8598ba7681991b565a1eacf9c7b58b48b2300fe4
4
+ data.tar.gz: a5c95f2f80d241d828e1278be0ce8eaf46cb7d16
5
5
  SHA512:
6
- metadata.gz: 50b7204672eaddf7be877e69334b0160392d225306942bc13ac5b298e570de9dd581382e4c121089dc1d883e428bcca090cefe0ca6aa321e66932ba74a999ee7
7
- data.tar.gz: 899cad3f5c377f7b4d89e88f7800abb9e6281800dbad7d05c4e0b88c52f5c2c147590546c3904fa748496d4f81ea21ebbe7c1ea7d75b8f3547fb84317647433c
6
+ metadata.gz: 2dcc921f022078edd8b05256679e9dc47f492ab3bc72037247093935aaa0224b6f23068999c8f6d4bfb827fa930daeafa68919e518196f2cc029c6b3de729931
7
+ data.tar.gz: e46fd67d0c71a719e7bf80834084d694d468d0ebc351fa468b3eba8e6b520ffe6ab4414496a4f525f5eca0a2141330daac9bccacd186f01d6e2901921c9ed797
@@ -16,16 +16,14 @@ module DTK::CrdParser
16
16
  component_obj = Component.create_from_kube(client, component_instance, component_name)
17
17
  actions = component_obj.component_def.executable_actions
18
18
  executable_actions = Hash.new
19
- if actions
20
- actions.to_hash.each do |name, action|
21
- params = {
22
- name: name.to_s,
23
- entrypoint: action[:entrypoint] || "",
24
- type: action[:type] || "",
25
- bash_script: action[:bash_script] || ""
26
- }
27
- executable_actions[name.to_sym] = ExecutableAction.new(params)
28
- end
19
+ actions.to_hash.each do |name, action|
20
+ params = {
21
+ name: name.to_s,
22
+ entrypoint: action[:entrypoint] || "",
23
+ type: action[:type] || "",
24
+ bash_script: action[:bash_script] || ""
25
+ }
26
+ executable_actions[name.to_sym] = ExecutableAction.new(params)
29
27
  end
30
28
  executable_actions
31
29
  end
@@ -3,32 +3,9 @@ module DTK::CrdParser
3
3
  module Helper
4
4
  module ClassAndInstanceMixin
5
5
  # Helper functions want to have available in all classes
6
- def self.isOnSpecificNode(actionComponent)
7
- actionComponent.include? "/"
8
- end
9
-
10
- def self.destructureActionComponent(actionComponent)
11
- # regex to match component: module::name[attrName].action
12
- regex = /(.*)::(.*)\[(.*)\].?(.*)/
13
- # if component on node group node, get full name first
14
- # i.e ec2::node[ng-1]/(node-utility::ssh-access[ubuntu])
15
- nodeName, actionComponent = actionComponent.match(/(.*)\/(.*)/).captures if isOnSpecificNode(actionComponent)
16
- compModule, compName, attributeName, action = actionComponent.match(regex).captures if actionComponent.match(regex)
17
- action = (action && !action.empty?) ? action.to_sym : nil
18
-
19
- if(compModule.nil? || compName.nil? || attributeName.nil?)
20
- raise "Could not resolve component module, name or attribute name for component: #{actionComponent}"
21
- end
22
- {
23
- moduleName: compModule,
24
- componentName: compName,
25
- attributeName: attributeName,
26
- action: action
27
- }
28
- end
29
6
 
30
7
  def fail_if_nil(value, property_name)
31
- fail Error::Usage, "Property #{property_name} should not be nil" if value.nil?
8
+ fail Error::Usage, "Property #{property_name} should not be nil" unless value
32
9
  value
33
10
  end
34
11
 
@@ -49,36 +26,6 @@ module DTK::CrdParser
49
26
  end
50
27
  fail "#{the_method} is not defined in the concrete class #{klass}"
51
28
  end
52
-
53
- def decrypt_if_encrypted(data_to_decrypt, encrypted)
54
- return nil if data_to_decrypt.nil?
55
- return data_to_decrypt unless encrypted
56
- #get secret to get the key
57
- secret = secret()
58
- decipher = OpenSSL::Cipher::AES256.new :CBC
59
- decipher.decrypt
60
- begin
61
- decoded = Base64.decode64(data_to_decrypt)
62
- # iv is 16byte string prepended to the encrypted value
63
- iv, encrypted = [decoded[0,16], decoded[16..-1]]
64
- decipher.key = secret[:key]
65
- decipher.iv = iv
66
- plain_text = decipher.update(encrypted) + decipher.final
67
- plain_text
68
- rescue => exception
69
- Logger.new('/proc/1/fd/1').error exception.message
70
- end
71
- end
72
-
73
- def secret
74
- encrypt_key = ENV["ENCRYPTION_KEY"]
75
- iv = ENV["ENCRYPTION_IV"]
76
- {
77
- key: encrypt_key,
78
- iv: iv
79
- }
80
- end
81
-
82
29
  end
83
30
  end
84
31
  end
@@ -4,13 +4,13 @@ module DTK::CrdParser
4
4
 
5
5
  attr_reader :name, :value
6
6
 
7
- def initialize(name, value, params = {})
7
+ def initialize(name, value)
8
8
  @name = fail_if_nil(name, 'Attribute.name')
9
- @value = fail_if_nil(decrypt_if_encrypted(value, params[:encrypted]), 'Attribute.value')
9
+ @value = fail_if_nil(value, 'Attribute.value')
10
10
  end
11
11
 
12
- def self.create_from_kube(attribute_name, attribute_value, params)
13
- Attribute.new(attribute_name, attribute_value, params)
12
+ def self.create_from_kube(attribute_name, attribute_value)
13
+ Attribute.new(attribute_name, attribute_value)
14
14
  end
15
15
 
16
16
  end
@@ -15,19 +15,13 @@ module DTK::CrdParser
15
15
  end
16
16
 
17
17
  def self.create_from_kube(client, component_instance, component_name)
18
- component_name.gsub!('_', '-')
19
18
  component_instance_obj = client.get_component(component_instance[:name], component_instance[:namespace])
20
- component_def = ComponentDef.create_from_kube(client, component_instance_obj, component_name)
19
+ component_def = ComponentDef.create_from_kube(client, component_instance_obj, component_name.gsub('_', '-'))
21
20
  component_attributes = getComponentAttributes(component_name, component_instance_obj[:spec][:components])
22
- attribute_name_value = BaseClass::Helper::ClassAndInstanceMixin.destructureActionComponent(component_name)[:attributeName]
23
21
  attributes = []
24
- attributes.push(Attribute.create_from_kube("name", attribute_name_value, {}))
25
22
  if component_attributes
26
- (component_attributes.to_hash || []).each do |attribute_name, attribute_value|
27
- attribute_type_info = (component_def.attribute_type_info
28
- .select {|attribute| attribute.name == attribute_name.to_s} || []).first
29
- encrypted = attribute_type_info.encrypted if attribute_type_info
30
- attributes.push Attribute.create_from_kube(attribute_name, attribute_value, {encrypted: encrypted || false})
23
+ component_attributes.to_hash.each do |attribute_name, attribute_value|
24
+ attributes.push Attribute.create_from_kube(attribute_name, attribute_value)
31
25
  end
32
26
  end
33
27
  Component.new(component_name, component_def, attributes)
@@ -37,9 +31,8 @@ module DTK::CrdParser
37
31
  protected
38
32
 
39
33
  def self.getComponentAttributes(fullComponentName, components)
40
- component = (components || []).each do |component|
41
- name = (component.to_h).keys.first.to_s.gsub!('_', '-')
42
- componentObj = component[(component.to_h).keys.first.to_s] if (fullComponentName == name)
34
+ component = components.each do |component|
35
+ componentObj = component[fullComponentName]
43
36
  if(componentObj && componentObj.is_a?(Kubeclient::Resource))
44
37
  return componentObj[:attributes]
45
38
  end
@@ -2,14 +2,13 @@ module DTK::CrdParser
2
2
  class ComponentDef
3
3
  class AttributeTypeInfo < BaseClass
4
4
 
5
- attr_reader :name, :type, :required, :dynamic, :encrypted
5
+ attr_reader :name, :type, :required, :dynamic
6
6
 
7
7
  def initialize(params)
8
8
  @name = params[:name]
9
9
  @type = params[:type]
10
- @required = params[:required] || false
11
- @dynamic = params[:dynamic] || false
12
- @encrypted = params[:encrypted] || false
10
+ @required = params[:required] || false
11
+ @dynamic = params[:dynamic] || false
13
12
  end
14
13
 
15
14
  def self.resolveAttr(attribute)
@@ -16,7 +16,7 @@ module DTK::CrdParser
16
16
  end
17
17
 
18
18
  def self.create_from_kube(client, component_instance, component_def_name)
19
- destructured_component = BaseClass::Helper::ClassAndInstanceMixin.destructureActionComponent(component_def_name)
19
+ destructured_component = destructureActionComponent(component_def_name)
20
20
  module_ref = resolveModuleReference(component_instance[:references][:module_refs], component_def_name, destructured_component[:moduleName])
21
21
 
22
22
  componentDef = client.get_componentdef("#{destructured_component[:moduleName]}-#{destructured_component[:componentName]}", module_ref[:namespace])
@@ -34,8 +34,8 @@ module DTK::CrdParser
34
34
  componentDefAction = componentDefSpec[:actions]
35
35
  end
36
36
  componentDefAttributes = []
37
-
38
- (componentDefSpec[:attributes] || []).each do |attribute|
37
+
38
+ (componentDefSpec[:attributes] || []).each do |attribute|
39
39
  componentDefAttributes.push AttributeTypeInfo.resolveAttr(attribute)
40
40
  end
41
41
 
@@ -64,6 +64,25 @@ module DTK::CrdParser
64
64
  actionComponent.include? "/"
65
65
  end
66
66
 
67
+ def self.destructureActionComponent(actionComponent)
68
+ # regex to match component: module::name[attrName].action
69
+ regex = /(.*)::(.*)\[(.*)\].?(.*)/
70
+ # if component on node group node, get full name first
71
+ # i.e ec2::node[ng-1]/(node-utility::ssh-access[ubuntu])
72
+ nodeName, actionComponent = actionComponent.match(/(.*)\/(.*)/).captures if isOnSpecificNode(actionComponent)
73
+ compModule, compName, attributeName, action = actionComponent.match(regex).captures if actionComponent.match(regex)
74
+ action = (action && !action.empty?) ? action.to_sym : nil
75
+
76
+ if(compModule.nil? || compName.nil? || attributeName.nil?)
77
+ raise "Could not resolve component module, name or attribute name for component: #{actionComponent}"
78
+ end
79
+ {
80
+ moduleName: compModule,
81
+ componentName: compName,
82
+ attributeName: attributeName,
83
+ action: action
84
+ }
85
+ end
67
86
  protected
68
87
  def self.metadata(componentDef)
69
88
  componentDef[:metadata]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dtk_crd_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.129
4
+ version: 0.0.130
5
5
  platform: ruby
6
6
  authors:
7
7
  - DTK
@@ -46,7 +46,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  requirements: []
49
- rubygems_version: 3.0.3
49
+ rubyforge_project:
50
+ rubygems_version: 2.4.5.4
50
51
  signing_key:
51
52
  specification_version: 4
52
53
  summary: Parse kubernetes DTK crd to ruby in memory object!