Skip to content

Commit cb78491

Browse files
authored
Introduce Black coding style (#96)
1 parent a4f97ea commit cb78491

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1777
-1247
lines changed

.pre-commit-config.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: stable
4+
hooks:
5+
- id: black
6+
language_version: python3
7+
- repo: https://github.com/pre-commit/pre-commit-hooks
8+
rev: v2.3.0
9+
hooks:
10+
- id: check-ast
11+
- id: flake8
12+
- id: check-merge-conflict
13+
- id: debug-statements
14+
- id: requirements-txt-fixer
15+
- repo: https://github.com/Lucas-C/pre-commit-hooks-bandit
16+
rev: v1.0.4
17+
hooks:
18+
- id: python-bandit-vulnerability-check

.pylintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ disable=print-statement,
144144
invalid-name,
145145
no-member,
146146
arguments-differ,
147-
ungrouped-imports
147+
ungrouped-imports,
148+
bad-continuation
148149

149150
# Enable the message, report, category or checker with the given id(s). You can
150151
# either give multiple identifier separated by comma (,) or put this option

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ install:
1616
before_script:
1717
- pytest --version
1818
script:
19-
- ./test/run.py
19+
- ./tests/run.py
2020
after_success:
2121
- codecov
2222
deploy:

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
------------------
33

44
* Add support for Linux in **bootstrap**
5+
* Black coding style is now used
6+
* pre-commit hooks are available for easier development
57

68
0.5.0 (2019-10-04)
79
------------------

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# aws-gate
2-
[![Build Status](https://travis-ci.org/xen0l/aws-gate.svg?branch=master)](https://travis-ci.org/xen0l/aws-gate)[![codecov](https://codecov.io/gh/xen0l/aws-gate/branch/master/graph/badge.svg)](https://codecov.io/gh/xen0l/aws-gate)[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5f4385e925e34788a20e40b4a3319b2d)](https://app.codacy.com/app/xen0l/aws-gate?utm_source=github.com&utm_medium=referral&utm_content=xen0l/aws-gate&utm_campaign=Badge_Grade_Settings)[![PyPI version](https://badge.fury.io/py/aws-gate.svg)](https://badge.fury.io/py/aws-gate)
2+
[![Build Status](https://travis-ci.org/xen0l/aws-gate.svg?branch=master)](https://travis-ci.org/xen0l/aws-gate)[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)[![codecov](https://codecov.io/gh/xen0l/aws-gate/branch/master/graph/badge.svg)](https://codecov.io/gh/xen0l/aws-gate)[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5f4385e925e34788a20e40b4a3319b2d)](https://app.codacy.com/app/xen0l/aws-gate?utm_source=github.com&utm_medium=referral&utm_content=xen0l/aws-gate&utm_campaign=Badge_Grade_Settings)[![PyPI version](https://badge.fury.io/py/aws-gate.svg)](https://badge.fury.io/py/aws-gate)
33

44
AWS SSM Session manager client
55

aws_gate/__init__.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
__version__ = '0.5.0'
2-
__description__ = 'aws-gate - AWS SSM Session Manager client CLI'
3-
__author__ = 'Adam Stevko'
4-
__author_email__ = '[email protected]'
5-
__url__ = 'https://github.com/xen0l/aws-gate'
1+
__version__ = "0.5.0"
2+
__description__ = "aws-gate - AWS SSM Session Manager client CLI"
3+
__author__ = "Adam Stevko"
4+
__author_email__ = "[email protected]"
5+
__url__ = "https://github.com/xen0l/aws-gate"

aws_gate/bootstrap.py

+38-23
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99
import requests
1010
import unix_ar
1111

12-
from aws_gate.constants import DEFAULT_GATE_BIN_PATH, PLUGIN_INSTALL_PATH, PLUGIN_NAME, SSM_PLUGIN_PATH
12+
from aws_gate.constants import (
13+
DEFAULT_GATE_BIN_PATH,
14+
PLUGIN_INSTALL_PATH,
15+
PLUGIN_NAME,
16+
SSM_PLUGIN_PATH,
17+
)
1318
from aws_gate.exceptions import UnsupportedPlatormError
1419
from aws_gate.utils import execute
1520

1621
logger = logging.getLogger(__name__)
1722

1823

1924
def _check_plugin_version(path=PLUGIN_INSTALL_PATH):
20-
return execute(path, ['--version'], capture_output=True)
25+
return execute(path, ["--version"], capture_output=True)
2126

2227

2328
class Plugin:
@@ -26,7 +31,7 @@ class Plugin:
2631

2732
@property
2833
def is_installed(self):
29-
logger.debug('Checking if %s exists and is executable', PLUGIN_INSTALL_PATH)
34+
logger.debug("Checking if %s exists and is executable", PLUGIN_INSTALL_PATH)
3035
return shutil.which(PLUGIN_INSTALL_PATH) is None
3136

3237
def download(self):
@@ -35,71 +40,81 @@ def download(self):
3540

3641
self.download_path = os.path.join(tmp_dir, file_name)
3742
try:
38-
logger.debug('Downloading session-manager-plugin archive from %s', self.url)
43+
logger.debug("Downloading session-manager-plugin archive from %s", self.url)
3944
with requests.get(self.url, stream=True) as req:
4045
req.raise_for_status()
41-
with open(self.download_path, 'wb') as f:
46+
with open(self.download_path, "wb") as f:
4247
shutil.copyfileobj(req.raw, f)
43-
logger.debug('Download stored at %s', self.download_path)
48+
logger.debug("Download stored at %s", self.download_path)
4449
except requests.exceptions.HTTPError as e:
45-
logger.error('HTTP error while downloading %s: %s', self.url, e)
50+
logger.error("HTTP error while downloading %s: %s", self.url, e)
4651

4752
def install(self):
4853
download_dir = os.path.split(self.download_path)[0]
49-
plugin_src_path = os.path.join(download_dir, SSM_PLUGIN_PATH[platform.system()]['bundle'])
54+
plugin_src_path = os.path.join(
55+
download_dir, SSM_PLUGIN_PATH[platform.system()]["bundle"]
56+
)
5057
plugin_dst_path = PLUGIN_INSTALL_PATH
5158

5259
if not os.path.exists(DEFAULT_GATE_BIN_PATH):
53-
logger.debug('Creating %s', DEFAULT_GATE_BIN_PATH)
60+
logger.debug("Creating %s", DEFAULT_GATE_BIN_PATH)
5461
os.makedirs(DEFAULT_GATE_BIN_PATH)
5562

56-
with open(plugin_src_path, 'rb') as f_src, open(plugin_dst_path, 'wb') as f_dst:
57-
logger.debug('Copying %s to %s', plugin_src_path, plugin_dst_path)
63+
with open(plugin_src_path, "rb") as f_src, open(plugin_dst_path, "wb") as f_dst:
64+
logger.debug("Copying %s to %s", plugin_src_path, plugin_dst_path)
5865
shutil.copyfileobj(f_src, f_dst)
5966

60-
logger.debug('Setting execution permissions on %s', plugin_dst_path)
67+
logger.debug("Setting execution permissions on %s", plugin_dst_path)
6168
os.chmod(plugin_dst_path, 0o755)
6269

6370
version = _check_plugin_version(PLUGIN_INSTALL_PATH)
64-
print('{} (version {}) installed successfully!'.format(PLUGIN_NAME, version))
71+
print("{} (version {}) installed successfully!".format(PLUGIN_NAME, version))
6572

6673
def extract(self):
6774
raise NotImplementedError
6875

6976

7077
class MacPlugin(Plugin):
71-
url = SSM_PLUGIN_PATH['Darwin']['download']
78+
url = SSM_PLUGIN_PATH["Darwin"]["download"]
7279

7380
def extract(self):
7481
if not zipfile.is_zipfile(self.download_path):
75-
raise ValueError('Invalid macOS session-manager-plugin ZIP file found {}'.format(self.download_path))
82+
raise ValueError(
83+
"Invalid macOS session-manager-plugin ZIP file found {}".format(
84+
self.download_path
85+
)
86+
)
7687

77-
with zipfile.ZipFile(self.download_path, 'r') as zip_file:
88+
with zipfile.ZipFile(self.download_path, "r") as zip_file:
7889
download_dir = os.path.split(self.download_path)[0]
79-
logger.debug('Extracting session-manager-plugin archive at %s', download_dir)
90+
logger.debug(
91+
"Extracting session-manager-plugin archive at %s", download_dir
92+
)
8093
zip_file.extractall(download_dir)
8194

8295

8396
class LinuxPlugin(Plugin):
84-
url = SSM_PLUGIN_PATH['Linux']['download']
97+
url = SSM_PLUGIN_PATH["Linux"]["download"]
8598

8699
def extract(self):
87100
ar_file = unix_ar.open(self.download_path)
88-
tarball = ar_file.open('data.tar.gz/')
101+
tarball = ar_file.open("data.tar.gz/")
89102
tar_file = tarfile.open(fileobj=tarball)
90103
download_dir = os.path.split(self.download_path)[0]
91-
logger.debug('Extracting session-manager-plugin archive at %s', download_dir)
104+
logger.debug("Extracting session-manager-plugin archive at %s", download_dir)
92105
tar_file.extractall(download_dir)
93106

94107

95108
def bootstrap(force=False):
96109
system = platform.system()
97-
if system == 'Darwin':
110+
if system == "Darwin":
98111
plugin = MacPlugin()
99-
elif system == 'Linux':
112+
elif system == "Linux":
100113
plugin = LinuxPlugin()
101114
else:
102-
raise UnsupportedPlatormError('Unable to bootstrap session-manager-plugin on {}'.format(system))
115+
raise UnsupportedPlatormError(
116+
"Unable to bootstrap session-manager-plugin on {}".format(system)
117+
)
103118

104119
if plugin.is_installed or force:
105120
plugin.download()

0 commit comments

Comments
 (0)