Esempio n. 1
0
def get_user_password(args):
    """
    Allows the user to print the credential for a particular keyring entry
    to the screen
    """
    username = '******' % (args.env, args.parameter)

    warnstring = rwrap("__ WARNING ".ljust(80, '_'))
    print """
%s

If this operation is successful, the credential stored for this username will
be displayed in your terminal as PLAIN TEXT:

  %s

Seriously.  It will just be hanging out there for anyone to see.  If you have
any concerns about having this credential displayed on your screen, press
CTRL-C right now.

%s
""" % (warnstring, username, warnstring)
    print "If you are completely sure you want to display it, type 'yes' and "\
          "press enter:",
    try:
        confirm = raw_input('')
    except:
        print ""
        sys.exit()

    if confirm != 'yes':
        print "\n[%s] Your keyring was not read or altered." % (
            rwrap("Canceled"))
        return False

    try:
        password = password_get(username)
    except:
        password = None

    if password:
        print """
[%s] Found credentials for %s: %s
""" % (
            gwrap("Success"), username, password)
        return True
    else:
        print """
[%s] Unable to retrieve credentials for %s.

It's likely that there aren't any credentials stored for this environment and
parameter combination.  If you want to set a credential, just run this command:

  supernova-keyring -s %s %s
""" % (rwrap("Failed"), username, args.env, args.parameter)
        return False
Esempio n. 2
0
def set_user_password(args):
    """
    Sets a user's password in the keyring storage
    """
    print """
[%s] Preparing to set a password in the keyring for:

  - Environment  : %s
  - Parameter    : %s

If this is correct, enter the corresponding credential to store in your keyring
or press CTRL-D to abort:""" % (gwrap("Keyring operation"), args.env,
                                args.parameter)

    # Prompt for a password and catch a CTRL-D
    try:
        password = getpass.getpass('')
    except:
        password = None
        print

    # Did we get a password from the prompt?
    if not password or len(password) < 1:
        print "\n[%s] No data was altered in your keyring.\n" % (
            rwrap("Canceled"))
        sys.exit()

    # Try to store the password
    username = '******' % (args.env, args.parameter)
    try:
        store_ok = password_set(username, password)
    except:
        store_ok = False

    if store_ok:
        print "[%s] Successfully stored credentials for %s under the " \
              "supernova service.\n" % (gwrap("Success"), username)
    else:
        print "[%s] Unable to store credentials for %s under the " \
              "supernova service.\n" % (rwrap("Failed"), username)
Esempio n. 3
0
def warn_missing_nova_args():
    """
    Provides a friendly warning for users who forget to provide commands to
    be passed on to nova.
    """
    msg = """
[%s] No arguments were provided to pass along to nova.
The supernova script expects to get commands structured like this:

  supernova [environment] [command]

Here are some example commands that may help you get started:

  supernova prod list
  supernova prod image-list
  supernova prod keypair-list
"""
    print msg % rwrap('Missing arguments')
Esempio n. 4
0
def load_supernova_config():
    """
    Pulls the supernova configuration file and reads it
    """
    xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or \
                      os.path.expanduser('~/.config')
    possible_configs = [os.path.join(xdg_config_home, "supernova"),
                        os.path.expanduser("~/.supernova"),
                        ".supernova"]
    supernova_config = ConfigParser.RawConfigParser()

    # Can we successfully read the configuration file?
    try:
        supernova_config.read(possible_configs)
    except:
        msg = """
[%s] A valid supernova configuration file is required.
Ensure that you have a properly configured supernova configuration file called
'.supernova' in your home directory or in your current working directory.
""" % rwrap('Invalid configuration file')
        print msg
        sys.exit(1)

    return supernova_config