In the docs they said:
Oracle Cloud Infrastructure SDKs and CLI require basic configuration information, like user credentials and tenancy OCID. You can provide this information by: Using a configuration file; Declaring a configuration at runtime.
Also, here they said:
If you're using one of the Oracle SDKs or tools, supply the required credentials in either a configuration file or a config object in the code [...].
I would like to know how to provide that information in an object instead of a config file. I haven't found any examples.
I'm receiving account credentials information dynamically as strings, there are no config files.
Here is an example of my code:
import * as identity from "oci-identity"
import common = require("oci-common")
interface Account {
cliente: string,
cloud_provider: {
provider_name: string,
tenancy: string,
configFile: string,
keyFile: string
},
}
// Credentials
const provider: common.ConfigFileAuthenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider()
const client = new identity.IdentityClient({ authenticationDetailsProvider: this.provider });
const getTenancy = (accounts: Account) => {
// Create a request and dependent object(s).
const request: identity.requests.GetTenancyRequest = {
tenancyId: id
}
// Send request to the Client.
const response = await client.getTenancy(request)
}
const ids = ['id', 'id2', 'id3']
ids.forEach(id => {
getTenancy(id)
})
Answered on https://github.com/oracle/oci-typescript-sdk/issues/175.
In a nutshell, I needed to use SimpleAuthenticationDetailsProvider
instead of ConfigFileAuthenticationDetailsProvider
.
This first one allows us to set up credentials like this:
const common = require("oci-common");
const identity = require("oci-identity");
// TODO: Fill in appropriate values for tenancy (str) / fingerprint (str) / passphrase(optional) (str | null) / privateKey (str) / region (common.Region)
const tenancy = "";
const user = "";
const fingerprint = "";
const passphrase = null; // optional parameter
const privateKey = ``;
const region = common.Region.US_PHOENIX_1; // Change to appropriate region
const provider = new common.SimpleAuthenticationDetailsProvider(
tenancy,
user,
fingerprint,
privateKey,
passphrase,
region
);