PluginProbe
Media Cloud Sync / 1.2.10
Media Cloud Sync v1.2.10
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / google / google / cloud-storage / src / HmacKey.php

HmacKey.php in Media Cloud Sync 1.2.10, at includes/sdk/google/google/cloud-storage/src/HmacKey.php

174 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Copyright 2019 Google LLC
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 namespace Dudlewebs\WPMCS\Google\Cloud\Storage;
19
20 use Dudlewebs\WPMCS\Google\Cloud\Storage\Connection\ConnectionInterface;
21 /**
22 * Represents a Service Account HMAC key.
23 *
24 * Example:
25 * ```
26 * use Google\Cloud\Storage\StorageClient;
27 *
28 * $storage = new StorageClient();
29 * $hmacKey = $storage->hmacKey($accessId);
30 * ```
31 */
32 class HmacKey
33 {
34 /**
35 * @var ConnectionInterface
36 * @internal
37 */
38 private $connection;
39 /**
40 * @var string
41 */
42 private $projectId;
43 /**
44 * @var string
45 */
46 private $accessId;
47 /**
48 * @var array|null
49 */
50 private $info;
51 /**
52 * @param ConnectionInterface $connection A connection to Cloud Storage.
53 * This object is created by StorageClient,
54 * and should not be instantiated outside of this client.
55 * @param string $projectId The current project ID.
56 * @param string $accessId The key identifier.
57 * @param array|null $info The key metadata.
58 */
59 public function __construct(ConnectionInterface $connection, $projectId, $accessId, array $info = [])
60 {
61 $this->connection = $connection;
62 $this->projectId = $projectId;
63 $this->accessId = $accessId;
64 $this->info = $info;
65 }
66 /**
67 * Get the HMAC Key Access ID.
68 *
69 * Example:
70 * ```
71 * $accessId = $hmacKey->accessId();
72 * ```
73 *
74 * @return string
75 */
76 public function accessId()
77 {
78 return $this->accessId;
79 }
80 /**
81 * Fetch the key metadata from Cloud Storage.
82 *
83 * Example:
84 * ```
85 * $keyMetadata = $hmacKey->reload();
86 * ```
87 *
88 * @param array $options {
89 * Configuration Options
90 *
91 * @type string $userProject If set, this is the ID of the project which
92 * will be billed for the request. **NOTE**: This option is
93 * currently ignored by Cloud Storage.
94 * }
95 * @return array
96 */
97 public function reload(array $options = [])
98 {
99 $this->info = $this->connection->getHmacKey(['projectId' => $this->projectId, 'accessId' => $this->accessId] + $options);
100 return $this->info;
101 }
102 /**
103 * Get the HMAC Key Metadata.
104 *
105 * If the metadata is not already available, it will be requested from Cloud
106 * Storage.
107 *
108 * Example:
109 * ```
110 * $keyMetadata = $hmacKey->info();
111 * ```
112 *
113 * @param array $options {
114 * Configuration Options
115 *
116 * @type string $userProject If set, this is the ID of the project which
117 * will be billed for the request. **NOTE**: This option is
118 * currently ignored by Cloud Storage.
119 * }
120 * @return array
121 */
122 public function info(array $options = [])
123 {
124 return $this->info ?: $this->reload($options);
125 }
126 /**
127 * Update the HMAC Key state.
128 *
129 * Example:
130 * ```
131 * $hmacKey->update('INACTIVE');
132 * ```
133 *
134 * @param string $state The key state. Either `ACTIVE` or `INACTIVE`.
135 * @param array $options {
136 * Configuration Options
137 *
138 * @type string $userProject If set, this is the ID of the project which
139 * will be billed for the request. **NOTE**: This option is
140 * currently ignored by Cloud Storage.
141 * }
142 * @return array
143 */
144 public function update($state, array $options = [])
145 {
146 $this->info = $this->connection->updateHmacKey(['accessId' => $this->accessId, 'projectId' => $this->projectId, 'state' => $state] + $options);
147 return $this->info;
148 }
149 /**
150 * Delete the HMAC Key.
151 *
152 * Key state must be set to `INACTIVE` prior to deletion. See
153 * {@see HmacKey::update()} for details.
154 *
155 * Example:
156 * ```
157 * $hmacKey->delete();
158 * ```
159 *
160 * @param array $options {
161 * Configuration Options
162 *
163 * @type string $userProject If set, this is the ID of the project which
164 * will be billed for the request. **NOTE**: This option is
165 * currently ignored by Cloud Storage.
166 * }
167 * @return void
168 */
169 public function delete(array $options = [])
170 {
171 $this->connection->deleteHmacKey(['accessId' => $this->accessId, 'projectId' => $this->projectId] + $options);
172 }
173 }
174