oracle/oci-typescript-sdk

Found line with no key-value pair: -----BEGIN RSA PRIVATE KEY-----

Closed this issue · 2 comments

export class OciMediaUploadFactory {
	authenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider('~/.oci/oci_api_key.pem');
	client = new os.ObjectStorageClient({ authenticationDetailsProvider: this.authenticationDetailsProvider });
	async uploadMedia({ file, fileName }: { file: any; fileName: string }) {
		const request: os.requests.GetNamespaceRequest = {};
		const response = await this.client.getNamespace(request);
		const namespace = response.value;

		const putObjectRequest: os.requests.PutObjectRequest = {
			namespaceName: namespace,
			bucketName: '---------',
			putObjectBody: file.buffer,
			objectName: fileName,
			contentLength: file.size,
		};

		return this.client.putObject(putObjectRequest);
	}
}

I am getting the following error

[Nest] 111916   - 05/27/2022, 4:51:09 PM   [ExceptionHandler] Found line with no key-value pair: -----BEGIN RSA PRIVATE KEY-----
Error: Found line with no key-value pair: -----BEGIN RSA PRIVATE KEY-----
    at ConfigAccumulator.accept (/home/shanurrahman/lib/config-file-reader.ts:188:13)
    at /home/shanurrahman/lib/config-file-reader.ts:104:19
    at Array.forEach (<anonymous>)
    at Function.parse (/home/shanurrahman/lib/config-file-reader.ts:103:11)
    at Function.parseFileFromPath (/home/shanurrahman/lib/config-file-reader.ts:95:31)
    at new ConfigFileAuthenticationDetailsProvider (/home/shanurrahman/lib/auth/config-file-auth.ts:38:26)
    at new OciMediaUploadFactory (/home/shanurrahman/penny/apps/api-v2/dist/webpack:/libs/api-utils/providers/oci/storage.ts:5:34)
    at new MediaUploadFactory (/home/shanurrahman/penny/apps/api-v2/dist/webpack:/libs/api-utils/base/factory/media-upload.factory.ts:21:13)
    at Injector.instantiateClass (/home/shanurrahman/penny/node_modules/@nestjs/core/injector/injector.js:286:19)
    at callback (/home/shanurrahman/penny/node_modules/@nestjs/core/injector/injector.js:42:41)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at Injector.resolveConstructorParams (/home/shanurrahman/penny/node_modules/@nestjs/core/injector/injector.js:114:24)
    at Injector.loadInstance (/home/shanurrahman/penny/node_modules/@nestjs/core/injector/injector.js:46:9)
    at Injector.loadProvider (/home/shanurrahman/penny/node_modules/@nestjs/core/injector/injector.js:68:9)
    at async Promise.all (index 4)

image

@shanurrahman I'm pretty sure this error is due to a problem with this line:
authenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider('~/.oci/oci_api_key.pem');

The ConfigFileAuthenticationDetailsProvider constructor should take the path to an OCI config file, not a private key file.

Can you try this instead?

authenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider('~/.oci/config');

Closing this since the solution is provided above and we haven't heard from you in 9 days, but feel free to reopen this if you are still facing issues