Browse code

Fixes #1094 - Fixes typo bug + mini cleanup

Florent Viard authored on 2020/04/27 08:10:02
Showing 1 changed files
... ...
@@ -305,8 +305,6 @@ class Config(object):
305 305
             elif not os.path.isfile(aws_credential_file):
306 306
                 return
307 307
 
308
-            warning("Errno %d accessing credentials file %s" % (e.errno, aws_credential_file))
309
-
310 308
             config = PyConfigParser()
311 309
 
312 310
             debug("Reading AWS credentials from %s" % (aws_credential_file))
... ...
@@ -319,8 +317,9 @@ class Config(object):
319 319
                     # but so far readfp it is still available.
320 320
                     config.readfp(io.StringIO(config_string))
321 321
                 except MissingSectionHeaderError:
322
-                    # if header is missing, this could be deprecated credentials file format
323
-                    # as described here: https://blog.csanchez.org/2011/05/
322
+                    # if header is missing, this could be deprecated
323
+                    # credentials file format as described here:
324
+                    # https://blog.csanchez.org/2011/05/
324 325
                     # then do the hacky-hack and add default header
325 326
                     # to be able to read the file with PyConfigParser()
326 327
                     config_string = u'[default]\n' + config_string
... ...
@@ -334,48 +333,64 @@ class Config(object):
334 334
             debug("Using AWS profile '%s'" % (profile))
335 335
 
336 336
             # get_key - helper function to read the aws profile credentials
337
-            # including the legacy ones as described here: https://blog.csanchez.org/2011/05/
337
+            # including the legacy ones as described here:
338
+            # https://blog.csanchez.org/2011/05/
338 339
             def get_key(profile, key, legacy_key, print_warning=True):
339 340
                 result = None
340 341
 
341 342
                 try:
342 343
                     result = config.get(profile, key)
343 344
                 except NoOptionError as e:
344
-                    if print_warning: # we may want to skip warning message for optional keys
345
-                        warning("Couldn't find key '%s' for the AWS Profile '%s' in the credentials file '%s'" % (e.option, e.section, aws_credential_file))
346
-                    if legacy_key: # if the legacy_key defined and original one wasn't found, try read the legacy_key
345
+                    # we may want to skip warning message for optional keys
346
+                    if print_warning:
347
+                        warning("Couldn't find key '%s' for the AWS Profile "
348
+                                "'%s' in the credentials file '%s'",
349
+                                e.option, e.section, aws_credential_file)
350
+                    # if the legacy_key defined and original one wasn't found,
351
+                    # try read the legacy_key
352
+                    if legacy_key:
347 353
                         try:
348 354
                             key = legacy_key
349 355
                             profile = "default"
350 356
                             result = config.get(profile, key)
351 357
                             warning(
352
-                                    "Legacy configuratin key '%s' used, " % (key) +
353
-                                    "please use the standardized config format as described here: " +
354
-                                    "https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/"
355
-                                     )
358
+                                "Legacy configuratin key '%s' used, please use"
359
+                                " the standardized config format as described "
360
+                                "here: https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/",
361
+                                key)
356 362
                         except NoOptionError as e:
357 363
                             pass
358 364
 
359 365
                 if result:
360
-                    debug("Found the configuration option '%s' for the AWS Profile '%s' in the credentials file %s" % (key, profile, aws_credential_file))
366
+                    debug("Found the configuration option '%s' for the AWS "
367
+                          "Profile '%s' in the credentials file %s",
368
+                          key, profile, aws_credential_file)
361 369
                 return result
362 370
 
363
-            profile_access_key = get_key(profile, "aws_access_key_id", "AWSAccessKeyId")
371
+            profile_access_key = get_key(profile, "aws_access_key_id",
372
+                                         "AWSAccessKeyId")
364 373
             if profile_access_key:
365
-                Config().update_option('access_key', config_unicodise(profile_access_key))
374
+                Config().update_option('access_key',
375
+                                       config_unicodise(profile_access_key))
366 376
 
367
-            profile_secret_key = get_key(profile, "aws_secret_access_key", "AWSSecretKey")
377
+            profile_secret_key = get_key(profile, "aws_secret_access_key",
378
+                                         "AWSSecretKey")
368 379
             if profile_secret_key:
369
-                Config().update_option('secret_key', config_unicodise(profile_secret_key))
380
+                Config().update_option('secret_key',
381
+                                       config_unicodise(profile_secret_key))
370 382
 
371
-            profile_access_token = get_key(profile, "aws_session_token", None, False)
383
+            profile_access_token = get_key(profile, "aws_session_token", None,
384
+                                           False)
372 385
             if profile_access_token:
373
-                Config().update_option('access_token', config_unicodise(profile_access_token))
386
+                Config().update_option('access_token',
387
+                                       config_unicodise(profile_access_token))
374 388
 
375 389
         except IOError as e:
376
-            warning("Errno %d accessing credentials file %s" % (e.errno, aws_credential_file))
390
+            warning("Errno %d accessing credentials file %s", e.errno,
391
+                    aws_credential_file)
377 392
         except NoSectionError as e:
378
-            warning("Couldn't find AWS Profile '%s' in the credentials file '%s'" % (profile, aws_credential_file))
393
+            warning("Couldn't find AWS Profile '%s' in the credentials file "
394
+                    "'%s'", profile, aws_credential_file)
379 395
 
380 396
     def option_list(self):
381 397
         retval = []