Skip to content

Commit

Permalink
🐛 Repetitive profile name warning
Browse files Browse the repository at this point in the history
 - Configure Java Logging to suppress AWS Java SDK warning

 - Update installers and existing commands to suppress logging

 - Refactor PowerShell install to use PowerShell naming conventions
  • Loading branch information
AlainODea committed Nov 23, 2018
1 parent 9a9ca5c commit 2111fba
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 55 deletions.
6 changes: 6 additions & 0 deletions Readme.MD
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ OKTA_ORG=acmecorp.oktapreview.com
OKTA_AWS_APP_URL=https://acmecorp.oktapreview.com/home/amazon_aws/0oa5zrwfs815KJmVF0h7/137
```

Create `~/.okta/logging.properties` with the following content,

```properties
com.amazonaws.auth.profile.internal.BasicProfileConfigLoader = NONE
```

Copy scripts from `.okta/bin` to somewhere on your PATH.

## Usage
Expand Down
109 changes: 60 additions & 49 deletions bin/Install-OktaAwsCli.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ OKTA_ORG=acmecorp.okta.com.changeme.local
OKTA_AWS_APP_URL=https://acmecorp.oktapreview.com.changeme.local/home/amazon_aws/0oa5zrwfs815KJmVF0h7/137
OKTA_USERNAME=$env:USERNAME
OKTA_BROWSER_AUTH=true
"
Add-Content -Path $Home/.okta/logging.properties -Value "
com.amazonaws.auth.profile.internal.BasicProfileConfigLoader = NONE
"
if (!(Test-Path $profile)) {
New-Item -Path $profile -ItemType File -Force | Out-Null
Expand All @@ -48,68 +51,76 @@ OKTA_BROWSER_AUTH=true
if (!$ProfileContent -or !$ProfileContent.Contains("#OktaAWSCLI")) {
Add-Content -Path $profile -Value '
#OktaAWSCLI
function With-Okta {
Param([string]$Profile)
$OriginalOKTA_PROFILE = $env:OKTA_PROFILE
try {
$env:OKTA_PROFILE = $Profile
$InternetOptions = Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
if ($InternetOptions.ProxyEnable) {
$ProxyStrings = $InternetOptions.ProxyServer.Split(";")
$Proxies = @{}
ForEach ($ProxyString in $ProxyStrings) {
if ($ProxyString.Contains("=")) {
($ProxyProtocol,$ProxyServerPort) = $ProxyString.Split("=")
} else {
($ProxyProtocol,$ProxyServerPort) = ("http", $ProxyString)
}
($ProxyHost, $ProxyPort) = $ProxyServerPort.Split(":")
$Proxies[$ProxyProtocol] = ($ProxyHost, $ProxyPort)
}
if ($Proxies.socks) {
($ProxyHost, $ProxyPort) = $Proxies.socks
} elseif ($Proxies.https) {
($ProxyHost, $ProxyPort) = $Proxies.https
} elseif ($Proxies.http) {
($ProxyHost, $ProxyPort) = $Proxies.http
}
if ($InternetOptions.ProxyOverride) {
$NonProxyHosts = [System.String]::Join("|", ($InternetOptions.ProxyOverride.Replace("<local>", "").Split(";") | Where-Object {$_}))
} else {
$NonProxyHosts = ""
}
if ($ProxyProtocol -eq "socks") {
java "-DsocksProxyHost=$ProxyHost" "-DsocksProxyPort=$ProxyPort" "-Dhttp.nonProxyHosts=$NonProxyHosts" -classpath $HOME\.okta\* com.okta.tools.WithOkta @args
function Invoke-Java {
Param([string]$MainClass)
$InternetOptions = Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
if ($InternetOptions.ProxyEnable) {
$ProxyStrings = $InternetOptions.ProxyServer.Split(";")
$Proxies = @{}
ForEach ($ProxyString in $ProxyStrings) {
if ($ProxyString.Contains("=")) {
($ProxyProtocol,$ProxyServerPort) = $ProxyString.Split("=")
} else {
java "-Dhttp.proxyHost=$ProxyHost" "-Dhttp.proxyPort=$ProxyPort" "-Dhttps.proxyHost=$ProxyHost" "-Dhttps.proxyPort=$ProxyPort" "-Dhttp.nonProxyHosts=$NonProxyHosts" -classpath $HOME\.okta\* com.okta.tools.WithOkta @args
($ProxyProtocol,$ProxyServerPort) = ("http", $ProxyString)
}
($ProxyHost, $ProxyPort) = $ProxyServerPort.Split(":")
$Proxies[$ProxyProtocol] = ($ProxyHost, $ProxyPort)
}
if ($Proxies.socks) {
($ProxyHost, $ProxyPort) = $Proxies.socks
$ProxyProtocol = "socks"
} elseif ($Proxies.https) {
($ProxyHost, $ProxyPort) = $Proxies.https
$ProxyProtocol = "https"
} elseif ($Proxies.http) {
($ProxyHost, $ProxyPort) = $Proxies.http
$ProxyProtocol = "http"
}
if ($InternetOptions.ProxyOverride) {
$NonProxyHosts = [System.String]::Join("|", ($InternetOptions.ProxyOverride.Replace("<local>", "").Split(";") | Where-Object {$_}))
} else {
java -classpath $HOME\.okta\* com.okta.tools.WithOkta @args
$NonProxyHosts = ""
}
if ($ProxyProtocol -eq "socks") {
java "-Djava.util.logging.config.file=$HOME\.okta\logging.properties" "-DsocksProxyHost=$ProxyHost" "-DsocksProxyPort=$ProxyPort" "-Dhttp.nonProxyHosts=$NonProxyHosts" -classpath $HOME\.okta\okta-aws-cli.jar $MainClass @args
} else {
java "-Djava.util.logging.config.file=$HOME\.okta\logging.properties" "-Dhttp.proxyHost=$ProxyHost" "-Dhttp.proxyPort=$ProxyPort" "-Dhttps.proxyHost=$ProxyHost" "-Dhttps.proxyPort=$ProxyPort" "-Dhttp.nonProxyHosts=$NonProxyHosts" -classpath $HOME\.okta\okta-aws-cli.jar $MainClass @args
}
} else {
java "-Djava.util.logging.config.file=$HOME\.okta\logging.properties" -classpath $HOME\.okta\okta-aws-cli.jar $MainClass @args
}
}
function Invoke-Okta {
Param([string]$Profile)
$args[0] = (Get-Command $args[0]).Name
$OriginalOKTA_PROFILE = $env:OKTA_PROFILE
try {
$env:OKTA_PROFILE = $Profile
Invoke-Java -MainClass com.okta.tools.WithOkta @args
} finally {
$env:OKTA_PROFILE = $OriginalOKTA_PROFILE
}
}
function Okta-ListRoles {
$InternetOptions = Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
if ($InternetOptions.ProxyServer) {
($ProxyHost, $ProxyPort) = $InternetOptions.ProxyServer.Split(":")
}
if ($InternetOptions.ProxyOverride) {
$NonProxyHosts = [System.String]::Join("|", ($InternetOptions.ProxyOverride.Replace("<local>", "").Split(";") | Where-Object {$_}))
} else {
$NonProxyHosts = ""
}
java "-Dhttp.proxyHost=$ProxyHost" "-Dhttp.proxyPort=$ProxyPort" "-Dhttps.proxyHost=$ProxyHost" "-Dhttps.proxyPort=$ProxyPort" "-Dhttp.nonProxyHosts=$NonProxyHosts" -classpath $HOME\.okta\* com.okta.tools.ListRoles
New-Alias -Name withokta -value Get-OktaRoles
New-Alias -Name with-okta -value Invoke-Okta
function Get-OktaRoles {
Invoke-Java -MainClass com.okta.tools.ListRoles
}
function okta-aws {
New-Alias -Name okta-listroles -value Get-OktaRoles
function Invoke-OktaAws {
Param([string]$Profile)
With-Okta -Profile $Profile ((Get-Command aws).Name) --profile $Profile @args
Invoke-Okta -Profile $Profile aws --profile $Profile @args
}
function okta-sls {
New-Alias -Name okta-aws -value Invoke-OktaAws
function Invoke-OktaSls {
Param([string]$Profile)
With-Okta -Profile $Profile sls --stage $Profile @args
Invoke-Okta -Profile $Profile sls --stage $Profile @args
}
New-Alias -Name okta-sls -value Invoke-OktaSls
'
}
}
Expand Down
2 changes: 1 addition & 1 deletion bin/awscli
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
java -classpath ~/.okta/*.jar com.okta.tools.awscli $@
java -Djava.util.logging.config.file=~/.okta/logging.properties -classpath ~/.okta/*.jar com.okta.tools.awscli $@
2 changes: 1 addition & 1 deletion bin/awscli.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.
rem
java -classpath "%USERPROFILE%\.okta\*" com.okta.tools.awscli %*
java -Djava.util.logging.config.file="%USERPROFILE%\.okta\logging.properties" -classpath "%USERPROFILE%\.okta\*" com.okta.tools.awscli %*
10 changes: 9 additions & 1 deletion bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,21 @@ fi
" >> "${bashProfile}"
fi

# Suppress "Your profile name includes a 'profile ' prefix" warnings from AWS Java SDK (Resolves #233)
loggingProperties="${HOME}/.okta/logging.properties"
echo "com.amazonaws.auth.profile.internal.BasicProfileConfigLoader = NONE
" > "${loggingProperties}"

# Create withokta command
echo '#!/bin/bash
command="$1"
profile=$2
shift;
shift;
env OKTA_PROFILE=$profile java -classpath ~/.okta/okta-aws-cli.jar com.okta.tools.WithOkta $command $@
env OKTA_PROFILE=$profile java \
-Djava.util.logging.config.file=~/.okta/logging.properties \
-classpath ~/.okta/okta-aws-cli.jar \
com.okta.tools.WithOkta $command $@
' > "$PREFIX/bin/withokta"
chmod +x "$PREFIX/bin/withokta"

Expand Down
2 changes: 1 addition & 1 deletion bin/okta-listroles
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
java -classpath ~/.okta/okta-aws-cli.jar com.okta.tools.ListRoles
java -Djava.util.logging.config.file=~/.okta/logging.properties -classpath ~/.okta/okta-aws-cli.jar com.okta.tools.ListRoles
2 changes: 1 addition & 1 deletion bin/withokta
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
java -classpath ~/.okta/*.jar com.okta.tools.WithOkta $@
java -Djava.util.logging.config.file=~/.okta/logging.properties -classpath ~/.okta/*.jar com.okta.tools.WithOkta $@
2 changes: 1 addition & 1 deletion bin/withokta.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.
rem
java -classpath "%USERPROFILE%\.okta\*" com.okta.tools.WithOkta %*
java -Djava.util.logging.config.file="%USERPROFILE%\.okta\logging.properties" -classpath "%USERPROFILE%\.okta\*" com.okta.tools.WithOkta %*

0 comments on commit 2111fba

Please sign in to comment.