def cmk_key_check()

in eksupdate/src/preflight_module.py [0:0]


def cmk_key_check(log_details,errors,cluster_name,region,cluster,report,customer_report):
    loading_config(cluster_name,region)
    cmk  = boto3.client('kms',region_name  = region)
    print('\n')
    log_pusher(log_details,cluster_name,region,'Checking if customer management key exists....')
    print('Checking if customer management key exists....')
    try : 
        if 'encryptionConfig' in cluster['cluster'].keys():
            cmk_key = cluster['cluster']['encryptionConfig'][0]['provider']['keyArn']
            customer_report['CMK Key'] = 'CMK Key with id ' + cmk_key + ' is present'
            log_pusher(log_details,cluster_name,region,'CMK Key with id ' + cmk_key + ' is present')
            print('CMK Key with id ' + cmk_key + ' is present')
            response = cmk.describe_key(
            KeyId=cmk_key,
            )
            try : 
                response = cmk.describe_key(
                KeyId=cmk_key,
                )
                if 'KeyId' in response['KeyMetadata'].keys() :
                    log_pusher(log_details,cluster_name,region,'Key with id ' + cmk_key + " exist in user account") 
                    customer_report['CMK Key'] = 'Key with id ' + cmk_key + " exist in user account"
                    print('Key with id ' + cmk_key + " exist in user account")
                else : 
                    report['preflight_status'] = False
                    errors.append('Key with id ' + cmk_key + " doesnt exist in user account")
                    log_pusher(log_details,cluster_name,region,'Key with id ' + cmk_key + " doesnt exist in user account")
                    customer_report['CMK Key'] ='Key with id ' + cmk_key + " doesnt exist in user account"
                    print('Key with id ' + cmk_key + " doesnt exist in user account")
            except : 
                report['preflight_status'] = False
                errors.append('Key with id ' + cmk_key + " doesnt exist in user account")
                log_pusher(log_details,cluster_name,region,'Key with id ' + cmk_key + " doesnt exist in user account")
                customer_report['CMK Key'] ='Key with id ' + cmk_key + " doesnt exist in user account"
                print('Key with id ' + cmk_key + " doesnt exist in user account")
        else : 
            customer_report['CMK Key'] = 'No CMK Key associated with the cluster'
            log_pusher(log_details,cluster_name,region,'No CMK Key associated with the cluster')
            print('No CMK Key associated with the cluster')
    except Exception as e : 
        
        errors.append('Error while checking for cluster CMK key {err}'.format(err=e))
        customer_report['CMK Key'] = 'Error while checking for cluster CMK key'
        log_pusher(log_details,cluster_name,region,'Error while checking for cluster CMK key {err}'.format(err=e))
        print('Error while checking for cluster CMK key {err}'.format(err=e))
        report['preflight_status'] = False