Skip to content

Commit 834b396

Browse files
authored
add support for windows for awsp & awsr (#1)
* add support for windows for awsp & awsr * update version --------- Co-authored-by: Snigdhajyoti Ghosh <[email protected]>
1 parent 2c61bf2 commit 834b396

File tree

5 files changed

+63
-5
lines changed

5 files changed

+63
-5
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ credential_process = aws-fusion okta device-auth --org-domain my.okta.com --oidc
182182
## Use case of `config-switch`
183183
A special of utility script to help easily switch `profile` and `region`
184184

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

196+
### For Windows
197+
This works with 2 powershell script, namely `_awsp.ps1` and `_awsr.ps1`
198+
199+
Post installing the app, create 2 aliases in `$PROFILE` (i.e. `$HOME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1`) file.
200+
```ps1
201+
## aws fusion setup
202+
Set-Alias awsp "_awsp.ps1"
203+
Set-Alias awsr "_awsr.ps1"
204+
```
205+
195206
<img src="https://raw.githubusercontent.com/snigdhasjg/aws-fusion/main/doc/images/config-switch.png" width="300" alt="config-switch-image"/>
196207

197208
---

aws_fusion/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.6.1'
1+
__version__ = '1.6.2'

bin/_awsp.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Switch AWS Fusion profile
2+
aws-fusion config-switch profile
3+
if ($LASTEXITCODE -ne 0) {
4+
return
5+
}
6+
7+
# Read the selected profile
8+
$selectedProfile = Get-Content "$HOME\.aws\fusion\profile"
9+
10+
# Unset AWS_REGION
11+
Remove-Item Env:AWS_REGION -ErrorAction SilentlyContinue
12+
13+
if ([string]::IsNullOrWhiteSpace($selectedProfile)) {
14+
# Unset AWS_PROFILE for default profile
15+
Remove-Item Env:AWS_PROFILE -ErrorAction SilentlyContinue
16+
} else {
17+
# Set AWS_PROFILE
18+
$Env:AWS_PROFILE = $selectedProfile
19+
}

bin/_awsr.ps1

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Switch AWS Fusion region
2+
aws-fusion config-switch region
3+
if ($LASTEXITCODE -ne 0) {
4+
return
5+
}
6+
7+
# Read the selected region
8+
$selectedRegion = Get-Content "$HOME\.aws\fusion\region"
9+
10+
# Check if the selected region is empty
11+
if ([string]::IsNullOrWhiteSpace($selectedRegion)) {
12+
# Unset AWS_REGION as it matches the one in the current profile
13+
Remove-Item Env:AWS_REGION -ErrorAction SilentlyContinue
14+
} else {
15+
# Set AWS_REGION
16+
$Env:AWS_REGION = $selectedRegion
17+
}

setup.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
import os
33
import re
4+
import platform
45

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

25+
# Determine the scripts based on the operating system
26+
if platform.system() in ["Linux", "Darwin"]:
27+
scripts = [
28+
'bin/_awsp',
29+
'bin/_awsr'
30+
]
31+
if platform.system() == "Windows":
32+
scripts = [
33+
'bin/_awsp.ps1',
34+
'bin/_awsr.ps1'
35+
]
36+
else:
37+
scripts = []
2438

2539
setup(
2640
name='aws-fusion',
@@ -42,10 +56,7 @@ def find_version(*file_paths):
4256
'aws-fusion = aws_fusion.app:main',
4357
]
4458
},
45-
scripts=[
46-
'bin/_awsp',
47-
'bin/_awsr'
48-
],
59+
scripts=scripts,
4960
install_requires=[
5061
'boto3>=1.29',
5162
'pyperclip>=1.8',

0 commit comments

Comments
 (0)