Esempio n. 1
0
def setupGrokAWSCredentials(publicDnsName, config):
  """
    Using the Grok CLI, connect to Grok to obtain the API Key for the instance.

    :param publicDnsName: A reachable DNS entry for the Grok 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.GrokConfigError if
      it is unable to obtain the API Key

    :returns: The API Key of the Grok server
  """
  credentials = {
    "aws_access_key_id": config["AWS_ACCESS_KEY_ID"],
    "aws_secret_access_key": config["AWS_SECRET_ACCESS_KEY"]
  }
  server = "https://%s" % publicDnsName
  grok = GrokSession(server=server)
  grok.apikey = grok.verifyCredentials(**credentials)
  if grok.apikey:
    grok.updateSettings(settings=credentials, section="aws")
    return grok.apikey
  else:
    raise GrokConfigError("Unable to obtain Grok API Key")
def setupHTMITAWSCredentials(publicDnsName, config):
    """
    Using the HTM-IT CLI, connect to HTM-IT to obtain the API Key
    for the instance.

    :param publicDnsName: A reachable DNS entry for the HTM-IT
      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.HTMITConfigError: if
      it is unable to obtain the API Key

    :returns: The API Key of the HTM-IT server
  """
    credentials = {
        "aws_access_key_id": config["AWS_ACCESS_KEY_ID"],
        "aws_secret_access_key": config["AWS_SECRET_ACCESS_KEY"],
    }
    server = "https://%s" % publicDnsName
    htmIt = GrokSession(server=server)
    htmIt.apikey = htmIt.verifyCredentials(**credentials)
    if htmIt.apikey:
        htmIt.updateSettings(settings=credentials, section="aws")
        return htmIt.apikey
    else:
        raise HTMITConfigError("Unable to obtain HTM-IT API Key")
Esempio n. 3
0
def handle(options, args):
    """ `grok credentials` handler.  Extracts credentials from command-line
  interface, updates Grok 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"
    }

    grok = GrokSession(server=server)
    grok.apikey = grok.verifyCredentials(**credentials)
    grok.updateSettings(settings=credentials, section="aws")
    grok.updateSettings(settings=usertrack, section="usertrack")
    print grok.apikey
Esempio n. 4
0
def handle(options, args):
  """ `grok credentials` handler.  Extracts credentials from command-line
  interface, updates Grok 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"
  }

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