export async function testAwsConnection()

in aws-core-ui/src/Utilities/testAwsConnection.ts [14:47]


export async function testAwsConnection(formData: {
  [key: string]: string | null;
}): Promise<TestAwsConnectionResponse> {
  const responseStr = await post(url, formData);
  const response = new DOMParser().parseFromString(responseStr, 'text/xml');
  const errors = getErrorsFromResponseIfAny(response);
  const result: Element | undefined = parseResponse(
    response,
    'callerIdentity'
  )[0];
  if (result) {
    const account = result.getAttribute('accountId');
    const userId = result.getAttribute('userId');
    const arn = result.getAttribute('userArn');

    return {
      success: true,
      message: `${BASE_TEST_CONNECTION_PREFIX}Caller Identity:\n Account ID: ${account}\n User ID: ${userId}\n ARN: ${arn}`,
    };
  } else if (errors) {
    const message = Object.keys(errors)
      .map((key) => errors[key].message)
      .join('\n');
    return {
      success: false,
      message,
    };
  } else {
    return {
      success: false,
      message: `${BASE_TEST_CONNECTION_PREFIX}Could not get the Caller Identity information from the response.`,
    };
  }
}