Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $application = "https://secret.coyote.com";
- Function Convert-SSToString([System.Security.SecureString]$ObsPass){
- return [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($ObsPass))
- }
- Function Get-Token{
- [CmdletBinding()]
- Param(
- [Switch] $UseTwoFactor
- )
- # Define the user credentials
- $cred = Get-Credential -credential "$env:userdomain\$env:username"
- $creds = @{
- username = $cred.UserName
- password = (Convert-SSToString $cred.Password)
- grant_type = "password"
- };
- $headers = $null
- If ($UseTwoFactor) {
- $headers = @{
- "OTP" = (Read-Host -Prompt "Enter your OTP for 2FA: ")
- }
- }
- try
- {
- $response = Invoke-RestMethod "$application/oauth2/token" -Method Post -Body $creds -Headers $headers;
- $token = $response.access_token;
- return $token;
- }
- catch
- {
- $result = $_.Exception.Response.GetResponseStream();
- $reader = New-Object System.IO.StreamReader($result);
- $reader.BaseStream.Position = 0;
- $reader.DiscardBufferedData();
- $responseBody = $reader.ReadToEnd() | ConvertFrom-Json
- Write-Host "ERROR: $($responseBody.error)"
- return;
- }
- }
- $token = Get-Token -UseTwoFactor
- $api = "https://secret.coyote.com/api/v1"
- $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
- $headers.Add("Authorization", "Bearer $token")
- #pull down live working dependency
- $livestub = Invoke-RestMethod "$api/secret-dependencies/8" -Method get -Headers $headers
- #generalize settings for dependency
- $livestub.id = 0
- $livestub.groupId = 0
- $livestub.secretId = 3288
- $livestub.sortOrder = 0
- $body = $livestub | ConvertTo-Json
- Invoke-RestMethod "$api/secret-dependencies" -Method Post -Body $body -Headers $headers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement