
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
ibm-cloud-sdk-core
Advanced tools
Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.
The ibm-cloud-sdk-core npm package provides core functionality for IBM Cloud SDKs, including authentication, request handling, and utility functions. It is used as a foundational library for building and interacting with IBM Cloud services.
Authentication
The package provides various authenticators, such as IAM, to handle authentication with IBM Cloud services. This code sample demonstrates how to create an IAM authenticator using an API key.
const { IamAuthenticator } = require('ibm-cloud-sdk-core');
const authenticator = new IamAuthenticator({ apikey: 'your-iam-api-key' });
Request Handling
The package provides a BaseService class to facilitate making HTTP requests to IBM Cloud services. This code sample shows how to extend BaseService to create a custom service with a method that makes a GET request.
const { BaseService } = require('ibm-cloud-sdk-core');
class MyService extends BaseService {
constructor(options) {
super(options);
}
myMethod() {
const parameters = {
options: {
url: '/v1/resource',
method: 'GET',
},
defaultOptions: this.baseOptions,
};
return this.createRequest(parameters);
}
}
Utility Functions
The package includes utility functions like getSdkHeaders to generate standard headers for SDK requests. This code sample demonstrates how to use getSdkHeaders to create headers for a specific service operation.
const { getSdkHeaders } = require('ibm-cloud-sdk-core');
const headers = getSdkHeaders('service-name', 'service-version', 'operation-id');
The aws-sdk package is the official SDK for AWS services, providing similar functionalities such as authentication, request handling, and utility functions for interacting with AWS services. It is comparable to ibm-cloud-sdk-core in terms of providing foundational support for cloud service interactions, but it is specific to AWS.
The google-auth-library package provides authentication support for Google Cloud services. It offers similar authentication functionalities as ibm-cloud-sdk-core but is tailored for Google Cloud's authentication mechanisms.
The azure-sdk-for-js is a collection of libraries for interacting with Azure services. It provides similar core functionalities like authentication and request handling, akin to ibm-cloud-sdk-core, but is designed for use with Microsoft Azure services.
This project contains core functionality required by Node.js code generated by the IBM Cloud OpenAPI SDK Generator (openapi-sdkgen).
`npm install ibm-cloud-sdk-core`
This package exports a single object containing a number of modules as top level properties.
Example:
// this is TypeScript, since the `openapi-sdkgen` project generates TypeScript
import { BaseService } from 'ibm-cloud-sdk-core';
class YourSDK extends BaseService { ... }
The node-sdk-core project supports the following types of authentication:
There are two ways to create an authenticator:
getAuthenticatorFromEnvironment
function to create an authenticator from externally-provided configurationFor more information about the various authentication types and how to use them with your services, click here.
import { IamAuthenticator } from 'ibm-cloud-sdk-core';
const authenticator = new IamAuthenticator({
apikey: '{apikey}',
});
import { getAuthenticatorFromEnvironment } from 'ibm-cloud-sdk-core';
// env vars
// MY_SERVICE_AUTH_TYPE=iam
// MY_SERVICE_APIKEY=<apikey>
const iamAuthenticator = getAuthenticatorFromEnvironment('my-service');
This package uses debug for logging.
DEBUG
including the desired log level.
DEBUG=ibm-cloud-sdk-core:error
enables error logsDEBUG=ibm-cloud-sdk-core:warning
enables warning logs and belowDEBUG=ibm-cloud-sdk-core:info
enables info logs and belowDEBUG=ibm-cloud-sdk-core:verbose
enables verbose logs and belowDEBUG=ibm-cloud-sdk-core:debug
enables debug logs and belowTo see the output from all of the debugging levels you can use:
DEBUG=ibm-cloud-sdk-core*
The debug logger can be configured to be used for more than one library. For example, you can set a comma-separated string:
DEBUG=ibm-cloud-sdk-core:debug,other-lib:debug
By default, cookies are not supported in the SDK requests. If your SDK would benefit from this functionality, simply edit your code to instantiate a cookie jar (or instruct your users to do so) and pass it in the object containing configuration options to the BaseService
class, as shown below. If the Boolean value true
is given for the jar
field, the SDK core will create a default instance of a Tough Cookie.
import tough = require('tough-cookie');
class MyClass extends BaseService {
constructor(options: MyOptions) {
// pass the cookie jar object or simply pass the value `true`
// and a tough-cookie instance will be created by default
options.jar = new tough.CookieJar();
super(options);
}
}
If you encounter an issue with this project, you are welcome to submit a bug report. Before opening a new issue, please search for similar issues. It's possible that someone has already reported it.
Run all test suites:
npm test
See CONTRIBUTING.
This library is licensed under Apache 2.0. Full license text is available in LICENSE.
FAQs
Core functionality to support SDKs generated with IBM's OpenAPI SDK Generator.
We found that ibm-cloud-sdk-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.