Skip to content

Commit

Permalink
refs #6568, RightAws::AcfDistribution: Streaming Distributions support
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin committed Apr 19, 2010
1 parent 457c842 commit 23b6772
Show file tree
Hide file tree
Showing 5 changed files with 278 additions and 22 deletions.
1 change: 1 addition & 0 deletions Manifest.txt
Expand Up @@ -27,6 +27,7 @@ lib/sqs/right_sqs_gen2.rb
lib/sqs/right_sqs_gen2_interface.rb
lib/sqs/right_sqs_interface.rb
lib/acf/right_acf_interface.rb
lib/acf/right_acf_streaming_interface.rb
lib/acf/right_acf_origin_access_identities.rb
lib/rds/right_rds_interface.rb
test/ec2/test_helper.rb
Expand Down
39 changes: 17 additions & 22 deletions lib/acf/right_acf_interface.rb
Expand Up @@ -20,7 +20,6 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

module RightAws

# = RightAws::AcfInterface -- RightScale Amazon's CloudFront interface
Expand Down Expand Up @@ -175,7 +174,7 @@ def merge_headers(hash) # :nodoc:
hash
end

def config_to_xml(config) # :nodoc:
def distribution_config_to_xml(config, xml_wrapper='DistributionConfig') # :nodoc:
cnames = ''
logging = ''
origin_access_identity = ''
Expand Down Expand Up @@ -214,7 +213,7 @@ def config_to_xml(config) # :nodoc:

# XML
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<DistributionConfig xmlns=\"http://#{@params[:server]}/doc/#{API_VERSION}/\">\n" +
"<#{xml_wrapper} xmlns=\"http://#{@params[:server]}/doc/#{API_VERSION}/\">\n" +
" <Origin>#{config[:origin]}</Origin>\n" +
" <CallerReference>#{config[:caller_reference]}</CallerReference>\n" +
" <Comment>#{AcfInterface::escape(config[:comment].to_s)}</Comment>\n" +
Expand All @@ -223,7 +222,7 @@ def config_to_xml(config) # :nodoc:
logging +
origin_access_identity +
trusted_signers +
"</DistributionConfig>"
"</#{xml_wrapper}>"
end

#-----------------------------------------------------------------
Expand Down Expand Up @@ -260,13 +259,11 @@ def list_distributions
# {:distributions=>
# [{:status=>"Deployed",
# :aws_id=>"E2Q0AOOMFNPSYL",
# :logging=>{},
# :origin=>"my-bucket.s3.amazonaws.com",
# :domain_name=>"d1s5gmdtmafnre.6hops.net",
# :comment=>"ONE LINE OF COMMENT",
# :last_modified_time=>Wed Oct 22 19:31:23 UTC 2008,
# :enabled=>true,
# :cnames=>[]}],
# :enabled=>true}],
# :is_truncated=>true,
# :max_items=>1,
# :marker=>"",
Expand Down Expand Up @@ -298,7 +295,7 @@ def incrementally_list_distributions(params={}, &block)
# Create a new distribution.
# Returns the just created distribution or RightAws::AwsError exception.
#
# acf.create_distribution('my-bucket.s3.amazonaws.com', 'Woo-Hoo!', true, ['web1.my-awesome-site.net'],
# acf.create_distribution('my-bucket.s3.amazonaws.com', 'Woo-Hoo!', true, ['web1.my-awesome-site.net'], nil,
# { :prefix=>"log/", :bucket=>"my-logs.s3.amazonaws.com" } ) #=>
# {:comment => "Woo-Hoo!",
# :enabled => true,
Expand All @@ -325,7 +322,7 @@ def create_distribution(origin, comment='', enabled=true, cnames=[], caller_refe

def create_distribution_by_config(config)
config[:caller_reference] ||= generate_call_reference
link = generate_request('POST', 'distribution', {}, config_to_xml(config))
link = generate_request('POST', 'distribution', {}, distribution_config_to_xml(config))
merge_headers(request_info(link, AcfDistributionListParser.new(:logger => @logger))[:distributions].first)
end

Expand Down Expand Up @@ -381,7 +378,6 @@ def get_distribution(aws_id)
#
# acf.get_distribution_config('E2FNSBHNVVF11E') #=>
# {:e_tag=>"E1Q2DJEPTQOLJD",
# :cnames=>[],
# :logging=>{:prefix=>"xlog/", :bucket=>"my-bucket.s3.amazonaws.com"},
# :enabled=>true,
# :caller_reference=>"201004171154450740700072",
Expand Down Expand Up @@ -417,7 +413,7 @@ def get_distribution_config(aws_id)
# acf.set_distribution_config('E2REJM3VUN5RSI', config) #=> true
#
def set_distribution_config(aws_id, config)
link = generate_request('PUT', "distribution/#{aws_id}/config", {}, config_to_xml(config),
link = generate_request('PUT', "distribution/#{aws_id}/config", {}, distribution_config_to_xml(config),
'If-Match' => config[:e_tag])
request_info(link, RightHttp2xxParser.new(:logger => @logger))
end
Expand Down Expand Up @@ -445,11 +441,10 @@ def tagstart(name, attributes)
case full_tag_name
when %r{/Signer$}
@active_signer = {}
when %r{DistributionSummary$},
%r{^Distribution$},
%r{^DistributionConfig$}
@distribution = { :cnames => [],
:logging => {} }
when %r{(Streaming)?DistributionSummary$},
%r{^(Streaming)?Distribution$},
%r{^(Streaming)?DistributionConfig$}
@distribution = { }
end
end
def tagend(name)
Expand All @@ -465,10 +460,10 @@ def tagend(name)
when 'Origin' then @distribution[:origin] = @text
when 'Comment' then @distribution[:comment] = AcfInterface::unescape(@text)
when 'CallerReference' then @distribution[:caller_reference] = @text
when 'CNAME' then @distribution[:cnames] << @text
when 'CNAME' then (@distribution[:cnames] ||= []) << @text
when 'Enabled' then @distribution[:enabled] = (@text == 'true')
when 'Bucket' then @distribution[:logging][:bucket] = @text
when 'Prefix' then @distribution[:logging][:prefix] = @text
when 'Bucket' then (@distribution[:logging] ||= {})[:bucket] = @text
when 'Prefix' then (@distribution[:logging] ||= {})[:prefix] = @text
when 'OriginAccessIdentity' then @distribution[:origin_access_identity] = @text
end
case full_tag_name
Expand All @@ -478,9 +473,9 @@ def tagend(name)
when %r{/Signer/AwsAccountNumber$} then @active_signer[:aws_account_number] = @text
when %r{/Signer/KeyPairId$} then (@active_signer[:key_pair_ids] ||= []) << @text
when %r{/Signer$} then (@distribution[:active_trusted_signers] ||= []) << @active_signer
when %r{DistributionSummary$},
%r{^Distribution$},
%r{^DistributionConfig$}
when %r{(Streaming)?DistributionSummary$},
%r{^(Streaming)?Distribution$},
%r{^(Streaming)?DistributionConfig$}
@result[:distributions] << @distribution
end
end
Expand Down
23 changes: 23 additions & 0 deletions lib/acf/right_acf_origin_access_identities.rb
@@ -1,4 +1,27 @@
#
# Copyright (c) 2010 RightScale Inc
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
module RightAws

class AcfInterface

# List Origin Access Identities.
Expand Down

0 comments on commit 23b6772

Please sign in to comment.