def configure()

in tasks/devtool.py [0:0]


def configure(_,
              profile=None,
              cluster_name=None,
              cluster_s3_bucket=None,
              aws_profile=None,
              aws_region=None,
              bastion_ip=None,
              ssh_key_file=None):
    # type: (Context, str, str, str, str, str, str, str) -> None
    """
    configure devtool
    :param _: Context
    :param profile: name of the idea configuration profile
    :param cluster_name: name of the idea cluster
    :param cluster_s3_bucket: name of the idea cluster
    :param aws_profile: name of the aws-cli profile to be used to access the AWS account. eg. default
    :param aws_region: name of the aws-region eg. us-west-2
    :param bastion_ip: Workstation IP address to SSH into the cluster.
    :param ssh_key_file: path to the SSH Key file to access the cluster nodes. ~/.ssh/my-key.pem
    """
    if profile is None:
        profile = 'default'

    if os.path.isfile(idea.props.idea_user_config_file):
        with open(idea.props.idea_user_config_file, 'r') as f:
            user_config = yaml.safe_load(f)
    else:
        user_config = {}

    if 'profiles' in user_config:
        profiles_config = user_config.get('profiles')
    else:
        profiles_config = {}
        user_config['profiles'] = profiles_config

    if profile in profiles_config:
        profile_config = profiles_config.get(profile)
    else:
        profile_config = {}
        profiles_config[profile] = profile_config

    if cluster_name is None:
        if 'cluster_name' in profile_config:
            cluster_name = profile_config.get('cluster_name')
        if cluster_name is None:
            cluster_name = ''
    if cluster_s3_bucket is None:
        if 'cluster_s3_bucket' in profile_config:
            cluster_s3_bucket = profile_config.get('cluster_s3_bucket')
        if cluster_s3_bucket is None:
            cluster_s3_bucket = ''
    if aws_profile is None:
        if 'aws_profile' in profile_config:
            aws_profile = profile_config.get('aws_profile')
        if aws_profile is None:
            aws_profile = ''
    if aws_region is None:
        if 'aws_region' in profile_config:
            aws_region = profile_config.get('aws_region')
        if aws_region is None:
            aws_region = ''
    if bastion_ip is None:
        if 'bastion_ip' in profile_config:
            bastion_ip = profile_config.get('bastion_ip')
        if bastion_ip is None:
            bastion_ip = ''
    if ssh_key_file is None:
        if 'ssh_key_file' in profile_config:
            ssh_key_file = profile_config.get('ssh_key_file')
        if ssh_key_file is None:
            ssh_key_file = ''

    questions = []
    if profile is None:
        questions.append({
            'type': 'text',
            'name': 'profile',
            'message': 'Enter the name of the profile',
            'default': profile
        })
    questions.append({
        'type': 'text',
        'name': 'cluster_name',
        'message': 'Enter the cluster name',
        'default': cluster_name
    })
    questions.append({
        'type': 'text',
        'name': 'aws_profile',
        'message': 'Enter the AWS CLI profile name',
        'default': aws_profile
    })
    questions.append({
        'type': 'text',
        'name': 'aws_region',
        'message': 'Enter the AWS Region name',
        'default': aws_region
    })
    questions.append({
        'type': 'text',
        'name': 'bastion_ip',
        'message': 'Enter the IP address of the workstation ',
        'default': bastion_ip
    })
    questions.append({
        'type': 'text',
        'name': 'ssh_key_file',
        'message': 'Enter path of the SSH Key File',
        'default': ssh_key_file
    })
    questions.append({
        'type': 'text',
        'name': 'cluster_s3_bucket',
        'message': 'Enter the name of the S3 bucket for the cluster',
        'default': cluster_s3_bucket
    })
    result = idea.console.ask(questions=questions)

    profile_config = {**profile_config, **result}
    profiles_config[profile] = profile_config

    with open(idea.props.idea_user_config_file, 'w') as f:
        f.write(yaml.safe_dump(user_config))

    idea.console.info(f'config file updated: {idea.props.idea_user_config_file}')