dtk_crd_parser 0.0.145 → 0.0.146

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: 0c3ef1ffaaf80253f7506b1cf41a9c29e7145583
4
- data.tar.gz: 79c997870d853034167b94b77e53164244a5c71d
3
+ metadata.gz: 258cd6c50988d7a61615b1faae1adcf52e56992d
4
+ data.tar.gz: 22a8cfdfcd36b64543efac8d9d803756e582ad9e
5
5
  SHA512:
6
- metadata.gz: 45865cfa3bdad15d18859e3529f01d8d66e37f4986ef63ecfb5d768e54904daa7323cdf70ae42ace47179562cdce91a47c68f721b0b5ec908183de2abdea5c8a
7
- data.tar.gz: 34ebb9818b0781f85ccd642472c8324cc4d4e8b5899b64f560b10f5fd708a48fefff04578778d9e666a0c11024df7f1708a8facce659cf51997eca810a0dcb1a
6
+ metadata.gz: 08df3b6887c37f9eec4119bebd1697a8e1a45ce40033a648fea253f63249a28d127b01fdba61a6be0cb6e3b69ed3554b91bc7961a410cc24cacbb1477f014787
7
+ data.tar.gz: 435739f77b51cdc7ca5294178ddacdc3e23873f53f0d93451cf9f384b55932b40b2ca8de011e65634c155356b9107a2d3985a2aeaa99c4f2cdde34bf5590fbc0
@@ -16,14 +16,16 @@ 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
- 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)
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
27
29
  end
28
30
  executable_actions
29
31
  end
@@ -3,6 +3,29 @@ 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
6
29
 
7
30
  def fail_if_nil(value, property_name)
8
31
  fail Error::Usage, "Property #{property_name} should not be nil" if value.nil?
@@ -26,6 +49,36 @@ module DTK::CrdParser
26
49
  end
27
50
  fail "#{the_method} is not defined in the concrete class #{klass}"
28
51
  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
+
29
82
  end
30
83
  end
31
84
  end
@@ -4,13 +4,13 @@ module DTK::CrdParser
4
4
 
5
5
  attr_reader :name, :value
6
6
 
7
- def initialize(name, value)
7
+ def initialize(name, value, params = {})
8
8
  @name = fail_if_nil(name, 'Attribute.name')
9
- @value = fail_if_nil(value, 'Attribute.value')
9
+ @value = fail_if_nil(decrypt_if_encrypted(value, params[:encrypted]), 'Attribute.value')
10
10
  end
11
11
 
12
- def self.create_from_kube(attribute_name, attribute_value)
13
- Attribute.new(attribute_name, attribute_value)
12
+ def self.create_from_kube(attribute_name, attribute_value, params)
13
+ Attribute.new(attribute_name, attribute_value, params)
14
14
  end
15
15
 
16
16
  end
@@ -18,10 +18,15 @@ module DTK::CrdParser
18
18
  component_instance_obj = client.get_component(component_instance[:name], component_instance[:namespace])
19
19
  component_def = ComponentDef.create_from_kube(client, component_instance_obj, component_name)
20
20
  component_attributes = getComponentAttributes(component_name, component_instance_obj[:spec][:components])
21
+ attribute_name_value = BaseClass::Helper::ClassAndInstanceMixin.destructureActionComponent(component_name)[:attributeName]
21
22
  attributes = []
23
+ attributes.push(Attribute.create_from_kube("name", attribute_name_value, {}))
22
24
  if component_attributes
23
- component_attributes.to_hash.each do |attribute_name, attribute_value|
24
- attributes.push Attribute.create_from_kube(attribute_name, attribute_value)
25
+ (component_attributes.to_hash || []).each do |attribute_name, attribute_value|
26
+ attribute_type_info = (component_def.attribute_type_info
27
+ .select {|attribute| attribute.name == attribute_name.to_s} || []).first
28
+ encrypted = attribute_type_info.encrypted if attribute_type_info
29
+ attributes.push Attribute.create_from_kube(attribute_name, attribute_value, {encrypted: encrypted || false})
25
30
  end
26
31
  end
27
32
  Component.new(component_name, component_def, attributes)
@@ -31,8 +36,9 @@ module DTK::CrdParser
31
36
  protected
32
37
 
33
38
  def self.getComponentAttributes(fullComponentName, components)
34
- component = components.each do |component|
35
- componentObj = component[fullComponentName]
39
+ component = (components || []).each do |component|
40
+ name = (component.to_h).keys.first.to_s.gsub!('_', '-')
41
+ componentObj = component[(component.to_h).keys.first.to_s] if (fullComponentName == name)
36
42
  if(componentObj && componentObj.is_a?(Kubeclient::Resource))
37
43
  return componentObj[:attributes]
38
44
  end
@@ -2,13 +2,14 @@ module DTK::CrdParser
2
2
  class ComponentDef
3
3
  class AttributeTypeInfo < BaseClass
4
4
 
5
- attr_reader :name, :type, :required, :dynamic
5
+ attr_reader :name, :type, :required, :dynamic, :encrypted
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
10
+ @required = params[:required] || false
11
+ @dynamic = params[:dynamic] || false
12
+ @encrypted = params[:encrypted] || false
12
13
  end
13
14
 
14
15
  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 = destructureActionComponent(component_def_name)
19
+ destructured_component = BaseClass::Helper::ClassAndInstanceMixin.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,25 +64,6 @@ 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
86
67
  protected
87
68
  def self.metadata(componentDef)
88
69
  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.145
4
+ version: 0.0.146
5
5
  platform: ruby
6
6
  authors:
7
7
  - DTK