Giter Club home page Giter Club logo

secrets-manager-java-sdk's Introduction

IBM Cloud Secrets Manager Java SDK

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

Table of Contents

Overview

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

Service name Imported class name
Secrets Manager SecretsManager

Prerequisites

Installation

Maven
<dependency>
    <groupId>com.ibm.cloud</groupId>
    <artifactId>secrets-manager</artifactId>
    <version>1.0.57</version>
</dependency>
Gradle
'com.ibm.cloud:secrets-manager:1.0.57'

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 com.ibm.cloud.sdk.core.security.

Examples

Programmatic credentials

import com.ibm.cloud.sdk.core.security.IamAuthenticator;
...
IamAuthenticator iamAuthenticator = new IamAuthenticator.Builder()
        .apikey("<IBM_CLOUD_API_KEY>")
        .build();

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

Using the SDK

Basic usage

  • Use the setServiceUrl method 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.

Here's an example main.java class file:

import com.ibm.cloud.secrets_manager_sdk.secrets_manager.v1.SecretsManager;
import com.ibm.cloud.secrets_manager_sdk.secrets_manager.v1.model.*;
import com.ibm.cloud.sdk.core.http.Response;
import com.ibm.cloud.sdk.core.security.IamAuthenticator;

import java.util.Collections;

public class main {

    protected static SecretsManager sm;
    protected static IamAuthenticator iamAuthenticator;

    public static void main(String[] args) { 
        iamAuthenticator = new IamAuthenticator.Builder()
              .apikey("IBM_CLOUD_API_KEY")
              .build();
        sm = new SecretsManager("My Secrets-Manager service", iamAuthenticator);
        sm.setServiceUrl("SERVICE_URL");

        // create arbitrary secret
        CollectionMetadata collectionMetadata = new CollectionMetadata.Builder()
                .collectionType("application/vnd.ibm.secrets-manager.secret+json")
                .collectionTotal(Long.parseLong("1"))
                .build();
      ArbitrarySecretResource arbitrarySecretResource = new ArbitrarySecretResource.Builder()
                .name("example-arbitrary-secret")
                .description("Extended description for this secret.")
                .payload("secret-data")
                .build();
        CreateSecretOptions createSecretOptions = new CreateSecretOptions.Builder()
                .secretType("arbitrary")
                .resources(new java.util.ArrayList<>(Collections.singletonList(arbitrarySecretResource)))
                .metadata(collectionMetadata)
                .build();
        Response<CreateSecret> createResp = sm.createSecret(createSecretOptions).execute();

        String secretId = createResp.getResult().resources().get(0).id();

        // get arbitrary secret
        GetSecretOptions getSecretOptions = new GetSecretOptions.Builder()
                .secretType("arbitrary")
                .id(secretId)
                .build();
        Response<GetSecret> getResp = sm.getSecret(getSecretOptions).execute();

        String secretPayload = (String) getResp.getResult().getResources().get(0).secretData().get("payload");

        System.out.println("The arbitrary secret payload is: " + secretPayload);
    }

}

Replace the IBM_CLOUD_API_KEY and SERVICE_URL values. Then run your application. You should see the payload of the arbitrary secret that was created.

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

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.

secrets-manager-java-sdk's People

Contributors

idanadar avatar shacharn avatar avidavidov86 avatar cadano avatar ydekel6 avatar haimsch avatar ranibm avatar naamak avatar stevemar avatar naama-ibm avatar rotembr avatar yonatanyell avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.