oktadev / okta-aws-cli-assume-role

Okta AWS CLI Assume Role Tool
Apache License 2.0
338 stars 177 forks source link

Provide a Homebrew Formula #123

Open mfulgo opened 6 years ago

mfulgo commented 6 years ago

It would be nice to be able to install this on a Mac using homebrew: Something like

brew tap oktadeveloper/tools
brew install okta-aws-cli

https://docs.brew.sh/Taps

AlainODea commented 6 years ago

That's a good idea and would be a useful contribution. Do you want to pursue that?

Looks like you could start with this okta-aws-cli.rb:

class OktaAwsCli < Formula
  desc "Command-line interface to AWS using Okta"
  homepage "https://github.com/oktadeveloper/okta-aws-cli-assume-role/blob/master/Readme.MD"
  url "https://github.com/oktadeveloper/okta-aws-cli-assume-role/releases/download/v1.0.2/okta-aws-cli-1.0.2.jar"
  sha256 "a28efeafdfa8b638fc635b7ea1031321fad17bfe68928f84aebbdf4ef97ba108"

  def install
    system "./install.sh", prefix
  end
end

There's no distribution build with the scripts like awscli and withokta needed to use this post-install which it would be annoying to use would. That should be added as well.

Here's a modified version of an install script I use to roll out to staff at work:

#!/usr/bin/env bash
#
# Copyright 2018 Okta
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

java -version > /dev/null 2>&1
if [ $? -ne 0 ];
then
    echo 'Warning: Java is not installed. Make sure to install that'
fi
aws --version > /dev/null 2>&1
if [ $? -ne 0 ];
then
    echo 'Warning: AWS CLI is not installed. Make sure to install that'
fi

mkdir -p ${HOME}/.okta
curl 'https://github.com/oktadeveloper/okta-aws-cli-assume-role/releases/download/v1.0.2/okta-aws-cli-1.0.2.jar' --output "${HOME}/.okta/okta-aws-cli.jar"

# bash functions
bash_functions="${HOME}/.okta/bash_functions"
grep '^#OktaAWSCLI' "${bash_functions}" > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo '
function aws {
    withokta "aws --profile $1" $@
}
function sls {
    withokta "sls --stage $1" $@
}
' >> "${bash_functions}"
fi

# Conditionally update fish profile
fishConfig="${HOME}/.config/fish/config.fish"
mkdir -p $(dirname "${fishConfig}")
touch "${fishConfig}"
grep '^#OktaAWSCLI' "${fishConfig}" > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo '
#OktaAWSCLI
export PATH="$HOME/bin:$PATH"
function aws
    withokta "aws --profile $argv[1]" $argv
end
function sls
    withokta "sls --stage $argv[1]" $argv
end
' >> "${fishConfig}"
fi

# Conditionally update bash profile
bashProfile="${HOME}/.bash_profile"
grep '^#OktaAWSCLI' "${bashProfile}" > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "
#OktaAWSCLI
if [ -f \"${bash_functions}\" ]; then
    . \"${bash_functions}\"
fi
" >> "${bashProfile}"
fi

# 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 $@
' > "/usr/local/bin/withokta"
chmod +x "/usr/local/bin/withokta"

# Configure Okta AWS CLI
oktaConfig="${HOME}/.okta/config.properties"
grep '^#OktaAWSCLI' "${oktaConfig}" > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "
#OktaAWSCLI
OKTA_ORG=${OKTA_ORG}
OKTA_AWS_APP_URL=${OKTA_AWS_APP_URL}
OKTA_USERNAME=${OKTA_USERNAME}
OKTA_BROWSER_AUTH=true
" > "${oktaConfig}"
fi
mfulgo commented 6 years ago

Yeah, I'm fine with exploring it. It'll just likely be a few weeks before I can get around to it. This issue was partly feature request and partly a reminder if no one else could implement it quickly. =P

AlainODea commented 6 years ago

@mfulgo any luck?

AlainODea commented 6 years ago

@mfulgo any luck with this?

mfulgo commented 6 years ago

Sorry @AlainODea, I'm likely not going to have time to work on this for a while. If I do, I'll be sure to link it here.

AlainODea commented 6 years ago

@mfulgo no worries and thank you :)

supergibbs commented 1 year ago

It would be nice to be able to install this on a Mac using homebrew: Something like

brew tap oktadeveloper/tools
brew install okta-aws-cli

https://docs.brew.sh/Taps

I propose we rename to brew install okta-aws to not confuse it with okta/okta-aws-cli which will hopefully have brew support in the future