npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ibm-cloud/secrets-manager

v2.0.8

Published

Client library for IBM Cloud Secrets Manager

Downloads

21,689

Readme

tests

IBM Cloud Secrets Manager Node SDK

A Node.js client library to interact with the IBM Cloud® Secrets Manager APIs.

Overview

The IBM Cloud Secrets Manager Node.js SDK allows developers to programmatically interact with the following IBM Cloud services:

| Service name | Import path | |------------------------------------------------------------------|-----------------------------------------------| | Secrets Manager | @ibm-cloud/secrets-manager/secrets-manager/v2 |

Prerequisites

Installation

npm install @ibm-cloud/secrets-manager

Authentication

Secrets Manager uses token-based Identity and Access Management (IAM) authentication.

With IAM authentication, you supply an API key that is used to generate an access token. Then, the access token is included in each API request to Secrets Manager. Access tokens are valid for a limited amount of time and must be regenerated.

Authentication for this SDK is accomplished by using IAM authenticators. Import authenticators from @ibm-cloud/secrets-manager/auth.

Examples

Programmatic credentials

import { IamAuthenticator } from '@ibm-cloud/secrets-manager/auth';

const authenticator = new IamAuthenticator({
  apikey: '{apikey}',
});

External configuration

import { getAuthenticatorFromEnvironment } from '@ibm-cloud/secrets-manager/auth';

// env vars
// SECRETS_MANAGER_API_APIKEY==<apikey>
const iamAuthenticator = getAuthenticatorFromEnvironment('SECRETS_MANAGER_API');

To learn more about IAM authenticators and how to use them in your Node.js application, see the IBM Node.js SDK Core documentation.

Using the SDK

Basic usage

  • All methods return a Promise that either resolves with the response from the service or rejects with an Error. The response contains the body, the headers, the status code, and the status text. If using async/await, use try/catch for handling errors.
  • Use the serviceUrl parameter to set the endpoint URL that is specific to your Secrets Manager service instance. To find your endpoint URL, you can copy it from the Endpoints page in the Secrets Manager UI.

Examples

Construct a service client and use it to create and retrieve a secret from your Secrets Manager instance.

const SecretsManager = require('@ibm-cloud/secrets-manager/secrets-manager/v2');
const { IamAuthenticator } = require('@ibm-cloud/secrets-manager/auth');


async function secretsManagerSdkExample() {
  // Authenticate with IAM using your IBM Cloud API key
  const authenticator = new IamAuthenticator({
    apikey: process.env.SECRETS_MANAGER_API_APIKEY,
  });

  // Create an instance of the SDK by providing an authentication mechanism and your Secrets Manager instance URL
  const secretsManager = new SecretsManager({
    authenticator,
    serviceUrl:
      'https://example-instance.us-south.secrets-manager.appdomain.cloud',
  });

  // Use the Secrets Manager API to create a secret
  let res = await secretsManager.createSecret({
    secretPrototype:  {
      custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
      description: 'Description of my arbitrary secret.',
      expiration_date: '2023-10-05T11:49:42Z',
      labels: ['dev', 'us-south'],
      name: 'example-arbitrary-secret',
      secret_group_id: 'default',
      secret_type: 'arbitrary',
      payload: 'secret-data',
      version_custom_metadata: { custom_version_key: 'custom_version_value' },
    }
  });

  console.log('Secret created:\n' + JSON.stringify(res.result, null, 2));

  // Get the ID of the newly created secret
  const secretId = res.result.id;

  // Use the Secrets Manager API to get the secret using the secret ID
  res = await secretsManager.getSecret({
    id: secretId,
  });

  console.log('Get secret:\n', JSON.stringify(res.result, null, 2));
}

secretsManagerSdkExample();

To delete a secret, specify its id.

  res = await secretsManager.deleteSecret({
    id: secretId,
  });

  console.log('Secret deleted.');

Create a secret group, and then add a new secret to this group.

 // Create a secret group
    const createGroupParams = { name: 'Test Group', description: 'Group my test secrets' };

    let res = await secretsManager.createSecretGroup(createGroupParams);
    const secretGroupId = res.result.id;

    // Create a secret and associate it with your secret group
    res = await secretsManager.createSecret({
      secretPrototype: {
          secret_group_id: secretGroupId,
          name: "Test secret",
          description: 'Secret used for testing.',
          username: 'test_user',
          password: 'test_password',
          labels: ['label1'],
          expiration_date: '2030-04-01T09:30:00Z',
        }
    });

Create a rotation policy of one month for a secret.

    let res = await secretsManager.createSecret({
  secretPrototype:  {
    custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
    description: 'Description of my arbitrary secret.',
    expiration_date: '2023-10-05T11:49:42Z',
    labels: ['dev', 'us-south'],
    name: 'example-arbitrary-secret',
    secret_group_id: 'default',
    secret_type: 'arbitrary',
    payload: 'secret-data',
    version_custom_metadata: { custom_version_key: 'custom_version_value' },
    rotation: {
      auto_rotate: true,
      interval: 1,
      unit: month,
    }
  }
});

For more information and IBM Cloud SDK usage examples for Node.js, see the IBM Cloud SDK Common documentation

Tests

This project includes unit tests test/unit and integration tests test/integration.

The integration tests are run against an actual Secrets Manager instance and require the following environment variables to be set:

SECRETS_MANAGER_API_APIKEY=<API_KEY>
SERVICE_URL=<SECRETS_MANAGER_ENDPOINT_URL>

To run the tests:

npm test

Questions

If you're having difficulties using this SDK, you can ask questions about this project by using Stack Overflow. Be sure to include the ibm-cloud and ibm-secrets-manager tags.

You can also check out the Secrets Manager documentation and API reference for more information about the service.

Issues

If you encounter an issue with the project, you're welcome to submit a bug report to help us improve.

Contributing

For general contribution guidelines, see CONTRIBUTING.

License

This SDK project is released under the Apache 2.0 license. The license's full text can be found in LICENSE.