bool IotRoleCredentialsProvider::ValidateResponse()

in aws_common/src/sdk_utils/auth/service_credentials_provider.cpp [356:402]


bool IotRoleCredentialsProvider::ValidateResponse(Aws::Utils::Json::JsonValue & value)
{
  if (!value.WasParseSuccessful()) {
    AWS_LOG_ERROR(AWS_LOG_TAG, "Unable to parse JSON response from AWS IoT credential provider");
    return false;
  }

  auto value_view = value.View();
  if (!value_view.ValueExists(FIELD_CREDENTIALS)) {
    AWS_LOG_ERROR(AWS_LOG_TAG, "Unable to find %s field in AWS IoT credential provider response",
                  FIELD_CREDENTIALS);
    return false;
  }

  auto creds = value_view.GetObject(FIELD_CREDENTIALS);

  if (!creds.IsObject()) {
    AWS_LOG_ERROR(AWS_LOG_TAG, "Expected object for %s in AWS IoT credential provider response",
                  FIELD_CREDENTIALS);
    return false;
  }

  if (!creds.ValueExists(FIELD_EXPIRATION)) {
    AWS_LOG_ERROR(AWS_LOG_TAG, "Unable to find %s field in AWS IoT credential provider response",
                  FIELD_EXPIRATION)
    return false;
  }

  if (!creds.ValueExists(FIELD_ACCESS_KEY)) {
    AWS_LOG_ERROR(AWS_LOG_TAG, "Unable to find %s field in AWS IoT credentials", FIELD_ACCESS_KEY);
    return false;
  }

  if (!creds.ValueExists(FIELD_SECRET_KEY)) {
    AWS_LOG_ERROR(AWS_LOG_TAG, "Unable to find %s in AWS IoT credentials", FIELD_SECRET_KEY);
    return false;
  }

  if (!creds.ValueExists(FIELD_SESSION_TOKEN)) {
    AWS_LOG_ERROR(AWS_LOG_TAG, "Unable to find %s in AWS IoT credentials", FIELD_SESSION_TOKEN);
    return false;
  }

  AWS_LOG_INFO(AWS_LOG_TAG, "Found valid credentials response from IoT");

  return true;
}