Exemplo n.º 1
0
def main():
    args = parse_arguments()
    config = import_config(args.config_file)

    pillar_periodic = config.get('repo', 'pillar_periodic')
    gitlab_token = config.get('gitlab', 'token')
    gitlab_url = config.get('gitlab', 'url')
    role_account_name = args.account_name

    if args.account_email:
        email = args.account_email
    else:
        email = None

    if args.password:
        password = args.password
    else:
        password = generate_random_password(args.random_password_length)

    try:
        assert os.path.isdir(pillar_periodic)
    except:
        print "Unable to located pillar_periodic directory"
        sys.exit(1)

    try:
        repo = git.cmd.Git(pillar_periodic)
        repo.pull()
    except:
        e = sys.exc_info()[0]
        print "Failed to pull down changes to pillar_periodic, error: {}".format(
            e)
        sys.exit(1)

    ssh_path = os.path.join(pillar_periodic, "core/accountz/ssh_auth.sls")
    user_path = os.path.join(pillar_periodic, "core/accountz/users.sls")

    # Okay lets create this account
    gl_connection = CreateRoleAccount(user_path,
                                      ssh_path,
                                      account_name=role_account_name,
                                      account_password=password,
                                      account_email=email,
                                      gitlab_key=gitlab_token,
                                      gitlab_url=gitlab_url)

    gl_connection.convert_to_api()
    role_user_id = gl_connection.send_to_gitlab()

    if gl_connection.verify_create(role_user_id):
        print "{} Role user successfully created".format(role_account_name)
        try:
            print "The random password is {}".format(password)
        except:
            pass
    else:
        print "{} Role user not created".format(role_account_name)
Exemplo n.º 2
0
def main():
    args = parse_arguments()
    config = import_config(args.config_file)

    pillar_periodic = config.get('repo', 'pillar_periodic')
    gitlab_token = config.get('gitlab', 'token')
    gitlab_url = config.get('gitlab', 'url')
    role_account_name = args.account_name

    if args.account_email:
        email = args.account_email
    else:
        email = None

    if args.password:
        password = args.password
    else:
        password = generate_random_password(args.random_password_length)

    try:
        assert os.path.isdir(pillar_periodic)
    except:
        print "Unable to located pillar_periodic directory"
        sys.exit(1)

    try:
        repo = git.cmd.Git(pillar_periodic)
        repo.pull()
    except:
        e = sys.exc_info()[0]
        print "Failed to pull down changes to pillar_periodic, error: {}".format(e)
        sys.exit(1)

    ssh_path = os.path.join(pillar_periodic, "core/accountz/ssh_auth.sls")
    user_path = os.path.join(pillar_periodic, "core/accountz/users.sls")

    # Okay lets create this account
    gl_connection = CreateRoleAccount(user_path, ssh_path, account_name=role_account_name,
                                      account_password=password, account_email=email, gitlab_key=gitlab_token,
                                      gitlab_url=gitlab_url)

    gl_connection.convert_to_api()
    role_user_id = gl_connection.send_to_gitlab()

    if gl_connection.verify_create(role_user_id):
        print "{} Role user successfully created".format(role_account_name)
        try:
            print "The random password is {}".format(password)
        except:
            pass
    else:
        print "{} Role user not created".format(role_account_name)