forked from oracle/oci-powershell-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthenticationTypes.ps1
More file actions
53 lines (44 loc) · 2.1 KB
/
Copy pathAuthenticationTypes.ps1
File metadata and controls
53 lines (44 loc) · 2.1 KB
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
<#
This example demonstrates different authentication types supported by OCI PS Modules.
This example requires:
1) Module OCI.PSModules.Audit. Install the module from Powershell Gallery.
2) Setting up the environment variable CompartmentId to a Compartment OCID.
#>
$UserErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = "Stop"
if ([string]::IsNullOrEmpty($env:CompartmentId)) {
Throw 'Configure $env:CompartmentId in the PS Session'
}
try {
#Import the module
Import-Module OCI.PSModules.Audit
#Read CompartmentId environment variable
$CompartmentId = $env:CompartmentId
#Use ApiKey configured in config file
Write-Host "Get-OCIAuditConfiguration -CompartmentId $CompartmentId -AuthType ApiKey"
Get-OCIAuditConfiguration -CompartmentId $CompartmentId -AuthType ApiKey| Out-Host
#Use InstancePrincipal authentication
Write-Host "Get-OCIAuditConfiguration -CompartmentId $CompartmentId -AuthType InstancePrincipal"
#Uncomment if needed. Succeeds when invoked on an oci instance.
#Get-OCIAuditConfiguration -CompartmentId $CompartmentId -AuthType InstancePrincipal | Out-Host
#Backup users debug preference
$Preference = $DebugPreference
$DebugPreference = "Continue"
Write-Host "Default authentication:"
Get-OCIAuditConfiguration -CompartmentId $CompartmentId | Out-Host
Write-Host "Setting ApiKey authentication as session preference."
Write-Host "Set-OCIClientSession -AuthType ApiKey"
Set-OCIClientSession -AuthType ApiKey | Out-Host
Get-OCIAuditConfiguration -CompartmentId $CompartmentId | Out-Host
Write-Host "Setting InstancePrincipal authentication as a session preference."
Write-Host "Set-OCIClientSession -AuthType InstancePrincipal"
#Uncomment if needed. Succeeds when invoked on an oci instance.
#Set-OCIClientSession -AuthType InstancePrincipal | Out-Host
#Get-OCIAuditConfiguration -CompartmentId $CompartmentId | Out-Host
#Restore debug preference
$DebugPreference = $Preference
}
finally {
$ErrorActionPreference = $UserErrorActionPreference
Clear-OCIClientSession -AuthType
}