Class: Cloudfront::Helpers::TrustedSigners

Inherits:
Object
  • Object
show all
Includes:
Utils::ConfigurationChecker, Utils::XmlSerializer
Defined in:
lib/cloudfront/helpers/trusted_signers.rb

Instance Attribute Summary collapse

Attributes included from Utils::ConfigurationChecker

#error_messages

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::XmlSerializer

#to_xml

Methods included from Utils::ConfigurationChecker

#check_configuration, #valid?

Constructor Details

#initialize(&block) ⇒ TrustedSigners

Returns a new instance of TrustedSigners.



12
13
14
15
16
17
18
19
# File 'lib/cloudfront/helpers/trusted_signers.rb', line 12

def initialize(&block)
  #set default values
  @enabled = false
  @trusted_signers = []

  #set values from block
  instance_eval &block if block_given?
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



9
10
11
# File 'lib/cloudfront/helpers/trusted_signers.rb', line 9

def enabled
  @enabled
end

#trusted_signersObject

Returns the value of attribute trusted_signers.



9
10
11
# File 'lib/cloudfront/helpers/trusted_signers.rb', line 9

def trusted_signers
  @trusted_signers
end

Class Method Details

.from_hash(hash) ⇒ Object

A factory method that creates a TrustedSigners instance from a hash Input example hash = {

"TrustedSigners" => {
    "Enabled" => "true | false",
    "Quantity" => "number of trusted signers",
    "Items" => {
        "AwsAccountNumber" => "self | AWS account that can create signed URLs"
    }
}

}



38
39
40
41
42
43
44
45
46
# File 'lib/cloudfront/helpers/trusted_signers.rb', line 38

def self.from_hash(hash)
  hash = hash["TrustedSigners"] || hash
  self.new do
    self.enabled = hash["Enabled"].nil? ? nil : hash["Enabled"].to_bool
    if (hash["Quantity"]|| "0").to_i > 0
      self.trusted_signers = Array.wrap((hash["Items"]|| {})["AwsAccountNumber"])
    end
  end
end

Instance Method Details

#build_xml(xml) ⇒ Object

Output example

<TrustedSigners>
  <Enabled>true</Enabled>
  <Quantity>number of trusted signers</Quantity>
  <Items>
    <AwsAccountNumber>self</AwsAccountNumber>
  </Items>
</TrustedSigners>


56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cloudfront/helpers/trusted_signers.rb', line 56

def build_xml(xml)
  check_configuration
  xml.TrustedSigners {
    xml.Enabled (@enabled || @trusted_signers.any?)
    xml.Quantity @trusted_signers.size
    if @trusted_signers.any?
      xml.Items {
        for signer in @trusted_signers
          xml.AwsAccountNumber signer
        end
      }
    end
  }
end

#validateObject



21
22
23
24
# File 'lib/cloudfront/helpers/trusted_signers.rb', line 21

def validate
  @trusted_signers = Array.wrap @trusted_signers
  @trusted_signers.push "self" unless @trusted_signers.include? "self"
end