コード例 #1
0
def trim_aws_credential_file(location, param_list, quiet = False):
    try:
        log.info(u'Trimming AWS credential file: "{0}"'.format(location))
        parser = NoSectionConfigParser()
        try:
            parser.read(location)
        except IOError as ex:
            return # File not exists
        
        for name in param_list:
            parser.remove_option(name)
        
        parser.write(location)
        log.info(u'Finished trimming AWS credential file.')
                
        # Set access permission
        set_access_permission(location, False)
        log.info(u'Set AWS credential file access permission.')
        
    except BaseException as ex:
        log.error(u'Failed to trim AWS credential file at "{0}", because: "{1}"'.\
                  format(location, ex))
        msg = CredentialFileErrorMessage.WriteError.format(location)
        prompt.error(msg)
        if not quiet:
            raise EBSCliException(msg)
        else:          
            return False # if failed, just skip 
コード例 #2
0
def write_aws_credential_file(location,
                              parameter_pool,
                              func_matrix,
                              quiet=False):
    try:
        log.info(u'Writing AWS credential to file: "{0}"'.format(location))
        parser = NoSectionConfigParser()
        try:
            parser.read(location)
        except IOError as ex:
            pass  # No existing file

        for branch, name, to_file_func in func_matrix:
            if branch:
                value = parameter_pool.get_value(ParameterName.Branches,
                                                 False)[branch][name]
                env_name = parameter_pool.get_value(ParameterName.Branches, False)[branch]\
                    [ParameterName.EnvironmentName]
            else:
                value = parameter_pool.get_value(name, False)
                env_name = parameter_pool.get_value(
                    ParameterName.EnvironmentName, False)

            if to_file_func:
                value = to_file_func(value)

            if name == ParameterName.RdsMasterPassword:
                key_name = rds_utils.password_key_name(env_name)
            else:
                key_name = AwsCredentialFileDefault.KeyName[name]
            parser.set(key_name, value)

        parser.write(location)
        log.info(u'Finished writing AWS credential to file.')

        # Set access permission
        set_access_permission(location, False)
        log.info(u'Set AWS credential file access permission.')

    except BaseException as ex:
        log.error(u'Failed to update AWS credential file at "{0}", because: "{1}"'.\
                  format(location, ex))
        msg = CredentialFileErrorMessage.WriteError.format(location)
        prompt.error(msg)
        if not quiet:
            raise EBSCliException(msg)
        else:
            return False  # if failed, just skip
コード例 #3
0
def write_aws_credential_file(location, parameter_pool, 
                              func_matrix,
                              quiet = False):
    try:
        log.info(u'Writing AWS credential to file: "{0}"'.format(location))
        parser = NoSectionConfigParser()
        try:
            parser.read(location)
        except IOError as ex:
            pass # No existing file
        
        for branch, name, to_file_func in func_matrix:
            if branch:
                value = parameter_pool.get_value(ParameterName.Branches)[branch][name]
                env_name = parameter_pool.get_value(ParameterName.Branches)[branch]\
                    [ParameterName.EnvironmentName]       
            else:
                value = parameter_pool.get_value(name)
                env_name = parameter_pool.get_value(ParameterName.EnvironmentName)       
            
            if to_file_func:
                value = to_file_func(value) 

            if name == ParameterName.RdsMasterPassword:
                key_name = rds_utils.password_key_name(env_name)
            else:
                key_name = AwsCredentialFileDefault.KeyName[name]
            parser.set(key_name, value)
        
        parser.write(location)
        log.info(u'Finished writing AWS credential to file.')
                
        # Set access permission
        set_access_permission(location, False)
        log.info(u'Set AWS credential file access permission.')
        
    except BaseException as ex:
        log.error(u'Failed to update AWS credential file at "{0}", because: "{1}"'.\
                  format(location, ex))
        msg = CredentialFileErrorMessage.WriteError.format(location)
        prompt.error(msg)
        if not quiet:
            raise EBSCliException(msg)
        else:          
            return False # if failed, just skip 
コード例 #4
0
ファイル: config_file.py プロジェクト: basilbeltran/bashitol
def save_eb_config_file(location, parameter_pool, quiet = False):
    try:
        log.info('Writing EB configuration to file: "{0}"'.format(location))
        parser = NoSectionConfigParser()

        for (name, _, to_file) in ConfigFileParameters:
            if parameter_pool.has(name):
                value = parameter_pool.get_value(name)
                if to_file is not None:
                    value = to_file(value)
                parser.set(name, value)

        parser.write(location)
        log.info('Finished writing EB configuration file.')
        
    except BaseException as ex:
        log.error('Failed to save EB configuration file, because: "{0}"'.format(ex))
        prompt.error(ConfigFileErrorMessage.WriteError.format(location))        
        raise
コード例 #5
0
ファイル: config_file.py プロジェクト: eduardog/aws-toolbox
def save_eb_config_file(location, parameter_pool, quiet=False):
    try:
        log.info(u'Writing EB configuration to file: "{0}"'.format(location))
        parser = NoSectionConfigParser()

        for (name, _, to_file) in ConfigFileParameters:
            if parameter_pool.has(name):
                value = parameter_pool.get_value(name)
                if to_file is not None:
                    value = to_file(value)
                parser.set(name, value)

        parser.write(location)
        log.info(u'Finished writing EB configuration file.')

    except BaseException as ex:
        log.error(
            u'Failed to save EB configuration file, because: "{0}"'.format(ex))
        prompt.error(ConfigFileErrorMessage.WriteError.format(location))
        raise