Skip to content

Commit 88b7134

Browse files
authored
Maintenance updates (#1175)
1 parent f1e80fe commit 88b7134

22 files changed

+46
-50
lines changed

.github/workflows/python-package.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
max-parallel: 5
1313
matrix:
1414
python-version:
15-
- '3.6'
1615
- '3.7'
1716
- '3.8'
1817
- '3.9'

.pylintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ disable=print-statement,
148148
bad-continuation,
149149
redefined-builtin,
150150
raise-missing-from,
151-
duplicate-code
151+
duplicate-code,
152+
consider-using-with,
153+
unspecified-encoding
152154

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

aws_gate/bootstrap.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def install(self):
6969
os.chmod(plugin_dst_path, 0o755)
7070

7171
version = _check_plugin_version(PLUGIN_INSTALL_PATH)
72-
print("{} (version {}) installed successfully!".format(PLUGIN_NAME, version))
72+
print(f"{PLUGIN_NAME} (version {version}) installed successfully!")
7373

7474
def extract(self):
7575
raise NotImplementedError
@@ -81,9 +81,7 @@ class MacPlugin(Plugin):
8181
def extract(self):
8282
if not zipfile.is_zipfile(self.download_path):
8383
raise ValueError(
84-
"Invalid macOS session-manager-plugin ZIP file found {}".format(
85-
self.download_path
86-
)
84+
f"Invalid macOS session-manager-plugin ZIP file found {self.download_path}"
8785
)
8886

8987
with zipfile.ZipFile(self.download_path, "r") as zip_file:
@@ -114,7 +112,7 @@ def bootstrap(force=False):
114112
plugin = LinuxPlugin()
115113
else:
116114
raise UnsupportedPlatormError(
117-
"Unable to bootstrap session-manager-plugin on {}".format(system)
115+
f"Unable to bootstrap session-manager-plugin on {system}"
118116
)
119117

120118
if plugin.is_installed or force:

aws_gate/cli.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ def get_argument_parser(*args, **kwargs):
5353
"-v", "--verbose", help="increase output verbosity", action="store_true"
5454
)
5555
parser.add_argument(
56-
"--version",
57-
action="version",
58-
version="%(prog)s {version}".format(version=__version__),
56+
"--version", action="version", version=f"%(prog)s {__version__}"
5957
)
6058
subparsers = parser.add_subparsers(title="subcommands", dest="subcommand")
6159

@@ -241,7 +239,7 @@ def main(args=None, argument_parser=None):
241239
try:
242240
config = load_config_from_files()
243241
except (ValidationError, ScannerError) as e:
244-
raise ValueError("Invalid configuration provided: {}".format(e))
242+
raise ValueError(f"Invalid configuration provided: {e}")
245243

246244
# We want to provide default values in cases they are not configured
247245
# in ~/.aws/config or availabe a environment variables

aws_gate/config.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ class EmptyConfigurationError(Exception):
1818

1919
def validate_profile(profile):
2020
if not is_existing_profile(profile):
21-
raise ValidationError("Invalid profile provided: {}".format(profile))
21+
raise ValidationError(f"Invalid profile provided: {profile}")
2222

2323

2424
def validate_region(region):
2525
if not is_existing_region(region):
26-
raise ValidationError("Invalid region name provided: {}".format(region))
26+
raise ValidationError(f"Invalid region name provided: {region}")
2727

2828

2929
def validate_defaults(data):
@@ -45,9 +45,9 @@ class HostSchema(Schema):
4545

4646
class GateConfigSchema(Schema):
4747
defaults = fields.Nested(
48-
DefaultsSchema, required=False, missing=dict(), validate=validate_defaults
48+
DefaultsSchema, required=False, missing={}, validate=validate_defaults
4949
)
50-
hosts = fields.List(fields.Nested(HostSchema), required=False, missing=list())
50+
hosts = fields.List(fields.Nested(HostSchema), required=False, missing=[])
5151

5252
# pylint: disable=no-self-use,unused-argument
5353
@post_load
@@ -115,9 +115,7 @@ def _merge_data(src, dst):
115115
dst[key] = src[key]
116116
else:
117117
raise TypeError(
118-
"Cannot merge {} with dict, src={} dst={}".format(
119-
type(src).__name__, src, dst
120-
)
118+
f"Cannot merge {type(src).__name__} with dict, src={src} dst={dst}"
121119
)
122120

123121
elif isinstance(dst, list):

aws_gate/decorators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def plugin_required(
3232
and not _plugin_exists_in_path()
3333
and not platform.system() == "Windows"
3434
):
35-
raise OSError("{} not found".format(PLUGIN_NAME))
35+
raise OSError(f"{PLUGIN_NAME} not found")
3636

3737
return wrapped_function(*args, **kwargs)
3838

@@ -50,7 +50,7 @@ def wrapper(
5050
)
5151

5252
if version and parse_version(version) < parse_version(required_version):
53-
raise ValueError("Invalid plugin version: {}".format(version))
53+
raise ValueError(f"Invalid plugin version: {version}")
5454

5555
return wrapped_function(*args, **kwargs)
5656

@@ -62,7 +62,7 @@ def valid_aws_profile(
6262
wrapped_function, instance, args, kwargs
6363
): # pylint: disable=unused-argument
6464
if not is_existing_profile(kwargs["profile_name"]):
65-
raise ValueError("Invalid profile provided: {}".format(kwargs["profile_name"]))
65+
raise ValueError(f"Invalid profile provided: {kwargs['profile_name']}")
6666

6767
return wrapped_function(*args, **kwargs)
6868

@@ -72,6 +72,6 @@ def valid_aws_region(
7272
wrapped_function, instance, args, kwargs
7373
): # pylint: disable=unused-argument
7474
if not is_existing_region(kwargs["region_name"]):
75-
raise ValueError("Invalid region provided: {}".format(kwargs["region_name"]))
75+
raise ValueError(f"Invalid region provided: {kwargs['region_name']}")
7676

7777
return wrapped_function(*args, **kwargs)

aws_gate/exec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def exec(
6262

6363
instance_id = query_instance(name=instance, ec2=ec2)
6464
if instance_id is None:
65-
raise ValueError("No instance could be found for name: {}".format(instance))
65+
raise ValueError(f"No instance could be found for name: {instance}")
6666

6767
logger.info(
6868
'Executing command "%s" on instance %s (%s) via profile %s',

aws_gate/list.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ def list_instances(
7272
):
7373
invalid_fields = list(set(fields) - set(DEFAULT_LIST_OUTPUT_FIELDS))
7474
if invalid_fields:
75+
invalid_fields_str = " ".join(invalid_fields)
76+
default_fields_str = " ".join(DEFAULT_LIST_OUTPUT_FIELDS)
77+
7578
raise ValueError(
76-
'Invalid fields provided: "{}". Valid fields: "{}"'.format(
77-
" ".join(invalid_fields), " ".join(DEFAULT_LIST_OUTPUT_FIELDS)
78-
)
79+
f'Invalid fields provided: "{invalid_fields_str}". Valid fields: "{default_fields_str}"' # noqa: B950
7980
)
8081

8182
ssm = get_aws_client("ssm", region_name=region_name, profile_name=profile_name)

aws_gate/query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ def getinstanceidbytag(name, ec2=None):
6767
else:
6868
key, value = name.split(":", 1)
6969

70-
filters = [{"Name": "tag:{}".format(key), "Values": [value]}]
70+
filters = [{"Name": f"tag:{key}", "Values": [value]}]
7171
return _query_aws_api(filters=filters, ec2=ec2)
7272

7373

7474
def getinstanceidbyinstancename(name, ec2=None):
75-
return getinstanceidbytag("Name:{}".format(name), ec2=ec2)
75+
return getinstanceidbytag(f"Name:{name}", ec2=ec2)
7676

7777

7878
def getinstanceidbyautoscalinggroup(name, ec2=None):
7979
_, asg_name = name.split(":")
80-
return getinstanceidbytag("aws:autoscaling:groupName:{}".format(asg_name), ec2=ec2)
80+
return getinstanceidbytag(f"aws:autoscaling:groupName:{asg_name}", ec2=ec2)
8181

8282

8383
def query_instance(name, ec2=None):

aws_gate/session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def session(
5353

5454
instance_id = query_instance(name=instance, ec2=ec2)
5555
if instance_id is None:
56-
raise ValueError("No instance could be found for name: {}".format(instance))
56+
raise ValueError(f"No instance could be found for name: {instance}")
5757

5858
logger.info(
5959
"Opening session on instance %s (%s) via profile %s",

0 commit comments

Comments
 (0)