Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Create installation script + fix release pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
containerscrew committed Nov 17, 2023
1 parent 08e725d commit 5dd98ba
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ jobs:
bin: aws-sso-auth
command: build

- release_for: linux-x86_64
- release_for: linux-amd64
os: ubuntu-latest
target: x86_64-unknown-linux-musl
bin: aws-sso-auth
command: build

- release_for: macOS-x86_64
- release_for: darwin-amd64
os: macOS-latest
target: x86_64-apple-darwin
bin: aws-sso-auth
command: build

- release_for: macOS-arm64
- release_for: darwin-arm64
os: macOS-latest
target: aarch64-apple-darwin
bin: aws-sso-auth
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ pre-commit: ## Run pre-commit
pre-commit run -a

package: ## Package binary with zip
zip -j ${BINARY_NAME}-v${VERSION}-$(ARCH).zip target/$(TARGET)/release/${BINARY_NAME}
zip -j ${BINARY_NAME}-$(ARCH).zip target/$(TARGET)/release/${BINARY_NAME}
45 changes: 29 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
- [Pipeline badges](#pipeline-badges)
- [Introduction](#introduction)
- [Installation](#installation)
- [Pre-commit](#pre-commit)
- [Usage](#usage)
- [Switching accounts](#switching-accounts)
- [Switching accounts in your terminal](#switching-accounts-in-your-terminal)
- [Fish shell](#fish-shell)
- [Setting AWS_PROFILE](#setting-aws_profile)
- [TO DO](#to-do)
- [Build](#build)
- [TO DO (not implemented yet)](#to-do-not-implemented-yet)
- [Contribution](#contribution)
- [LICENSE](#license)
Expand All @@ -58,10 +57,6 @@
...TO DO



## Pre-commit
[pre-commit](./docs/pre-commit.md)

# Usage

```bash
Expand All @@ -73,9 +68,9 @@ aws-sso-auth --start-url https://XXXXXX.awsapps.com/start --region eu-west-1

> All the credentials will be saved in your $HOME/.aws/credentials with the following pattern: [AccountName@RoleName] you are assuming
## Switching accounts
## Switching accounts in your terminal

Copy the following function in your `.zshrc` or `.bashrc`:
Copy the following function in your `~/.zshrc` or `~/.bashrc`:

```shell
aws-profile () {
Expand All @@ -84,33 +79,49 @@ aws-profile () {
}
```

Then, `source` the file if needed:
```shell
source ~/.zshrc or source ~/.bashrc
```

# Fish shell

Copy the following function inside `~/.config/fish/function/aws-profile.fish`

```shell
TO DO
function aws-profile
set -Ux AWS_PROFILES $(cat ~/.aws/credentials | sed -n -e 's/^\[\(.*\)\]/\1/p' | fzf)
if test -n "$AWS_PROFILES"
set -xg AWS_PROFILE $AWS_PROFILES
echo "Selected profile: $AWS_PROFILES"
else
echo "No profile selected"
end
end
```
Then, `source` the file if needed:
Then `source` the fish configuration:
```shell
source ~/.zshrc or source ~/.bashrc
source ~/.config/fish/config.fish
```
## Setting AWS_PROFILE
Type `aws-profile` in your terminal, and you will see all the accounts you have credentials in your `$HOME/.aws/credentials`
> **fzf** is needed as a dependency for the interactive account switcher
[Official documentation](https://github.com/junegunn/fzf#installation)
# TO DO
> https://github.com/awslabs/aws-sdk-rust/discussions/771
* Github actions pipeline to create binary and push to `releases`
* Testing
* Imagine you have 600 accounts with access in your AWS SSO portal, but you only want to fetch 100. How you can limit that?
## Build
```bash
cargo build --release # --release flag for production environment, without --release flag for testing
```
# TO DO (not implemented yet)
* Multiple AWS SSO account configurations inside `aws-sso-auth.json` Imagine you are working in a consultant, and you have multiple customers with AWS SSO, and you want to save
Expand All @@ -123,6 +134,8 @@ all their config (start-url, region) inside the config file.
* Implement multiple retries when you have 429 errors in API calls
* Overwrite `~/.aws/credentials` file every time you fetch account credentials
* Create function to open file
* Codecoverage pipeline not working
* Changelog with release-please
# Contribution
Expand Down
119 changes: 119 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#! /usr/bin/bash

PROJECT="aws-sso-auth"

set -eu
declare -a commands=("curl" "jq" "unzip")

trap ctrl_c INT

function ctrl_c(){
clean
echo -e "\nBye!"
exit 0
}

command_exists() {
for command in "${commands[@]}"
do
if ! command -v "$command" &> /dev/null
then
echo "ERROR: $command could not be found. Install it!"
exit 1
fi
done
}

clean(){
echo -e "Cleaning $tmpdir"
rm -r "$tmpdir"
}

# Pre flight checks
command_exists

happyexit(){
echo ""
echo "${PROJECT} successfully installed! 🎉"
echo ""
echo "Now run:"
echo ""
echo " ${PROJECT} usage"
echo ""
exit 0
}

validate_checksum(){
echo "Not implemented yet"
}

# Check OS
OS=$(uname -s)
arch=$(uname -m)
cli_arch=""
case $OS in
Darwin)
case $arch in
x86_64)
cli_arch=amd64
;;
arm64)
cli_arch=$arch
;;
*)
echo "There is no ${PROJECT} $OS support for $arch"
exit 1
;;
esac
;;
Linux)
case $arch in
x86_64)
cli_arch=amd64
;;
armv8*)
cli_arch=arm64
;;
aarch64*)
cli_arch=arm64
;;
amd64|arm64)
cli_arch=$arch
;;
*)
echo "There is no ${PROJECT} $OS support for $arch"
exit 1
;;
esac
;;
*)
echo "There is no ${PROJECT} $OS support for $arch"
exit 1
;;
esac
OS=$(echo "$OS" | tr '[:upper:]' '[:lower:]')

download_release() {
LATEST_VERSION=$(curl -s https://api.github.com/repos/containerscrew/$PROJECT/releases/latest | jq -r ".name")
INSTALLATION_PATH="/usr/local/bin/"
tmpdir=$(mktemp -d)

cd $tmpdir
echo -e "Downloading... ${LATEST_VERSION}/${PROJECT}-${OS}-${cli_arch}.zip \n"
curl -L --fail --remote-name-all https://github.com/containerscrew/${PROJECT}/releases/download/"${LATEST_VERSION}"/${PROJECT}-${OS}-${cli_arch}.zip
unzip ${PROJECT}-${OS}-${cli_arch}.zip ${PROJECT}
}

# Start install
download_release

if [ "$EUID" -ne 0 ]
then command_exists sudo
sudo mv ${PROJECT} $INSTALLATION_PATH
else
mv ${PROJECT} $INSTALLATION_PATH
chmod +x $INSTALLATION_PATH/${PROJECT}
fi

clean
happyexit

0 comments on commit 5dd98ba

Please sign in to comment.