@@ -204,201 +204,6 @@ function Get-GitHubSecretInfo {
204
204
}
205
205
}
206
206
207
- function Set-GitHubSecret {
208
- <#
209
- . SYNOPSIS
210
- Creates or updates a repository secret with a value.
211
-
212
- . DESCRIPTION
213
- Creates or updates a repository secret with a value. The value is encrypted using PSSodium which
214
- is simple wrapper around Sodium.Core.
215
-
216
- . PARAMETER OwnerName
217
- Owner of the repository.
218
- If not supplied here, the DefaultOwnerName configuration property value will be used.
219
-
220
- . PARAMETER RepositoryName
221
- Name of the repository.
222
- If not supplied here, the DefaultRepositoryName configuration property value will be used.
223
-
224
- . PARAMETER Uri
225
- Uri for the repository.
226
- The OwnerName and RepositoryName will be extracted from here instead of needing to provide
227
- them individually.
228
-
229
- . PARAMETER Name
230
- Name of the secret.
231
- If not provided, it will retrieve all secrets in a repository.
232
-
233
- . PARAMETER Value
234
- Value for the secret.
235
- If not provided, it will retrieve all secrets in a repository.
236
-
237
- . PARAMETER AccessToken
238
- If provided, this will be used as the AccessToken for authentication with the
239
- REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
240
-
241
- . PARAMETER NoStatus
242
- If this switch is specified, long-running commands will run on the main thread
243
- with no commandline status update. When not specified, those commands run in
244
- the background, enabling the command prompt to provide status information.
245
- If not supplied here, the DefaultNoStatus configuration property value will be used.
246
-
247
- . EXAMPLE
248
- Set-GitHubSecret -OwnerName Microsoft -RepositoryName PowerShellForGitHub -SecretName MySecret -SecretValue 'my text'
249
-
250
- . EXAMPLE
251
- Set-GitHubSecret -Uri 'https://github.com/Microsoft/PowerShellForGitHub' -SecretName MySecret -SecretValue 'my text'
252
- #>
253
- [CmdletBinding (
254
- SupportsShouldProcess ,
255
- DefaultParameterSetName = ' Elements' )]
256
- [Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSShouldProcess" , " " , Justification= " Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently." )]
257
- param (
258
- [Parameter (ParameterSetName = ' Elements' )]
259
- [string ] $OwnerName ,
260
-
261
- [Parameter (ParameterSetName = ' Elements' )]
262
- [string ] $RepositoryName ,
263
-
264
- [Parameter (Mandatory , ParameterSetName = ' Uri' )]
265
- [string ] $Uri ,
266
-
267
- [Parameter (Mandatory , ParameterSetName = ' Uri' )]
268
- [Parameter (Mandatory , ParameterSetName = ' Elements' )]
269
- [string ] $SecretName ,
270
-
271
- [Parameter (Mandatory , ParameterSetName = ' Uri' )]
272
- [Parameter (Mandatory , ParameterSetName = ' Elements' )]
273
- [SecureString ] $SecretValue ,
274
-
275
- [string ] $AccessToken ,
276
-
277
- [switch ] $NoStatus
278
- )
279
-
280
- Write-InvocationLog
281
-
282
- $elements = Resolve-RepositoryElements
283
- $OwnerName = $elements.ownerName
284
- $RepositoryName = $elements.repositoryName
285
-
286
- $publicKeyInfo = Get-GitHubRepositoryPublicKey - OwnerName $OwnerName - RepositoryName $RepositoryName - NoStatus
287
-
288
- $hashBody = @ {
289
- encrypted_value = ConvertTo-SodiumEncryptedString - Text $SecretValue - PublicKey $publicKeyInfo.key
290
- key_id = $publicKeyInfo.key_id
291
- }
292
-
293
- $telemetryProperties = @ {
294
- ' OwnerName' = (Get-PiiSafeString - PlainText $OwnerName )
295
- ' RepositoryName' = (Get-PiiSafeString - PlainText $RepositoryName )
296
- }
297
-
298
- $description = " Setting secret of $SecretName for $RepositoryName "
299
- $uriFragment = " /repos/$OwnerName /$RepositoryName /actions/secrets/$SecretName "
300
-
301
- $params = @ {
302
- ' UriFragment' = $uriFragment
303
- ' Description' = $description
304
- ' Body' = (ConvertTo-Json - InputObject $hashBody )
305
- ' Method' = ' Put'
306
- ' AcceptHeader' = ' application/vnd.github.symmetra-preview+json'
307
- ' AccessToken' = $AccessToken
308
- ' TelemetryEventName' = $MyInvocation.MyCommand.Name
309
- ' TelemetryProperties' = $telemetryProperties
310
- ' NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue - Name NoStatus - ConfigValueName DefaultNoStatus)
311
- }
312
-
313
- Invoke-GHRestMethod @params
314
- }
315
-
316
- function New-GitHubSecret {
317
- <#
318
- . SYNOPSIS
319
- Creates a repository secret with a value. Throws if the secret already exists.
320
-
321
- . DESCRIPTION
322
- Creates a repository secret with a value. Throws if the secret already exists.
323
- The value is encrypted using PSSodium which is simple wrapper around Sodium.Core.
324
-
325
- . PARAMETER OwnerName
326
- Owner of the repository.
327
- If not supplied here, the DefaultOwnerName configuration property value will be used.
328
-
329
- . PARAMETER RepositoryName
330
- Name of the repository.
331
- If not supplied here, the DefaultRepositoryName configuration property value will be used.
332
-
333
- . PARAMETER Uri
334
- Uri for the repository.
335
- The OwnerName and RepositoryName will be extracted from here instead of needing to provide
336
- them individually.
337
-
338
- . PARAMETER Name
339
- Name of the secret.
340
- If not provided, it will retrieve all secrets in a repository.
341
-
342
- . PARAMETER Value
343
- Value for the secret.
344
- If not provided, it will retrieve all secrets in a repository.
345
-
346
- . PARAMETER AccessToken
347
- If provided, this will be used as the AccessToken for authentication with the
348
- REST Api. Otherwise, will attempt to use the configured value or will run unauthenticated.
349
-
350
- . PARAMETER NoStatus
351
- If this switch is specified, long-running commands will run on the main thread
352
- with no commandline status update. When not specified, those commands run in
353
- the background, enabling the command prompt to provide status information.
354
- If not supplied here, the DefaultNoStatus configuration property value will be used.
355
-
356
- . EXAMPLE
357
- New-GitHubSecret -OwnerName Microsoft -RepositoryName PowerShellForGitHub -SecretName MySecret -SecretValue 'my text'
358
-
359
- . EXAMPLE
360
- New-GitHubSecret -Uri 'https://github.com/Microsoft/PowerShellForGitHub' -SecretName MySecret -SecretValue 'my text'
361
- #>
362
- [CmdletBinding (
363
- SupportsShouldProcess ,
364
- DefaultParameterSetName = ' Elements' )]
365
- [Diagnostics.CodeAnalysis.SuppressMessageAttribute (" PSShouldProcess" , " " , Justification= " Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently." )]
366
- param (
367
- [Parameter (ParameterSetName = ' Elements' )]
368
- [string ] $OwnerName ,
369
-
370
- [Parameter (ParameterSetName = ' Elements' )]
371
- [string ] $RepositoryName ,
372
-
373
- [Parameter (Mandatory , ParameterSetName = ' Uri' )]
374
- [string ] $Uri ,
375
-
376
- [Parameter (Mandatory , ParameterSetName = ' Uri' )]
377
- [Parameter (Mandatory , ParameterSetName = ' Elements' )]
378
- [string ] $SecretName ,
379
-
380
- [Parameter (Mandatory , ParameterSetName = ' Uri' )]
381
- [Parameter (Mandatory , ParameterSetName = ' Elements' )]
382
- [SecureString ] $SecretValue ,
383
-
384
- [string ] $AccessToken ,
385
-
386
- [switch ] $NoStatus
387
- )
388
-
389
- Write-InvocationLog
390
-
391
- $elements = Resolve-RepositoryElements
392
- $OwnerName = $elements.ownerName
393
- $RepositoryName = $elements.repositoryName
394
-
395
- if (Get-GitHubSecretInfo - OwnerName $OwnerName - RepositoryName $RepositoryName - SecretName $SecretName - ErrorAction Ignore) {
396
- throw " Secret already exists."
397
- }
398
-
399
- Set-GitHubSecret @PSBoundParameters
400
- }
401
-
402
207
function Remove-GitHubSecret {
403
208
<#
404
209
. SYNOPSIS
0 commit comments