Class: InstanceAgent::CodeDeployPlugin::ApplicationSpecification::AceInfo
- Inherits:
-
Object
- Object
- InstanceAgent::CodeDeployPlugin::ApplicationSpecification::AceInfo
- Defined in:
- lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb
Overview
Helper Class for storing an ace
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#execute ⇒ Object
readonly
Returns the value of attribute execute.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#read ⇒ Object
readonly
Returns the value of attribute read.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#write ⇒ Object
readonly
Returns the value of attribute write.
Instance Method Summary collapse
-
#get_ace ⇒ Object
format [default:]:[name]:(r|-)(w|-)(x|-).
-
#initialize(ace, internal = false) ⇒ AceInfo
constructor
A new instance of AceInfo.
- #to_bits(num, min_size) ⇒ Object
Constructor Details
#initialize(ace, internal = false) ⇒ AceInfo
Returns a new instance of AceInfo.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb', line 10 def initialize(ace, internal=false) @default = false @type = nil @name = "" parts = ace.split(":", -1).reverse if (parts.length < 2) || (parts.length > 4) raise AppSpecValidationException, "invalid acl entry #{ace}" end if (parts.length == 4) if !(parts[3].eql?("d") || (parts[3].eql?("default"))) raise AppSpecValidationException, "invalid acl entry #{ace}" end @default = true end if parts.length >= 3 if parts[2].eql?("d") || (parts[2].eql?("default")) if @default raise AppSpecValidationException, "invalid acl entry #{ace}" end @default = true elsif parts[2].eql?("m") || parts[2].eql?("mask") @type = "mask" elsif parts[2].eql?("o") || parts[2].eql?("other") @type = "other" elsif parts[2].eql?("g") || parts[2].eql?("group") @type = "group" elsif parts[2].eql?("u") || parts[2].eql?("user") @type = "user" else raise AppSpecValidationException, "invalid acl entry #{ace}" end end if parts[1].eql?("m") || parts[1].eql?("mask") if @type.nil? @type = "mask" else @name = "mask" end elsif parts[1].eql?("o") || parts[1].eql?("other") if @type.nil? @type = "other" else @name = "other" end else if @type.nil? @type = "user" end @name = parts[1] end if (@type.eql?("mask") || @type.eql?("other")) && !@name.empty? raise AppSpecValidationException, "invalid acl entry #{ace}" end if (!internal && !@default && !@type.eql?("mask") && @name.empty?) raise AppSpecValidationException, "use mode to set the base acl entry #{ace}" end perm_chars = parts[0].chars.entries if (perm_chars.length == 1) && (perm_chars[0].ord >= "0".ord) && (perm_chars[0].ord <= "7".ord) perm_bits = to_bits(perm_chars[0].to_i, 3) @read = (perm_bits[0] == 1) @write = (perm_bits[1] == 1) @execute = (perm_bits[2] == 1) else @read = false @write = false @execute = false perm_chars.each do |perm| case perm when 'r' @read = true when 'w' @write = true when 'x' @execute = true when '-' else raise AppSpecValidationException, "unrecognized permission character #{perm} in #{ace}" end end end end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
8 9 10 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb', line 8 def default @default end |
#execute ⇒ Object (readonly)
Returns the value of attribute execute.
8 9 10 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb', line 8 def execute @execute end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb', line 8 def name @name end |
#read ⇒ Object (readonly)
Returns the value of attribute read.
8 9 10 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb', line 8 def read @read end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb', line 8 def type @type end |
#write ⇒ Object (readonly)
Returns the value of attribute write.
8 9 10 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb', line 8 def write @write end |
Instance Method Details
#get_ace ⇒ Object
format [default:]:[name]:(r|-)(w|-)(x|-)
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb', line 98 def get_ace result = ""; if @default result = "default:" end result = result + type + ":" + name + ":" if (@read) result = result + "r" else result = result + "-" end if (@write) result = result + "w" else result = result + "-" end if (@execute) result = result + "x" else result = result + "-" end result end |
#to_bits(num, min_size) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb', line 122 def to_bits(num, min_size) bits = Array.new(min_size, 0) num_bits = num.to_s(2).split("") diff = [0, min_size - num_bits.length].max num_bits.map.with_index {|n,i| bits[i+diff] = n.to_i} bits end |