Skip to content

Commit

Permalink
add support for windows for awsp & awsr (#1)
Browse files Browse the repository at this point in the history
* add support for windows for awsp & awsr

* update version

---------

Co-authored-by: Snigdhajyoti Ghosh <snigdhasjg@users.noreply.github.com>
  • Loading branch information
snigdhasjg and snigdhasjg authored Jan 30, 2025
1 parent 2c61bf2 commit 834b396
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ credential_process = aws-fusion okta device-auth --org-domain my.okta.com --oidc
## Use case of `config-switch`
A special of utility script to help easily switch `profile` and `region`

### For Linux & Darwin (MacOS)
This works with 2 bash script, namely `_awsp` and `_awsr`
> _Using the command without the bash script will have no effect_
Expand All @@ -192,6 +193,16 @@ alias awsp="source _awsp"
alias awsr="source _awsr"
```

### For Windows
This works with 2 powershell script, namely `_awsp.ps1` and `_awsr.ps1`

Post installing the app, create 2 aliases in `$PROFILE` (i.e. `$HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1`) file.
```ps1
## aws fusion setup
Set-Alias awsp "_awsp.ps1"
Set-Alias awsr "_awsr.ps1"
```

<img src="https://raw.githubusercontent.com/snigdhasjg/aws-fusion/main/doc/images/config-switch.png" width="300" alt="config-switch-image"/>

---
Expand Down
2 changes: 1 addition & 1 deletion aws_fusion/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.6.1'
__version__ = '1.6.2'
19 changes: 19 additions & 0 deletions bin/_awsp.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Switch AWS Fusion profile
aws-fusion config-switch profile
if ($LASTEXITCODE -ne 0) {
return
}

# Read the selected profile
$selectedProfile = Get-Content "$HOME\.aws\fusion\profile"

# Unset AWS_REGION
Remove-Item Env:AWS_REGION -ErrorAction SilentlyContinue

if ([string]::IsNullOrWhiteSpace($selectedProfile)) {
# Unset AWS_PROFILE for default profile
Remove-Item Env:AWS_PROFILE -ErrorAction SilentlyContinue
} else {
# Set AWS_PROFILE
$Env:AWS_PROFILE = $selectedProfile
}
17 changes: 17 additions & 0 deletions bin/_awsr.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Switch AWS Fusion region
aws-fusion config-switch region
if ($LASTEXITCODE -ne 0) {
return
}

# Read the selected region
$selectedRegion = Get-Content "$HOME\.aws\fusion\region"

# Check if the selected region is empty
if ([string]::IsNullOrWhiteSpace($selectedRegion)) {
# Unset AWS_REGION as it matches the one in the current profile
Remove-Item Env:AWS_REGION -ErrorAction SilentlyContinue
} else {
# Set AWS_REGION
$Env:AWS_REGION = $selectedRegion
}
19 changes: 15 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import os
import re
import platform

from setuptools import find_packages
from setuptools import setup
Expand All @@ -21,6 +22,19 @@ def find_version(*file_paths):
return version_match.group(1)
raise RuntimeError("Unable to find version string.")

# Determine the scripts based on the operating system
if platform.system() in ["Linux", "Darwin"]:
scripts = [
'bin/_awsp',
'bin/_awsr'
]
if platform.system() == "Windows":
scripts = [
'bin/_awsp.ps1',
'bin/_awsr.ps1'
]
else:
scripts = []

setup(
name='aws-fusion',
Expand All @@ -42,10 +56,7 @@ def find_version(*file_paths):
'aws-fusion = aws_fusion.app:main',
]
},
scripts=[
'bin/_awsp',
'bin/_awsr'
],
scripts=scripts,
install_requires=[
'boto3>=1.29',
'pyperclip>=1.8',
Expand Down

0 comments on commit 834b396

Please sign in to comment.