Skip to content

Commit

Permalink
Implement --version and add Homebrew install to README
Browse files Browse the repository at this point in the history
  • Loading branch information
ksperling committed May 18, 2017
1 parent d8655be commit 9469034
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# aws-session

Manage shell sessions with temporary AWS credentials

[![Build Status](https://travis-ci.org/ksperling/aws-session.svg?branch=master)](https://travis-ci.org/ksperling/aws-session)
[![Code Climate](https://codeclimate.com/github/ksperling/aws-session/badges/gpa.svg)](https://codeclimate.com/github/ksperling/aws-session)

Expand All @@ -11,9 +13,11 @@ In supported shells (`bash`, `zsh`) it also enhances the shell prompt to display

## Installation

Before using `aws-session`, you must have the [AWS CLI](https://aws.amazon.com/cli/) installed (through whatever [method](http://docs.aws.amazon.com/cli/latest/userguide/installing.html) you choose) on your PATH and configured (through `aws configure` or manually).
On OS X, the easiest way to install `aws-session` is via [Homebrew](https://brew.sh/): `brew install ksperling/tap/aws-session`.

`aws-session` itself is a stand-alone shell script, just [download the script](https://raw.githubusercontent.com/ksperling/aws-session/master/aws-session) and place it somewhere on your PATH, e.g. in `/usr/local/bin`.
Otherwise a manual install is straightforward: just [download the script](https://raw.githubusercontent.com/ksperling/aws-session/master/aws-session) and place it somewhere on your PATH, e.g. in `/usr/local/bin`.

Before using `aws-session`, you must have the [AWS CLI](https://aws.amazon.com/cli/) installed (through whatever [method](http://docs.aws.amazon.com/cli/latest/userguide/installing.html) you choose) on your PATH and configured (through `aws configure` or manually).

## Usage

Expand Down
16 changes: 16 additions & 0 deletions aws-session
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
# aws-session: Run a shell environment with AWS MFA credentials
version=HEAD
set -o pipefail

function main() {
Expand All @@ -20,11 +21,13 @@ function main() {
shift 2
;;
--debug) export AWS_SESSION_DEBUG=1; shift;;
--version) version; exit 0;;
--help) echo "$usage
Options:
--profile PROFILE set profile from ~/.aws, see AWS_DEFAULT_PROFILE
--session-duration SECONDS requested session validity (default 12 hours)
--debug enable debug output
--version display version information
--help display this help text
Commands:
Expand All @@ -50,6 +53,19 @@ Environment variables:
esac
}

function version() {
local cli="$(command aws --version 2>&1)"
if [[ "$cli" =~ ^aws-cli/([0-9]+)\.([0-9]+)\. ]]; then
echo "aws-session/${version} ${cli}"
local maj="${BASH_REMATCH[1]}" min="${BASH_REMATCH[2]}"
if [[ "$maj" -lt 1 || "$maj" -eq 1 && "$min" -lt 11 ]]; then
info "Warning: aws-session may not work correctly with aws-cli < 1.11"
fi
else
echo "aws-session/${version} aws-cli/unknown"
fi
}

function session_exec() { # cmd args ...
[[ $# -ge 1 ]] || fail 1 "Usage: ${0##*/} exec COMMAND [ARGS...]"
establish_mfa_session || return $?
Expand Down

0 comments on commit 9469034

Please sign in to comment.