This file is indexed.

/usr/lib/python2.7/dist-packages/boto/gs/lifecycle.py is in python-boto 2.34.0-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# Copyright 2013 Google 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, dis-
# tribute, sublicense, and/or sell copies of the Software, and to permit
# persons to whom the Software is furnished to do so, subject to the fol-
# lowing 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 MERCHANTABIL-
# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
# SHALL THE AUTHOR 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.

from boto.exception import InvalidLifecycleConfigError

# Relevant tags for the lifecycle configuration XML document.
LIFECYCLE_CONFIG   = 'LifecycleConfiguration'
RULE               = 'Rule'
ACTION             = 'Action'
DELETE             = 'Delete'
CONDITION          = 'Condition'
AGE                = 'Age'
CREATED_BEFORE     = 'CreatedBefore'
NUM_NEWER_VERSIONS = 'NumberOfNewerVersions'
IS_LIVE            = 'IsLive'

# List of all action elements.
LEGAL_ACTIONS = [DELETE]
# List of all action parameter elements.
LEGAL_ACTION_PARAMS = []
# List of all condition elements.
LEGAL_CONDITIONS = [AGE, CREATED_BEFORE, NUM_NEWER_VERSIONS, IS_LIVE]
# Dictionary mapping actions to supported action parameters for each action.
LEGAL_ACTION_ACTION_PARAMS = {
    DELETE: [],
}

class Rule(object):
    """
    A lifecycle rule for a bucket.

    :ivar action: Action to be taken.

    :ivar action_params: A dictionary of action specific parameters. Each item
    in the dictionary represents the name and value of an action parameter.

    :ivar conditions: A dictionary of conditions that specify when the action
    should be taken. Each item in the dictionary represents the name and value
    of a condition.
    """

    def __init__(self, action=None, action_params=None, conditions=None):
        self.action = action
        self.action_params = action_params or {}
        self.conditions = conditions or {}

        # Name of the current enclosing tag (used to validate the schema).
        self.current_tag = RULE

    def validateStartTag(self, tag, parent):
        """Verify parent of the start tag."""
        if self.current_tag != parent:
            raise InvalidLifecycleConfigError(
                'Invalid tag %s found inside %s tag' % (tag, self.current_tag))

    def validateEndTag(self, tag):
        """Verify end tag against the start tag."""
        if tag != self.current_tag:
            raise InvalidLifecycleConfigError(
                'Mismatched start and end tags (%s/%s)' %
                (self.current_tag, tag))

    def startElement(self, name, attrs, connection):
        if name == ACTION:
            self.validateStartTag(name, RULE)
        elif name in LEGAL_ACTIONS:
            self.validateStartTag(name, ACTION)
            # Verify there is only one action tag in the rule.
            if self.action is not None:
                raise InvalidLifecycleConfigError(
                    'Only one action tag is allowed in each rule')
            self.action = name
        elif name in LEGAL_ACTION_PARAMS:
            # Make sure this tag is found in an action tag.
            if self.current_tag not in LEGAL_ACTIONS:
                raise InvalidLifecycleConfigError(
                    'Tag %s found outside of action' % name)
            # Make sure this tag is allowed for the current action tag.
            if name not in LEGAL_ACTION_ACTION_PARAMS[self.action]:
                raise InvalidLifecycleConfigError(
                    'Tag %s not allowed in action %s' % (name, self.action))
        elif name == CONDITION:
            self.validateStartTag(name, RULE)
        elif name in LEGAL_CONDITIONS:
            self.validateStartTag(name, CONDITION)
            # Verify there is no duplicate conditions.
            if name in self.conditions:
                raise InvalidLifecycleConfigError(
                    'Found duplicate conditions %s' % name)
        else:
            raise InvalidLifecycleConfigError('Unsupported tag ' + name)
        self.current_tag = name

    def endElement(self, name, value, connection):
        self.validateEndTag(name)
        if name == RULE:
            # We have to validate the rule after it is fully populated because
            # the action and condition elements could be in any order.
            self.validate()
        elif name == ACTION:
            self.current_tag = RULE
        elif name in LEGAL_ACTIONS:
            self.current_tag = ACTION
        elif name in LEGAL_ACTION_PARAMS:
            self.current_tag = self.action
            # Add the action parameter name and value to the dictionary.
            self.action_params[name] = value.strip()
        elif name == CONDITION:
            self.current_tag = RULE
        elif name in LEGAL_CONDITIONS:
            self.current_tag = CONDITION
            # Add the condition name and value to the dictionary.
            self.conditions[name] = value.strip()
        else:
            raise InvalidLifecycleConfigError('Unsupported end tag ' + name)

    def validate(self):
        """Validate the rule."""
        if not self.action:
            raise InvalidLifecycleConfigError(
                'No action was specified in the rule')
        if not self.conditions:
            raise InvalidLifecycleConfigError(
                'No condition was specified for action %s' % self.action)

    def to_xml(self):
        """Convert the rule into XML string representation."""
        s = '<' + RULE + '>'
        s += '<' + ACTION + '>'
        if self.action_params:
            s += '<' + self.action + '>'
            for param in LEGAL_ACTION_PARAMS:
                if param in self.action_params:
                    s += ('<' + param + '>' + self.action_params[param] + '</'
                          + param + '>')
            s += '</' + self.action + '>'
        else:
            s += '<' + self.action + '/>'
        s += '</' + ACTION + '>'
        s += '<' + CONDITION + '>'
        for condition in LEGAL_CONDITIONS:
            if condition in self.conditions:
                s += ('<' + condition + '>' + self.conditions[condition] + '</'
                      + condition + '>')
        s += '</' + CONDITION + '>'
        s += '</' + RULE + '>'
        return s

class LifecycleConfig(list):
    """
    A container of rules associated with a lifecycle configuration.
    """

    def __init__(self):
        # Track if root tag has been seen.
        self.has_root_tag = False

    def startElement(self, name, attrs, connection):
        if name == LIFECYCLE_CONFIG:
            if self.has_root_tag:
                raise InvalidLifecycleConfigError(
                    'Only one root tag is allowed in the XML')
            self.has_root_tag = True
        elif name == RULE:
            if not self.has_root_tag:
                raise InvalidLifecycleConfigError('Invalid root tag ' + name)
            rule = Rule()
            self.append(rule)
            return rule
        else:
            raise InvalidLifecycleConfigError('Unsupported tag ' + name)

    def endElement(self, name, value, connection):
        if name == LIFECYCLE_CONFIG:
            pass
        else:
            raise InvalidLifecycleConfigError('Unsupported end tag ' + name)

    def to_xml(self):
        """Convert LifecycleConfig object into XML string representation."""
        s = '<?xml version="1.0" encoding="UTF-8"?>'
        s += '<' + LIFECYCLE_CONFIG + '>'
        for rule in self:
            s += rule.to_xml()
        s += '</' + LIFECYCLE_CONFIG + '>'
        return s

    def add_rule(self, action, action_params, conditions):
        """
        Add a rule to this Lifecycle configuration.  This only adds the rule to
        the local copy.  To install the new rule(s) on the bucket, you need to
        pass this Lifecycle config object to the configure_lifecycle method of
        the Bucket object.

        :type action: str
        :param action: Action to be taken.

        :type action_params: dict
        :param action_params: A dictionary of action specific parameters. Each
        item in the dictionary represents the name and value of an action
        parameter.

        :type conditions: dict
        :param conditions: A dictionary of conditions that specify when the
        action should be taken. Each item in the dictionary represents the name
        and value of a condition.
        """
        rule = Rule(action, action_params, conditions)
        self.append(rule)