This file is indexed.

/usr/lib/python3/dist-packages/maascli/init.py is in python3-maas-client 2.4.0~beta2-6865-gec43e47e6-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
# Copyright 2012-2018 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Methods related to initializing a MAAS deployment."""

import argparse
import json
import os
import subprocess


def add_idm_options(parser):
    parser.add_argument(
        '--idm-url', default=None, metavar='IDM_URL',
        help=("The URL to the external IDM server to use for "
              "authentication."))
    parser.add_argument(
        '--idm-user', default=None,
        help="The username to access the IDM server API.")
    parser.add_argument(
        '--idm-key', default=None,
        help="The private key to access the IDM server API.")
    parser.add_argument(
        '--idm-agent-file', type=argparse.FileType('r'),
        help="Agent file containing IDM authentication information")


def add_create_admin_options(parser):
    parser.add_argument(
        '--admin-username', default=None, metavar='USERNAME',
        help="Username for the admin account.")
    parser.add_argument(
        '--admin-password', default=None, metavar='PASSWORD',
        help="Force a given admin password instead of prompting.")
    parser.add_argument(
        '--admin-email', default=None, metavar='EMAIL',
        help="Email address for the admin.")
    parser.add_argument(
        '--admin-ssh-import', default=None, metavar='LP_GH_USERNAME',
        help=(
            "Import SSH keys from Launchpad (lp:user-id) or "
            "Github (gh:user-id) for the admin."))


def create_admin_account(options):
    """Create the first admin account."""
    print_create_header = not all([
        options.admin_username,
        options.admin_password,
        options.admin_email])
    if print_create_header:
        print_msg('Create first admin account:')
    cmd = [get_maas_region_bin_path(), 'createadmin']
    if options.admin_username:
        cmd.extend(['--username', options.admin_username])
    if options.admin_password:
        cmd.extend(['--password', options.admin_password])
    if options.admin_email:
        cmd.extend(['--email', options.admin_email])
    if options.admin_ssh_import:
        cmd.extend(['--ssh-import', options.admin_ssh_import])
    subprocess.call(cmd)


def configure_authentication(options):
    cmd = [get_maas_region_bin_path(), 'configauth']
    if options.idm_url is not None:
        cmd.extend(['--idm-url', options.idm_url])
    if options.idm_user is not None:
        cmd.extend(['--idm-user', options.idm_user])
    if options.idm_key is not None:
        cmd.extend(['--idm-key', options.idm_key])
    if options.idm_agent_file is not None:
        cmd.extend(['--idm-agent-file', options.idm_agent_file.name])
    subprocess.call(cmd)


def get_maas_region_bin_path():
    maas_region = 'maas-region'
    if 'SNAP' in os.environ:
        maas_region = os.path.join(
            os.environ['SNAP'], 'bin', maas_region)
    return maas_region


def get_current_auth_config():
    cmd = [
        get_maas_region_bin_path(),
        'configauth', '--json']
    output = subprocess.check_output(cmd)
    return json.loads(output)


def print_msg(msg='', newline=True):
    """Print a message to stdout.

    Flushes the message to ensure its written immediately.
    """
    print(msg, end=('\n' if newline else ''), flush=True)


def init_maas(options):
        if options.enable_idm:
            print_msg('Configuring authentication')
            configure_authentication(options)
        auth_config = get_current_auth_config()
        skip_create_admin = (
            options.skip_admin or auth_config['external_auth_url'])
        if not skip_create_admin:
            create_admin_account(options)