Skip to content

Commit

Permalink
Add installation with a script
Browse files Browse the repository at this point in the history
The `install.sh` installs the tool from the current `main` branch
version. The ~/.cache/aws-creds` directory will store dependencies and
cache files instead of a directory colocated with the script.
  • Loading branch information
extsoft committed Apr 25, 2024
1 parent 7f694a6 commit f167591
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ requested commands.


## Installation
TODO

The latest version can be installed using the following command:
`curl -sSL https://raw.githubusercontent.com/bees-hive/aws-creds/main/install.sh | bash`

## Getting Started

### AWS IAM Identity Center (AWS SSO)

You should have the IAM Identity Center start URL (like `https://xxxxxx.awsapps.com/start`)
and its region (like `us-east-1`). `python aws-creds.py scan-ic https://xxxxxx.awsapps.com/start us-east-1` command
and its region (like `us-east-1`). `aws-creds scan-ic https://xxxxxx.awsapps.com/start us-east-1` command
generates all possible login aliases. Pick those you want and save them to the shell configuration profile file.
Once you run an alias, it will open the browser and ask you to authenticate. After successful authentication,
it will export the AWS session environment variables to the current shell session.
20 changes: 16 additions & 4 deletions aws-creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
import os
import sys

_me = Path(__file__).absolute()
_prog = Path(__file__).name.split(".")[0]
_dependencies_home = _me.parent.joinpath(f".{_prog}")
_dependencies_home = Path.home().joinpath(".cache").joinpath(_prog)


def _remove_contents(directory: Path) -> None:
for entry in directory.iterdir():
if entry.is_dir():
_remove_contents(entry)
entry.rmdir()
else:
if str(entry).startswith(".ic."):
continue
entry.unlink()


def pip_wtf(dependencies: str) -> None:
Expand All @@ -18,7 +28,9 @@ def pip_wtf(dependencies: str) -> None:
dependencies_hash = _dependencies_home.joinpath(f".d.{sha1(dependencies.encode()).hexdigest()}")
if dependencies_hash.exists():
return
print("Cache directory:", _dependencies_home)
_dependencies_home.mkdir(exist_ok=True)
_remove_contents(_dependencies_home)
dependencies_hash.touch(exist_ok=True)
os.system(" ".join([sys.executable, "-m", "pip", "install", "--target", str(_dependencies_home), dependencies]))

Expand All @@ -27,7 +39,7 @@ def pip_wtf(dependencies: str) -> None:
print("Support Python 3.7 or above", file=sys.stderr)
exit(1)

pip_wtf("boto3==1.34.38")
pip_wtf("boto3==1.34.40")
from botocore.session import Session # noqa: E402


Expand Down Expand Up @@ -137,7 +149,7 @@ def _connect(ic: IdentityCenter, account_id: str, role: str) -> None:

def main():
parser = ArgumentParser(
description="Painless CLI authentification using various AWS identities.",
description="Painless CLI authentication using various AWS identities.",
prog=_prog,
formatter_class=lambda prog: HelpFormatter(prog, width=72),
)
Expand Down
13 changes: 13 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

DOWNLOAD_URL="https://raw.githubusercontent.com/bees-hive/aws-creds/main/aws-creds.py"
read -r -p "Enter the installation directory (leave blank for '/usr/local/bin'): " INSTALL_DIR
if [ -z "$INSTALL_DIR" ]; then
INSTALL_DIR="/usr/local/bin"
fi
mkdir -p "$INSTALL_DIR"
INSTALLATION="$INSTALL_DIR/aws-creds"
curl -sSLo "$INSTALLATION" "$DOWNLOAD_URL"
chmod +x "$INSTALLATION"

echo "Installation complete. Please re-start the shell to use 'aws-creds'."

0 comments on commit f167591

Please sign in to comment.