1
# Copyright (c) 2006-2010 Mitch Garnaat http://garnaat.org/
2
# Copyright (c) 2010, Eucalyptus Systems, Inc.
4
# Permission is hereby granted, free of charge, to any person obtaining a
5
# copy of this software and associated documentation files (the
6
# "Software"), to deal in the Software without restriction, including
7
# without limitation the rights to use, copy, modify, merge, publish, dis-
8
# tribute, sublicense, and/or sell copies of the Software, and to permit
9
# persons to whom the Software is furnished to do so, subject to the fol-
12
# The above copyright notice and this permission notice shall be included
13
# in all copies or substantial portions of the Software.
15
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
18
# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23
from identity import OriginAccessIdentity
25
def get_oai_value(origin_access_identity):
26
if isinstance(origin_access_identity, OriginAccessIdentity):
27
return origin_access_identity.uri()
29
return origin_access_identity
31
class S3Origin(object):
33
Origin information to associate with the distribution.
34
If your distribution will use an Amazon S3 origin,
35
then you use the S3Origin element.
38
def __init__(self, dns_name=None, origin_access_identity=None):
40
:param dns_name: The DNS name of your Amazon S3 bucket to
41
associate with the distribution.
42
For example: mybucket.s3.amazonaws.com.
45
:param origin_access_identity: The CloudFront origin access
46
identity to associate with the
47
distribution. If you want the
48
distribution to serve private content,
49
include this element; if you want the
50
distribution to serve public content,
52
:type origin_access_identity: str
55
self.dns_name = dns_name
56
self.origin_access_identity = origin_access_identity
59
return '<S3Origin: %s>' % self.dns_name
61
def startElement(self, name, attrs, connection):
64
def endElement(self, name, value, connection):
67
elif name == 'OriginAccessIdentity':
68
self.origin_access_identity = value
70
setattr(self, name, value)
74
s += ' <DNSName>%s</DNSName>\n' % self.dns_name
75
if self.origin_access_identity:
76
val = get_oai_value(self.origin_access_identity)
77
s += ' <OriginAccessIdentity>%s</OriginAccessIdentity>\n' % val
81
class CustomOrigin(object):
83
Origin information to associate with the distribution.
84
If your distribution will use a non-Amazon S3 origin,
85
then you use the CustomOrigin element.
88
def __init__(self, dns_name=None, http_port=80, https_port=443,
89
origin_protocol_policy=None):
91
:param dns_name: The DNS name of your Amazon S3 bucket to
92
associate with the distribution.
93
For example: mybucket.s3.amazonaws.com.
96
:param http_port: The HTTP port the custom origin listens on.
99
:param https_port: The HTTPS port the custom origin listens on.
102
:param origin_protocol_policy: The origin protocol policy to
103
apply to your origin. If you
104
specify http-only, CloudFront
105
will use HTTP only to access the origin.
106
If you specify match-viewer, CloudFront
107
will fetch from your origin using HTTP
108
or HTTPS, based on the protocol of the
110
:type origin_protocol_policy: str
113
self.dns_name = dns_name
114
self.http_port = http_port
115
self.https_port = https_port
116
self.origin_protocol_policy = origin_protocol_policy
119
return '<CustomOrigin: %s>' % self.dns_name
121
def startElement(self, name, attrs, connection):
124
def endElement(self, name, value, connection):
125
if name == 'DNSName':
126
self.dns_name = value
127
elif name == 'HTTPPort':
129
self.http_port = int(value)
131
self.http_port = value
132
elif name == 'HTTPSPort':
134
self.https_port = int(value)
136
self.https_port = value
137
elif name == 'OriginProtocolPolicy':
138
self.origin_protocol_policy = value
140
setattr(self, name, value)
143
s = ' <CustomOrigin>\n'
144
s += ' <DNSName>%s</DNSName>\n' % self.dns_name
145
s += ' <HTTPPort>%d</HTTPPort>\n' % self.http_port
146
s += ' <HTTPSPort>%d</HTTPSPort>\n' % self.https_port
147
s += ' <OriginProtocolPolicy>%s</OriginProtocolPolicy>\n' % self.origin_protocol_policy
148
s += ' </CustomOrigin>\n'