leverage 1.12.1__tar.gz → 1.12.2__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.
Files changed (43) hide show
  1. leverage-1.12.2/PKG-INFO +279 -0
  2. leverage-1.12.2/README.md +243 -0
  3. {leverage-1.12.1 → leverage-1.12.2}/leverage/__init__.py +1 -1
  4. {leverage-1.12.1 → leverage-1.12.2}/leverage/leverage.py +2 -1
  5. {leverage-1.12.1 → leverage-1.12.2}/leverage/modules/__init__.py +0 -1
  6. {leverage-1.12.1 → leverage-1.12.2}/leverage/modules/aws.py +0 -9
  7. {leverage-1.12.1 → leverage-1.12.2}/leverage/modules/credentials.py +19 -24
  8. {leverage-1.12.1 → leverage-1.12.2}/leverage/modules/project.py +8 -5
  9. {leverage-1.12.1 → leverage-1.12.2}/leverage/modules/terraform.py +44 -4
  10. {leverage-1.12.1 → leverage-1.12.2}/leverage/modules/tfautomv.py +0 -4
  11. {leverage-1.12.1 → leverage-1.12.2}/leverage/path.py +17 -5
  12. leverage-1.12.2/pyproject.toml +64 -0
  13. leverage-1.12.1/PKG-INFO +0 -139
  14. leverage-1.12.1/README.md +0 -114
  15. leverage-1.12.1/leverage.egg-info/PKG-INFO +0 -139
  16. leverage-1.12.1/leverage.egg-info/SOURCES.txt +0 -39
  17. leverage-1.12.1/leverage.egg-info/dependency_links.txt +0 -1
  18. leverage-1.12.1/leverage.egg-info/entry_points.txt +0 -3
  19. leverage-1.12.1/leverage.egg-info/requires.txt +0 -11
  20. leverage-1.12.1/leverage.egg-info/top_level.txt +0 -3
  21. leverage-1.12.1/pyproject.toml +0 -9
  22. leverage-1.12.1/setup.cfg +0 -62
  23. leverage-1.12.1/setup.py +0 -4
  24. leverage-1.12.1/tests/test__parsing.py +0 -45
  25. leverage-1.12.1/tests/test_conf.py +0 -54
  26. leverage-1.12.1/tests/test_logger.py +0 -88
  27. leverage-1.12.1/tests/test_path.py +0 -120
  28. leverage-1.12.1/tests/test_tasks.py +0 -113
  29. leverage-1.12.1/tests/test_utils.py +0 -86
  30. {leverage-1.12.1 → leverage-1.12.2}/LICENSE.txt +0 -0
  31. {leverage-1.12.1 → leverage-1.12.2}/leverage/_internals.py +0 -0
  32. {leverage-1.12.1 → leverage-1.12.2}/leverage/_parsing.py +0 -0
  33. {leverage-1.12.1 → leverage-1.12.2}/leverage/_utils.py +0 -0
  34. {leverage-1.12.1 → leverage-1.12.2}/leverage/conf.py +0 -0
  35. {leverage-1.12.1 → leverage-1.12.2}/leverage/container.py +0 -0
  36. {leverage-1.12.1 → leverage-1.12.2}/leverage/containers/kubectl.py +0 -0
  37. {leverage-1.12.1 → leverage-1.12.2}/leverage/logger.py +0 -0
  38. {leverage-1.12.1 → leverage-1.12.2}/leverage/modules/auth.py +0 -0
  39. {leverage-1.12.1 → leverage-1.12.2}/leverage/modules/kubectl.py +0 -0
  40. {leverage-1.12.1 → leverage-1.12.2}/leverage/modules/run.py +0 -0
  41. {leverage-1.12.1 → leverage-1.12.2}/leverage/modules/shell.py +0 -0
  42. {leverage-1.12.1 → leverage-1.12.2}/leverage/modules/utils.py +0 -0
  43. {leverage-1.12.1 → leverage-1.12.2}/leverage/tasks.py +0 -0
@@ -0,0 +1,279 @@
1
+ Metadata-Version: 2.1
2
+ Name: leverage
3
+ Version: 1.12.2
4
+ Summary: Binbash Leverage Command-Line tool.
5
+ Home-page: https://github.com/binbashar/leverage
6
+ License: MIT
7
+ Keywords: leverage,binbash
8
+ Author: BinBash Inc
9
+ Author-email: leverage@binbash.com.ar
10
+ Requires-Python: >=3.8,<3.12
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Topic :: Software Development :: Build Tools
20
+ Requires-Dist: boto3 (==1.33.2)
21
+ Requires-Dist: click (==8.0.1)
22
+ Requires-Dist: configupdater (==3.2)
23
+ Requires-Dist: docker (==6.1.0)
24
+ Requires-Dist: dockerpty (==0.4.1)
25
+ Requires-Dist: docutils (==0.17.1)
26
+ Requires-Dist: jinja2 (==3.0.1)
27
+ Requires-Dist: python-hcl2 (==3.0.1)
28
+ Requires-Dist: questionary (==1.10.0)
29
+ Requires-Dist: rich (==10.4.0)
30
+ Requires-Dist: ruamel.yaml (==0.17.10)
31
+ Requires-Dist: yaenv (==1.4.1)
32
+ Project-URL: Documentation, https://leverage.binbash.co/
33
+ Project-URL: Repository, https://github.com/binbashar/leverage
34
+ Description-Content-Type: text/markdown
35
+
36
+ <a href="https://github.com/binbashar">
37
+ <img src="https://raw.githubusercontent.com/binbashar/le-ref-architecture-doc/master/docs/assets/images/logos/binbash-leverage-banner.png" width="1032" align="left" alt="Binbash"/>
38
+ </a>
39
+ <br clear="left"/>
40
+
41
+ # Leverage CLI
42
+
43
+ Leverage CLI is the tool used to manage and interact with any Leverage project.
44
+
45
+ It transparently handles the most complex and error prone tasks that arise from working with a state-of-the-art
46
+ infrastructure definition like our Leverage Reference Architecture. Leverage CLI uses a dockerized approach to
47
+ encapsulate the tools needed to perform such tasks and to free the user from having to deal with the configuration and
48
+ management of said tools.
49
+ Provides the means to interact with your Leverage project and allows you to define custom tasks to run.
50
+
51
+ Reviewing and implementing the [Binbash Leverage Landing Zone for AWS](https://leverage.binbash.co/try-leverage/) would
52
+ be a very good place to start!
53
+
54
+ ## Documentation
55
+
56
+ For installation instructions and all documentation regarding Leverage CLI, please refer
57
+ to [this page](https://leverage.binbash.co/user-guide/leverage-cli/installation/).
58
+
59
+ ### Note for migration from previous versions
60
+
61
+ If you come from Leverage CLI version <1.8.0 and want to install Leverage CLI version >= 1.8.0 keep into account the
62
+ following.
63
+
64
+ The `build.env` file format has changed. As an example, this is the old format:
65
+
66
+ ```
67
+ # Project settings
68
+ PROJECT=bb
69
+
70
+ # General
71
+ MFA_ENABLED=false
72
+
73
+ # Terraform
74
+ TERRAFORM_IMAGE_NAME=binbash/terraform-awscli-slim
75
+ TERRAFORM_IMAGE_TAG=1.1.9
76
+ ```
77
+
78
+ New version example:
79
+
80
+ ```
81
+ # Project settings
82
+ PROJECT=bb
83
+
84
+ # General
85
+ MFA_ENABLED=false
86
+
87
+ # Terraform
88
+ TERRAFORM_IMAGE_TAG=1.2.7-0.1.0
89
+ ```
90
+
91
+ So, if you have created a project with version <1.8.0 and want to use it with version >=1.8.0 you should:
92
+
93
+ - remove TERRAFORM_IMAGE_NAME line
94
+ - update TERRAFORM_IMAGE_TAG from this form '9.9.9' to this one '9.9.9-9.9.9'.
95
+
96
+ For the second item you can check the version [here](https://hub.docker.com/r/binbash/leverage-toolbox/tags).
97
+
98
+ ## System requirements
99
+
100
+ ### Supported python versions
101
+
102
+ Leverage CLI explicitly supports the following Python versions:
103
+
104
+ - Python 3.8.x
105
+ - Python 3.9.x
106
+ - Python 3.10.x
107
+ - Python 3.11.x
108
+
109
+ These versions are not only supported but are also the only versions used in our CI/CD pipelines to ensure compatibility
110
+ and performance. This rigorous testing helps prevent compatibility issues and ensures that the Leverage CLI performs as
111
+ expected under these versions.
112
+
113
+ Please ensure that your development and deployment environments are set up with one of these supported versions. Our
114
+ GitHub Actions and other CI workflows are specifically configured to test against these Python versions, which
115
+ reinforces our commitment to maintaining a reliable and stable toolset.
116
+
117
+ ### Installing multiple python versions with pyenv
118
+
119
+ If you need to install one of the supported Python versions (3.8, 3.9, 3.10 or 3.11) and would like to manage multiple
120
+ Python environments, `pyenv` is a highly recommended tool. Here’s how you can use `pyenv` to install and manage Python
121
+ versions:
122
+
123
+ 1. Installing Pyenv:
124
+
125
+ ```bash
126
+ curl https://pyenv.run | bash
127
+ ```
128
+
129
+ 2. Add Pyenv to your shell to automate the setup process (if using bash, otherwise you can find details on how to set it
130
+ up [here](https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv)):
131
+
132
+ ```bash
133
+ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
134
+ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
135
+ echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
136
+ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
137
+ exec "$SHELL"
138
+ ```
139
+
140
+ 3. Installing python versions:
141
+
142
+ Once pyenv is installed, you can install any supported Python version by following these steps:
143
+
144
+ ```bash
145
+ pyenv install 3.8.10
146
+ pyenv install 3.9.7
147
+ pyenv install 3.10.1
148
+ pyenv install 3.11.8
149
+ ```
150
+
151
+ 4. Create a virtual environment for the leverage project:
152
+
153
+ Create a virtual environment for your project using Python 3.9.7:
154
+
155
+ ```bash
156
+ pyenv virtualenv 3.9.7 leverage_py_39_venv
157
+ ```
158
+
159
+ 5. Set your virtual environment to be used in the project:
160
+
161
+ To set this virtual environment as the local environment for your project, navigate to your project directory and run:
162
+
163
+ ```bash
164
+ cd <path_to_leverage_project_root>
165
+ pyenv local leverage_py_39_venv
166
+ ```
167
+
168
+ This setup commands `pyenv` to use `leverage_py_39_venv` as the local Python version for your project directory,
169
+ ensuring that all Python operations within this directory use this isolated environment.
170
+
171
+ ## Setting up development environment
172
+
173
+ Before you begin, ensure you are running Python 3.8, 3.9, or 3.10 as these are the only versions Leverage CLI supports
174
+ and tests against.
175
+
176
+ We now use Poetry for dependency management. Setup your development environment as follows:
177
+
178
+ 1. Install Poetry:
179
+
180
+ ```bash
181
+ curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.2 python -
182
+ ```
183
+
184
+ 2. Clone the repository and navigate into it:
185
+
186
+ ```bash
187
+ git clone https://github.com/binbashar/leverage.git
188
+ cd leverage
189
+ ```
190
+
191
+ 3. Install dependencies using Poetry:
192
+
193
+ ```bash
194
+ poetry install --with=dev --with=main
195
+ ```
196
+
197
+ 4. To activate the virtual environment and start using the CLI in dev mode, use:
198
+
199
+ ```bash
200
+ poetry shell
201
+ ```
202
+
203
+ ## Pre-commit hooks
204
+
205
+ In order to run black automatically on every commit, you should install `pre-commit` first:
206
+
207
+ https://pre-commit.com/#installation
208
+
209
+ And then the hooks:
210
+
211
+ ```
212
+ poetry run pre-commit install
213
+ ```
214
+
215
+ ## Running Tests
216
+
217
+ To run unit tests, pytest is the tool of choice, and the required dependencies are available in the
218
+ corresponding `dev-requirements.txt`.
219
+
220
+ Integration tests are implemented using [bats](https://github.com/bats-core/bats-core/). Bear in mind that bats tests
221
+ are meant to be run in a throwaway environment since they perform filesystem manipulations and installation and removal
222
+ of packages, and the cleanup may not be completely thorough. As such, is highly recommended to run these tests using the
223
+ docker image.
224
+
225
+ ### Manually
226
+
227
+ 1. Unit tests:
228
+
229
+ ```bash
230
+ poetry run pytest
231
+ ```
232
+
233
+ 2. Integration tests:
234
+
235
+ Install dependencies (MacOS):
236
+
237
+ ```bash
238
+ brew install bats-core
239
+ brew tap bats-core/bats-core
240
+ brew install bats-support
241
+ brew install bats-assert
242
+ ```
243
+
244
+ ```bash
245
+ bats -r tests/bats
246
+ ```
247
+
248
+ ### Using docker image
249
+
250
+ A Docker image suitable for running all tests can be crafted by running `make build-image`. After crafting the image all
251
+ tests can be executed.
252
+
253
+ To run all tests, run `make tests`. Alternatively `make test-unit` or `make test-int` for unit or integration tests
254
+ respectively.
255
+
256
+ ## Release Process
257
+
258
+ * On every PR, a Github Action workflow is triggered to create/update a release draft.
259
+ * The version number is determined by the labels of those PRs (major, minor, fix).
260
+ * The release draft has to be manually published. This allows for any number of PR (features, fixes) to make the cut.
261
+ * Once a release is published, another workflow is triggered to create and push the package to PyPi.
262
+
263
+ ## Release Candidate Process
264
+
265
+ * There is an Action called "Test Build Package and Push".
266
+ * This Action can be called manually on any branch specifying the version to release to test.
267
+ * The version is a Release Candidate following the Semver: e.g. if the next release is 1.2.3, the test version
268
+ should be 1.2.3-rc.1
269
+ * The package will be published to [PyPi](https://pypi.org/project/leverage/).
270
+
271
+ ## Contributors/Contributing
272
+
273
+ * Leverage CLI was initially based on Pynt: https://github.com/rags/pynt
274
+
275
+ ## License
276
+
277
+ Leverage CLI is licensed
278
+ under [MIT license](http://opensource.org/licenses/MIT)[BinBash Inc](https://github.com/binbashar)
279
+
@@ -0,0 +1,243 @@
1
+ <a href="https://github.com/binbashar">
2
+ <img src="https://raw.githubusercontent.com/binbashar/le-ref-architecture-doc/master/docs/assets/images/logos/binbash-leverage-banner.png" width="1032" align="left" alt="Binbash"/>
3
+ </a>
4
+ <br clear="left"/>
5
+
6
+ # Leverage CLI
7
+
8
+ Leverage CLI is the tool used to manage and interact with any Leverage project.
9
+
10
+ It transparently handles the most complex and error prone tasks that arise from working with a state-of-the-art
11
+ infrastructure definition like our Leverage Reference Architecture. Leverage CLI uses a dockerized approach to
12
+ encapsulate the tools needed to perform such tasks and to free the user from having to deal with the configuration and
13
+ management of said tools.
14
+ Provides the means to interact with your Leverage project and allows you to define custom tasks to run.
15
+
16
+ Reviewing and implementing the [Binbash Leverage Landing Zone for AWS](https://leverage.binbash.co/try-leverage/) would
17
+ be a very good place to start!
18
+
19
+ ## Documentation
20
+
21
+ For installation instructions and all documentation regarding Leverage CLI, please refer
22
+ to [this page](https://leverage.binbash.co/user-guide/leverage-cli/installation/).
23
+
24
+ ### Note for migration from previous versions
25
+
26
+ If you come from Leverage CLI version <1.8.0 and want to install Leverage CLI version >= 1.8.0 keep into account the
27
+ following.
28
+
29
+ The `build.env` file format has changed. As an example, this is the old format:
30
+
31
+ ```
32
+ # Project settings
33
+ PROJECT=bb
34
+
35
+ # General
36
+ MFA_ENABLED=false
37
+
38
+ # Terraform
39
+ TERRAFORM_IMAGE_NAME=binbash/terraform-awscli-slim
40
+ TERRAFORM_IMAGE_TAG=1.1.9
41
+ ```
42
+
43
+ New version example:
44
+
45
+ ```
46
+ # Project settings
47
+ PROJECT=bb
48
+
49
+ # General
50
+ MFA_ENABLED=false
51
+
52
+ # Terraform
53
+ TERRAFORM_IMAGE_TAG=1.2.7-0.1.0
54
+ ```
55
+
56
+ So, if you have created a project with version <1.8.0 and want to use it with version >=1.8.0 you should:
57
+
58
+ - remove TERRAFORM_IMAGE_NAME line
59
+ - update TERRAFORM_IMAGE_TAG from this form '9.9.9' to this one '9.9.9-9.9.9'.
60
+
61
+ For the second item you can check the version [here](https://hub.docker.com/r/binbash/leverage-toolbox/tags).
62
+
63
+ ## System requirements
64
+
65
+ ### Supported python versions
66
+
67
+ Leverage CLI explicitly supports the following Python versions:
68
+
69
+ - Python 3.8.x
70
+ - Python 3.9.x
71
+ - Python 3.10.x
72
+ - Python 3.11.x
73
+
74
+ These versions are not only supported but are also the only versions used in our CI/CD pipelines to ensure compatibility
75
+ and performance. This rigorous testing helps prevent compatibility issues and ensures that the Leverage CLI performs as
76
+ expected under these versions.
77
+
78
+ Please ensure that your development and deployment environments are set up with one of these supported versions. Our
79
+ GitHub Actions and other CI workflows are specifically configured to test against these Python versions, which
80
+ reinforces our commitment to maintaining a reliable and stable toolset.
81
+
82
+ ### Installing multiple python versions with pyenv
83
+
84
+ If you need to install one of the supported Python versions (3.8, 3.9, 3.10 or 3.11) and would like to manage multiple
85
+ Python environments, `pyenv` is a highly recommended tool. Here’s how you can use `pyenv` to install and manage Python
86
+ versions:
87
+
88
+ 1. Installing Pyenv:
89
+
90
+ ```bash
91
+ curl https://pyenv.run | bash
92
+ ```
93
+
94
+ 2. Add Pyenv to your shell to automate the setup process (if using bash, otherwise you can find details on how to set it
95
+ up [here](https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv)):
96
+
97
+ ```bash
98
+ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
99
+ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
100
+ echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
101
+ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
102
+ exec "$SHELL"
103
+ ```
104
+
105
+ 3. Installing python versions:
106
+
107
+ Once pyenv is installed, you can install any supported Python version by following these steps:
108
+
109
+ ```bash
110
+ pyenv install 3.8.10
111
+ pyenv install 3.9.7
112
+ pyenv install 3.10.1
113
+ pyenv install 3.11.8
114
+ ```
115
+
116
+ 4. Create a virtual environment for the leverage project:
117
+
118
+ Create a virtual environment for your project using Python 3.9.7:
119
+
120
+ ```bash
121
+ pyenv virtualenv 3.9.7 leverage_py_39_venv
122
+ ```
123
+
124
+ 5. Set your virtual environment to be used in the project:
125
+
126
+ To set this virtual environment as the local environment for your project, navigate to your project directory and run:
127
+
128
+ ```bash
129
+ cd <path_to_leverage_project_root>
130
+ pyenv local leverage_py_39_venv
131
+ ```
132
+
133
+ This setup commands `pyenv` to use `leverage_py_39_venv` as the local Python version for your project directory,
134
+ ensuring that all Python operations within this directory use this isolated environment.
135
+
136
+ ## Setting up development environment
137
+
138
+ Before you begin, ensure you are running Python 3.8, 3.9, or 3.10 as these are the only versions Leverage CLI supports
139
+ and tests against.
140
+
141
+ We now use Poetry for dependency management. Setup your development environment as follows:
142
+
143
+ 1. Install Poetry:
144
+
145
+ ```bash
146
+ curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.8.2 python -
147
+ ```
148
+
149
+ 2. Clone the repository and navigate into it:
150
+
151
+ ```bash
152
+ git clone https://github.com/binbashar/leverage.git
153
+ cd leverage
154
+ ```
155
+
156
+ 3. Install dependencies using Poetry:
157
+
158
+ ```bash
159
+ poetry install --with=dev --with=main
160
+ ```
161
+
162
+ 4. To activate the virtual environment and start using the CLI in dev mode, use:
163
+
164
+ ```bash
165
+ poetry shell
166
+ ```
167
+
168
+ ## Pre-commit hooks
169
+
170
+ In order to run black automatically on every commit, you should install `pre-commit` first:
171
+
172
+ https://pre-commit.com/#installation
173
+
174
+ And then the hooks:
175
+
176
+ ```
177
+ poetry run pre-commit install
178
+ ```
179
+
180
+ ## Running Tests
181
+
182
+ To run unit tests, pytest is the tool of choice, and the required dependencies are available in the
183
+ corresponding `dev-requirements.txt`.
184
+
185
+ Integration tests are implemented using [bats](https://github.com/bats-core/bats-core/). Bear in mind that bats tests
186
+ are meant to be run in a throwaway environment since they perform filesystem manipulations and installation and removal
187
+ of packages, and the cleanup may not be completely thorough. As such, is highly recommended to run these tests using the
188
+ docker image.
189
+
190
+ ### Manually
191
+
192
+ 1. Unit tests:
193
+
194
+ ```bash
195
+ poetry run pytest
196
+ ```
197
+
198
+ 2. Integration tests:
199
+
200
+ Install dependencies (MacOS):
201
+
202
+ ```bash
203
+ brew install bats-core
204
+ brew tap bats-core/bats-core
205
+ brew install bats-support
206
+ brew install bats-assert
207
+ ```
208
+
209
+ ```bash
210
+ bats -r tests/bats
211
+ ```
212
+
213
+ ### Using docker image
214
+
215
+ A Docker image suitable for running all tests can be crafted by running `make build-image`. After crafting the image all
216
+ tests can be executed.
217
+
218
+ To run all tests, run `make tests`. Alternatively `make test-unit` or `make test-int` for unit or integration tests
219
+ respectively.
220
+
221
+ ## Release Process
222
+
223
+ * On every PR, a Github Action workflow is triggered to create/update a release draft.
224
+ * The version number is determined by the labels of those PRs (major, minor, fix).
225
+ * The release draft has to be manually published. This allows for any number of PR (features, fixes) to make the cut.
226
+ * Once a release is published, another workflow is triggered to create and push the package to PyPi.
227
+
228
+ ## Release Candidate Process
229
+
230
+ * There is an Action called "Test Build Package and Push".
231
+ * This Action can be called manually on any branch specifying the version to release to test.
232
+ * The version is a Release Candidate following the Semver: e.g. if the next release is 1.2.3, the test version
233
+ should be 1.2.3-rc.1
234
+ * The package will be published to [PyPi](https://pypi.org/project/leverage/).
235
+
236
+ ## Contributors/Contributing
237
+
238
+ * Leverage CLI was initially based on Pynt: https://github.com/rags/pynt
239
+
240
+ ## License
241
+
242
+ Leverage CLI is licensed
243
+ under [MIT license](http://opensource.org/licenses/MIT)[BinBash Inc](https://github.com/binbashar)
@@ -3,7 +3,7 @@
3
3
  """
4
4
  # pylint: disable=wrong-import-position
5
5
 
6
- __version__ = "1.12.1"
6
+ __version__ = "1.12.2"
7
7
  __toolbox_version__ = "1.2.7-0.1.12"
8
8
 
9
9
  import sys
@@ -9,7 +9,8 @@ from leverage.tasks import list_tasks as _list_tasks
9
9
  from leverage._internals import pass_state
10
10
 
11
11
  from leverage.modules.aws import aws
12
- from leverage.modules import run, project, terraform, credentials, tfautomv, kubectl, shell
12
+ from leverage.modules.credentials import credentials
13
+ from leverage.modules import run, project, terraform, tfautomv, kubectl, shell
13
14
 
14
15
 
15
16
  @click.group(invoke_without_command=True)
@@ -1,7 +1,6 @@
1
1
  from .run import run
2
2
  from .project import project
3
3
  from .terraform import terraform
4
- from .credentials import credentials
5
4
  from .tfautomv import tfautomv
6
5
  from .kubectl import kubectl
7
6
  from .shell import shell
@@ -202,15 +202,6 @@ def sso(context, cli, args):
202
202
  @pass_container
203
203
  def login(cli):
204
204
  """Login"""
205
- # only from account or layer directories
206
- # when to fail:
207
- # - when this cond meets:
208
- # - no account dir
209
- # - no layer dir
210
- if not cli.paths.get_location_type() in ["account", "layer", "layers-group"]:
211
- logger.error("SSO configuration can only be performed at [bold]layer[/bold] or [bold]account[/bold] level.")
212
- raise Exit(1)
213
-
214
205
  exit_code, region = cli.exec(f"configure get sso_region --profile {cli.project}-sso")
215
206
  if exit_code:
216
207
  logger.error(f"Region configuration for [bold]{cli.project}-sso[/bold] profile not found.")
@@ -1,27 +1,27 @@
1
1
  """
2
2
  Credentials managing module.
3
3
  """
4
- import re
5
4
  import csv
6
5
  import json
7
- from pathlib import Path
6
+ import re
8
7
  from functools import wraps
8
+ from pathlib import Path
9
9
 
10
10
  import click
11
- from click.exceptions import Exit
12
11
  import questionary
12
+ from click.exceptions import Exit
13
13
  from questionary import Choice
14
14
  from ruamel.yaml import YAML
15
15
 
16
16
  from leverage import __toolbox_version__
17
17
  from leverage import logger
18
- from leverage.path import get_root_path
19
- from leverage.path import get_global_config_path
20
- from leverage.path import NotARepositoryError
21
18
  from leverage._internals import pass_state
22
- from leverage.container import get_docker_client
19
+ from leverage._utils import ExitError
23
20
  from leverage.container import AWSCLIContainer
24
-
21
+ from leverage.container import get_docker_client
22
+ from leverage.path import NotARepositoryError
23
+ from leverage.path import get_global_config_path
24
+ from leverage.path import get_project_root_or_current_dir_path
25
25
 
26
26
  # Regexes for general validation
27
27
  PROJECT_SHORT = r"[a-z]{2,4}"
@@ -37,11 +37,11 @@ ACCOUNT_ID = r"[0-9]{12}"
37
37
  MFA_SERIAL = rf"arn:aws:iam::{ACCOUNT_ID}:mfa/{USERNAME}"
38
38
 
39
39
  # TODO: Remove these and get them into the global app state
40
+ PROJECT_ROOT = get_project_root_or_current_dir_path()
40
41
  try:
41
42
  PROJECT_COMMON_TFVARS = Path(get_global_config_path())
42
- PROJECT_ROOT = Path(get_root_path())
43
43
  except NotARepositoryError:
44
- PROJECT_COMMON_TFVARS = PROJECT_ROOT = Path.cwd()
44
+ PROJECT_COMMON_TFVARS = Path.cwd()
45
45
 
46
46
  PROJECT_COMMON_TFVARS_FILE = "common.tfvars"
47
47
  PROJECT_COMMON_TFVARS = PROJECT_COMMON_TFVARS / PROJECT_COMMON_TFVARS_FILE
@@ -446,8 +446,7 @@ def configure_credentials(profile, file=None, make_backup=False):
446
446
  for key, value in values.items():
447
447
  exit_code, output = AWSCLI.exec(f"configure set {key} {value}", profile)
448
448
  if exit_code:
449
- logger.error(f"AWS CLI error: {output}")
450
- raise Exit(exit_code)
449
+ raise ExitError(exit_code, f"AWS CLI error: {output}")
451
450
 
452
451
 
453
452
  def _credentials_are_valid(profile):
@@ -481,8 +480,7 @@ def _get_management_account_id(profile):
481
480
  """
482
481
  exit_code, caller_identity = AWSCLI.exec("--output json sts get-caller-identity", profile)
483
482
  if exit_code:
484
- logger.error(f"AWS CLI error: {caller_identity}")
485
- raise Exit(exit_code)
483
+ raise ExitError(exit_code, f"AWS CLI error: {caller_identity}")
486
484
 
487
485
  caller_identity = json.loads(caller_identity)
488
486
  return caller_identity["Account"]
@@ -526,8 +524,7 @@ def _get_mfa_serial(profile):
526
524
  """
527
525
  exit_code, mfa_devices = AWSCLI.exec("--output json iam list-mfa-devices", profile)
528
526
  if exit_code:
529
- logger.error(f"AWS CLI error: {mfa_devices}")
530
- raise Exit(exit_code)
527
+ raise ExitError(exit_code, f"AWS CLI error: {mfa_devices}")
531
528
  mfa_devices = json.loads(mfa_devices)
532
529
 
533
530
  # Either zero or one MFA device should be configured for either `management` or `security` accounts users.
@@ -554,8 +551,7 @@ def configure_profile(profile, values):
554
551
  for key, value in values.items():
555
552
  exit_code, output = AWSCLI.exec(f"configure set {key} {value}", profile)
556
553
  if exit_code:
557
- logger.error(f"AWS CLI error: {output}")
558
- raise Exit(exit_code)
554
+ raise ExitError(exit_code, f"AWS CLI error: {output}")
559
555
 
560
556
 
561
557
  def configure_accounts_profiles(profile, region, organization_accounts, project_accounts, fetch_mfa_device):
@@ -565,18 +561,17 @@ def configure_accounts_profiles(profile, region, organization_accounts, project_
565
561
  profile(str): Name of the profile to configure.
566
562
  region (str): Region.
567
563
  organization_accounts (dict): Name and id of all accounts in the organization.
568
- project_accounts (dict): Name and email of all accounts in project configuration file.
564
+ project_accounts (list): Name and email of all accounts in project configuration file.
569
565
  fetch_mfa_device (bool): Whether to fetch MFA device for profiles.
570
566
  """
571
- short_name, type = profile.split("-")
567
+ short_name, _type = profile.split("-")
572
568
 
573
569
  mfa_serial = ""
574
570
  if fetch_mfa_device:
575
571
  logger.info("Fetching MFA device serial.")
576
572
  mfa_serial = _get_mfa_serial(profile)
577
573
  if not mfa_serial:
578
- logger.error("No MFA device found for user.")
579
- raise Exit(1)
574
+ raise ExitError(1, "No MFA device found for user.")
580
575
 
581
576
  account_profiles = {}
582
577
  for account in project_accounts:
@@ -593,13 +588,13 @@ def configure_accounts_profiles(profile, region, organization_accounts, project_
593
588
  account_profile = {
594
589
  "output": "json",
595
590
  "region": region,
596
- "role_arn": f"arn:aws:iam::{account_id}:role/{PROFILES[type]['role']}",
591
+ "role_arn": f"arn:aws:iam::{account_id}:role/{PROFILES[_type]['role']}",
597
592
  "source_profile": profile,
598
593
  }
599
594
  if mfa_serial:
600
595
  account_profile["mfa_serial"] = mfa_serial
601
596
  # A profile identifier looks like `le-security-oaar`
602
- account_profiles[f"{short_name}-{account_name}-{PROFILES[type]['profile_role']}"] = account_profile
597
+ account_profiles[f"{short_name}-{account_name}-{PROFILES[_type]['profile_role']}"] = account_profile
603
598
 
604
599
  logger.info("Backing up account profiles file.")
605
600
  _backup_file("config")