Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Service.php « ObjectStore « OpenCloud « lib « php-opencloud « 3rdparty « files_external « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 571b33378ace1a025f8cf7e66dc1ce0d780676ad (plain)
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
<?php
/**
 * PHP OpenCloud library.
 * 
 * @copyright Copyright 2013 Rackspace US, Inc. See COPYING for licensing information.
 * @license   https://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
 * @version   1.6.0
 * @author    Glen Campbell <glen.campbell@rackspace.com>
 * @author    Jamie Hannaford <jamie.hannaford@rackspace.com>
 */

namespace OpenCloud\ObjectStore;

use OpenCloud\OpenStack;
use OpenCloud\Common\Exceptions;
use OpenCloud\Common\Lang;

/**
 * The ObjectStore (Cloud Files) service.
 */
class Service extends AbstractService 
{
    
    /**
     * This holds the associated CDN service (for Rackspace public cloud)
     * or is NULL otherwise. The existence of an object here is
     * indicative that the CDN service is available.
     */
    private $cdn;

    /**
     * Creates a new ObjectStore service object.
     *
     * @param OpenCloud\OpenStack $connection    The connection object
     * @param string              $serviceName   The name of the service
     * @param string              $serviceRegion The service's region
     * @param string              $urlType       The type of URL (normally 'publicURL')
     */
    public function __construct(
        OpenStack $connection,
        $serviceName = RAXSDK_OBJSTORE_NAME,
        $serviceRegion = RAXSDK_OBJSTORE_REGION,
        $urltype = RAXSDK_OBJSTORE_URLTYPE
    ) {
        $this->getLogger()->info('Initializing Container Service...');

        parent::__construct(
            $connection,
            'object-store',
            $serviceName,
            $serviceRegion,
            $urltype
        );

        // establish the CDN container, if available
        try {
            $this->cdn = new CDNService(
                $connection,
                $serviceName . 'CDN',
                $serviceRegion,
                $urltype
            );
        } catch (Exceptions\EndpointError $e) {
             // If we have an endpoint error, then the CDN functionality is not 
             // available. In this case, we silently ignore  it.
        }
    }

    /** 
     * Sets the shared secret value for the TEMP_URL
     *
     * @param string $secret the shared secret
     * @return HttpResponse
     */
    public function setTempUrlSecret($secret) 
    {
        $response = $this->request(
            $this->url(), 
            'POST',
            array('X-Account-Meta-Temp-Url-Key' => $secret)
        );
        
        // @codeCoverageIgnoreStart
        if ($response->httpStatus() > 204) {
            throw new Exceptions\HttpError(sprintf(
                Lang::translate('Error in request, status [%d] for URL [%s] [%s]'),
                $response->httpStatus(),
                $this->url(),
                $response->httpBody()
            ));
        }
        // @codeCoverageIgnoreEnd

        return $response;
    }

    /**
     * Get the CDN service.
     * 
     * @return null|CDNService
     */
    public function getCDNService() 
    {
        return $this->cdn;
    }
    
    /**
     * Backwards compability.
     */
    public function CDN()
    {
        return $this->getCDNService();
    }
    
}