sso-config-generator 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sso_config_generator-0.2.0/LICENSE +21 -0
- sso_config_generator-0.2.0/PKG-INFO +243 -0
- sso_config_generator-0.2.0/README.md +192 -0
- sso_config_generator-0.2.0/pyproject.toml +43 -0
- sso_config_generator-0.2.0/setup.cfg +4 -0
- sso_config_generator-0.2.0/src/sso_config_generator/__init__.py +7 -0
- sso_config_generator-0.2.0/src/sso_config_generator/cli.py +97 -0
- sso_config_generator-0.2.0/src/sso_config_generator/core.py +726 -0
- sso_config_generator-0.2.0/src/sso_config_generator.egg-info/PKG-INFO +243 -0
- sso_config_generator-0.2.0/src/sso_config_generator.egg-info/SOURCES.txt +12 -0
- sso_config_generator-0.2.0/src/sso_config_generator.egg-info/dependency_links.txt +1 -0
- sso_config_generator-0.2.0/src/sso_config_generator.egg-info/entry_points.txt +2 -0
- sso_config_generator-0.2.0/src/sso_config_generator.egg-info/requires.txt +3 -0
- sso_config_generator-0.2.0/src/sso_config_generator.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 easytocloud
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: sso-config-generator
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Python tool for generating AWS SSO configuration and directory structure
|
|
5
|
+
Author-email: easytocloud <info@easytocloud.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2024 easytocloud
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/easytocloud/sso-config-generator
|
|
29
|
+
Project-URL: Repository, https://github.com/easytocloud/sso-config-generator
|
|
30
|
+
Project-URL: Issues, https://github.com/easytocloud/sso-config-generator/issues
|
|
31
|
+
Project-URL: Changelog, https://github.com/easytocloud/sso-config-generator/blob/main/CHANGELOG.md
|
|
32
|
+
Keywords: aws,sso,config,generator,cli,aws-cli
|
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
|
34
|
+
Classifier: Environment :: Console
|
|
35
|
+
Classifier: Intended Audience :: Developers
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Operating System :: OS Independent
|
|
38
|
+
Classifier: Programming Language :: Python :: 3
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
43
|
+
Classifier: Topic :: Software Development :: Build Tools
|
|
44
|
+
Classifier: Topic :: System :: Systems Administration
|
|
45
|
+
Requires-Python: >=3.8
|
|
46
|
+
Description-Content-Type: text/markdown
|
|
47
|
+
License-File: LICENSE
|
|
48
|
+
Requires-Dist: boto3>=1.34.0
|
|
49
|
+
Requires-Dist: click>=8.1.0
|
|
50
|
+
Requires-Dist: pyyaml>=6.0.1
|
|
51
|
+
|
|
52
|
+
# SSO Config Generator
|
|
53
|
+
|
|
54
|
+
A Python CLI tool for generating AWS SSO configuration and directory structures.
|
|
55
|
+
|
|
56
|
+
## Overview
|
|
57
|
+
|
|
58
|
+
SSO Config Generator is a standalone Python tool that simplifies AWS SSO configuration management by:
|
|
59
|
+
|
|
60
|
+
1. Generating properly configured AWS CLI config files
|
|
61
|
+
2. Creating directory structures that mirror your AWS Organization
|
|
62
|
+
3. Setting up environment files for easy role switching using `direnv`
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
You can install SSO Config Generator using pip:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install sso-config-generator
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Prerequisites
|
|
73
|
+
|
|
74
|
+
- Python 3.8 or higher
|
|
75
|
+
- AWS CLI v2 configured with:
|
|
76
|
+
- Default region set in `~/.aws/config` or via `AWS_DEFAULT_REGION` environment variable
|
|
77
|
+
- AWS SSO configured via `aws configure sso`
|
|
78
|
+
- `direnv` (optional, for automatic profile switching)
|
|
79
|
+
|
|
80
|
+
### AWS Configuration
|
|
81
|
+
|
|
82
|
+
Before using the tool, ensure you have:
|
|
83
|
+
|
|
84
|
+
1. Set your AWS region:
|
|
85
|
+
```bash
|
|
86
|
+
# Either in ~/.aws/config
|
|
87
|
+
[default]
|
|
88
|
+
region = eu-west-1
|
|
89
|
+
|
|
90
|
+
# Or via environment variable
|
|
91
|
+
export AWS_DEFAULT_REGION=eu-west-1
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
2. Configure AWS SSO:
|
|
95
|
+
```bash
|
|
96
|
+
# Configure SSO
|
|
97
|
+
aws configure sso
|
|
98
|
+
# Follow the prompts to enter:
|
|
99
|
+
# - SSO start URL (e.g., https://your-domain.awsapps.com/start)
|
|
100
|
+
# - SSO Region
|
|
101
|
+
# - SSO registration scopes (accept default)
|
|
102
|
+
|
|
103
|
+
# Login to SSO to create credentials
|
|
104
|
+
aws sso login
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Troubleshooting
|
|
108
|
+
|
|
109
|
+
1. "Error: You must specify a region"
|
|
110
|
+
- Set AWS_DEFAULT_REGION environment variable
|
|
111
|
+
- Or configure default region in ~/.aws/config
|
|
112
|
+
|
|
113
|
+
2. "Unable to locate credentials"
|
|
114
|
+
- Run `aws sso login` to refresh your SSO credentials
|
|
115
|
+
- Ensure you've completed AWS SSO configuration with `aws configure sso`
|
|
116
|
+
- Check if your SSO session has expired (sessions typically last 8 hours)
|
|
117
|
+
|
|
118
|
+
3. "SSO session is expired"
|
|
119
|
+
- Run `aws sso login` to start a new session
|
|
120
|
+
|
|
121
|
+
## Usage
|
|
122
|
+
|
|
123
|
+
### Basic Usage
|
|
124
|
+
|
|
125
|
+
Simply run:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
uvx sso-config-generator
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
This will:
|
|
132
|
+
- Create/update your AWS CLI config file (`~/.aws/config`)
|
|
133
|
+
- Generate a directory structure in the current directory + sso-name
|
|
134
|
+
- Create `.envrc` files in each account directory with AdministratorAccess role
|
|
135
|
+
- Use OU structure for directory organization (cached for performance)
|
|
136
|
+
|
|
137
|
+
The tool caches OU structure information in `~/.aws/.ou` to improve performance. When the cache exists, it will be used automatically with a notification. To rebuild the cache:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
uvx sso-config-generator --rebuild-cache
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Command Options
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
Usage: sso-config-generator [OPTIONS]
|
|
147
|
+
|
|
148
|
+
Options:
|
|
149
|
+
--create-directories/--no-create-directories Create a directory for each account (default: True)
|
|
150
|
+
--use-ou-structure/--no-use-ou-structure Create directories for each OU (default: True)
|
|
151
|
+
--developer-role-name NAME Role name to use for .envrc files (default: AdministratorAccess)
|
|
152
|
+
--rebuild-cache Force rebuild of OU structure cache
|
|
153
|
+
--sso-name NAME Use specified SSO name instead of extracting from SSO start URL
|
|
154
|
+
--create-repos-md Create repos.md files in each account directory
|
|
155
|
+
--skip-sso-name Do not create a directory for the SSO name (default: False)
|
|
156
|
+
--unified-root PATH Directory where account directories are created
|
|
157
|
+
(default: current directory)
|
|
158
|
+
If current directory is named "environment", SSO name is
|
|
159
|
+
automatically skipped
|
|
160
|
+
--validate Validate current AWS SSO configuration instead of generating
|
|
161
|
+
--help Show this message and exit
|
|
162
|
+
--version Show the version and exit
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Examples
|
|
166
|
+
|
|
167
|
+
1. Basic config generation (uses defaults):
|
|
168
|
+
```bash
|
|
169
|
+
uvx sso-config-generator
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
2. Disable OU structure (flat account directories):
|
|
173
|
+
```bash
|
|
174
|
+
uvx sso-config-generator --no-use-ou-structure
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
3. Use different role for .envrc files:
|
|
178
|
+
```bash
|
|
179
|
+
uvx sso-config-generator --developer-role-name ReadOnlyAccess
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
4. Force rebuild of OU cache:
|
|
183
|
+
```bash
|
|
184
|
+
uvx sso-config-generator --rebuild-cache
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
5. Specify custom root directory:
|
|
188
|
+
```bash
|
|
189
|
+
uvx sso-config-generator --unified-root ~/aws-environments
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
6. Skip creating directories (config file only):
|
|
193
|
+
```bash
|
|
194
|
+
uvx sso-config-generator --no-create-directories
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
7. Working in an "environment" directory (automatic behavior):
|
|
198
|
+
```bash
|
|
199
|
+
# If your current directory is named 'environment'
|
|
200
|
+
cd environment
|
|
201
|
+
uvx sso-config-generator
|
|
202
|
+
# This will automatically skip creating the SSO name directory
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
8. Validate existing configuration:
|
|
206
|
+
```bash
|
|
207
|
+
uvx sso-config-generator --validate
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Development
|
|
211
|
+
|
|
212
|
+
### Setup Development Environment
|
|
213
|
+
|
|
214
|
+
1. Clone the repository:
|
|
215
|
+
```bash
|
|
216
|
+
git clone https://github.com/easytocloud/sso-config-generator.git
|
|
217
|
+
cd sso-config-generator
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
2. Create a virtual environment:
|
|
221
|
+
```bash
|
|
222
|
+
python -m venv venv
|
|
223
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
3. Install the package in development mode:
|
|
227
|
+
```bash
|
|
228
|
+
pip install -e .
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Common Development Tasks
|
|
232
|
+
|
|
233
|
+
- Build the package: `pip install build && python -m build`
|
|
234
|
+
- Run the tool: `uvx sso-config-generator`
|
|
235
|
+
- Test changes: `./test_sso_config.sh`
|
|
236
|
+
|
|
237
|
+
## Contributing
|
|
238
|
+
|
|
239
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
240
|
+
|
|
241
|
+
## License
|
|
242
|
+
|
|
243
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# SSO Config Generator
|
|
2
|
+
|
|
3
|
+
A Python CLI tool for generating AWS SSO configuration and directory structures.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
SSO Config Generator is a standalone Python tool that simplifies AWS SSO configuration management by:
|
|
8
|
+
|
|
9
|
+
1. Generating properly configured AWS CLI config files
|
|
10
|
+
2. Creating directory structures that mirror your AWS Organization
|
|
11
|
+
3. Setting up environment files for easy role switching using `direnv`
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
You can install SSO Config Generator using pip:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install sso-config-generator
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Prerequisites
|
|
22
|
+
|
|
23
|
+
- Python 3.8 or higher
|
|
24
|
+
- AWS CLI v2 configured with:
|
|
25
|
+
- Default region set in `~/.aws/config` or via `AWS_DEFAULT_REGION` environment variable
|
|
26
|
+
- AWS SSO configured via `aws configure sso`
|
|
27
|
+
- `direnv` (optional, for automatic profile switching)
|
|
28
|
+
|
|
29
|
+
### AWS Configuration
|
|
30
|
+
|
|
31
|
+
Before using the tool, ensure you have:
|
|
32
|
+
|
|
33
|
+
1. Set your AWS region:
|
|
34
|
+
```bash
|
|
35
|
+
# Either in ~/.aws/config
|
|
36
|
+
[default]
|
|
37
|
+
region = eu-west-1
|
|
38
|
+
|
|
39
|
+
# Or via environment variable
|
|
40
|
+
export AWS_DEFAULT_REGION=eu-west-1
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
2. Configure AWS SSO:
|
|
44
|
+
```bash
|
|
45
|
+
# Configure SSO
|
|
46
|
+
aws configure sso
|
|
47
|
+
# Follow the prompts to enter:
|
|
48
|
+
# - SSO start URL (e.g., https://your-domain.awsapps.com/start)
|
|
49
|
+
# - SSO Region
|
|
50
|
+
# - SSO registration scopes (accept default)
|
|
51
|
+
|
|
52
|
+
# Login to SSO to create credentials
|
|
53
|
+
aws sso login
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Troubleshooting
|
|
57
|
+
|
|
58
|
+
1. "Error: You must specify a region"
|
|
59
|
+
- Set AWS_DEFAULT_REGION environment variable
|
|
60
|
+
- Or configure default region in ~/.aws/config
|
|
61
|
+
|
|
62
|
+
2. "Unable to locate credentials"
|
|
63
|
+
- Run `aws sso login` to refresh your SSO credentials
|
|
64
|
+
- Ensure you've completed AWS SSO configuration with `aws configure sso`
|
|
65
|
+
- Check if your SSO session has expired (sessions typically last 8 hours)
|
|
66
|
+
|
|
67
|
+
3. "SSO session is expired"
|
|
68
|
+
- Run `aws sso login` to start a new session
|
|
69
|
+
|
|
70
|
+
## Usage
|
|
71
|
+
|
|
72
|
+
### Basic Usage
|
|
73
|
+
|
|
74
|
+
Simply run:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
uvx sso-config-generator
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
This will:
|
|
81
|
+
- Create/update your AWS CLI config file (`~/.aws/config`)
|
|
82
|
+
- Generate a directory structure in the current directory + sso-name
|
|
83
|
+
- Create `.envrc` files in each account directory with AdministratorAccess role
|
|
84
|
+
- Use OU structure for directory organization (cached for performance)
|
|
85
|
+
|
|
86
|
+
The tool caches OU structure information in `~/.aws/.ou` to improve performance. When the cache exists, it will be used automatically with a notification. To rebuild the cache:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
uvx sso-config-generator --rebuild-cache
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Command Options
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
Usage: sso-config-generator [OPTIONS]
|
|
96
|
+
|
|
97
|
+
Options:
|
|
98
|
+
--create-directories/--no-create-directories Create a directory for each account (default: True)
|
|
99
|
+
--use-ou-structure/--no-use-ou-structure Create directories for each OU (default: True)
|
|
100
|
+
--developer-role-name NAME Role name to use for .envrc files (default: AdministratorAccess)
|
|
101
|
+
--rebuild-cache Force rebuild of OU structure cache
|
|
102
|
+
--sso-name NAME Use specified SSO name instead of extracting from SSO start URL
|
|
103
|
+
--create-repos-md Create repos.md files in each account directory
|
|
104
|
+
--skip-sso-name Do not create a directory for the SSO name (default: False)
|
|
105
|
+
--unified-root PATH Directory where account directories are created
|
|
106
|
+
(default: current directory)
|
|
107
|
+
If current directory is named "environment", SSO name is
|
|
108
|
+
automatically skipped
|
|
109
|
+
--validate Validate current AWS SSO configuration instead of generating
|
|
110
|
+
--help Show this message and exit
|
|
111
|
+
--version Show the version and exit
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Examples
|
|
115
|
+
|
|
116
|
+
1. Basic config generation (uses defaults):
|
|
117
|
+
```bash
|
|
118
|
+
uvx sso-config-generator
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
2. Disable OU structure (flat account directories):
|
|
122
|
+
```bash
|
|
123
|
+
uvx sso-config-generator --no-use-ou-structure
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
3. Use different role for .envrc files:
|
|
127
|
+
```bash
|
|
128
|
+
uvx sso-config-generator --developer-role-name ReadOnlyAccess
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
4. Force rebuild of OU cache:
|
|
132
|
+
```bash
|
|
133
|
+
uvx sso-config-generator --rebuild-cache
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
5. Specify custom root directory:
|
|
137
|
+
```bash
|
|
138
|
+
uvx sso-config-generator --unified-root ~/aws-environments
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
6. Skip creating directories (config file only):
|
|
142
|
+
```bash
|
|
143
|
+
uvx sso-config-generator --no-create-directories
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
7. Working in an "environment" directory (automatic behavior):
|
|
147
|
+
```bash
|
|
148
|
+
# If your current directory is named 'environment'
|
|
149
|
+
cd environment
|
|
150
|
+
uvx sso-config-generator
|
|
151
|
+
# This will automatically skip creating the SSO name directory
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
8. Validate existing configuration:
|
|
155
|
+
```bash
|
|
156
|
+
uvx sso-config-generator --validate
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Development
|
|
160
|
+
|
|
161
|
+
### Setup Development Environment
|
|
162
|
+
|
|
163
|
+
1. Clone the repository:
|
|
164
|
+
```bash
|
|
165
|
+
git clone https://github.com/easytocloud/sso-config-generator.git
|
|
166
|
+
cd sso-config-generator
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
2. Create a virtual environment:
|
|
170
|
+
```bash
|
|
171
|
+
python -m venv venv
|
|
172
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
3. Install the package in development mode:
|
|
176
|
+
```bash
|
|
177
|
+
pip install -e .
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Common Development Tasks
|
|
181
|
+
|
|
182
|
+
- Build the package: `pip install build && python -m build`
|
|
183
|
+
- Run the tool: `uvx sso-config-generator`
|
|
184
|
+
- Test changes: `./test_sso_config.sh`
|
|
185
|
+
|
|
186
|
+
## Contributing
|
|
187
|
+
|
|
188
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "sso-config-generator"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Python tool for generating AWS SSO configuration and directory structure"
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "easytocloud", email = "info@easytocloud.com"}
|
|
7
|
+
]
|
|
8
|
+
dependencies = [
|
|
9
|
+
"boto3>=1.34.0",
|
|
10
|
+
"click>=8.1.0",
|
|
11
|
+
"pyyaml>=6.0.1",
|
|
12
|
+
]
|
|
13
|
+
requires-python = ">=3.8"
|
|
14
|
+
readme = "README.md"
|
|
15
|
+
license = {file = "LICENSE"}
|
|
16
|
+
keywords = ["aws", "sso", "config", "generator", "cli", "aws-cli"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Environment :: Console",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Programming Language :: Python :: 3",
|
|
24
|
+
"Programming Language :: Python :: 3.8",
|
|
25
|
+
"Programming Language :: Python :: 3.9",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Topic :: Software Development :: Build Tools",
|
|
29
|
+
"Topic :: System :: Systems Administration",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/easytocloud/sso-config-generator"
|
|
34
|
+
Repository = "https://github.com/easytocloud/sso-config-generator"
|
|
35
|
+
Issues = "https://github.com/easytocloud/sso-config-generator/issues"
|
|
36
|
+
Changelog = "https://github.com/easytocloud/sso-config-generator/blob/main/CHANGELOG.md"
|
|
37
|
+
|
|
38
|
+
[build-system]
|
|
39
|
+
requires = ["setuptools>=45"]
|
|
40
|
+
build-backend = "setuptools.build_meta"
|
|
41
|
+
|
|
42
|
+
[project.scripts]
|
|
43
|
+
sso-config-generator = "sso_config_generator.cli:cli"
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
from typing import Optional
|
|
4
|
+
import click
|
|
5
|
+
from . import __version__
|
|
6
|
+
from .core import SSOConfigGenerator
|
|
7
|
+
|
|
8
|
+
@click.command()
|
|
9
|
+
@click.version_option(version=__version__)
|
|
10
|
+
@click.option('--create-directories/--no-create-directories', default=True,
|
|
11
|
+
help='Create a directory for each account')
|
|
12
|
+
@click.option('--use-ou-structure/--no-use-ou-structure', default=True,
|
|
13
|
+
help='Create directories for each OU')
|
|
14
|
+
@click.option('--developer-role-name', default="AdministratorAccess",
|
|
15
|
+
help='Role name to use for .envrc files')
|
|
16
|
+
@click.option('--rebuild-cache', is_flag=True,
|
|
17
|
+
help='Force rebuild of OU structure cache')
|
|
18
|
+
@click.option('--sso-name',
|
|
19
|
+
help='Use specified SSO name instead of extracting from SSO start URL')
|
|
20
|
+
@click.option('--create-repos-md', is_flag=True,
|
|
21
|
+
help='Create repos.md files in each account directory')
|
|
22
|
+
@click.option('--skip-sso-name', is_flag=True,
|
|
23
|
+
help='Do not create a directory for the SSO name')
|
|
24
|
+
@click.option('--unified-root',
|
|
25
|
+
help='Directory where account directories are created (default: current directory). '
|
|
26
|
+
'If current directory is named "environment", SSO name is automatically skipped.')
|
|
27
|
+
@click.option('--validate', is_flag=True,
|
|
28
|
+
help='Validate current AWS SSO configuration instead of generating')
|
|
29
|
+
def cli(create_directories: bool, use_ou_structure: bool, developer_role_name: str,
|
|
30
|
+
sso_name: Optional[str], create_repos_md: bool, skip_sso_name: bool, unified_root: Optional[str],
|
|
31
|
+
rebuild_cache: bool, validate: bool):
|
|
32
|
+
"""SSO Config Generator - Generate AWS SSO configuration and directory structures.
|
|
33
|
+
|
|
34
|
+
This tool will:
|
|
35
|
+
1. Generate AWS CLI config file with SSO profiles for each account/role
|
|
36
|
+
2. Create directory structure using OU hierarchy (if --use-ou-structure)
|
|
37
|
+
3. Set up environment files (.envrc) for direnv with the specified role
|
|
38
|
+
|
|
39
|
+
The tool uses a cache file (~/.aws/.ou) to store the OU structure and account information.
|
|
40
|
+
Use --rebuild-cache to force a refresh of the cache.
|
|
41
|
+
|
|
42
|
+
Example usage:
|
|
43
|
+
# Basic usage (uses defaults)
|
|
44
|
+
sso-config-generator
|
|
45
|
+
|
|
46
|
+
# Force rebuild of OU cache
|
|
47
|
+
sso-config-generator --rebuild-cache
|
|
48
|
+
|
|
49
|
+
# Use different role for .envrc files
|
|
50
|
+
sso-config-generator --developer-role-name ReadOnlyAccess
|
|
51
|
+
|
|
52
|
+
# Disable OU structure (flat account directories)
|
|
53
|
+
sso-config-generator --no-use-ou-structure
|
|
54
|
+
|
|
55
|
+
# Specify custom root directory
|
|
56
|
+
sso-config-generator --unified-root ~/aws-environments
|
|
57
|
+
|
|
58
|
+
# Skip creating the SSO name directory
|
|
59
|
+
sso-config-generator --skip-sso-name
|
|
60
|
+
|
|
61
|
+
# Validate existing configuration
|
|
62
|
+
sso-config-generator --validate
|
|
63
|
+
"""
|
|
64
|
+
try:
|
|
65
|
+
if validate:
|
|
66
|
+
# Run validation
|
|
67
|
+
generator = SSOConfigGenerator()
|
|
68
|
+
if not generator.validate():
|
|
69
|
+
sys.exit(1)
|
|
70
|
+
else:
|
|
71
|
+
# Remove cache if rebuild requested
|
|
72
|
+
if rebuild_cache:
|
|
73
|
+
cache_path = os.path.expanduser("~/.aws/.ou")
|
|
74
|
+
if os.path.exists(cache_path):
|
|
75
|
+
os.remove(cache_path)
|
|
76
|
+
print("Removed existing OU cache.")
|
|
77
|
+
|
|
78
|
+
# Generate configuration
|
|
79
|
+
generator = SSOConfigGenerator(
|
|
80
|
+
create_directories=create_directories,
|
|
81
|
+
use_ou_structure=use_ou_structure,
|
|
82
|
+
developer_role_name=developer_role_name,
|
|
83
|
+
sso_name=sso_name,
|
|
84
|
+
create_repos_md=create_repos_md,
|
|
85
|
+
skip_sso_name=skip_sso_name,
|
|
86
|
+
unified_root=unified_root
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if not generator.generate():
|
|
90
|
+
sys.exit(1)
|
|
91
|
+
|
|
92
|
+
except Exception as e:
|
|
93
|
+
print(f"Error: {str(e)}", file=sys.stderr)
|
|
94
|
+
sys.exit(1)
|
|
95
|
+
|
|
96
|
+
if __name__ == '__main__':
|
|
97
|
+
cli()
|