コード例 #1
0
ファイル: grok_server.py プロジェクト: darian19/what
def setupYOMPAWSCredentials(publicDnsName, config):
  """
    Using the YOMP CLI, connect to YOMP to obtain the API Key for the instance.

    :param publicDnsName: A reachable DNS entry for the YOMP server that needs
      to be configured

    :param config: A dict containing values for `AWS_ACCESS_KEY_ID`
      and `AWS_SECRET_ACCESS_KEY`

    :raises: infrastructure.utilities.exceptions.YOMPConfigError if
      it is unable to obtain the API Key

    :returns: The API Key of the YOMP server
  """
  credentials = {
    "aws_access_key_id": config["AWS_ACCESS_KEY_ID"],
    "aws_secret_access_key": config["AWS_SECRET_ACCESS_KEY"]
  }
  server = "https://%s" % publicDnsName
  YOMP = YOMPSession(server=server)
  YOMP.apikey = YOMP.verifyCredentials(**credentials)
  if YOMP.apikey:
    YOMP.updateSettings(settings=credentials, section="aws")
    return YOMP.apikey
  else:
    raise YOMPConfigError("Unable to obtain YOMP API Key")
コード例 #2
0
def setupYOMPAWSCredentials(publicDnsName, config):
    """
    Using the YOMP CLI, connect to YOMP to obtain the API Key for the instance.

    :param publicDnsName: A reachable DNS entry for the YOMP server that needs
      to be configured

    :param config: A dict containing values for `AWS_ACCESS_KEY_ID`
      and `AWS_SECRET_ACCESS_KEY`

    :raises: infrastructure.utilities.exceptions.YOMPConfigError if
      it is unable to obtain the API Key

    :returns: The API Key of the YOMP server
  """
    credentials = {
        "aws_access_key_id": config["AWS_ACCESS_KEY_ID"],
        "aws_secret_access_key": config["AWS_SECRET_ACCESS_KEY"]
    }
    server = "https://%s" % publicDnsName
    YOMP = YOMPSession(server=server)
    YOMP.apikey = YOMP.verifyCredentials(**credentials)
    if YOMP.apikey:
        YOMP.updateSettings(settings=credentials, section="aws")
        return YOMP.apikey
    else:
        raise YOMPConfigError("Unable to obtain YOMP API Key")
コード例 #3
0
ファイル: credentials.py プロジェクト: bopopescu/what
def handle(options, args):
  """ `YOMP credentials` handler.  Extracts credentials from command-line
  interface, updates YOMP server using web API. """
  try:
    server = args.pop(0)
  except IndexError:
    parser.print_help(sys.stderr)
    sys.exit(1)

  if not options.acceptEULA:
    print >> sys.stderr, (
            "Please read and accept the product End User License Agreement "
            "(EULA) before proceeding.\n"
            "The EULA can be found here: "
            "https://aws.amazon.com/marketplace/agreement?asin=B00I18SNQ6\n\n"
            "To accept the EULA, re-run this command with the "
            "--accept-eula option.")
    sys.exit(1)

  credentials = {
    "aws_access_key_id": options.AWS_ACCESS_KEY_ID,
    "aws_secret_access_key": options.AWS_SECRET_ACCESS_KEY
  }

  if options.data:
    if options.data.strip() == "-":
      updateCredentialsFromFile(sys.stdin, credentials)
    elif options.data:
      with open(options.data, "r") as fp:
        updateCredentialsFromFile(fp, credentials)
  elif options.use_boto:
    updateCredentialsFromBoto(credentials)

  if not (credentials["aws_access_key_id"] and
          credentials["aws_secret_access_key"]):
    parser.print_help(sys.stderr)
    sys.exit(1)

  usertrack = {
    "optin": "false" if options.optOutOfDataCollection else "true"
  }

  YOMP = YOMPSession(server=server)
  YOMP.apikey = YOMP.verifyCredentials(**credentials)
  YOMP.updateSettings(settings=credentials, section="aws")
  YOMP.updateSettings(settings=usertrack, section="usertrack")
  print YOMP.apikey