-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(build): Regenerate API with KMIP Mgmt APIs (#40)
* autogenerated Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * use generics to fix mvn test problems Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * regen for crk filter Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * regenerate with correct openapi spec Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * add generics fix back Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * add examples Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * regenerate spec without s2s calls Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * redo generics fix Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * move kputils Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * add back a method deleted by autogen Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * working SDK examples Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * finish KMIP examples Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * add kmip cert test Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * fix certs example Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * rename organize examples Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * add readme to examples Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * format pom Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * readme add Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * add KMIP Adapter List CRK Filter Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * add PR template Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * fix logging string Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> * refine PR template Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com> --------- Signed-off-by: Michael Darmawan <michael.darmawan@ibm.com>
- Loading branch information
Showing
392 changed files
with
14,193 additions
and
7,309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
**Title**: PR Title | ||
|
||
**Short Description**: Short explanation/description of PR (or issue/task) | ||
|
||
## Checklist | ||
- [ ] I have performed a self-review of my changes | ||
- [ ] My code/changes are commented (especially hard-to-understand areas) | ||
- [ ] I have written/updated new unit tests for the core changes or new/updated tests are not necessary | ||
- [ ] I have posted test results from local tests or made sure the TravisCI tests succeeded | ||
- [ ] I have made changes to the examples in `examples/kp-sdk-example` where relevant, and tested those changes | ||
- run `mvn clean install` to build the sdk, then run `mvn clean install` in the `examples/kp-sdk-example` directory to build the examples. | ||
- To run the example jar's examples, use `java -jar kp-sdk-example-1.0-SNAPSHOT.jar $EXAMPLE_NAME` | ||
|
||
## Changes | ||
> _Briefly identify changes made in this PR_ | ||
<!-- BEGIN CHANGES --> | ||
<!-- END CHANGES --> | ||
|
||
## Test Results | ||
|
||
<!-- BEGIN TEST RESULTS --> | ||
Test results may be run by the TravisCI build. If so, please verify whether they are running properly. | ||
<!-- END TEST RESULTS --> | ||
|
||
## Dependencies | ||
> _Is anything changing with respect to dependencies (the pom.xml or gradle file)? Explain that here and why they were changed._ | ||
<!-- BEGIN DEPENDENCIES --> | ||
<!-- END DEPENDENCIES --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Example project using the Java SDK | ||
|
||
Notes: The pom file included here uses a snapshot version to be convenient for development. | ||
|
||
Make sure to build the Java SDK using `mvn clean install` before building this example project. | ||
|
||
This example takes 1 argument, which is the name of the example to run. `java -jar path/to/jar $EXAMPLE_NAME`. | ||
See MainExamples.java to see list of examples. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.ibm.cloud</groupId> | ||
<artifactId>kp-sdk-example</artifactId> | ||
<packaging>jar</packaging> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>kp-sdk-example</name> | ||
<url>http://maven.apache.org</url> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
||
<git-repository-name>keyprotect-java-client</git-repository-name> | ||
<my-main-class>com.ibm.cloud.MainExamples</my-main-class> | ||
|
||
<!-- version props --> | ||
<sdk-core-version>9.17.3</sdk-core-version> | ||
<testng-version>7.4.0</testng-version> | ||
<okhttp3-version>4.10.0</okhttp3-version> | ||
<surefire-version>3.0.0-M7</surefire-version> | ||
<maven-deploy-plugin-version>3.0.0</maven-deploy-plugin-version> | ||
<maven-source-plugin-version>3.2.1</maven-source-plugin-version> | ||
<maven-shade-plugin-version>3.3.0</maven-shade-plugin-version> | ||
<maven-jar-plugin-version>3.2.2</maven-jar-plugin-version> | ||
<maven-javadoc-plugin-version>3.4.1</maven-javadoc-plugin-version> | ||
<maven-compiler-plugin-version>3.10.1</maven-compiler-plugin-version> | ||
<maven-site-plugin-version>3.12.1</maven-site-plugin-version> | ||
<maven-checkstyle-plugin-version>3.2.0</maven-checkstyle-plugin-version> | ||
<checkstyle-version>8.41</checkstyle-version> | ||
<maven-failsafe-plugin-version>3.0.0-M7</maven-failsafe-plugin-version> | ||
<maven-reports-plugin-version>3.4.1</maven-reports-plugin-version> | ||
<maven-buildnumber-plugin-version>3.0.0</maven-buildnumber-plugin-version> | ||
<powermock-version>2.0.9</powermock-version> | ||
<mockito-version>3.2.4</mockito-version> | ||
<nexus-staging-plugin-version>1.6.13</nexus-staging-plugin-version> | ||
<maven-gpg-plugin-version>3.0.1</maven-gpg-plugin-version> | ||
<slf4j-version>2.0.0</slf4j-version> | ||
<jacoco-plugin-version>0.8.8</jacoco-plugin-version> | ||
<ic-rc-version>0.19.2</ic-rc-version> | ||
<gson-version>2.9.1</gson-version> | ||
<slf4j-version>1.7.12</slf4j-version> | ||
<javax-json-version>1.0</javax-json-version> | ||
<glassfish-version>1.0.4</glassfish-version> | ||
|
||
<!-- versions of transitive dependencies we need to override to avoid vulnerability alerts --> | ||
<junit-version>4.13.2</junit-version> | ||
</properties> | ||
|
||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.2.2</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>${my-main-class}</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.6.0</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>${my-main-class}</mainClass> | ||
</transformer> | ||
</transformers> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.ibm.cloud</groupId> | ||
<artifactId>ibm-key-protect-sdk</artifactId> | ||
<version>99-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.ibm.cloud</groupId> | ||
<artifactId>sdk-core</artifactId> | ||
<version>${sdk-core-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.ibm.cloud</groupId> | ||
<artifactId>resource-controller</artifactId> | ||
<version>${ic-rc-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>${gson-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.json</groupId> | ||
<artifactId>javax.json-api</artifactId> | ||
<version>${javax-json-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>${slf4j-version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>${slf4j-version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
examples/kp-sdk-example/src/main/java/com/ibm/cloud/KMIPExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2020. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package com.ibm.cloud; | ||
|
||
import com.ibm.cloud.utils.KpUtilities; | ||
import com.ibm.cloud.ibm_key_protect_api.v2.*; | ||
import com.ibm.cloud.ibm_key_protect_api.v2.model.*; | ||
import com.ibm.cloud.platform_services.resource_controller.v2.ResourceController; | ||
import com.ibm.cloud.sdk.core.security.IamAuthenticator; | ||
import com.ibm.cloud.sdk.core.service.exception.ServiceResponseException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Base64; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
// | ||
// This class provides examples of how to use the Key Protect key services. | ||
// | ||
// The following configuration properties are assumed to be exported as environment variables | ||
// | ||
// APIKEY=<IBM Cloud APIKEY for the User> | ||
// AUTH_URL=<IAM Token Service URL> | ||
// RESOURCE_GROUP=<ID of the User's Resource Group> | ||
// KP_SERVICE_URL=<Service URL> | ||
// | ||
// API docs: https://cloud.ibm.com/apidocs/key-protect | ||
|
||
public class KMIPExample { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(KMIPExample.class); | ||
|
||
// values to be read from the env setting | ||
private static Map<String, String> config; | ||
private static String exampleInstance; | ||
private static String resourceGroup; | ||
private static String serviceUrl; | ||
|
||
static { | ||
config = System.getenv(); | ||
resourceGroup = config.get("RESOURCE_GROUP"); | ||
serviceUrl = config.get("KP_SERVICE_URL"); | ||
} | ||
|
||
public static void kmipExamples() { | ||
IamAuthenticator authenticator = IamAuthenticator.fromConfiguration(config); | ||
|
||
String keyName = "example-root-key"; | ||
String keyDesc = "created via java sdk"; | ||
|
||
try { | ||
// Create an instance | ||
ResourceController controllerService = KpUtilities.getResourceController(authenticator); | ||
exampleInstance = KpUtilities.createInstance(controllerService, resourceGroup); | ||
|
||
IbmKeyProtectApi exampleService = IbmKeyProtectApi.newInstance(authenticator); | ||
exampleService.setServiceUrl(serviceUrl); | ||
|
||
// Create key | ||
logger.info("Create a key"); | ||
String keyId = KpUtilities.createKey(exampleService, exampleInstance, keyName, keyDesc, | ||
null, false); | ||
logger.info(String.format("Key with ID %s created", keyId)); | ||
|
||
// Create a KMIP adapter | ||
logger.info("Create a KMIP adapter"); | ||
KMIPAdapter adapter = KpUtilities.createKmipAdapterNative(exampleService, exampleInstance, keyId, "myadapter", null); | ||
logger.info("KMIP adapter created with ID " + adapter.getId()); | ||
|
||
// Create a KMIP client cert | ||
logger.info("Create a KMIP client certificate"); | ||
// This is an example self-signed certificate. | ||
String certPayload = "-----BEGIN CERTIFICATE-----\n" + // | ||
"MIIC9zCCAd+gAwIBAgIUc0tA6jgIVaFUM9jeV7fkY5wRXwgwDQYJKoZIhvcNAQEL\n" + // | ||
"BQAwADAeFw0yNDA2MTkxNzA5MDlaFw0yNTA2MTkxNzA5MDlaMAAwggEiMA0GCSqG\n" + // | ||
"SIb3DQEBAQUAA4IBDwAwggEKAoIBAQCs/37mbKL6s0Ln8PGZRGVocjGIyUZM5fOu\n" + // | ||
"qTjIf+6YvsCILr7HHG6+otBY9bldPcdTu1RNvoEj7JKiQhbefiGh3aeN/j1/JYXS\n" + // | ||
"EXD02s9lfZnAbgMQGo6dtf7ONM0E07pNpoAdOxMPAdFsc4IN4lM6x1qVQIYiMR3A\n" + // | ||
"Uz/xkKvJYPv8Dti6R6VAGVrXoy+De2HjwDw/7rNyf9s0I70Yy6eDmnWLj8mLfy/L\n" + // | ||
"4YcaQuMtNEQRYmNggskUkJyFuDRddbcs+Ffq9CaK3jAGlceC9lBbYXbhU46uRxUd\n" + // | ||
"P5jb1B8uV7IZ9qPG6j3oVqeX36If3RkiJBAELbc53XtbvPxEecuDAgMBAAGjaTBn\n" + // | ||
"MB0GA1UdDgQWBBQKQpXelJJb0wa60VtDtGNyFgO0ZDAfBgNVHSMEGDAWgBQKQpXe\n" + // | ||
"lJJb0wa60VtDtGNyFgO0ZDAPBgNVHRMBAf8EBTADAQH/MBQGA1UdEQQNMAuCCTEy\n" + // | ||
"Ny4wLjAuMTANBgkqhkiG9w0BAQsFAAOCAQEAAQbW2z5xUsw6AykHqknps4XoeigP\n" + // | ||
"mWthNVo6dAZ+udE7jmGSUiwrHlbeb/rlc4mgVh7DVG1UnaOwJQmKjSDl/RdMtibP\n" + // | ||
"6AEIdoeDNDTygeIxn+mVlmpUw8LGeUU8m1SgctVdsaugQjyuYxHZJLP7RewYKftv\n" + // | ||
"MHkSt26YO8kIYQ0K4+IV0synz6ITUpsUenxrbsOY2UyAX1e4yIF9M5yZ67+r9zUN\n" + // | ||
"A23L2o1IifHBcWbFZagoGv0aZrF9iqZOV0dkcJgZ1XnjW/Lny4SSg4J4tRLFlEtU\n" + // | ||
"vg6GwJVcti/wHF6cgBay02gNRABiLeP7jaTbmy8ntuGG42Hi5yDbEourFA==\n" + // | ||
"-----END CERTIFICATE-----"; | ||
KMIPClientCertificate cert = KpUtilities.addKmipClientCertificate(exampleService, exampleInstance, "myadapter",certPayload, "mycert"); | ||
logger.info("KMIP client cert created with ID " + cert.getId()); | ||
|
||
// Delete a KMIP adapter | ||
logger.info("Delete a KMIP adapter with ID " + adapter.getId()); | ||
KpUtilities.deleteKmipAdapter(exampleService, exampleInstance, adapter.getId()); | ||
|
||
// Delete a key | ||
logger.info("Delete a key"); | ||
KpUtilities.deleteKey(exampleService, exampleInstance, keyId); | ||
logger.info(String.format("Key with ID %s deleted", keyId)); | ||
|
||
KpUtilities.deleteInstance(controllerService, exampleInstance); | ||
} catch (ServiceResponseException sre) { | ||
logger.error(String.format("Service returned status code %s: %s\nError details: %s", | ||
sre.getStatusCode(), sre.getMessage(), sre.getDebuggingInfo()), sre); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.