Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/configure/__init__.py
1567 views
1
# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
import string
14
from awscli.compat import shlex
15
16
NOT_SET = '<not set>'
17
PREDEFINED_SECTION_NAMES = ('preview', 'plugins')
18
_WHITESPACE = ' \t'
19
20
21
class ConfigValue(object):
22
23
def __init__(self, value, config_type, config_variable):
24
self.value = value
25
self.config_type = config_type
26
self.config_variable = config_variable
27
28
def mask_value(self):
29
if self.value is NOT_SET:
30
return
31
self.value = mask_value(self.value)
32
33
34
class SectionNotFoundError(Exception):
35
pass
36
37
38
def mask_value(current_value):
39
if current_value is None:
40
return 'None'
41
else:
42
return ('*' * 16) + current_value[-4:]
43
44
45
def profile_to_section(profile_name):
46
"""Converts a profile name to a section header to be used in the config."""
47
if any(c in _WHITESPACE for c in profile_name):
48
profile_name = shlex.quote(profile_name)
49
return 'profile %s' % profile_name
50
51