This file is indexed.

/usr/share/php/OpenCloud/Image/Resource/Image.php is in php-opencloud 1.10.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
<?php
/**
 * Copyright 2012-2014 Rackspace US, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace OpenCloud\Image\Resource;

use OpenCloud\Image\Enum\OperationType;
use OpenCloud\Image\Resource\JsonPatch\Document as JsonDocument;
use OpenCloud\Image\Resource\JsonPatch\Operation as JsonOperation;
use OpenCloud\Image\Resource\Schema\Schema;

/**
 * Class that represents a Glance Image. In more general terms, a virtual machine image is a single file which contains
 * a virtual disk that has an installed bootable operating system. In the Cloud Images API, an image is represented by
 * a JSON-encoded data structure (the image schema) and its raw binary data (the image file).
 *
 * @package OpenCloud\Images\Resource
 */
class Image extends AbstractSchemaResource implements ImageInterface
{
    protected static $url_resource = 'images';
    protected static $json_name = '';
    protected static $json_collection_name = 'images';

    /**
     * Update this resource
     *
     * @param array  $params
     * @param Schema $schema
     * @return \Guzzle\Http\Message\Response
     * @throws \RuntimeException
     */
    public function update(array $params, Schema $schema = null)
    {
        $schema = $schema ?: $this->getService()->getImageSchema();

        $document = new JsonDocument();

        foreach ($params as $propertyName => $value) {

            // find property object
            if (!($property = $schema->getProperty($propertyName))) {
                // check whether additional properties are found
                if (false === ($property = $schema->validateAdditionalProperty($value))) {
                    throw new \RuntimeException(
                        'If a property does not exist in the schema, the `additionalProperties` property must be set'
                    );
                }
            }

            // do validation checks
            $property->setName($propertyName);
            $property->setValue($value);
            $property->validate();

            // decide operation type
            if (!$value) {
                $operationType = OperationType::REMOVE;
            } elseif ($this->offsetExists($propertyName)) {
                $operationType = OperationType::REPLACE;
            } else {
                $operationType = $schema->decideOperationType($property);
            }

            // create JSON-patch operation
            $operation = JsonOperation::factory($schema, $property, $operationType);

            // add to JSON document
            $document->addOperation($operation);
        }

        // create request
        $body = $document->toString();

        return $this->getClient()
            ->patch($this->getUrl(), $this->getService()->getPatchHeaders(), $body)
            ->send();
    }

    /**
     * Refresh this resource
     *
     * @return \Guzzle\Http\Message\Response
     */
    public function refresh()
    {
        $response = $this->getClient()->get($this->getUrl())->send();

        $this->setData($response->json());

        return $response;
    }

    /**
     * Delete this resource
     *
     * @return \Guzzle\Http\Message\Response
     */
    public function delete()
    {
        return $this->getClient()->delete($this->getUrl())->send();
    }

    /**
     * List the members of this image
     *
     * @param array $params
     * @return mixed
     */
    public function listMembers(array $params = array())
    {
        $url = clone $this->getUrl();
        $url->addPath(Member::resourceName())->setQuery($params);

        return $this->getService()->resourceList('Member', $url, $this);
    }

    /**
     * Iterator use only
     *
     * @param $data
     * @return mixed
     */
    public function member($data)
    {
        $data = (array) $data;

        $member = $this->getService()->resource('Member', null, $this);
        $member->setData($data);

        if (isset($data['member_id'])) {
            $member->setId($data['member_id']);
        }

        return $member;
    }

    /**
     * Get a member belonging to this image
     *
     * @param $memberId
     * @return mixed
     */
    public function getMember($memberId)
    {
        $url = clone $this->getUrl();
        $url->addPath('members');
        $url->addPath((string) $memberId);

        $data = $this->getClient()->get($url)->send()->json();

        return $this->member($data);
    }

    /**
     * Add a member to this image
     *
     * @param $tenantId
     * @return \Guzzle\Http\Message\Response
     */
    public function createMember($tenantId)
    {
        $url = $this->getUrl();
        $url->addPath('members');

        $json = json_encode(array('member' => $tenantId));
        return $this->getClient()->post($url, self::getJsonHeader(), $json)->send();
    }

    /**
     * Delete a member from this image
     *
     * @param $tenantId
     * @return \Guzzle\Http\Message\Response
     */
    public function deleteMember($tenantId)
    {
        $url = $this->getUrl();
        $url->addPath('members');
        $url->addPath((string)$tenantId);

        return $this->getClient()->delete($url)->send();
    }

    /**
     * Add a tag to this image
     *
     * @param string $tag
     * @return \Guzzle\Http\Message\Response
     */
    public function addTag($tag)
    {
        $url = clone $this->getUrl();
        $url->addPath('tags')->addPath((string) $tag);

        return $this->getClient()->put($url)->send();
    }

    /**
     * Delete a tag from this image
     *
     * @param $tag
     * @return \Guzzle\Http\Message\Response
     */
    public function deleteTag($tag)
    {
        $url = clone $this->getUrl();
        $url->addPath('tags')->addPath((string) $tag);

        return $this->getClient()->delete($url)->send();
    }
}