dtk_crd_parser 0.0.141 → 0.0.142

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: 99b49a025dd321de393fc028ff69692f492fed6e
4
- data.tar.gz: ebdfbc850c67b77296bd9d348a11cda658091f64
3
+ metadata.gz: 6e4d795c7de81003022f7d6b4e1c0d43bdb793bc
4
+ data.tar.gz: a39d3475452c38ce2cc3910fc664c90849c26446
5
5
  SHA512:
6
- metadata.gz: 484ed3104e6d45c4f0cc94378fa6cb4bda9b3636b2682f0b354129120548d206b08cb3d4843d49d772ae65466aac066644afcc799a184a3e6ae984884a405430
7
- data.tar.gz: 1cb529cca089d09bd2b3b5fb56c2702e4064c1719baad486ee15ef704edd0f52af2b2831d369b624f1aafee3046bd93e0155ec359a5379f934dc5768b226c130
6
+ metadata.gz: 26e8d08f78a0d7a8ba75dddb5ade164de797d5b242fcfb37c7d1e39d531a598cc68cc7d834bd7444c32c3743ae31bd5bf1c6c4f5108c2e5ccf31c2ae70dd1f17
7
+ data.tar.gz: 4842b329890b511743c2f1de75b75020af9e3bbc83730314d05b8bfd9f3af92fcd470a11b57255cc8a04247710bfdc41f50b39b438500d6a1c4bfa9bfe551b80
@@ -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
@@ -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
19
  component_def = ComponentDef.create_from_kube(client, component_instance_obj, component_name)
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
@@ -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
@@ -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
 
@@ -52,7 +52,7 @@ module DTK::CrdParser
52
52
 
53
53
  def self.resolveModuleReference(module_refs, component_full_name, module_name)
54
54
  raise "There are no module refs for component #{component_full_name} in component instance." if module_refs.nil?
55
- module_ref = module_refs.find { |module_ref| module_ref[:name].gsub!('_', '-') == module_name.gsub!('_', '-') }
55
+ module_ref = module_refs.find { |module_ref| module_ref[:name] == module_name }
56
56
  if(module_ref.nil?)
57
57
  raise "Could not resolve module reference for component #{component_full_name} in component instance. Expected to find: #{module_name}"
58
58
  end
@@ -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]
@@ -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)
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.141
4
+ version: 0.0.142
5
5
  platform: ruby
6
6
  authors:
7
7
  - DTK