#!/usr/bin/env python3

# usage: ./sunet-arista-sshkeys.py < ~/.ssh/authorized_keys > users_template.j2

def main():
    keydata = []
    # read stdin until end of file
    while True:
        try:
            line = input()
        except EOFError:
            break
        keydata.append(line)

    # print arista cli syntax users to stdout
    for line in keydata:
        if line.startswith("ssh-rsa"):
            _, key, descr = line.split()
            username = descr.split('@')[0].split('+')[0]
            print("username {} privilege 15 role network-admin secret *".format(username))
            print("username {} ssh-key ssh-rsa {} {}".format(username, key, descr))

if __name__ == "__main__":
    main()
