Skip to content

Commit

Permalink
Major update awsctx (to Go, completion, Firefox integration etc...)
Browse files Browse the repository at this point in the history
  • Loading branch information
Laica-Lunasys committed Oct 13, 2021
1 parent fc77b5e commit 77e3eb2
Show file tree
Hide file tree
Showing 14 changed files with 2,030 additions and 57 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
jobs:
build:
name: build-binaries
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Golang
uses: actions/setup-go@v2
with:
go-version: "^1.15"
- name: Run Go Releaser
uses: goreleaser/goreleaser-action@v2
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: latest
args: release --rm-dist
228 changes: 228 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,229 @@
aws_profile
# Created by https://www.gitignore.io/api/go,web,vim,node,react,linux,macos,windows,visualstudiocode
# Edit at https://www.gitignore.io/?templates=go,web,vim,node,react,linux,macos,windows,visualstudiocode

### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

### Go Patch ###
/vendor/
/Godeps/

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

### react ###
.DS_*
**/*.backup.*
**/*.back.*

node_modules
bower_componets

*.sublime*

psd
thumb
sketch

### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### VisualStudioCode Patch ###
# Ignore all local history of files
.history

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/go,web,vim,node,react,linux,macos,windows,visualstudiocode
35 changes: 35 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
project_name: "awsctx"
release:
prerelease: auto
draft: false
before:
hooks:
- go mod download
builds:
- main: ./main.go
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm
goarm:
- 6
archives:
- name_template: '{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}'
replacements:
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
65 changes: 47 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,65 @@ awsctx
===========================

## Setup
Add your `.bashrc` or `.zshrc` and follow "REPLACE ME" and "OPTIONAL"
Add your `.bashrc` or `.zshrc` and follow "OPTIONAL"
```bash
AWSCTX="$HOME/awsctx" # <-- REPLACE ME: path to awsctx
sync-aws-profile() {
if [ -e "$AWSCTX/aws_profile" ]; then
export AWS_PROFILE=$(cat $AWSCTX/aws_profile)
fi
}
awsctx() {
# ---
# OPTIONAL: Insert MFA Secret
# Uncomment me If you want to use CLI based 2FA
# MFA_TOKEN=$(oathtool -b --totp $AWS_MFA_SECRET)
# ---
if [ "$MFA_TOKEN" != "" ]; then
bash $AWSCTX/awsctx.sh $1 $MFA_TOKEN $([ "$#" -gt 1 ] && shift 1 && echo $@)
else
bash $AWSCTX/awsctx.sh $@
fi
sync-aws-profile
}
sync-aws-profile

# ---
# Enable tab completion

# zsh:
eval "$(awsctx completion zsh)"

# bash:
eval "$(awsctx completion bash)"
# ---

# ---
# OPTIONAL: Insert MFA Secret
# Uncomment me If you want to use CLI based 2FA
# MFA_TOKEN=$(oathtool -b --totp $AWS_MFA_SECRET)
# alias awsctx='awsctx --mfa=$(oathtool -b --totp $MFA_TOKEN)'
# ---
```

## Usage
```bash
awsctx <AWS_ACCOUNT/all> [MFA_TOKEN] [login|list-roles|console|...]
# If you defined MFA_TOKEN: `awsctx myservice-production`
# or else: `awsctx myservice-production 123456`
awsctx [completion|help|list|login|show] ...

# List available accounts
awsctx list

# Show current AWS account
awsctx show

# Login
awsctx login myservice-production

# Login with MFA
awsctx login --mfa=123456 myservice-production

# Login and open AWS Management Console (-c, --console)
awsctx login -c myservice-production

# Login and get login URL (-l, --link)
awsctx login -l myservice-production

# Login and open AWS Management Console (with Firefox Multi-Account Containers) (-F, --firefox)
awsctx login -cF myservice-production
```
## Extra: Setup Firefox (Multi-Account Containers)
### Install addons:
Multi-Account Containers:
https://addons.mozilla.org/ja/firefox/addon/multi-account-containers/

Open container tabs from URL (Protocol Handler):
https://addons.mozilla.org/en-US/firefox/addon/open-url-in-container/

## Extra: Setup oathtool (MFA_TOKEN)

Expand Down
Loading

0 comments on commit 77e3eb2

Please sign in to comment.