aws-codedeploy-agent 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. data/aws-codedeploy-agent.gemspec +5 -5
  2. data/certs/host-agent-deployment-signer-ca-chain.pem +30 -0
  3. data/conf/codedeployagent.yml +0 -1
  4. data/lib/instance_agent.rb +1 -13
  5. data/lib/instance_agent/agent/base.rb +38 -12
  6. data/lib/instance_agent/agent/plugin.rb +21 -0
  7. data/lib/instance_agent/config.rb +2 -1
  8. data/lib/instance_agent/platform/linux_util.rb +4 -0
  9. data/lib/instance_agent/plugins/codedeploy/application_specification/ace_info.rb +133 -0
  10. data/lib/instance_agent/plugins/codedeploy/application_specification/acl_info.rb +163 -0
  11. data/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb +143 -0
  12. data/lib/instance_agent/plugins/codedeploy/application_specification/context_info.rb +23 -0
  13. data/lib/instance_agent/plugins/codedeploy/application_specification/file_info.rb +23 -0
  14. data/lib/instance_agent/plugins/codedeploy/application_specification/linux_permission_info.rb +121 -0
  15. data/lib/instance_agent/plugins/codedeploy/application_specification/mode_info.rb +66 -0
  16. data/lib/instance_agent/plugins/codedeploy/application_specification/range_info.rb +134 -0
  17. data/lib/instance_agent/plugins/codedeploy/application_specification/script_info.rb +27 -0
  18. data/lib/instance_agent/plugins/codedeploy/codedeploy_control.rb +100 -0
  19. data/lib/instance_agent/plugins/codedeploy/command_executor.rb +359 -0
  20. data/lib/instance_agent/plugins/codedeploy/command_poller.rb +178 -0
  21. data/lib/instance_agent/plugins/codedeploy/deployment_specification.rb +161 -0
  22. data/lib/instance_agent/plugins/codedeploy/hook_executor.rb +226 -0
  23. data/lib/instance_agent/plugins/codedeploy/install_instruction.rb +389 -0
  24. data/lib/instance_agent/plugins/codedeploy/installer.rb +147 -0
  25. data/lib/instance_agent/plugins/codedeploy/onpremise_config.rb +42 -0
  26. data/lib/instance_agent/plugins/codedeploy/register_plugin.rb +17 -0
  27. data/lib/instance_agent/runner/child.rb +20 -5
  28. data/lib/instance_agent/runner/master.rb +2 -15
  29. data/lib/instance_metadata.rb +2 -2
  30. data/test/certificate_helper.rb +1 -1
  31. data/test/helpers/instance_agent_helper.rb +1 -0
  32. data/test/instance_agent/agent/base_test.rb +16 -3
  33. data/test/instance_agent/config_test.rb +2 -1
  34. data/test/instance_agent/plugins/codedeploy/application_specification_test.rb +1713 -0
  35. data/test/instance_agent/{codedeploy_plugin → plugins/codedeploy}/codedeploy_control_test.rb +1 -1
  36. data/test/instance_agent/{codedeploy_plugin → plugins/codedeploy}/command_executor_test.rb +32 -9
  37. data/test/instance_agent/{codedeploy_plugin → plugins/codedeploy}/command_poller_test.rb +13 -14
  38. data/test/instance_agent/{codedeploy_plugin → plugins/codedeploy}/deployment_specification_test.rb +98 -25
  39. data/test/instance_agent/{codedeploy_plugin → plugins/codedeploy}/hook_executor_test.rb +83 -15
  40. data/test/instance_agent/plugins/codedeploy/install_instruction_test.rb +568 -0
  41. data/test/instance_agent/{codedeploy_plugin → plugins/codedeploy}/installer_test.rb +12 -9
  42. data/test/instance_agent/plugins/codedeploy/onpremise_config_test.rb +72 -0
  43. data/test/instance_agent/runner/child_test.rb +1 -1
  44. data/vendor/gems/.codedeploy-commands-1.0.0.created.rid +1 -1
  45. data/vendor/gems/codedeploy-commands/lib/aws/plugins/deploy_control_endpoint.rb +4 -0
  46. data/vendor/gems/jmespath-1.0.1/lib/jmespath.rb +41 -0
  47. data/vendor/gems/jmespath-1.0.1/lib/jmespath/caching_parser.rb +30 -0
  48. data/vendor/gems/jmespath-1.0.1/lib/jmespath/errors.rb +17 -0
  49. data/vendor/gems/jmespath-1.0.1/lib/jmespath/expr_node.rb +15 -0
  50. data/vendor/gems/jmespath-1.0.1/lib/jmespath/lexer.rb +116 -0
  51. data/vendor/gems/jmespath-1.0.1/lib/jmespath/parser.rb +347 -0
  52. data/vendor/gems/jmespath-1.0.1/lib/jmespath/runtime.rb +71 -0
  53. data/vendor/gems/jmespath-1.0.1/lib/jmespath/token.rb +41 -0
  54. data/vendor/gems/jmespath-1.0.1/lib/jmespath/token_stream.rb +60 -0
  55. data/vendor/gems/jmespath-1.0.1/lib/jmespath/tree_interpreter.rb +523 -0
  56. data/vendor/gems/jmespath-1.0.1/lib/jmespath/version.rb +3 -0
  57. data/vendor/gems/process_manager/lib/process_manager/master.rb +16 -5
  58. data/vendor/specifications/{aws-sdk-core-2.0.5.gemspec → aws-sdk-core-2.0.42.gemspec} +9 -11
  59. data/vendor/specifications/builder-3.2.2.gemspec +1 -1
  60. data/vendor/specifications/codedeploy-commands-1.0.0.gemspec +7 -6
  61. data/vendor/specifications/gli-2.5.6.gemspec +1 -1
  62. data/vendor/specifications/jmespath-1.0.1.gemspec +29 -0
  63. data/vendor/specifications/little-plugger-1.1.3.gemspec +1 -1
  64. data/vendor/specifications/logging-1.8.1.gemspec +1 -1
  65. data/vendor/specifications/multi_json-1.7.7.gemspec +1 -1
  66. data/vendor/specifications/multi_json-1.8.4.gemspec +1 -1
  67. data/vendor/specifications/multi_xml-0.5.5.gemspec +1 -1
  68. data/vendor/specifications/process_manager-0.0.13.gemspec +1 -1
  69. data/vendor/specifications/simple_pid-0.2.1.gemspec +1 -1
  70. metadata +76 -63
  71. data/lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb +0 -133
  72. data/lib/instance_agent/codedeploy_plugin/application_specification/acl_info.rb +0 -163
  73. data/lib/instance_agent/codedeploy_plugin/application_specification/application_specification.rb +0 -142
  74. data/lib/instance_agent/codedeploy_plugin/application_specification/context_info.rb +0 -23
  75. data/lib/instance_agent/codedeploy_plugin/application_specification/file_info.rb +0 -23
  76. data/lib/instance_agent/codedeploy_plugin/application_specification/linux_permission_info.rb +0 -121
  77. data/lib/instance_agent/codedeploy_plugin/application_specification/mode_info.rb +0 -66
  78. data/lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb +0 -134
  79. data/lib/instance_agent/codedeploy_plugin/application_specification/script_info.rb +0 -27
  80. data/lib/instance_agent/codedeploy_plugin/codedeploy_control.rb +0 -72
  81. data/lib/instance_agent/codedeploy_plugin/command_executor.rb +0 -357
  82. data/lib/instance_agent/codedeploy_plugin/command_poller.rb +0 -170
  83. data/lib/instance_agent/codedeploy_plugin/deployment_specification.rb +0 -150
  84. data/lib/instance_agent/codedeploy_plugin/hook_executor.rb +0 -206
  85. data/lib/instance_agent/codedeploy_plugin/install_instruction.rb +0 -374
  86. data/lib/instance_agent/codedeploy_plugin/installer.rb +0 -143
  87. data/lib/instance_agent/codedeploy_plugin/request_helper.rb +0 -28
  88. data/test/instance_agent/codedeploy_plugin/application_specification_test.rb +0 -1710
  89. data/test/instance_agent/codedeploy_plugin/install_instruction_test.rb +0 -566
  90. data/test/instance_agent/codedeploy_plugin/request_helper_test.rb +0 -37
  91. data/vendor/specifications/jamespath-0.5.1.gemspec +0 -35
@@ -5,7 +5,7 @@ $:.push File.expand_path("../vendor/gems/process_manager/lib", __FILE__)
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'aws-codedeploy-agent'
8
- s.version = '0.0.2'
8
+ s.version = '0.0.3'
9
9
  s.license = 'Apache-2.0'
10
10
  s.summary = 'AWS CodeDeploy Agent'
11
11
  s.description = 'CodeDeploy Agent is responsible for doing the actual work of deploying software on an individual EC2 instance.'
@@ -21,16 +21,16 @@ Gem::Specification.new do |s|
21
21
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
22
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
23
23
 
24
- s.add_dependency('json')
25
- s.add_dependency('rubyzip')
24
+ s.add_dependency('json_pure', '~> 1.6')
25
+ s.add_dependency('rubyzip', '~> 1.1.0')
26
26
  s.add_dependency('httpclient')
27
27
  s.add_dependency('rake')
28
+ s.add_dependency('archive-tar-minitar', '~> 0.5.2')
28
29
 
29
30
  s.add_dependency('gli', '~> 2.5')
30
- s.add_dependency('aws-sdk-core', '~> 2.0.5')
31
+ s.add_dependency('aws-sdk-core', '~> 2.0.42')
31
32
  s.add_dependency('builder', '~> 3.2.2')
32
33
  s.add_dependency('gli', '~> 2.5.6')
33
- s.add_dependency('jamespath', '~> 0.5.1')
34
34
  s.add_dependency('little-plugger', '~> 1.1.3')
35
35
  s.add_dependency('logging', '~> 1.8.1')
36
36
  s.add_dependency('multi_json', '~> 1.8.4')
@@ -74,3 +74,33 @@ CSqGSIb3DQEBBQUAA4GBABByUqkFFBkyCEHwxWsKzH4PIRnN5GfcX6kb5sroc50i
74
74
  2JhucwNhkcV8sEVAbkSdjbCxlnRhLQ2pRdKkkirWmnWXbj9T/UWZYB2oK0z5XqcJ
75
75
  2HUw19JlYD1n1khVdWk/kfVIC0dpImmClr7JyDiGSnoscxlIaU5rfGW/D/xwzoiQ
76
76
  -----END CERTIFICATE-----
77
+ -----BEGIN CERTIFICATE-----
78
+ MIIFODCCBCCgAwIBAgIQUT+5dDhwtzRAQY0wkwaZ/zANBgkqhkiG9w0BAQsFADCB
79
+ yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
80
+ ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp
81
+ U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW
82
+ ZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0
83
+ aG9yaXR5IC0gRzUwHhcNMTMxMDMxMDAwMDAwWhcNMjMxMDMwMjM1OTU5WjB+MQsw
84
+ CQYDVQQGEwJVUzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xHzAdBgNV
85
+ BAsTFlN5bWFudGVjIFRydXN0IE5ldHdvcmsxLzAtBgNVBAMTJlN5bWFudGVjIENs
86
+ YXNzIDMgU2VjdXJlIFNlcnZlciBDQSAtIEc0MIIBIjANBgkqhkiG9w0BAQEFAAOC
87
+ AQ8AMIIBCgKCAQEAstgFyhx0LbUXVjnFSlIJluhL2AzxaJ+aQihiw6UwU35VEYJb
88
+ A3oNL+F5BMm0lncZgQGUWfm893qZJ4Itt4PdWid/sgN6nFMl6UgfRk/InSn4vnlW
89
+ 9vf92Tpo2otLgjNBEsPIPMzWlnqEIRoiBAMnF4scaGGTDw5RgDMdtLXO637QYqzu
90
+ s3sBdO9pNevK1T2p7peYyo2qRA4lmUoVlqTObQJUHypqJuIGOmNIrLRM0XWTUP8T
91
+ L9ba4cYY9Z/JJV3zADreJk20KQnNDz0jbxZKgRb78oMQw7jW2FUyPfG9D72MUpVK
92
+ Fpd6UiFjdS8W+cRmvvW1Cdj/JwDNRHxvSz+w9wIDAQABo4IBYzCCAV8wEgYDVR0T
93
+ AQH/BAgwBgEB/wIBADAwBgNVHR8EKTAnMCWgI6Ahhh9odHRwOi8vczEuc3ltY2Iu
94
+ Y29tL3BjYTMtZzUuY3JsMA4GA1UdDwEB/wQEAwIBBjAvBggrBgEFBQcBAQQjMCEw
95
+ HwYIKwYBBQUHMAGGE2h0dHA6Ly9zMi5zeW1jYi5jb20wawYDVR0gBGQwYjBgBgpg
96
+ hkgBhvhFAQc2MFIwJgYIKwYBBQUHAgEWGmh0dHA6Ly93d3cuc3ltYXV0aC5jb20v
97
+ Y3BzMCgGCCsGAQUFBwICMBwaGmh0dHA6Ly93d3cuc3ltYXV0aC5jb20vcnBhMCkG
98
+ A1UdEQQiMCCkHjAcMRowGAYDVQQDExFTeW1hbnRlY1BLSS0xLTUzNDAdBgNVHQ4E
99
+ FgQUX2DPYZBV34RDFIpgKrL1evRDGO8wHwYDVR0jBBgwFoAUf9Nlp8Ld7LvwMAnz
100
+ Qzn6Aq8zMTMwDQYJKoZIhvcNAQELBQADggEBAF6UVkndji1l9cE2UbYD49qecxny
101
+ H1mrWH5sJgUs+oHXXCMXIiw3k/eG7IXmsKP9H+IyqEVv4dn7ua/ScKAyQmW/hP4W
102
+ Ko8/xabWo5N9Q+l0IZE1KPRj6S7t9/Vcf0uatSDpCr3gRRAMFJSaXaXjS5HoJJtG
103
+ QGX0InLNmfiIEfXzf+YzguaoxX7+0AjiJVgIcWjmzaLmFN5OUiQt/eV5E1PnXi8t
104
+ TRttQBVSK/eHiXgSgW7ZTaoteNTCLD0IX4eRnh8OsN4wUmSGiaqdZpwOdgyA8nTY
105
+ Kvi4Os7X1g8RvmurFPW9QaAiY4nxug9vKWNmLT+sjHLF+8fk1A/yO0+MKcc=
106
+ -----END CERTIFICATE-----
@@ -5,5 +5,4 @@
5
5
  :program_name: codedeploy-agent
6
6
  :root_dir: '/tmp/codedeploy-agent'
7
7
  :verbose: false
8
- :wait_after_error: 1
9
8
  :wait_between_runs: 1
@@ -8,20 +8,8 @@ unless defined?(InstanceAgent)
8
8
  require 'instance_agent/log'
9
9
  require 'instance_agent/platform'
10
10
  require 'instance_agent/platform/linux_util'
11
+ require 'instance_agent/agent/plugin'
11
12
  require 'instance_agent/agent/base'
12
- require 'instance_agent/codedeploy_plugin/command_poller'
13
- require 'instance_agent/codedeploy_plugin/command_executor'
14
- require 'instance_agent/codedeploy_plugin/deployment_specification'
15
- require 'instance_agent/codedeploy_plugin/application_specification/application_specification'
16
- require 'instance_agent/codedeploy_plugin/application_specification/file_info'
17
- require 'instance_agent/codedeploy_plugin/application_specification/script_info'
18
- require 'instance_agent/codedeploy_plugin/application_specification/linux_permission_info'
19
- require 'instance_agent/codedeploy_plugin/application_specification/mode_info'
20
- require 'instance_agent/codedeploy_plugin/application_specification/acl_info'
21
- require 'instance_agent/codedeploy_plugin/application_specification/ace_info'
22
- require 'instance_agent/codedeploy_plugin/application_specification/context_info'
23
- require 'instance_agent/codedeploy_plugin/application_specification/range_info'
24
- require 'instance_agent/codedeploy_plugin/install_instruction'
25
13
  require 'instance_agent/runner/master'
26
14
  require 'instance_agent/runner/child'
27
15
  end
@@ -1,10 +1,15 @@
1
1
  # encoding: UTF-8
2
+ require 'instance_agent/agent/plugin'
3
+
2
4
  module InstanceAgent
3
5
  module Agent
4
6
  class Base
7
+ include InstanceAgent::Agent::Plugin
5
8
 
6
9
  def self.runner
7
- self.new
10
+ instance = self.new
11
+ instance.validate if instance.respond_to?('validate')
12
+ instance
8
13
  end
9
14
 
10
15
  def description
@@ -17,18 +22,39 @@ module InstanceAgent
17
22
  end
18
23
 
19
24
  def run
20
- perform
21
- rescue Aws::Errors::MissingCredentialsError
22
- log(:error, "Missing credentials - please check if this instance was started with an IAM instance profile")
23
- sleep InstanceAgent::Config.config[:wait_after_error]
24
- rescue SocketError, Errno::ENETDOWN, Aws::Errors::ServiceError => e
25
- log(:error, "Cannot reach InstanceService: #{e.class} - #{e.message}")
26
- sleep InstanceAgent::Config.config[:wait_after_error]
27
- rescue Exception => e
28
- log(:error, "Error during perform: #{e.class} - #{e.message} - #{e.backtrace.join("\n")}")
29
- sleep InstanceAgent::Config.config[:wait_after_error]
30
- end
25
+ start_time = Time.now
26
+
27
+ begin
28
+ perform
29
+ @error_count = 0
30
+ rescue Aws::Errors::MissingCredentialsError
31
+ log(:error, "Missing credentials - please check if this instance was started with an IAM instance profile")
32
+ @error_count = @error_count.to_i + 1
33
+ rescue SocketError, Errno::ENETDOWN, Aws::Errors::ServiceError => e
34
+ log(:error, "Cannot reach InstanceService: #{e.class} - #{e.message}")
35
+ @error_count = @error_count.to_i + 1
36
+ rescue Exception => e
37
+ log(:error, "Error during perform: #{e.class} - #{e.message} - #{e.backtrace.join("\n")}")
38
+ @error_count = @error_count.to_i + 1
39
+ end
40
+
41
+ if @error_count > 0
42
+ # Max out at 90 seconds between calls and take 5 minutes before reaching the cap and allowing 10 calls to get there
31
43
 
44
+ if @error_count > 10
45
+ @error_count = 10
46
+ end
47
+
48
+ elapsed_time = (Time.now - start_time).ceil
49
+ backoff_time = (((1.2675 ** @error_count) * (90.0 / (1.2675 ** 10)))).floor
50
+ sleep_time = backoff_time - elapsed_time
51
+
52
+ if(sleep_time > 0)
53
+ log(:debug, "Sleeping #{sleep_time} seconds.")
54
+ sleep sleep_time
55
+ end
56
+ end
57
+ end
32
58
  end
33
59
  end
34
60
  end
@@ -0,0 +1,21 @@
1
+ require 'set'
2
+
3
+ module InstanceAgent
4
+ module Agent
5
+ module Plugin
6
+ module PluginMethods
7
+ def plugins
8
+ @plugins ||= Set.new
9
+ end
10
+
11
+ def inherited(plugin)
12
+ plugins << plugin
13
+ end
14
+ end
15
+
16
+ def self.included(klass)
17
+ klass.extend PluginMethods
18
+ end
19
+ end
20
+ end
21
+ end
@@ -30,7 +30,8 @@ module InstanceAgent
30
30
  :instance_service_port => nil,
31
31
  :wait_between_runs => 30,
32
32
  :wait_after_error => 30,
33
- :codedeploy_test_profile => 'prod'
33
+ :codedeploy_test_profile => 'prod',
34
+ :on_premises_config_file => '/etc/codedeploy-agent/conf/codedeploy.onpremises.yml'
34
35
  })
35
36
  end
36
37
 
@@ -30,6 +30,10 @@ module InstanceAgent
30
30
  execute_tar_command("/bin/tar -zxpsf #{bundle_file} -C #{dst}")
31
31
  end
32
32
 
33
+ def self.supports_process_groups?()
34
+ true
35
+ end
36
+
33
37
  private
34
38
  def self.execute_tar_command(cmd)
35
39
  log(:debug, "Executing #{cmd}")
@@ -0,0 +1,133 @@
1
+ module InstanceAgent
2
+ module Plugins
3
+ module CodeDeployPlugin
4
+ module ApplicationSpecification
5
+ #Helper Class for storing an ace
6
+ class AceInfo
7
+
8
+ attr_reader :default, :type, :name, :read, :write, :execute
9
+ def initialize(ace, internal=false)
10
+ @default = false
11
+ @type = nil
12
+ @name = ""
13
+ parts = ace.split(":", -1).reverse
14
+ if (parts.length < 2) || (parts.length > 4)
15
+ raise AppSpecValidationException, "invalid acl entry #{ace}"
16
+ end
17
+
18
+ if (parts.length == 4)
19
+ if !(parts[3].eql?("d") || (parts[3].eql?("default")))
20
+ raise AppSpecValidationException, "invalid acl entry #{ace}"
21
+ end
22
+ @default = true
23
+ end
24
+
25
+ if parts.length >= 3
26
+ if parts[2].eql?("d") || (parts[2].eql?("default"))
27
+ if @default
28
+ raise AppSpecValidationException, "invalid acl entry #{ace}"
29
+ end
30
+ @default = true
31
+ elsif parts[2].eql?("m") || parts[2].eql?("mask")
32
+ @type = "mask"
33
+ elsif parts[2].eql?("o") || parts[2].eql?("other")
34
+ @type = "other"
35
+ elsif parts[2].eql?("g") || parts[2].eql?("group")
36
+ @type = "group"
37
+ elsif parts[2].eql?("u") || parts[2].eql?("user")
38
+ @type = "user"
39
+ else
40
+ raise AppSpecValidationException, "invalid acl entry #{ace}"
41
+ end
42
+ end
43
+
44
+ if parts[1].eql?("m") || parts[1].eql?("mask")
45
+ if @type.nil?
46
+ @type = "mask"
47
+ else
48
+ @name = "mask"
49
+ end
50
+ elsif parts[1].eql?("o") || parts[1].eql?("other")
51
+ if @type.nil?
52
+ @type = "other"
53
+ else
54
+ @name = "other"
55
+ end
56
+ else
57
+ if @type.nil?
58
+ @type = "user"
59
+ end
60
+ @name = parts[1]
61
+ end
62
+
63
+ if (@type.eql?("mask") || @type.eql?("other")) && !@name.empty?
64
+ raise AppSpecValidationException, "invalid acl entry #{ace}"
65
+ end
66
+ if (!internal && !@default && !@type.eql?("mask") && @name.empty?)
67
+ raise AppSpecValidationException, "use mode to set the base acl entry #{ace}"
68
+ end
69
+
70
+ perm_chars = parts[0].chars.entries
71
+ if (perm_chars.length == 1) && (perm_chars[0].ord >= "0".ord) && (perm_chars[0].ord <= "7".ord)
72
+ perm_bits = to_bits(perm_chars[0].to_i, 3)
73
+ @read = (perm_bits[0] == 1)
74
+ @write = (perm_bits[1] == 1)
75
+ @execute = (perm_bits[2] == 1)
76
+ else
77
+ @read = false
78
+ @write = false
79
+ @execute = false
80
+ perm_chars.each do |perm|
81
+ case perm
82
+ when 'r'
83
+ @read = true
84
+ when 'w'
85
+ @write = true
86
+ when 'x'
87
+ @execute = true
88
+ when '-'
89
+ else
90
+ raise AppSpecValidationException, "unrecognized permission character #{perm} in #{ace}"
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ #format [default:][user|group|mask|other]:[name]:(r|-)(w|-)(x|-)
97
+ def get_ace
98
+ result = "";
99
+ if @default
100
+ result = "default:"
101
+ end
102
+ result = result + type + ":" + name + ":"
103
+ if (@read)
104
+ result = result + "r"
105
+ else
106
+ result = result + "-"
107
+ end
108
+ if (@write)
109
+ result = result + "w"
110
+ else
111
+ result = result + "-"
112
+ end
113
+ if (@execute)
114
+ result = result + "x"
115
+ else
116
+ result = result + "-"
117
+ end
118
+ result
119
+ end
120
+
121
+ def to_bits(num, min_size)
122
+ bits = Array.new(min_size, 0)
123
+ num_bits = num.to_s(2).split("")
124
+ diff = [0, min_size - num_bits.length].max
125
+ num_bits.map.with_index {|n,i| bits[i+diff] = n.to_i}
126
+ bits
127
+ end
128
+ end
129
+
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,163 @@
1
+ module InstanceAgent
2
+ module Plugins
3
+ module CodeDeployPlugin
4
+ module ApplicationSpecification
5
+ #Helper Class for storing an acl
6
+ class AclInfo
7
+
8
+ attr_reader :aces, :additional
9
+ def initialize(acl)
10
+ @aces = []
11
+ @additional = []
12
+ acl.each do |ace|
13
+ @aces << AceInfo.new(ace)
14
+ end
15
+ end
16
+
17
+ #format [default:][user|group|mask|other]:[name]:(r|-)(w|-)(x|-) (or nil if none present)
18
+ def get_default_ace
19
+ @aces.each do |ace|
20
+ if ace.default
21
+ return ace.get_ace
22
+ end
23
+ end
24
+ @additional.each do |ace|
25
+ if ace.default
26
+ return ace.get_ace
27
+ end
28
+ end
29
+ nil
30
+ end
31
+
32
+ #format array of aces with format: [default:][user|group|mask|other]:[name]:(r|-)(w|-)(x|-)
33
+ def get_acl
34
+ aces = []
35
+ @aces.each do |ace|
36
+ aces << ace.get_ace
37
+ end
38
+ @additional.each do |ace|
39
+ aces << ace.get_ace
40
+ end
41
+ aces
42
+ end
43
+
44
+ def add_ace(ace)
45
+ additional << AceInfo.new(ace, true)
46
+ end
47
+
48
+ def clear_additional()
49
+ additional = []
50
+ end
51
+
52
+ def has_base_named?
53
+ @aces.each do |ace|
54
+ if !ace.default && !ace.name.eql?("")
55
+ return true
56
+ end
57
+ end
58
+ @additional.each do |ace|
59
+ if !ace.default && !ace.name.eql?("")
60
+ return true
61
+ end
62
+ end
63
+ false
64
+ end
65
+
66
+ def has_base_mask?
67
+ @aces.each do |ace|
68
+ if !ace.default && ace.type.eql?("mask")
69
+ return true
70
+ end
71
+ end
72
+ @additional.each do |ace|
73
+ if !ace.default && ace.type.eql?("mask")
74
+ return true
75
+ end
76
+ end
77
+ false
78
+ end
79
+
80
+ def has_default?
81
+ !get_default_ace.nil?
82
+ end
83
+
84
+ def has_default_user?
85
+ @aces.each do |ace|
86
+ if ace.default && ace.type.eql?("user") && ace.name.eql?("")
87
+ return true
88
+ end
89
+ end
90
+ @additional.each do |ace|
91
+ if ace.default && ace.type.eql?("user") && ace.name.eql?("")
92
+ return true
93
+ end
94
+ end
95
+ false
96
+ end
97
+
98
+ def has_default_group?
99
+ !get_default_group_ace.nil?
100
+ end
101
+
102
+ #format [default:][user|group|mask|other]:[name]:(r|-)(w|-)(x|-) (or nil if not present)
103
+ def get_default_group_ace
104
+ @aces.each do |ace|
105
+ if ace.default && ace.type.eql?("group") && ace.name.eql?("")
106
+ return ace.get_ace
107
+ end
108
+ end
109
+ @additional.each do |ace|
110
+ if ace.default && ace.type.eql?("group") && ace.name.eql?("")
111
+ return ace.get_ace
112
+ end
113
+ end
114
+ nil
115
+ end
116
+
117
+ def has_default_other?
118
+ @aces.each do |ace|
119
+ if ace.default && ace.type.eql?("other")
120
+ return true
121
+ end
122
+ end
123
+ @additional.each do |ace|
124
+ if ace.default && ace.type.eql?("other")
125
+ return true
126
+ end
127
+ end
128
+ false
129
+ end
130
+
131
+ def has_default_named?
132
+ @aces.each do |ace|
133
+ if ace.default && !ace.name.eql?("")
134
+ return true
135
+ end
136
+ end
137
+ @additional.each do |ace|
138
+ if ace.default && !ace.name.eql?("")
139
+ return true
140
+ end
141
+ end
142
+ false
143
+ end
144
+
145
+ def has_default_mask?
146
+ @aces.each do |ace|
147
+ if ace.default && ace.type.eql?("mask")
148
+ return true
149
+ end
150
+ end
151
+ @additional.each do |ace|
152
+ if ace.default && ace.type.eql?("mask")
153
+ return true
154
+ end
155
+ end
156
+ false
157
+ end
158
+ end
159
+
160
+ end
161
+ end
162
+ end
163
+ end