2
2
/*
3
3
* Copyright 2020 Google LLC.
4
4
*
5
- * Licensed under the Apache License, Version 2.0 (the " License" );
5
+ * Licensed under the Apache License, Version 2.0 (the ' License' );
6
6
* you may not use this file except in compliance with the License.
7
7
* You may obtain a copy of the License at
8
8
*
9
9
* http://www.apache.org/licenses/LICENSE-2.0
10
10
*
11
11
* Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an " AS IS" BASIS,
12
+ * distributed under the License is distributed on an ' AS IS' BASIS,
13
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
14
* See the License for the specific language governing permissions and
15
15
* limitations under the License.
@@ -108,133 +108,102 @@ private static function deleteSecret(string $name)
108
108
}
109
109
}
110
110
111
- private static function explodeName (string $ str ): array
112
- {
113
- preg_match ('/^projects\/(.+)(\/secrets\/(.+)(\/versions\/(.+))?)?$/U ' , $ str , $ matches );
114
-
115
- if (count ($ matches ) > 5 ) {
116
- return [$ matches [1 ], $ matches [3 ], $ matches [5 ]];
117
- } elseif (count ($ matches ) > 3 ) {
118
- return [$ matches [1 ], $ matches [3 ]];
119
- } elseif (count ($ matches ) > 1 ) {
120
- return [$ matches [1 ]];
121
- }
122
-
123
- return [];
124
- }
125
-
126
111
public function testAccessSecretVersion ()
127
112
{
128
- list ($ projectId , $ secretId , $ versionId ) = self ::explodeName (
129
- self ::$ testSecretVersion ->getName ()
130
- );
113
+ $ name = self ::$ client ->parseName (self ::$ testSecretVersion ->getName ());
131
114
132
115
$ output = $ this ->runSnippet ('access_secret_version ' , [
133
- $ projectId ,
134
- $ secretId ,
135
- $ versionId ,
116
+ $ name [ ' project ' ] ,
117
+ $ name [ ' secret ' ] ,
118
+ $ name [ ' secret_version ' ] ,
136
119
]);
137
120
138
121
$ this ->assertContains ('my super secret data ' , $ output );
139
122
}
140
123
141
124
public function testAddSecretVersion ()
142
125
{
143
- list ($ projectId , $ secretId ) = self ::explodeName (
144
- self ::$ testSecretWithVersions ->getName ()
145
- );
126
+ $ name = self ::$ client ->parseName (self ::$ testSecretWithVersions ->getName ());
146
127
147
128
$ output = $ this ->runSnippet ('add_secret_version ' , [
148
- $ projectId ,
149
- $ secretId ,
129
+ $ name [ ' project ' ] ,
130
+ $ name [ ' secret ' ] ,
150
131
]);
151
132
152
133
$ this ->assertContains ('Added secret version ' , $ output );
153
134
}
154
135
155
136
public function testCreateSecret ()
156
137
{
157
- list ($ projectId , $ secretId ) = self ::explodeName (
158
- self ::$ testSecretToCreateName
159
- );
138
+ $ name = self ::$ client ->parseName (self ::$ testSecretToCreateName );
160
139
161
140
$ output = $ this ->runSnippet ('create_secret ' , [
162
- $ projectId ,
163
- $ secretId ,
141
+ $ name [ ' project ' ] ,
142
+ $ name [ ' secret ' ] ,
164
143
]);
165
144
166
145
$ this ->assertContains ('Created secret ' , $ output );
167
146
}
168
147
169
148
public function testDeleteSecret ()
170
149
{
171
- list ($ projectId , $ secretId ) = self ::explodeName (
172
- self ::$ testSecretToDelete ->getName ()
173
- );
150
+ $ name = self ::$ client ->parseName (self ::$ testSecretToDelete ->getName ());
174
151
175
152
$ output = $ this ->runSnippet ('delete_secret ' , [
176
- $ projectId ,
177
- $ secretId ,
153
+ $ name [ ' project ' ] ,
154
+ $ name [ ' secret ' ] ,
178
155
]);
179
156
180
157
$ this ->assertContains ('Deleted secret ' , $ output );
181
158
}
182
159
183
160
public function testDestroySecretVersion ()
184
161
{
185
- list ($ projectId , $ secretId , $ versionId ) = self ::explodeName (
186
- self ::$ testSecretVersionToDestroy ->getName ()
187
- );
162
+ $ name = self ::$ client ->parseName (self ::$ testSecretVersionToDestroy ->getName ());
188
163
189
164
$ output = $ this ->runSnippet ('destroy_secret_version ' , [
190
- $ projectId ,
191
- $ secretId ,
192
- $ versionId ,
165
+ $ name [ ' project ' ] ,
166
+ $ name [ ' secret ' ] ,
167
+ $ name [ ' secret_version ' ] ,
193
168
]);
194
169
195
170
$ this ->assertContains ('Destroyed secret version ' , $ output );
196
171
}
197
172
198
173
public function testDisableSecretVersion ()
199
174
{
200
- list ($ projectId , $ secretId , $ versionId ) = self ::explodeName (
201
- self ::$ testSecretVersionToDisable ->getName ()
202
- );
175
+ $ name = self ::$ client ->parseName (self ::$ testSecretVersionToDisable ->getName ());
203
176
204
177
$ output = $ this ->runSnippet ('disable_secret_version ' , [
205
- $ projectId ,
206
- $ secretId ,
207
- $ versionId ,
178
+ $ name [ ' project ' ] ,
179
+ $ name [ ' secret ' ] ,
180
+ $ name [ ' secret_version ' ] ,
208
181
]);
209
182
210
183
$ this ->assertContains ('Disabled secret version ' , $ output );
211
184
}
212
185
213
186
public function testEnableSecretVersion ()
214
187
{
215
- list ($ projectId , $ secretId , $ versionId ) = self ::explodeName (
216
- self ::$ testSecretVersionToEnable ->getName ()
217
- );
188
+ $ name = self ::$ client ->parseName (self ::$ testSecretVersionToEnable ->getName ());
218
189
219
190
$ output = $ this ->runSnippet ('enable_secret_version ' , [
220
- $ projectId ,
221
- $ secretId ,
222
- $ versionId ,
191
+ $ name [ ' project ' ] ,
192
+ $ name [ ' secret ' ] ,
193
+ $ name [ ' secret_version ' ] ,
223
194
]);
224
195
225
196
$ this ->assertContains ('Enabled secret version ' , $ output );
226
197
}
227
198
228
199
public function testGetSecretVersion ()
229
200
{
230
- list ($ projectId , $ secretId , $ versionId ) = self ::explodeName (
231
- self ::$ testSecretVersion ->getName ()
232
- );
201
+ $ name = self ::$ client ->parseName (self ::$ testSecretVersion ->getName ());
233
202
234
203
$ output = $ this ->runSnippet ('get_secret_version ' , [
235
- $ projectId ,
236
- $ secretId ,
237
- $ versionId ,
204
+ $ name [ ' project ' ] ,
205
+ $ name [ ' secret ' ] ,
206
+ $ name [ ' secret_version ' ] ,
238
207
]);
239
208
240
209
$ this ->assertContains ('Got secret version ' , $ output );
@@ -243,13 +212,11 @@ public function testGetSecretVersion()
243
212
244
213
public function testGetSecret ()
245
214
{
246
- list ($ projectId , $ secretId ) = self ::explodeName (
247
- self ::$ testSecret ->getName ()
248
- );
215
+ $ name = self ::$ client ->parseName (self ::$ testSecret ->getName ());
249
216
250
217
$ output = $ this ->runSnippet ('get_secret ' , [
251
- $ projectId ,
252
- $ secretId ,
218
+ $ name [ ' project ' ] ,
219
+ $ name [ ' secret ' ] ,
253
220
]);
254
221
255
222
$ this ->assertContains ('secret ' , $ output );
@@ -258,41 +225,35 @@ public function testGetSecret()
258
225
259
226
public function testListSecretVersions ()
260
227
{
261
- list ($ projectId , $ secretId ) = self ::explodeName (
262
- self ::$ testSecretWithVersions ->getName ()
263
- );
228
+ $ name = self ::$ client ->parseName (self ::$ testSecretWithVersions ->getName ());
264
229
265
230
$ output = $ this ->runSnippet ('list_secret_versions ' , [
266
- $ projectId ,
267
- $ secretId ,
231
+ $ name [ ' project ' ] ,
232
+ $ name [ ' secret ' ] ,
268
233
]);
269
234
270
235
$ this ->assertContains ('secret version ' , $ output );
271
236
}
272
237
273
238
public function testListSecrets ()
274
239
{
275
- list ($ projectId , $ secretId ) = self ::explodeName (
276
- self ::$ testSecret ->getName ()
277
- );
240
+ $ name = self ::$ client ->parseName (self ::$ testSecret ->getName ());
278
241
279
242
$ output = $ this ->runSnippet ('list_secrets ' , [
280
- $ projectId ,
243
+ $ name [ ' project ' ] ,
281
244
]);
282
245
283
246
$ this ->assertContains ('secret ' , $ output );
284
- $ this ->assertContains ($ secretId , $ output );
247
+ $ this ->assertContains ($ name [ ' secret ' ] , $ output );
285
248
}
286
249
287
250
public function testUpdateSecret ()
288
251
{
289
- list ($ projectId , $ secretId ) = self ::explodeName (
290
- self ::$ testSecret ->getName ()
291
- );
252
+ $ name = self ::$ client ->parseName (self ::$ testSecret ->getName ());
292
253
293
254
$ output = $ this ->runSnippet ('update_secret ' , [
294
- $ projectId ,
295
- $ secretId ,
255
+ $ name [ ' project ' ] ,
256
+ $ name [ ' secret ' ] ,
296
257
]);
297
258
298
259
$ this ->assertContains ('Updated secret ' , $ output );
0 commit comments