dtk_crd_parser 0.0.140 → 0.0.141
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/crd_parser/action/executable_action.rb +10 -8
- data/lib/crd_parser/base_class/helper_mixins.rb +53 -0
- data/lib/crd_parser/component.rb +10 -8
- data/lib/crd_parser/component/attribute.rb +4 -7
- data/lib/crd_parser/component_def.rb +3 -22
- data/lib/crd_parser/component_def/attribute_type_info.rb +4 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99b49a025dd321de393fc028ff69692f492fed6e
|
4
|
+
data.tar.gz: ebdfbc850c67b77296bd9d348a11cda658091f64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 484ed3104e6d45c4f0cc94378fa6cb4bda9b3636b2682f0b354129120548d206b08cb3d4843d49d772ae65466aac066644afcc799a184a3e6ae984884a405430
|
7
|
+
data.tar.gz: 1cb529cca089d09bd2b3b5fb56c2702e4064c1719baad486ee15ef704edd0f52af2b2831d369b624f1aafee3046bd93e0155ec359a5379f934dc5768b226c130
|
@@ -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
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
data/lib/crd_parser/component.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
1
|
module DTK::CrdParser
|
4
2
|
class Component < BaseClass
|
5
3
|
require_relative('component/attribute')
|
@@ -21,12 +19,15 @@ module DTK::CrdParser
|
|
21
19
|
component_instance_obj = client.get_component(component_instance[:name], component_instance[:namespace])
|
22
20
|
component_def = ComponentDef.create_from_kube(client, component_instance_obj, component_name)
|
23
21
|
component_attributes = getComponentAttributes(component_name, component_instance_obj[:spec][:components])
|
24
|
-
|
22
|
+
attribute_name_value = BaseClass::Helper::ClassAndInstanceMixin.destructureActionComponent(component_name)[:attributeName]
|
25
23
|
attributes = []
|
24
|
+
attributes.push(Attribute.create_from_kube("name", attribute_name_value, {}))
|
26
25
|
if component_attributes
|
27
|
-
|
28
|
-
|
29
|
-
|
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})
|
30
31
|
end
|
31
32
|
end
|
32
33
|
Component.new(component_name, component_def, attributes)
|
@@ -36,8 +37,9 @@ module DTK::CrdParser
|
|
36
37
|
protected
|
37
38
|
|
38
39
|
def self.getComponentAttributes(fullComponentName, components)
|
39
|
-
component = components.each do |component|
|
40
|
-
|
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)
|
41
43
|
if(componentObj && componentObj.is_a?(Kubeclient::Resource))
|
42
44
|
return componentObj[:attributes]
|
43
45
|
end
|
@@ -1,19 +1,16 @@
|
|
1
|
-
require 'logger'
|
2
1
|
module DTK::CrdParser
|
3
2
|
class Component
|
4
3
|
class Attribute < BaseClass
|
5
4
|
|
6
5
|
attr_reader :name, :value
|
7
6
|
|
8
|
-
def initialize(name, value)
|
9
|
-
Logger.new('/proc/1/fd/1').info("DEBUGGING in new: #{name}, #{value}")
|
7
|
+
def initialize(name, value, params = {})
|
10
8
|
@name = fail_if_nil(name, 'Attribute.name')
|
11
|
-
@value = fail_if_nil(value, 'Attribute.value')
|
9
|
+
@value = fail_if_nil(decrypt_if_encrypted(value, params[:encrypted]), 'Attribute.value')
|
12
10
|
end
|
13
11
|
|
14
|
-
def self.create_from_kube(attribute_name, attribute_value)
|
15
|
-
|
16
|
-
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)
|
17
14
|
end
|
18
15
|
|
19
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 = 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]
|
@@ -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]
|
11
|
-
@dynamic = params[:dynamic]
|
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)
|