oracle/oci-typescript-sdk

Error with SimpleAuthenticationDetailsProvider

Closed this issue · 8 comments

I'm creating a SimpleAuthenticationDetailsProvider because I'm using Vercel, but I'm getting an error.

Error:

{
  "code": undefined,
  "message": "Cannot parse host from url",
  "requestEndpoint": "GET /n/.../b/.../o",
  "troubleshootingPage": "See https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdk_troubleshooting.htm for help troubleshooting this error, or contact support and provide this full error message."
}

my function:

import * as os from "oci-objectstorage";
import * as common from "oci-common";
import path from "path";
import fs from "fs";

async function authUser() {
  const config = JSON.parse(await fs.promises.readFile(path.join(process.cwd(), "src/storage/oci.json"), "utf8"));
  const {
    tenancy,
    user,
    fingerprint,
    private_key,
    // region
  } = config;

  const provider = new common.SimpleAuthenticationDetailsProvider(tenancy, user, fingerprint, private_key, null);
  return new os.ObjectStorageClient({ authenticationDetailsProvider: provider });
}

Hi @Sirherobrine23, at which line of code does the error occur? From this example and the error message, it does not look like the error is occuring in this code snippet but rather somewhere else where your possibly making an API call with object storaoge? From the error, I can see the requestEndpoint does not look correct. It is missing https://

uploadFileToBucket function current no use.

My file:

import * as os from "oci-objectstorage";
import * as common from "oci-common";
import stream from "stream";
import path from "path";
import fs from "fs";

async function authUser() {
  const config = JSON.parse(await fs.promises.readFile(path.join(process.cwd(), "src/storage/oci.json"), "utf8"));
  const {
    tenancy,
    user,
    fingerprint,
    private_key
  } = config;
  // const region = "sa-saopaulo-1";

  const provider = new common.SimpleAuthenticationDetailsProvider(tenancy, user, fingerprint, private_key, null);
  return new os.ObjectStorageClient({ authenticationDetailsProvider: provider });
}

export async function uploadFileToBucket(fileBuffer: stream.Readable, fileName: string) {
  const putObjectResponse = await (await authUser()).putObject({
    bucketName: "...",
    namespaceName: "...",
    objectName: fileName,
    putObjectBody: fileBuffer
  });
  return putObjectResponse;
}

export async function getFiles() {
  const data = await (await authUser()).listObjects({
    bucketName: "...",
    namespaceName: "...",
  });
  return data.listObjects.objects.map(a => ({name: a.name, size: a.size}));
}

export async function getFileStream(objectName: string) {
  const file = (await getFiles()).find(obj => obj.name.endsWith(objectName));
  if (!file) throw new Error("Invalid file name");
  return await (await authUser()).getObject({
    bucketName: "...",
    namespaceName: "...",
    objectName: file.name
  });
}

My console log: log

is this issue in getFiles() as well? I see the error say its giving an error on a "GET" to '/n/.../b/.../o'. This makes me believe its failing on the getFiles() call.
What environment are you running the SDK in? Is it in NodeJS environment or Browser? Please note, our SDK do not support browser environment.

Nodejs (nextjs API)

Can you try providing a region when instantiating a new SimpleAuthenticationDetailsProvider object.
new common.SimpleAuthenticationDetailsProvider(tenancy, user, fingerprint, private_key, null, common.Region.SA_SAOPAULO_1)

worked, thank you.

Very thanks, now at least i have some feedback.
i had changed the retrier to:
console.warn(Request failed with Exception (jaime): ${JSON.stringify(lastKnownError)}\nRetrying request -> Total Attempts : ${waitContext.attemptCount}, Retrying after ${delayTime} seconds...);
to find out that was a host url parser error, and than i got here.
i still didnt fixed but i really find this error quite dificulty to track.